diff --git a/geomagio/metadata/instrument/InstrumentCalibrations.py b/geomagio/metadata/instrument/InstrumentCalibrations.py index 330ab8e89a3e3af46711d9b4ff88ff4fb85b14b3..40052b9ce59d11554e3dc2c49fce371b0aafe379 100644 --- a/geomagio/metadata/instrument/InstrumentCalibrations.py +++ b/geomagio/metadata/instrument/InstrumentCalibrations.py @@ -327,16 +327,34 @@ def get_instrument_calibrations( # remove invalid metadata entries for i, m in enumerate(metadata): - if not m.data_valid: - metadata.pop(i) - - instrumentCalibrations = InstrumentCalibrations(metadata) - calibrations = instrumentCalibrations.get_calibrations() - - return [ - c - for c in calibrations - if c["station"] == observatory - and (end_time is None or c["start_time"] is None or c["start_time"] < end_time) - and (start_time is None or c["end_time"] is None or c["end_time"] > start_time) - ] + if not m.data_valid or "instrument_category" not in m.metadata: + metadata.remove(m) + + if not metadata or metadata is None: + raise ValueError( + f"No valid metadata returned for {observatory} for time interval: {start_time} - {end_time}" + ) + else: + instrumentCalibrations = InstrumentCalibrations(metadata) + calibrations = instrumentCalibrations.get_calibrations() + + if not calibrations or calibrations is None: + raise ValueError( + f"No valid calibrations returned for {observatory} for time interval: {start_time} - {end_time}" + ) + else: + return [ + c + for c in calibrations + if c["station"] == observatory + and ( + end_time is None + or c["start_time"] is None + or c["start_time"] < end_time + ) + and ( + start_time is None + or c["end_time"] is None + or c["end_time"] > start_time + ) + ]