Implement compatibility with older nexus file mappings
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
Presever compatibility with previous versions of AMOR datafiles.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
# old hdf parameter mappings, key is last date of validity
|
||||
legacy_hdf_paths = {
|
||||
datetime(2026, 3, 18).timestamp():
|
||||
dict(
|
||||
title=('entry1/title', str),
|
||||
proposal_id=('entry1/proposal_id', str),
|
||||
user_name=('entry1/user/name', str),
|
||||
user_email=('entry1/user/email', str),
|
||||
sample_name=('entry1/sample/name', str),
|
||||
source_name=('entry1/Amor/source/name', str),
|
||||
sample_model=('entry1/sample/model', str),
|
||||
start_time=('entry1/start_time', str),
|
||||
start_time_fallback=('entry1/Amor/instrument_control_parameters/start_time', str),
|
||||
|
||||
chopper_separation=('entry1/Amor/chopper/pair_separation', float),
|
||||
detector_distance=('entry1/Amor/detector/transformation/distance', float),
|
||||
chopper_distance=('entry1/Amor/chopper/distance', float),
|
||||
sample_temperature=('entry1/sample/temperature', float),
|
||||
sample_magnetic_field=('entry1/sample/magnetic_field', float),
|
||||
|
||||
mu=('entry1/Amor/instrument_control_parameters/mu', float, 'mu'),
|
||||
nu=('entry1/Amor/instrument_control_parameters/nu', float, 'nu'),
|
||||
kap=('entry1/Amor/instrument_control_parameters/kappa', float, 'kappa'),
|
||||
kad=('entry1/Amor/instrument_control_parameters/kappa_offset', float, 'kappa_offset'),
|
||||
div=('entry1/Amor/instrument_control_parameters/div', float, 'div'),
|
||||
ch1_trigger_phase=('entry1/Amor/chopper/ch1_trigger_phase', float, 'ch1_trigger_phase'),
|
||||
ch2_trigger_phase=('entry1/Amor/chopper/ch2_trigger_phase', float, 'ch2_trigger_phase'),
|
||||
chopper_speed=('entry1/Amor/chopper/rotation_speed', float, 'chopper_phase'),
|
||||
chopper_phase=('entry1/Amor/chopper/phase', float, 'chopper_phase'),
|
||||
polarization_config_label=('entry1/Amor/polarization/configuration', int, 'polarization_config_label', '/*'),
|
||||
)
|
||||
}
|
||||
# create a sorted list of validity timestamps for quick comparison
|
||||
legacy_cutoffs = list(sorted(legacy_hdf_paths.keys()))
|
||||
+10
-1
@@ -14,7 +14,7 @@ from datetime import datetime
|
||||
from orsopy import fileio
|
||||
from orsopy.fileio.model_language import SampleModel
|
||||
|
||||
from . import const
|
||||
from . import const, compat
|
||||
from .header import Header
|
||||
from .event_data_types import AmorGeometry, AmorTiming, AmorEventStream, LOG_TYPE, PACKET_TYPE, EVENT_TYPE, PULSE_TYPE, \
|
||||
PC_TYPE
|
||||
@@ -147,6 +147,15 @@ class AmorHeader:
|
||||
else:
|
||||
TZ = AMOR_LOCAL_TIMEZONE
|
||||
start_date = datetime.fromisoformat(start_time)
|
||||
|
||||
start_timestamp = start_date.timestamp()
|
||||
if start_timestamp<=compat.legacy_cutoffs[-1]:
|
||||
logging.info(" Detected legacy file format, using older mapping")
|
||||
for cutoff in compat.legacy_cutoffs:
|
||||
if start_timestamp<=cutoff:
|
||||
self.hdf_paths = compat.legacy_hdf_paths[cutoff]
|
||||
break
|
||||
|
||||
self.fileDate = start_date.replace(tzinfo=TZ)
|
||||
self._start_time_ns = np.uint64(self.fileDate.timestamp()*1e9)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user