113 lines
4.1 KiB
Python
113 lines
4.1 KiB
Python
import h5py
|
|
|
|
import sys, os
|
|
|
|
import argparse
|
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import pandas as pd
|
|
|
|
def sort_acquisition(data_directory, acquisition):
|
|
detector='JF17T16V01j'
|
|
bsdata_path = os.path.join(data_directory,'data','acq{0:0=4d}.BSDATA.h5'.format(acquisition))
|
|
try:
|
|
f = h5py.File(bsdata_path, "r") #r"/sf/cristallina/data/p21630/raw/run0065-lov_movestop_normal_1/data/acq0001.BSDATA.h5"
|
|
except Exception as e:
|
|
print("didn't open bsdata due to error {e}") #_logger.error(f"Cannot open {data_file} (due to {e})")
|
|
return
|
|
jf_path=os.path.join(data_directory,'data','acq{0:0=4d}.{1}.h5'.format(acquisition, detector))
|
|
print(jf_path)
|
|
try:
|
|
#r"/sf/cristallina/data/p21630/raw/run0065-lov_movestop_normal_1/data/acq0001.JF17T16V01.h5"
|
|
x = h5py.File(jf_path, "r")
|
|
except Exception as e:
|
|
print("didn't open JF17T16V01.h5 due to error {e}") #_logger.error(f"Cannot open {data_file} (due to {e})")
|
|
return
|
|
pulseids_JF = x[f"/entry/xfel/pulseID"][:]
|
|
pulseids_BS = f[f"/SAR-CVME-TIFALL6:EvtSet/pulse_id"][:]
|
|
|
|
power_meter = pd.DataFrame(f[f"/SARES33-GPS:PR1_CH0_VAL_GET/data"][:], columns=['data']) #gass monitor
|
|
power_meter.index = f[f"/SARES33-GPS:PR1_CH0_VAL_GET/pulse_id"][:]
|
|
pulseids_psss = f[f"/SARFE10-PSSS059:SPECTRUM_Y_SUM/pulse_id"][:] #Group PSSS
|
|
evt_set=pd.DataFrame(f[f"/SAR-CVME-TIFALL6:EvtSet/data"][:])
|
|
evt_set.index = f[f"/SAR-CVME-TIFALL6:EvtSet/pulse_id"][:]
|
|
common_pulses = power_meter.index.intersection(evt_set.index)
|
|
power_meter= power_meter.loc[common_pulses]
|
|
common_pulses = evt_set.index.intersection(power_meter.index)
|
|
evt_set = evt_set.loc[common_pulses]
|
|
print(power_meter.index.duplicated())
|
|
x=power_meter.index.duplicated()
|
|
for i in range(len(power_meter.index)):
|
|
if x[i] == True:
|
|
print(power_meter.index[i])
|
|
fig, ax1 = plt.subplots()
|
|
|
|
color = 'tab:red'
|
|
ax1.set_xlabel('pulse_id')
|
|
ax1.set_ylabel('exp', color=color)
|
|
ax1.scatter(common_pulses, evt_set.loc[common_pulses][evt_set.columns[63]], color=color)
|
|
ax1.tick_params(axis='y', labelcolor=color)
|
|
|
|
ax1.invert_yaxis()
|
|
ax2 = ax1.twinx() # instantiate a second Axes that shares the same x-axis
|
|
|
|
color = 'tab:blue'
|
|
ax2.set_ylabel('sin', color=color) # we already handled the x-label with ax1
|
|
ax2.scatter(common_pulses, power_meter.loc[common_pulses]['data'].values, color=color)
|
|
ax2.tick_params(axis='y', labelcolor=color)
|
|
|
|
fig.tight_layout() # otherwise the right y-label is slightly clipped
|
|
plt.show()
|
|
|
|
plt.scatter(power_meter['data'].loc[common_pulses].values, evt_set.loc[common_pulses][evt_set.columns[63]])
|
|
#plt.scatter(common_pulses, power_meter['data'].values[1:])
|
|
plt.show()
|
|
|
|
def main(args):
|
|
data_directory = args.input_data_directory
|
|
try:
|
|
output_name = args.output_name
|
|
except:
|
|
output_name=data_directory.split('/')[-1]
|
|
number_of_acqusitions = os.listdir(os.path.join(data_directory,'meta'))
|
|
index_light=[]
|
|
index_dark=[]
|
|
blanks = []
|
|
for i in range(len(number_of_acqusitions)):
|
|
print(i)
|
|
sort_acquisition(data_directory, i)
|
|
#index_light+=(acq_light)
|
|
#index_dark+=(acq_dark)
|
|
#blanks+=(acq_blank)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
"-i",
|
|
"--input_data_directory",
|
|
help="raw data directory and run i.e. /sf/cristallina/data/p21630/raw/run0065-lov_movestop_normal_1/",
|
|
type=os.path.abspath,
|
|
required=True
|
|
)
|
|
parser.add_argument(
|
|
"-o",
|
|
"--ouput_name",
|
|
help="the name of the job to be done. if not included file names will be automatically generated based on input run name",
|
|
type=str,
|
|
)
|
|
parser.add_argument(
|
|
"-l",
|
|
"--log_file_name",
|
|
help="the name of the logger.",
|
|
type=str,
|
|
default='logging_logger_of_logs.log'
|
|
)
|
|
args = parser.parse_args()
|
|
#logfile = args.log_file_name
|
|
#logger.add( logfile, format="{message}", level="INFO")
|
|
main(args)
|