Skip to content

Commit

Permalink
ran black
Browse files Browse the repository at this point in the history
  • Loading branch information
kujaku11 committed Jan 22, 2021
1 parent 1b1c5ac commit 6078f5d
Show file tree
Hide file tree
Showing 33 changed files with 312 additions and 803 deletions.
48 changes: 12 additions & 36 deletions docs/create_metadata_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from pathlib import Path
import textwrap

fn = Path(
r"c:\Users\peaco\Documents\GitHub\mth5\mth5\docs\mt_metadata_guide.tex"
)
fn = Path(r"c:\Users\peaco\Documents\GitHub\mth5\mth5\docs\mt_metadata_guide.tex")


def wrap_description(description, column_width):
Expand Down Expand Up @@ -53,55 +51,43 @@ def write_lines(lines_list, c1, c2, c3):

lines = [
hline,
line.format(
"**Metadata Key**", c1, "**Description**", c2, "**Example**", c3
),
line.format("**Metadata Key**", c1, "**Description**", c2, "**Example**", c3),
mline,
]

for entry in lines_list:
d_lines = wrap_description(entry[5], c2)
e_lines = wrap_description(entry[-1], c3)
# line 1 is with the entry
lines.append(
line.format(f"**{entry[0]}**", c1, d_lines[0], c2, e_lines[0], c3)
)
lines.append(line.format(f"**{entry[0]}**", c1, d_lines[0], c2, e_lines[0], c3))
# line 2 skip an entry in the
lines.append(line.format("", c1, d_lines[1], c2, e_lines[1], c3))
# line 3 required
lines.append(
line.format(
f"Required: {entry[1]}", c1, d_lines[2], c2, e_lines[2], c3
)
line.format(f"Required: {entry[1]}", c1, d_lines[2], c2, e_lines[2], c3)
)
# line 4 blank
lines.append(line.format("", c1, d_lines[3], c2, e_lines[3], c3))

# line 5 units
lines.append(
line.format(
f"Units: {entry[2]}", c1, d_lines[4], c2, e_lines[4], c3
)
line.format(f"Units: {entry[2]}", c1, d_lines[4], c2, e_lines[4], c3)
)

# line 6 blank
lines.append(line.format("", c1, d_lines[5], c2, e_lines[5], c3))

# line 7 type
lines.append(
line.format(
f"Type: {entry[3]}", c1, d_lines[6], c2, e_lines[6], c3
)
line.format(f"Type: {entry[3]}", c1, d_lines[6], c2, e_lines[6], c3)
)

# line 8 blank
lines.append(line.format("", c1, d_lines[7], c2, e_lines[7], c3))

# line 9 type
lines.append(
line.format(
f"Style: {entry[4]}", c1, d_lines[8], c2, e_lines[8], c3
)
line.format(f"Style: {entry[4]}", c1, d_lines[8], c2, e_lines[8], c3)
)

# line 10 blank
Expand Down Expand Up @@ -151,46 +137,36 @@ def write_block(entry, c1, c2, c3):
f" :widths: {c1} {c2} {c3}",
"",
hline,
line.format(
f"**{entry[0]}**", c1, "**Description**", c2, "**Example**", c3
),
line.format(f"**{entry[0]}**", c1, "**Description**", c2, "**Example**", c3),
mline,
]

d_lines = wrap_description(entry[5], c2)
e_lines = wrap_description(entry[-1], c3)
# line 1 is with the entry
lines.append(
line.format(
f"**Required**: {entry[1]}", c1, d_lines[0], c2, e_lines[0], c3
)
line.format(f"**Required**: {entry[1]}", c1, d_lines[0], c2, e_lines[0], c3)
)
# line 2 skip an entry in the
lines.append(line.format("", c1, d_lines[1], c2, e_lines[1], c3))
# line 3 required
lines.append(
line.format(
f"**Units**: {entry[2]}", c1, d_lines[2], c2, e_lines[2], c3
)
line.format(f"**Units**: {entry[2]}", c1, d_lines[2], c2, e_lines[2], c3)
)
# line 4 blank
lines.append(line.format("", c1, d_lines[3], c2, e_lines[3], c3))

# line 5 units
lines.append(
line.format(
f"**Type**: {entry[3]}", c1, d_lines[4], c2, e_lines[4], c3
)
line.format(f"**Type**: {entry[3]}", c1, d_lines[4], c2, e_lines[4], c3)
)

# line 6 blank
lines.append(line.format("", c1, d_lines[5], c2, e_lines[5], c3))

# line 7 type
lines.append(
line.format(
f"**Style**: {entry[4]}", c1, d_lines[6], c2, e_lines[6], c3
)
line.format(f"**Style**: {entry[4]}", c1, d_lines[6], c2, e_lines[6], c3)
)

# line 8 blank
Expand Down
2 changes: 1 addition & 1 deletion examples/make_mth5_from_nims.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#
# =============================================================================


def test_make_mth5_from_nims():
print(f"Data Directory: {DATA_DIR}")
# set to true if you want to interact with the mth5 object in the console
Expand Down Expand Up @@ -98,6 +99,5 @@ def test_make_mth5_from_nims():
m.close_mth5()



if __name__ == "__main__":
test_make_mth5_from_nims()
17 changes: 9 additions & 8 deletions examples/make_mth5_from_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
# functions
# =============================================================================

#<XML HELPERS>
# <XML HELPERS>
def is_a_station_xml(fn):
return fn.count(".") == 1


def is_a_run_xml(fn):
return fn.count(".") == 2


def is_a_channel_xml(fn):
return fn.count(".") > 2

Expand Down Expand Up @@ -92,7 +94,10 @@ def collect_xml_fn(station, directory):
continue

return station_dict
#</XML HELPERS>


# </XML HELPERS>


def add_station(station, directory, h5_obj):
"""
Expand All @@ -108,9 +113,7 @@ def add_station(station, directory, h5_obj):

# add station
new_station = h5_obj.stations_group.add_station(station)
new_station.metadata.from_xml(
read_xml(directory.joinpath(station_dict["station"]))
)
new_station.metadata.from_xml(read_xml(directory.joinpath(station_dict["station"])))
new_station.write_metadata()

# loop over runs
Expand All @@ -126,9 +129,7 @@ def add_station(station, directory, h5_obj):
# loop over channels
for channel, channel_fn in run_dict["channels"].items():
_, _, channel_type, component, _ = channel_fn.split(".")
channel = run.add_channel(
component, channel_type, np.random.rand(4096)
)
channel = run.add_channel(component, channel_type, np.random.rand(4096))
channel.metadata.from_xml(read_xml(directory.joinpath(channel_fn)))
channel.metadata.time_period.start = run.metadata.time_period.start
channel.metadata.time_period.end = run.metadata.time_period.end
Expand Down
6 changes: 2 additions & 4 deletions examples/make_mth5_from_z3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def test_make_mth5_from_z3d():
mtts_obj = read_file(zen_dir.joinpath(fn.filename))

station_group = m.add_station(
mtts_obj.station_metadata.id,
station_metadata=mtts_obj.station_metadata,
mtts_obj.station_metadata.id, station_metadata=mtts_obj.station_metadata,
)

run_id = station_group.locate_run(mtts_obj.sample_rate, mtts_obj.start)
Expand All @@ -78,7 +77,6 @@ def test_make_mth5_from_z3d():
)
station_group.validate_station_metadata()


end = MTime()
end.now()

Expand All @@ -87,6 +85,6 @@ def test_make_mth5_from_z3d():
if not interact:
m.close_mth5()


if __name__ == "__main__":
test_make_mth5_from_z3d()

3 changes: 0 additions & 3 deletions examples/make_stationxml_from_mt.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,5 @@ def test_make_stationxml_from_mt():
to_stationxml.to_stationxml("Test_station.xml")




if __name__ == "__main__":
test_make_stationxml_from_mt()

8 changes: 2 additions & 6 deletions examples/metadata/make_example_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@
s = getattr(metadata, c)()
if style == "xml":
x = s.to_xml(required=False)
with open(
p.joinpath("{0}_example.xml".format(c.lower())), "w"
) as fid:
with open(p.joinpath("{0}_example.xml".format(c.lower())), "w") as fid:
fid.write(
minidom.parseString(et.tostring(x).decode()).toprettyxml(
indent=" "
)
)
elif style == "json":
jstr = s.to_json(nested=True, required=False)
with open(
p.joinpath("{0}_example.json".format(c.lower())), "w"
) as fid:
with open(p.joinpath("{0}_example.json".format(c.lower())), "w") as fid:
fid.write(jstr)
2 changes: 1 addition & 1 deletion examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""


def run_the_tests():
"""
"""
Expand All @@ -22,6 +23,5 @@ def run_the_tests():
test_make_stationxml_from_mt()



if __name__ == "__main__":
run_the_tests()
4 changes: 1 addition & 3 deletions examples/translate_mt_metadata_to_station_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
# Inputs: xml file names for each level
# =============================================================================
# directory where xml files reside
print(
"WARNING THIS TEST IS NOT YET READY TO BE PART OF THE REGULAR TESTING SUITE"
)
print("WARNING THIS TEST IS NOT YET READY TO BE PART OF THE REGULAR TESTING SUITE")
xml_path = Path(r"c:\Users\peaco\Documents\MT\mth5")

# filenames for each level
Expand Down
38 changes: 8 additions & 30 deletions mth5/filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ def to_lookup_table(self, frequencies=None):
"""

pz = signal.ZerosPolesGain(
self.zeros,
self.poles,
self.normalization_factor,
dt=self.sample_rate,
self.zeros, self.poles, self.normalization_factor, dt=self.sample_rate,
)

f, amp = signal.dfreqresp(pz, frequencies)
Expand Down Expand Up @@ -217,16 +214,10 @@ class LookupTable:

def __init__(self, frequency, real, imaginary, amplitude_phase=False):

self.logger = logging.getLogger(
f"{__name__}.{self.__class__.__name__}"
)
self.logger = logging.getLogger(f"{__name__}.{self.__class__.__name__}")
self.lookup_table = None

if (
frequency is not None
and real is not None
and imaginary is not None
):
if frequency is not None and real is not None and imaginary is not None:
if not isinstance(frequency, np.ndarray):
frequency = np.array(frequency)
if not isinstance(real, np.ndarray):
Expand Down Expand Up @@ -274,10 +265,7 @@ def __str__(self):
+ [
f"{ff:<14.5e}{vv.real:<14.5e}{vv.imag:<14.5e}{aa:<14.5e}{pp:<14.5e}"
for ff, vv, aa, pp in zip(
self.frequency,
self.filter_values,
self.amplitude,
self.phase,
self.frequency, self.filter_values, self.amplitude, self.phase,
)
]
)
Expand Down Expand Up @@ -331,9 +319,7 @@ def filter_values(self, values):
@property
def amplitude(self):
try:
return np.sqrt(
self.filter_values.real ** 2 + self.filter_values.imag ** 2
)
return np.sqrt(self.filter_values.real ** 2 + self.filter_values.imag ** 2)
except AttributeError:
return None

Expand Down Expand Up @@ -437,9 +423,7 @@ def __init__(
instrument_gain=None,
):

self.logger = logging.getLogger(
f"{__name__}.{self.__class__.__name__}"
)
self.logger = logging.getLogger(f"{__name__}.{self.__class__.__name__}")
self.metadata = metadata.Filter()
if zeros is None:
zeros = []
Expand Down Expand Up @@ -475,20 +459,14 @@ def __str__(self):
info = self.metadata.__str__()
if self.conversion_factor is not None:
info += "\n".join(
[
"",
"Conversion Factor:",
f"\t{self.conversion_factor:<12.5e}",
]
["", "Conversion Factor:", f"\t{self.conversion_factor:<12.5e}",]
)
if self.instrument_gain is not None:
info += "\n".join(
["", "Instrument Gain:", f"\t{self.instrument_gain:<12.5e}"]
)
if self.time_delay is not None:
info += "\n".join(
["", "Time Delay:", f"\t{self.time_delay:<12.5e}"]
)
info += "\n".join(["", "Time Delay:", f"\t{self.time_delay:<12.5e}"])

if len(self.zpk.poles) > 0 or len(self.zpk.zeros) > 0:
pz = [""]
Expand Down
4 changes: 1 addition & 3 deletions mth5/groups/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ def initialize_summary_table(self):
)
self.logger.debug(
"used options: "
+ "; ".join(
[f"{k} = {v}" for k, v in self.dataset_options.items()]
)
+ "; ".join([f"{k} = {v}" for k, v in self.dataset_options.items()])
)

def initialize_group(self):
Expand Down
4 changes: 1 addition & 3 deletions mth5/groups/filter_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ def write_metadata(self):

for key, value in self.metadata.to_dict(single=True):
value = to_numpy_type(value)
self.logger.debug(
f"wrote metadata {key} = {value}".format(key, value)
)
self.logger.debug(f"wrote metadata {key} = {value}".format(key, value))
self.hdf5_dataset.attrs.create(key, value)

def to_filter_object(self):
Expand Down
Loading

0 comments on commit 6078f5d

Please sign in to comment.