Basic principle¶
In a DSSC binner object we basically define maps, here called ‘binners’. They define into which bucket a value along a certain dimension will be put into.
map: coordinate array along specified dimension -> array of buckets
Example 1¶
Bin static run¶
import os
import logging
import importlib
import numpy as np
import xarray as xr
import pandas as pd
import extra_data as ed
import toolbox_scs as tb
import toolbox_scs.detectors as tbdet
import toolbox_scs.detectors.dssc_plot as dssc_plot
#logging.basicConfig(level=logging.INFO)
# run settings
proposal_nb = 2711
run_nb = 97
# create a extra_data run object and collect detector information
run = tb.load_run(proposal_nb, run_nb)
dssc_info = tbdet.load_dssc_info(proposal_nb, run_nb)
# create toolbox bin object
bin_obj = tbdet.DSSCBinner(proposal_nb, run_nb)
# create array that will map the pulse dimension into
# buckets 'image' and 'dark' -> resulting dimension length = 2
buckets_pulse = ['image', 'dark'] * 30 # put all 60 pulses into buckets image and dark
# create array that will map the trainId dimension into
# buckets [0] -> resulting dimension length = 1
buckets_train = np.zeros(len(run.train_ids)).astype(int) # put all train Ids to the same bucket called 0.
#create binners (xarray data arrays that basically act as a map)
fpt = dssc_info['frames_per_train']
binnertrain = tbdet.create_dssc_bins("trainId",run.train_ids,buckets_train)
binnerpulse = tbdet.create_dssc_bins("pulse",np.linspace(0,fpt-1,fpt, dtype=int),buckets_pulse)
# add binners to bin object
bin_obj.add_binner('trainId', binnertrain)
bin_obj.add_binner('pulse', binnerpulse)
# get a prediction of how the data will look like (minus module dimension)
bin_obj.get_info()
Frozen(SortedKeysDict({'trainId': 1, 'pulse': 2, 'x': 128, 'y': 512}))
# bin 2 modules in parallel
mod_list = [0,15]
bin_obj.bin_data(chunksize=248, modules=mod_list, filepath='./')
# Save metadata into file
fname = 'testfile.h5'
tbdet.save_xarray(fname, binnertrain, group='binner1', mode='a')
tbdet.save_xarray(fname, binnerpulse, group='binner2', mode='a')
Example2¶
bin pump-probe data¶
# run settings
proposal_nb = 2212
run_nb = 235
# Collect information about run
run_obj = tb.load_run(proposal_nb, run_nb)
detector_info = tbdet.load_dssc_info(proposal_nb, run_nb)
bin_obj = tbdet.DSSCBinner(proposal_nb, run_nb)
# define buckets
buckets_trainId = (tb.get_array(run_obj, 'PP800_PhaseShifter', 0.03)).values
buckets_pulse = ['pumped', 'unpumped'] * 10
# create binner
binnerTrain = tbdet.create_dssc_bins("trainId",
detector_info['trainIds'],
buckets_trainId)
binnerPulse = tbdet.create_dssc_bins("pulse",
np.linspace(0,19,20, dtype=int),
buckets_pulse)
bin_obj.add_binner('trainId', binnerTrain)
bin_obj.add_binner('pulse', binnerPulse)
# get a prediction of how the data will look like (minus module dimension)
bin_obj.get_info()
Frozen(SortedKeysDict({'trainId': 271, 'pulse': 2, 'x': 128, 'y': 512}))
# bin 2 modules using the joblib module to precess the two modules
# in parallel.
bin_obj.bin_data(chunksize=248, modules=mod_list, filepath='./')