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
parent
52147ade28
commit
37daecf507
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue