reborn.fileio package¶
Submodules¶
reborn.fileio.getters module¶
- reborn.fileio.getters.threadlocked(method)[source]¶
Simple decorator that ensures that the mutex is locked when calling the method. This ensures that the function cannot be called by another thread when one is already executing lines within the method. This wrapper assumes that the class has a threading.Lock attribute named _lock.
- class reborn.fileio.getters.FrameGetter(*args, **kwargs)[source]¶
Bases:
ABC
A
FrameGetter
is meant to serve upDataFrame
instances. It exists so that we have a standard interface that hides the details of where data come from (disk, shared memory, on-the-fly simulations, etc.). With such standardizations, we can sometimes build software that can work in a way that is agnostic to the data source. A good example of this isPADView
, which allows one to flip through dataframes for any experiment, provided that aFrameGetter
can be provided.The
DataFrame
instances contain diffraction raw data, x-rayBeam
info,PADGeometry
info, etc. It is assumed that a set of frames can be indexed with integers, starting with zero.This
FrameGetter
class is an Abstract Base Class (ABC). You cannot use it directly. Instead, you must create a subclass. Here is what a very simple subclass should look like:class MyFrameGetter(FrameGetter): def __init__(self, arguments, **kwargs): # Do whatever is needed to set up the data source. # Be sure to set the n_frames attribute: self.n_frames = something_based_on_arguments def get_data(self, frame_number): # Do something to fetch data and create a proper DataFrame instance return mydataframe
Minimally, your
FrameGetter
subclass should set the n_frames attribute that specifies how many frames there are, and the get_data method should be defined such that it returns a properly constructedDataFrame
instance. TheFrameGetter
base class will then implement other conveniences such as get_next_frame(), get_previous_frame(), etc.POSTPROCESSING: Sometimes you have a
FrameGetter
subclass that serves up data, but for each frame you need to perform a couple of extra manipulations to theDataFrame
that are not already implemented in your subclass. For example, you need to create a mask for a liquid jet streak in a diffraction pattern. To do this, you can define a list of postprocessing functions as follows:def myprocessor(self, dataframe): # Do something to your dataframe. The self argument allows access to the internals of the FrameGetter return dataframe mygetter = MyFrameGetter(param1=something, postprocessors=[myprocessor]) df = mygetter.get_next_frame()
In the above, the mygetter instance will perform the usual steps when you call the get_frame method, but the list of postprocessor functions will first intercept the
DataFrame
s before they are returned.When overriding the __init__ method, you should be sure to set the self.n_frames property. Do not use any positional or keyword arguments that cannot be serialized, such as file handlers (instead, provide a file path and create the handler within the __init__ method). If you pass in objects that cannot be serialized, your subclass will still work, but it will not be possible to pass your subclass into any of the parallelized processors that utilize FrameGetters
- run_id = None¶
- current_frame = 0¶
- current_random_frame = 0¶
- current_dataframe = None¶
- geom_dict = None¶
- history_length = 100¶
- history = array([0, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])¶
- history_index = 0¶
- init_params = None¶
- skip_empty_frames = True¶
- postprocessors = []¶
- property n_frames¶
- abstract get_data(frame_number=0) DataFrame [source]¶
You must overrider this when making a subclass. You can do anything you want here, but you must return a valid
DataFrame
instance. Do not attempt to modify any private attributes of the abstract base class. Any property prefixed with an underscore is off-limits.
- property pandas_dataframe¶
- sort_by(column, ascending=True)[source]¶
If you have a pandas dataframe, and you wish to sort by a particular column, provide the column name here.
- property is_sorted¶
- get_frame(frame_number=0, raw_frame_number=None, wrap_around=True, log_history=True) DataFrame [source]¶
Get the dataframe corresponding to a given index.
- class reborn.fileio.getters.ListFrameGetter(*args, **kwargs)[source]¶
Bases:
FrameGetter
Very simple FrameGetter subclass that operates on a list or similar type of iterable object.
When overriding the __init__ method, you should be sure to set the self.n_frames property. Do not use any positional or keyword arguments that cannot be serialized, such as file handlers (instead, provide a file path and create the handler within the __init__ method). If you pass in objects that cannot be serialized, your subclass will still work, but it will not be possible to pass your subclass into any of the parallelized processors that utilize FrameGetters
- class reborn.fileio.getters.TestFrameGetter(*args, **kwargs)[source]¶
Bases:
FrameGetter
FrameGetter for testing. Serves unmasked random values.
- Parameters:
pad_geometry (
PADGeometryList
) – Detector geometry for experiment.n_frames (int) – Number of frames to simulate.
experiment_id (str) – A
FrameGetter
requires experiment id.run_id (int) – A
FrameGetter
requires a run id.
reborn.fileio.misc module¶
- reborn.fileio.misc.load_pickle(pickle_file)[source]¶
Open a pickle file. :param pickle_file: Path to the pickle file :type pickle_file: str
Returns: data