" warn(\"arrays in tpx data must be of same length ( len(tpx_data[%s])=%i!=%i=(len(tpx_data[%s]) )\" % (reference_n_samples_key, n_samples, len(tpx_data[key]), key),\n",
" category=UserWarning)\n",
" return -2\n",
" if n_samples == 0:\n",
" warn(\"no samples were provides with tpx data\", category=UserWarning)\n",
" return -3\n",
" return 0\n",
"\n",
"def apply_single_filter(tpx_data, _filter):\n",
" \"\"\"\n",
" Simple function to apply a selecting or sorting filter to a dictionary of equally sized arrays\n",
" Note: at no point a copy of the dictionary is made, as they are mutable, the input array is changed in memory!\n",
"\n",
" Parameters\n",
" ----------\n",
" tpx_data: dictionary with timepix data, all arrays behind each key must be of same length\n",
" _filter: 1d array or list of integers or booleans or np.s_ to select or sort data like a = a[_filter]\n",
"\n",
" Returns\n",
" -------\n",
" tpx_data: like input tpx_data but with applied filter\n",
-1:"tpx_data has an invalid structure - ignore provided data",
-2:"tpx_data arrays are of invalid lengths - ignore provided data",
-3:"tpx_data arrays are empty"
}
defcheck_data(tpx_data):
required_keys=["x","y","tof","tot"]
forkeyinrequired_keys:
ifkeynotintpx_data.keys():
warn("tpx data must contain the keys %s, but key %s not in tpx data keys (%s)"%(required_keys,key,list(tpx_data.keys())),
category=UserWarning)
return-1
reference_n_samples_key="x"
n_samples=len(tpx_data[reference_n_samples_key])
forkeyintpx_data.keys():
ifn_samples!=len(tpx_data[key]):
warn("arrays in tpx data must be of same length ( len(tpx_data[%s])=%i!=%i=(len(tpx_data[%s]) )"%(reference_n_samples_key,n_samples,len(tpx_data[key]),key),
category=UserWarning)
return-2
ifn_samples==0:
warn("no samples were provides with tpx data",category=UserWarning)
return-3
return0
defapply_single_filter(tpx_data,_filter):
"""
Simple function to apply a selecting or sorting filter to a dictionary of equally sized arrays
Note: at no point a copy of the dictionary is made, as they are mutable, the input array is changed in memory!
Parameters
----------
tpx_data: dictionary with timepix data, all arrays behind each key must be of same length
_filter: 1d array or list of integers or booleans or np.s_ to select or sort data like a = a[_filter]
Returns
-------
tpx_data: like input tpx_data but with applied filter