legend-exp / legend-data-monitor

LEGEND data monitoring
https://legend-data-monitor.readthedocs.io
MIT License
0 stars 5 forks source link

new plot ideas #92

Open sofia-calgaro opened 1 year ago

sofia-calgaro commented 1 year ago
sofia-calgaro commented 1 year ago

Slow Control Monitoring:

Params to make available

At least the ones present in the shifter page:

Load and flag params

I guess a new module responsible for retrieving the correct data is needed. Quite some flags are needed to arrive to the correct dataset needed for plotting a given SC parameter. Some examples:

# --------------- How to get the temperature 1 or 2 from the Left or Right DAQ
# 1. Connect to  SC database
from legendmeta import LegendSlowControlDB
scdb = LegendSlowControlDB()
scdb.connect(password="...")

# 2. Set some flags
is_in_time = (...) # put here the time interval of interest specified in the config file
is_temperature = (rack_snap["name"] == "Temp") 
is_DaqLeft = (rack_snap["rack"] == "CleanRoom-DaqLeft")
is_DaqRight = (rack_snap["rack"] == "CleanRoom-DaqRight")
is_Temp_1 = (rack_snap["sensor"] == "Temp-1")
is_Temp_2 = (rack_snap["sensor"] == "Temp-2")

# 2. Flag the data
rack_snap = scdb.dataframe("rack_snap")
rack_snap = rack_snap.sort_values(by="tstamp") # need it! Timestamps are NOT in ascending order by default 
temp_1L = rack_snap[(is_in_time & is_temperature & is_DaqLeft & is_Temp_1)]["value"]
temp_1R = rack_snap[(is_in_time & is_temperature & is_DaqRight & is_Temp_1)]["value"]
temp_2L = rack_snap[(is_in_time & is_temperature & is_DaqLeft & is_Temp_2)]["value"]
temp_2R = rack_snap[(is_in_time & is_temperature & is_DaqRight & is_Temp_2)]["value"]

Maybe an external json file saved under settings/ can help to build the flags we want? Like

{
  "SC_DB_params": {
      "PT118": {
          "table": "cryostat_snap",
          "flags": [is_Pressure, is_PT18]
       },
      "CleanRoom-DaqLeft-Temp1.Temp": {
          "table": "rack_snap",
          "flags": [is_temperature, is_DaqLeft, is_Temp_1]
       },
  },
  "expressions":{
          "is_Pressure": {
                      "column": "group", // column in which to apply the 'df[column] == "sth" condition'
                      "entry": "Pressure" // = sth 
           },
          "is_PT118": {
                      "column": "name",
                      "entry": "PT118"
           },
          "is_temperature ": {
                      "column": "name",
                      "entry": "Temp"
           },
          "is_DaqLeft ": {
                      "column": "rack",
                      "entry": "CleanRoom-DaqLeft"
           },
          "is_Temp_1": {
                      "column": "sensor",
                      "entry": "Temp-1"
           }
          }
  }
}

And then, in a module,

flags_info = ... load here the dict from json file (it knows which parameters are available and which flags to apply for each of them)...
param_to_plot = "PT118" # actually retrieved from config json file
df_param = load_and_apply_flags(param_to_plot , flags_info) # -> returns a dataframe for the table of interest (NOTE: usually the loading part is super heavy and slow down everything - can we load just a bunch of data, considering atp we already have a time interval we can retrieve from the config json file?) -> build the final dataframe with ONLY the parameter of interest (throw away sensors/names/.../columns that are not needed)

Like, if we want to plot "PT118" pressure values from the cryostat, we must be able to do something equivalent to the following:

is_Pressure = (cryostat_snap["group"] == "Pressure")
is_PT118 = (cryostat_snap["name"] == "PT118")
flag = (is_Pressure & is_PT118)
cryostat_snap = scdb.dataframe("cryostat_snap")
cryostat_snap = cryostat_snap.sort_values(by='tstamp') # sort bt tstamps (not by default)
values_PT188 = cryostat_snap_small[flag]["value"]
times_PT188 = cryostat_snap_small[flag]["tstamp"]

Units

Can be retrieved from the corresponding _info dataframe:

cryostat_info = scdb.dataframe("cryostat_info")
unit = ... read value inside column="unit"...

Limits

Can be retrieved from the corresponding _info dataframe:

cryostat_info = scdb.dataframe("cryostat_info")
low_lim = ... read value inside column="ltol"...
upper_lim = ... read value inside column="utol"...

NOTE: keep in mind this feature would work only for those who have access to LNGS machines (pswd on internal pages)