Skip to content

Commit

Permalink
invert filters applied booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
kkappler committed Dec 7, 2023
1 parent aae83fb commit a9657b7
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 48 deletions.
6 changes: 3 additions & 3 deletions mth5/io/phoenix/readers/receiver_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _to_electric_metadata(self, tag):
f"{self.lp_filter_base_name}_{int(ch.lp)}hz_low_pass",
f"dipole_{int(c.dipole_length)}m",
]
c.filter.applied = [False, False]
c.filter.applied = [True, True]
return c

def _to_magnetic_metadata(self, tag):
Expand All @@ -167,10 +167,10 @@ def _to_magnetic_metadata(self, tag):
c.filter.name = [
f"{self.lp_filter_base_name}_{int(ch.lp)}hz_low_pass"
]
c.filter.applied = [False]
c.filter.applied = [True]
if c.sensor.id is not None:
c.filter.name.append(f"coil_{c.sensor.id}_response")
c.filter.applied.append(False)
c.filter.applied.append(True)

return c

Expand Down
2 changes: 1 addition & 1 deletion mth5/io/zen/zen.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def channel_metadata(self):
ch.units = "digital counts"
ch.channel_number = self.channel_number
ch.filter.name = self.channel_response.names
ch.filter.applied = [False] * len(self.channel_response.names)
ch.filter.applied = [True] * len(self.channel_response.names)

return ch

Expand Down
7 changes: 4 additions & 3 deletions mth5/timeseries/channel_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ def channel_response_filter(self, value):

for f_name in self._channel_response.names:
self.channel_metadata.filter.name.append(f_name)
self.channel_metadata.filter.applied = [False] * len(
self.channel_metadata.filter.applied = [True] * len(
self.channel_metadata.filter.name
)

Expand Down Expand Up @@ -1137,9 +1137,10 @@ def remove_instrument_response(self, **kwargs):
calibration_operation, calibrated_units = self.get_response_correction_operation_and_units()
calibrated_ts.ts = remover.remove_instrument_response(operation=calibration_operation)

# change applied booleans
# change applied booleans
# TODO use invert on bool, instead of direct assignement to False
applied_filters = calibrated_ts.channel_metadata.filter.applied
calibrated_ts.channel_metadata.filter.applied = [True] * len(
calibrated_ts.channel_metadata.filter.applied = [False] * len(
self.channel_metadata.filter.applied
)

Expand Down
4 changes: 2 additions & 2 deletions tests/clients/test_geomag_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_hx_metadata(self):
("channel_number", 0),
("component", "hx"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("location.elevation", 331.0),
("location.latitude", 37.091),
Expand Down Expand Up @@ -279,7 +279,7 @@ def test_hy_metadata(self):
("channel_number", 0),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("location.elevation", 331.0),
("location.latitude", 37.091),
Expand Down
18 changes: 9 additions & 9 deletions tests/io/nims/test_read_nims.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_ex_metadata(self):
("component", "ex"),
("data_quality.rating.value", 0),
("dipole_length", 109.0),
("filter.applied", [False, False, False, False, False, False]),
("filter.applied", [True, True, True, True, True, True]),
(
"filter.name",
[
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_ey_metadata(self):
("component", "ey"),
("data_quality.rating.value", 0),
("dipole_length", 101.0),
("filter.applied", [False, False, False, False, False, False]),
("filter.applied", [True, True, True, True, True, True]),
(
"filter.name",
[
Expand Down Expand Up @@ -349,7 +349,7 @@ def test_hx_metadata(self):
("channel_number", 1),
("component", "hx"),
("data_quality.rating.value", 0),
("filter.applied", [False, False, False]),
("filter.applied", [True, True, True]),
(
"filter.name",
[
Expand Down Expand Up @@ -387,7 +387,7 @@ def test_hy_metadata(self):
("channel_number", 2),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False, False, False]),
("filter.applied", [True, True, True]),
(
"filter.name",
[
Expand Down Expand Up @@ -425,7 +425,7 @@ def test_hz_metadata(self):
("channel_number", 3),
("component", "hz"),
("data_quality.rating.value", 0),
("filter.applied", [False, False, False]),
("filter.applied", [True, True, True]),
(
"filter.name",
[
Expand Down Expand Up @@ -463,7 +463,7 @@ def test_temperature_metadata(self):
("channel_number", 6),
("component", "temperature"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("location.elevation", 0.0),
("location.latitude", 0.0),
Expand Down Expand Up @@ -500,7 +500,7 @@ def test_calibrate(self):
self.assertEqual(ch.channel_metadata.units, "nT")
with self.subTest("applied"):
self.assertListEqual(
ch.channel_metadata.filter.applied, [True, True, True]
ch.channel_metadata.filter.applied, [False, False, False]
)

for comp in ["ex", "ey"]:
Expand All @@ -510,7 +510,7 @@ def test_calibrate(self):
with self.subTest("applied"):
self.assertListEqual(
ch.channel_metadata.filter.applied,
[True, True, True, True, True, True],
[False, False, False, False, False, False],
)

ch = getattr(calibrated_run, "temperature")
Expand All @@ -519,7 +519,7 @@ def test_calibrate(self):
with self.subTest("applied"):
self.assertListEqual(
ch.channel_metadata.filter.applied,
[True],
[False],
)


Expand Down
2 changes: 1 addition & 1 deletion tests/io/phoenix/test_base_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_channel_metadata(self):
("channel_number", 0),
("component", "h2"),
("data_quality.rating.value", 0),
("filter.applied", [False, False]),
("filter.applied", [True, True]),
(
"filter.name",
["mtu-5c_rmt03_10128_10000hz_low_pass", "coil_0_response"],
Expand Down
2 changes: 1 addition & 1 deletion tests/io/phoenix/test_read_phoenix_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_to_channel_ts(self):
("channel_number", 0),
("component", "h2"),
("data_quality.rating.value", 0),
("filter.applied", [False, False]),
("filter.applied", [True, True]),
(
"filter.name",
["mtu-5c_rmt03-j_666_h2_10000hz_lowpass", "v_to_mv"],
Expand Down
2 changes: 1 addition & 1 deletion tests/io/phoenix/test_read_phoenix_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_metadata(self):
("channel_number", 0),
("component", "h2"),
("data_quality.rating.value", 0),
("filter.applied", [False, False]),
("filter.applied", [True, True]),
(
"filter.name",
["mtu-5c_rmt03-j_666_h2_10000hz_lowpass", "v_to_mv"],
Expand Down
2 changes: 1 addition & 1 deletion tests/io/phoenix/test_read_phoenix_segmented.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_to_channel_ts(self):
("channel_number", 0),
("component", "h2"),
("data_quality.rating.value", 0),
("filter.applied", [False, False]),
("filter.applied", [True, True]),
(
"filter.name",
["mtu-5c_rmt03-j_666_h2_10000hz_lowpass", "v_to_mv"],
Expand Down
10 changes: 5 additions & 5 deletions tests/io/usgs_ascii/test_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_ex(self):
("component", "ex"),
("data_quality.rating.value", 0),
("dipole_length", 100.0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("measurement_azimuth", 9.0),
("measurement_tilt", 0.0),
Expand Down Expand Up @@ -86,7 +86,7 @@ def test_ey(self):
("component", "ey"),
("data_quality.rating.value", 0),
("dipole_length", 102.0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("measurement_azimuth", 99.0),
("measurement_tilt", 0.0),
Expand Down Expand Up @@ -119,7 +119,7 @@ def test_hx(self):
("channel_number", 31),
("component", "hx"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("location.elevation", 0.0),
("location.latitude", 0.0),
Expand All @@ -146,7 +146,7 @@ def test_hy(self):
("channel_number", 33),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("location.elevation", 0.0),
("location.latitude", 0.0),
Expand All @@ -173,7 +173,7 @@ def test_hz(self):
("channel_number", 35),
("component", "hz"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("location.elevation", 0.0),
("location.latitude", 0.0),
Expand Down
4 changes: 2 additions & 2 deletions tests/io/zen/test_z3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_channel_metadata(self):
("dc.end", 0.019371436521409924),
("dc.start", 0.019130984313785026),
("dipole_length", 56.0),
("filter.applied", [False, False]),
("filter.applied", [True, True]),
(
"filter.name",
["dipole_56.00m", "zen_counts2mv"],
Expand Down Expand Up @@ -571,7 +571,7 @@ def test_channel_metadata(self):
("channel_number", 2),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False, False]),
("filter.applied", [True, True]),
(
"filter.name",
[
Expand Down
33 changes: 22 additions & 11 deletions tests/timeseries/test_remove_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,40 @@

class TestRemoveResponse(unittest.TestCase):
"""
Test remove response, make a fake signal add some trends,
Test remove response, make a fake signal add some trends,
ToDo:
- Add more than one filter to the test.
- Utilize the is_channel_response attributes
"""

@classmethod
def setUpClass(self):
# pole zero filter
pz = PoleZeroFilter(
pz1 = PoleZeroFilter(
units_in="volts", units_out="nanotesla", name="instrument_response"
)
pz.poles = [
pz1.poles = [
(-6.283185 + 10.882477j),
(-6.283185 - 10.882477j),
(-12.566371 + 0j),
]
pz.zeros = []
pz.normalization_factor = 18244400

pz1.zeros = []
pz1.normalization_factor = 18244400
pz2 = PoleZeroFilter(
units_in="nanotesla", units_out="volts", name="instrument_response2"
)
pz2.poles = []
pz2.zeros = []
pz2.normalization_factor = 10
pz2.gain = 12
# channel properties
self.channel = ChannelTS()
self.channel.channel_metadata.filter.applied = [False]
self.channel.channel_metadata.filter.name = ["instrument_response"]
self.channel.channel_metadata.filter.applied = [True, ]#False]
self.channel.channel_metadata.filter.name = ["instrument_response",]# "instrument_response2"]
self.channel.channel_metadata.component = "hx"
self.channel.channel_response_filter.filters_list.append(pz)
self.channel.channel_metadata.units = "digital counts"
self.channel.channel_response_filter.filters_list.append(pz1)
# self.channel.channel_response_filter.filters_list.append(pz2)
self.channel.sample_rate = 1
n_samples = 4096
self.t = np.arange(n_samples) * self.channel.sample_interval
Expand All @@ -61,7 +72,7 @@ def setUpClass(self):
# multiply by filter response
f = np.fft.rfftfreq(self.t.size, self.channel.sample_interval)
response_ts = np.fft.irfft(
np.fft.rfft(self.example_ts) * pz.complex_response(f)[::-1]
np.fft.rfft(self.example_ts) * pz1.complex_response(f)[::-1]
)

# add in a linear trend
Expand All @@ -74,7 +85,7 @@ def test_return_type(self):

def test_applied(self):
self.assertTrue(
(np.array(self.calibrated_ts.channel_metadata.filter.applied) == True).all()
(np.array(self.calibrated_ts.channel_metadata.filter.applied) == False).all()
)

def test_returned_metadata(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/version_1/test_make_mth5_geomag.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_fresno_run_001_hx_metadata(self):
("channel_number", 0),
("component", "hx"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 331.0),
Expand Down Expand Up @@ -235,7 +235,7 @@ def test_fresno_run_001_hy_metadata(self):
("channel_number", 0),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 331.0),
Expand Down Expand Up @@ -375,7 +375,7 @@ def test_ottowa_run_001_hx_metadata(self):
("channel_number", 0),
("component", "hx"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 0.0),
Expand Down Expand Up @@ -408,7 +408,7 @@ def test_ottowa_run_001_hy_metadata(self):
("channel_number", 0),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 0.0),
Expand Down
8 changes: 4 additions & 4 deletions tests/version_2/test_make_mth5_geomag.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_fresno_run_001_hx_metadata(self):
("channel_number", 0),
("component", "hx"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 331.0),
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_fresno_run_001_hy_metadata(self):
("channel_number", 0),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 331.0),
Expand Down Expand Up @@ -376,7 +376,7 @@ def test_ottowa_run_001_hx_metadata(self):
("channel_number", 0),
("component", "hx"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 0.0),
Expand Down Expand Up @@ -409,7 +409,7 @@ def test_ottowa_run_001_hy_metadata(self):
("channel_number", 0),
("component", "hy"),
("data_quality.rating.value", 0),
("filter.applied", [False]),
("filter.applied", [True]),
("filter.name", []),
("hdf5_reference", "<HDF5 object reference>"),
("location.elevation", 0.0),
Expand Down

0 comments on commit a9657b7

Please sign in to comment.