1
0
Fork 0

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 <kerel@mailbox.org>
spacecruft
Fabian P. Schmidt 2021-10-21 00:43:49 +03:00
parent 52147ade28
commit 37daecf507
1 changed files with 8 additions and 1 deletions

View File

@ -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)