import src.openbis_lib as openbis_lib import hdf5_lib import datetime import os import logging def main(): #df_h5 = hdf5_lib.read_hdf5_as_dataframe_v2('BeamTimeMetaData.h5') #df_h5['lastModifiedDatestr'] = df_h5['lastModifiedDatestr'].astype('datetime64[ns]') #df_h5 = df_h5.sort_values(by='lastModifiedDatestr') openbis_obj = openbis_lib.initialize_openbis_obj() # Create df with sample measurements of type 'ISS_MEASUREMENT' samples = openbis_obj.get_samples(type='ISS_MEASUREMENT',props=['FILENUMBER']) for sample in samples: print(type(sample)) print(sample.identifier) df_openbis = samples.df.copy(deep=True) h5_file_path = os.path.join(os.path.curdir,'input_files\\BeamTimeMetaData.h5') df_h5 = hdf5_lib.read_hdf5_as_dataframe(h5_file_path) # dataframe preprocessing steps df_h5, df_openbis = openbis_lib.align_datetime_observation_windows(df_h5, df_openbis) df_openbis = openbis_lib.pair_openbis_and_h5_dataframes(df_openbis, df_h5, 'REFORMATED_FILENUMBER', 'name') current_date = datetime.date.today() log_filename = 'logs\\computed_openbis_props_logs_' + current_date.strftime('%d-%m-%Y') + '.log' logging_flag = True #logger = logging.getLogger(__name__) #logger.setLevel(logging.DEBUG) log_file_path = os.path.join(os.path.curdir,log_filename) logging.basicConfig(filename=log_file_path, level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s", datefmt="%d-%m-%Y %H:%M:%S", ) for sample_idx in df_openbis.index: # logging.basicConfig(log_filename) #print(formatted_dict) sample_props_dict = openbis_lib.compute_openbis_sample_props_from_h5(df_openbis, df_h5, sample_idx) formatted_dict = [f"{key}:{value}" for key, value in sample_props_dict.items()] formatted_dict = "\n".join(formatted_dict) logging.debug('\n'+formatted_dict) #print(props_dict) openbis_obj.logout() # Choose samples and specifici properties to update: create a log if __name__=="__main__": main()