From 37daecf507b752ee2342f0162b7df70a8f70f2f5 Mon Sep 17 00:00:00 2001 From: "Fabian P. Schmidt" Date: Thu, 21 Oct 2021 00:43:49 +0300 Subject: [PATCH] Add support for satnogs artifacts version 2 In SatNOGS artifacts format version 2 the observation id was moved from its own hdf5 field into a newly created metadata field. This commit adds support for reading this field so db can handle version 1 and version 2 artifact files now. Fixes #493. Signed-off-by: Fabian P. Schmidt --- db/base/signals.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/db/base/signals.py b/db/base/signals.py index 865e6e5..887f7b1 100644 --- a/db/base/signals.py +++ b/db/base/signals.py @@ -1,4 +1,5 @@ """Django signals for SatNOGS DB""" +import json import logging import h5py @@ -24,7 +25,13 @@ def _extract_network_obs_id(sender, instance, created, **kwargs): # pylint: dis post_save.disconnect(_extract_network_obs_id, sender=Artifact) try: with h5py.File(instance.artifact_file, 'r') as h5_file: - instance.network_obs_id = h5_file.attrs["observation_id"] + if h5_file.attrs["artifact_version"] == 1: + # Artifacts version 1 + instance.network_obs_id = h5_file.attrs["observation_id"] + else: + # Artifacts version 2 or later + metadata = json.loads(h5_file.attrs["metadata"]) + instance.network_obs_id = metadata["version"] except OSError as error: LOGGER.warning(error)