reborn.fileio package

Submodules

reborn.fileio.getters module

reborn.fileio.getters.do_nothing(self, *args, **kwargs)[source]
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 up DataFrame 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 is PADView, which allows one to flip through dataframes for any experiment, provided that a FrameGetter can be provided.

The DataFrame instances contain diffraction raw data, x-ray Beam 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 constructed DataFrame instance. The FrameGetter 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 the DataFrame 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 = []
factory()[source]
property n_frames
dbgmsg(*args, **kwargs)[source]
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
set_pandas_dataframe(df)[source]
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.

set_sorted_indices(indices)[source]
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.

Parameters:

frame_number (int) – The raw frame number of the desired DataFrame

get_history_previous() DataFrame[source]

Do not override this method.

get_history_next() DataFrame[source]

Do not override this method.

get_next_frame(skip=1, wrap_around=True) DataFrame[source]

Do not override this method.

get_previous_frame(skip=1, wrap_around=True) DataFrame[source]

Do not override this method.

get_random_frame() DataFrame[source]

Do not override this method.

get_first_frame() DataFrame[source]

Get first frame (and skip empty frames if self.skip_empty_frames is True).

view(**kwargs)[source]

Create a PADView instance and start it with this FrameGetter instance.

get_padview(**kwargs)[source]

Create a PADView instance with this FrameGetter instance.

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

get_data(frame_number=0)[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.

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.

get_data(frame_number=0)[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.

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

reborn.fileio.misc.save_pickle(data, pickle_file)[source]

Save something in pickle format. :param data: The data you want to pickle :type data: anything, usually a dict :param pickle_file: Path to the pickle file :type pickle_file: str

reborn.fileio.misc.load_xyz(fname)[source]

Load an “xyz” file.

Parameters:

fname (str) – Path to the xyz file.

Returns: Molecule

Module contents