Skip to content

Commit

Permalink
add calibration operation option back into remove instrument response
Browse files Browse the repository at this point in the history
  • Loading branch information
kkappler committed Dec 12, 2023
1 parent 6484d96 commit 09c6fac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
18 changes: 16 additions & 2 deletions mth5/timeseries/channel_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,18 @@ def channel_response(self, value):
)


def get_calibration_operation(self):
if self.channel_response.units_out == self.channel_metadata.unit_object.abbreviation:
calibration_operation = "divide"
elif self.channel_response.units_in == self.channel_metadata.unit_object.abbreviation:
calibration_operation = "multiply"
self.logger.warning("Unexpected Inverse Filter is being corrected -- something maybe wrong here ")
else:
msg = "cannot determine multiply or divide via units -- setting to divide"
self.logger.warning(msg)
calibration_operation = "divide"
return calibration_operation

def get_calibrated_units(self):
"""
Follows the FDSN standard which has the filter stages starting with physical units to digital counts.
Expand Down Expand Up @@ -1157,8 +1169,10 @@ def bool_flip(x):
**kwargs,
)


calibrated_ts.ts = remover.remove_instrument_response(filters_to_remove=filters_to_remove)
calibration_operation = self.get_calibration_operation()
calibrated_ts.ts = remover.remove_instrument_response(filters_to_remove=filters_to_remove,
operation=calibration_operation,
)

# update "applied" booleans
applied_filters = calibrated_ts.channel_metadata.filter.applied
Expand Down
18 changes: 15 additions & 3 deletions mth5/timeseries/ts_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def _get_subplot_count(self):
return subplot_dict

def remove_instrument_response(self,
operation="divide",
include_decimation=None,
include_delay=None,
filters_to_remove=[]):
Expand Down Expand Up @@ -581,9 +582,20 @@ def remove_instrument_response(self,

# calibrate the time series, compute real part of fft, divide out
# channel response, inverse fft
calibrated_ts = np.fft.irfft(data / cr)[0 : self.ts.size]
self.logger.debug(f"Step {step}: Removing Calibration via divide channel response")
step += 1
if operation == "divide":
calibrated_ts = np.fft.irfft(data / cr)[0 : self.ts.size]
self.logger.debug(f"Step {step}: Removing Calibration via divide channel response")
step += 1
elif operation == "multiply":
calibrated_ts = np.fft.irfft(data * cr)[0: self.ts.size]
self.logger.warning(f"Instrument response being applied rather that expected "
f"operation of removing the response")
step += 1
else:
msg = f"Operation {operation} not recognized method of instrument response correction"
logger.error(msg)
raise Exception


# If a time window was applied, need to un-apply it to reconstruct the signal.
if self.t_window is not None:
Expand Down

0 comments on commit 09c6fac

Please sign in to comment.