diff --git a/geomagio/edge/FDSNFactory.py b/geomagio/edge/FDSNFactory.py index 97e742b8e220da92c53a15c05b123ebbfe5fd18e..afd9de172a55f0f2875327db7354a7e070918d96 100644 --- a/geomagio/edge/FDSNFactory.py +++ b/geomagio/edge/FDSNFactory.py @@ -256,14 +256,12 @@ class FDSNFactory(TimeseriesFactory): endtime=endtime + half_delta, attach_response=True, ) + except FDSNNoDataException: data = Stream() + data.merge() - if channel in channel_rotations: - data = self._rotate_and_return_requested_channel( - data, sncl, starttime, endtime, channel - ) if data.count() == 0 and add_empty_channels: data += self._get_empty_trace( starttime=starttime, @@ -275,39 +273,49 @@ class FDSNFactory(TimeseriesFactory): network=sncl.network, location=sncl.location, ) + + # Skip further processing if the data is still empty + if data.count() == 0: + return data + if data.count() != 0: TimeseriesUtility.pad_and_trim_trace( trace=data[0], starttime=starttime, endtime=endtime ) + if channel in channel_rotations: + data = self._rotate_and_return_requested_channel( + data, sncl, starttime, endtime, channel + ) for trace in data: - response = trace.stats.response - if self.remove_sensitivity is not None: - if self.remove_sensitivity_flag == "remove_sensitivity": - trace.remove_sensitivity() - - elif self.remove_sensitivity_flag == "remove_response": - trace.remove_response() - else: - raise ValueError( - f"Warning: Unrecognized remove_sensitivity value '{self.remove_sensitivity}'. No sensitivity or response removal applied." - ) - else: - if response.instrument_sensitivity: - if response.instrument_sensitivity.input_units == "T": - # some ASL stations produce data in Teslas, not nanoteslas - response.instrument_sensitivity.value /= 1e9 - response.instrument_sensitivity.input_units = "nT" - # apply total gain/sensitivity, ignore any frequency response - trace.remove_sensitivity() + if hasattr(trace.stats, "response") and trace.stats.response is not None: + response = trace.stats.response + if self.remove_sensitivity is not None: + if self.remove_sensitivity_flag == "remove_sensitivity": + trace.remove_sensitivity() + + elif self.remove_sensitivity_flag == "remove_response": + trace.remove_response() + else: + raise ValueError( + f"Warning: Unrecognized remove_sensitivity value '{self.remove_sensitivity}'. No sensitivity or response removal applied." + ) else: - # according to fdsn docs, if no instrument_sensitivity, - # the response must be an instrument_polynomial - # https://docs.fdsn.org/projects/stationxml/en/latest/reference.html#instrumentsensitivity - - # Geomag Program observatories use 2nd order instrument_polynomial - # to capture both offset and scale, but no frequency response - data.remove_response() + if response.instrument_sensitivity: + if response.instrument_sensitivity.input_units == "T": + # some ASL stations produce data in Teslas, not nanoteslas + response.instrument_sensitivity.value /= 1e9 + response.instrument_sensitivity.input_units = "nT" + # apply total gain/sensitivity, ignore any frequency response + trace.remove_sensitivity() + else: + # according to fdsn docs, if no instrument_sensitivity, + # the response must be an instrument_polynomial + # https://docs.fdsn.org/projects/stationxml/en/latest/reference.html#instrumentsensitivity + + # Geomag Program observatories use 2nd order instrument_polynomial + # to capture both offset and scale, but no frequency response + data.remove_response() else: self._set_metadata(data, observatory, channel, type, interval)