preparing_to_merge.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import pandas as pd
  2. import pymongo
  3. from collections import defaultdict
  4. from config_info.config import *
  5. def prepare_to_merge_12d(date, cluster, a_crit, fr):
  6. """Накладываем на события из noSQL БД маску и отбираем нужные для сшивки по критериям отбора"""
  7. data_cl = pd.DataFrame.from_records(
  8. pymongo.MongoClient(DB_URL)["prisma-32_db"][f'{str(date)}_12d'].find({'cluster': cluster}))
  9. amp_dict = defaultdict(list)
  10. n_dict = defaultdict(list)
  11. for item in data_cl['detectors']:
  12. for j in [f'det_{i:02}' for i in range(1, 17)]:
  13. amp_dict[j].append(item[j]['amplitude'])
  14. n_dict[j].append(item[j]['neutrons'])
  15. amp_mask, n_mask = defaultdict(list), defaultdict(list)
  16. for amp_mask_event, n_mask_event in zip(data_cl['mask_of_hit_counters_a'], data_cl['mask_of_hit_counters_n']):
  17. for i in range(16):
  18. amp_mask[i + 1].append(list(f'{int(bin(amp_mask_event)[2:]):016}')[i])
  19. n_mask[i + 1].append(list(f'{int(bin(n_mask_event)[2:]):016}')[i])
  20. for i in range(1, 17):
  21. data_cl[f'amp_{i}'] = amp_dict[f'det_{i:02}']
  22. data_cl[f'n_{i}'] = n_dict[f'det_{i:02}']
  23. data_cl[f'amp_{i}_mask'] = amp_mask[i]
  24. data_cl[f'n_{i}_mask'] = n_mask[i]
  25. for i in range(1, 17): # Нужны разные алгоритмы, с выборочным применением масок
  26. data_cl.loc[data_cl[data_cl[f'amp_{i}_mask'] == 0].index, f'amp_{i}'] = 0
  27. data_cl.loc[data_cl[data_cl[f'n_{i}_mask'] == 0].index, f'n_{i}'] = 0
  28. data_cl['fr_sum'] = data_cl[
  29. ['amp_1', 'amp_2', 'amp_3', 'amp_4', 'amp_5', 'amp_6', 'amp_7', 'amp_8', 'amp_9', 'amp_10', 'amp_11', 'amp_12',
  30. 'amp_13', 'amp_14', 'amp_15', 'amp_16']].isin(range(a_crit, 550)).sum(axis=1, skipna=True)
  31. data_cl = data_cl.loc[data_cl[data_cl['fr_sum'] >= fr].index, :].reset_index(
  32. drop=True)
  33. return data_cl
  34. def prepare_to_merge_7d(date, cluster):
  35. data_cl = pd.DataFrame.from_records(
  36. pymongo.MongoClient(DB_URL)["prisma-32_db"][f'{str(date)}_7d'].find({'cluster': cluster}))
  37. amp_dict = defaultdict(list)
  38. print(data_cl)
  39. for item in data_cl['detectors']:
  40. for j in [f'det_{i:02}' for i in range(1, 17)]:
  41. amp_dict[j].append(item[j]['amplitude'])
  42. for i in range(1, 17):
  43. data_cl[f'amp_{i}'] = amp_dict[f'det_{i:02}']
  44. return data_cl