Skip to content
Snippets Groups Projects
Commit f372030e authored by Sander Snoo's avatar Sander Snoo
Browse files

Reduce station snapshot

parent 07fb50c5
No related branches found
No related tags found
No related merge requests found
import logging import logging
from core_tools.data.ds.data_set_core import data_set from core_tools.data.ds.data_set_core import data_set
from core_tools.data.ds.data_set_raw import data_set_raw from core_tools.data.ds.data_set_raw import data_set_raw
from core_tools.data.SQL.SQL_dataset_creator import SQL_dataset_creator from core_tools.data.SQL.SQL_dataset_creator import SQL_dataset_creator
import json import json
...@@ -12,6 +12,9 @@ DATA_POINTS_MAX = 20_000_000 ...@@ -12,6 +12,9 @@ DATA_POINTS_MAX = 20_000_000
DATASET_SIZE_WARNING = 50_000_000 DATASET_SIZE_WARNING = 50_000_000
DATASET_SIZE_MAX = 200_000_000 DATASET_SIZE_MAX = 200_000_000
REDUCE_SNAPSHOT = True
def load_by_id(exp_id): def load_by_id(exp_id):
''' '''
load a dataset by specifying its id (search in local db) load a dataset by specifying its id (search in local db)
...@@ -22,6 +25,7 @@ def load_by_id(exp_id): ...@@ -22,6 +25,7 @@ def load_by_id(exp_id):
SQL_mgr = SQL_dataset_creator() SQL_mgr = SQL_dataset_creator()
return data_set(SQL_mgr.fetch_raw_dataset_by_Id(exp_id)) return data_set(SQL_mgr.fetch_raw_dataset_by_Id(exp_id))
def load_by_uuid(exp_uuid, copy2localdb=False): def load_by_uuid(exp_uuid, copy2localdb=False):
''' '''
load a dataset by specifying its uuid (searches in local and remote db) load a dataset by specifying its uuid (searches in local and remote db)
...@@ -33,6 +37,7 @@ def load_by_uuid(exp_uuid, copy2localdb=False): ...@@ -33,6 +37,7 @@ def load_by_uuid(exp_uuid, copy2localdb=False):
SQL_mgr = SQL_dataset_creator() SQL_mgr = SQL_dataset_creator()
return data_set(SQL_mgr.fetch_raw_dataset_by_UUID(exp_uuid, copy2localdb)) return data_set(SQL_mgr.fetch_raw_dataset_by_UUID(exp_uuid, copy2localdb))
def create_new_data_set(experiment_name, measurement_snapshot, *m_params): def create_new_data_set(experiment_name, measurement_snapshot, *m_params):
''' '''
generates a dataclass for a given set of measurement parameters generates a dataclass for a given set of measurement parameters
...@@ -51,6 +56,8 @@ def create_new_data_set(experiment_name, measurement_snapshot, *m_params): ...@@ -51,6 +56,8 @@ def create_new_data_set(experiment_name, measurement_snapshot, *m_params):
if qc.Station.default is not None: if qc.Station.default is not None:
station_snapshot = qc.Station.default.snapshot() station_snapshot = qc.Station.default.snapshot()
if REDUCE_SNAPSHOT:
station_snapshot = _reduce_snapshot(station_snapshot)
snapshot = {'station': station_snapshot} snapshot = {'station': station_snapshot}
else: else:
logger.warning('No station configured. No snapshot will be stored.') logger.warning('No station configured. No snapshot will be stored.')
...@@ -84,3 +91,31 @@ def create_new_data_set(experiment_name, measurement_snapshot, *m_params): ...@@ -84,3 +91,31 @@ def create_new_data_set(experiment_name, measurement_snapshot, *m_params):
return data_set(ds) return data_set(ds)
def _reduce_snapshot(snapshot: dict[str, any]):
if "__class__" in snapshot:
exclude_keys = [
"__class__",
"full_name",
"functions",
"instrument",
"instrument_name",
"inter_delay",
"post_delay",
"raw_value",
"val_mapping",
"validators",
"vals",
]
else:
exclude_keys = []
result = {}
for key, value in snapshot.items():
if key not in exclude_keys:
if isinstance(value, dict):
value = _reduce_snapshot(value)
if not value:
continue
result[key] = value
return result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment