Saving tools

This is a collection of useful methods related to saving data and metadata used along hyperion.

copyright:by Hyperion Authors, see AUTHORS for more details.
license:BSD, see LICENSE for more details.
hyperion.tools.saving_tools.create_filename(file_path)

Creates the filename, so all the methods point to the same folder and save with the same name. The output does not include the extension but the input does.

Parameters:filename (string (path)) – config filename complete path (INCLUDING the extension)
Returns:filename with a number appended so it would not be overwritten.
Return type:string
hyperion.tools.saving_tools.name_incrementer(basename, list_of_existing, separator='_', fill_zeros=0, use_number_for_first=None, only_larger_number=True)

This function is meant to avoid rewriting existing files.

Parameters:
  • basename – The basename. May include extension.
  • list_of_existing – List of names to avoid
  • separator – Optional separator between basename and number, DEFAULT is ‘_’
  • fill_zeros – If you set this to 4, numbers will look like 0012, 0013. Special case 0 (DEFAULT) will match the longest one in list_of_existing
  • use_number_for_first – 0, 1, None. If the name does not occur yet it will get 0, 1 or no sufix, DEFAULT is None
  • only_larger_number – If name_1 and name_3 exist and only_larger_number is True DEFAULT, name_4 will be suggested, otherwise name_2
Returns:

The suggested name.

hyperion.tools.saving_tools.read_netcdf4_and_plot_all(filename)

Reads the file in filename and plots all the detectors

hyperion.tools.saving_tools.save_metadata(file_path, properties)

Saves the the properties in a yml file at the file file_path

type file_path:str
param properties:
 dictionary containing the me :param file_path: complete filepath to the location to be saved.
tadata
type properties:
 dict
hyperion.tools.saving_tools.save_netCDF4(filename, detectors, data, axes, axes_name, errors=None, extra_dims=None, description=None)

This function saves the data in a netCDF4 format, including units and the axes corresponding to the data. For more info about the package used, please see http://unidata.github.io/netcdf4-python/netCDF4/index.html. For info on the format itself, refer to: https://www.unidata.ucar.edu/software/netcdf/docs/index.html

Parameters:
  • detectors (list of strings) – list of the detectors used
  • data (list of numpy ndarrays of pint quantities) – list with the actual data corresponding to each detector
  • axes – corresponding coordinates for the data. the dimension of the i element

in the list has to match the dimension of the i-th dimension of data. :type axes: list of vectors of pint quantity :param axes_name: the name of each of the axes :type axes_name: list of strings :param errors: measured errors for each of the detectors. It has to have the same dimensions as data. :type errors: list of numpy ndarrays of pint quantities :param extra_dims: A dict containing extra values fixed and all the same for the set. :type extra_dims: dict :param description: an extra descriptive message can be put here. :type description: string

hyperion.tools.saving_tools.yaml_dump_builtin_types_only(object, stream=None, mode='remove', replace_with='_invalid_', dump=True)

A replacement for yaml.dump that skips object that can’t be dumped safely. Dictionaries and lists are searched recursively. It has 3 modes how to handle invalid entries: remove: removes the entry repr: replaces the object with object.__repr__() replace: replaces with the value in replace_with To return the modified object instead of dumping it, set dump to False. (Note, in case of DefaultDict or ActionDict it only stores the main dict).

Parameters:
  • object – The object to dump
  • stream – The stream to save the yaml dump (default: None)
  • (str) (mode) – ‘remove’ (default), ‘repr’, ‘replace’
  • replace_with – What to replace the invalid entry with (default ‘_invalid_’)
  • (bool) (dump) – Dumps to stream when True, returns modified object when False. (default: True)
Returns: