linefinder.analyze_data.worldline_set module

Tools for loading in multiple worldline data sets, for comparison

@author: Zach Hafen @contact: zachary.h.hafen@gmail.com @status: Development

class linefinder.analyze_data.worldline_set.WorldlineSet(defaults, variations)[source]

Bases: verdict.Dict

Container for multiple Worldlines classes. The nice thing about this class is you can use it like a Worldlines class, with the output being a dictionary of the different sets instead.

apply(fn, *args, **kwargs)

Apply some function to each item in the smart dictionary, and return the results as a Dict.

array()

Returns a np.ndarray of values with unique order (sorted keys )

call_custom_kwargs(kwargs, default_kwargs={}, verbose=False)

Perform call, but using custom keyword arguments per dictionary tag.

Parameters:
  • kwargs (dict) – Custom keyword arguments to pass.
  • default_kwargs (dict) – Defaults shared between keyword arguments.
Returns:

Dictionary of results.

Return type:

results (dict)

call_iteratively(args_list)
depth(level=1)

Depth of the Dict.

Parameters:level (int) – A level of N means this Dict is contained in N-1 other Dict.
classmethod from_class_and_args(contained_cls, args, default_args={})

Alternate constructor. Creates a Dict of contained_cls objects, with arguments passed to it from the dictionary created by defaults and variations.

Parameters:
  • contained_cls (type of object/constructor) – What class should the smart dict consist of?
  • args (dict/other) – Arguments that should be passed to contained_cls. If not a dict, assumed to be the first and only argument for the constructor.
  • default_args – Default arguments to fill in args
Returns:

The constructed instance.

Return type:

Dict

classmethod from_hdf5(filepath, load_attributes=True, unpack=False)

Load a HDF5 file as a verdict Dict.

Parameters:
  • filepath (str) – Location to load the hdf5 file from.
  • load_attributes (boolean) – If True, load attributes stored in the hdf5 file’s .attrs keys and return as a separate dictionary.
  • unpack (boolean) – If True and the inner-most groups are combined into a condensed DataFrame/array-like format, unpack them into a traditional structure.
classmethod from_tag_expansion(defaults, tag_expansion)[source]

Create a worldline set using a bash-style expansion for the variations.

Parameters:
  • defaults (dict) – Set of default arguments for loading worldline data.
  • tag_expansion (str) – String that can be expanded through wildcards to find different worldline data. For example, ‘analyze_*’ would look for all data files with tags starting with ‘analyze’ and ending with something else;
Returns:

worldline_set (WorldlineSet instance)

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
inner_item(item)

When Dict is a dictionary of dicts themselves, this can be used to get an item from those dictionaries.

inner_keys()
items() → a set-like object providing a view on D's items
keymax()
keymin()
keys() → a set-like object providing a view on D's keys
keys_array()

Returns a np.ndarray of keys with unique order (sorted keys )

log10()

Wrapper for np.log10

median()
nanmedian()
nanpercentile(q)
percentile(q)
plot_classification_bar_same_axis(kwargs=<object object>, ind=0, width=0.5, data_order=<object object>, legend_args=<object object>, y_label='Classification Fraction', out_dir=None, save_file='bar_map.pdf', **default_kwargs)[source]
plot_w_set_same_axis(plotting_method, *args, **kwargs)[source]
remove_empty_items()

Look for empty items and delete them.

split_by_dict(d, return_list=False)

Break the smart dictionary into smaller smart dictionaries according to their label provided by a dictionary

Parameters:
  • d (dict) – Dictionary to use to split into smaller dictionaries
  • return_list (bool) – If True, return a list of arrays.
split_by_key_slice(sl, str_to_match=None)

Break the smart dictionary into smaller smart dictionaries according to a subset of the key.

Parameters:
  • sl (slice) – Part of the key to use to make subsets.
  • str_to_match (str) – If True, split into broad categories that match this string in the given slice or don’t.
store_quantity(output_filepath, quantity_method='get_categories_selected_quantity_fraction', variations=None, verbose=True, *args, **kwargs)[source]

Iterate over each Worldlines class in the set, obtaining a specified quantity and then saving that to an .hdf5 file. Note that verdict.Dict’s to_hdf5 method is simpler and more functional for many cases.

Parameters:
  • output_filepath (str) – Full path to store the output at.
  • quantity_method (str) – What method to use for getting the quantity out.
  • variations (dict) – If provided, we get different quantities from each Worldlines instance by passing different args to quantity_method according to variations. kwargs is taken as the default arguments when none are specified.
  • **kwargs (*args,) –

    Arguments to be passed to quantity_method.

store_redshift_dependent_quantity(output_filepath, max_snum, choose_snum_by='pulling_from_ids', *args, **kwargs)[source]

Store a redshift dependent quantity. In particular, this method assumes that the differences between the Worldlines is a redshift difference, and that the label for each Worldlines class contains the relevant snapshot number. It then parses the label for that snapshot number, and passes it to store_dependent_quantity as a key.

Parameters:
  • output_filepath (str) – Where to save the output data.
  • max_snum (int) – Maximum snapshot number the snapshots can go to. Used for parsing the label as well as specifying the ind.
  • choose_snum_by (str) – How to to vary the snapshot used when the arguments are passed to the Worldlines.
  • **kwargs (*args,) –

    Arguments passed to self.store_dependent_quantity()

sum_contents()

Get the sum of all the contents inside the Dict.

to_df()

Join the innermost Dict classes into a pandas DataFrame, where the keys in the innermost dictionaries are the index and the keys for the innermost dictionaries are the column headers.

to_hdf5(filepath, attributes=None, overwrite_existing_file=True, condensed=False)

Save the contents as a HDF5 file.

Parameters:
  • filepath (str) – Location to save the hdf5 file at.
  • attributes (dict) – Dictionary of attributes to store as attributes for the HDF5 file.
  • overwrite_existing_file (boolean) – If True and a file already exists at filepath, delete it prior to saving.
  • condensed (boolean) – If True, combine the innermost dictionaries into a condensed DataFrame/array-like format.
transpose()
values() → an object providing a view on D's values