Skip to content

Commit

Permalink
Merge pull request #170 from kujaku11/bug_fixes
Browse files Browse the repository at this point in the history
- Minor Bug fixes
- Removing restriction on Pandas < 2
kujaku11 authored Nov 9, 2023
2 parents 952ada7 + 6323bc5 commit f4d3b05
Showing 9 changed files with 56 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.4.0
current_version = 0.4.1
files = setup.py mth5/__init__.py README.md docs/README.rst
commit = True
tag = True
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ jobs:
conda install pytest=7.1.2
conda install pytest-cov
conda install pytest-subtests
pip install git+https://github.com/kujaku11/mt_metadata.git@fcs
pip install git+https://github.com/kujaku11/mt_metadata.git@patches
- name: Install Our Package
shell: bash
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ MTH5 uses [h5py](https://www.h5py.org/) to interact with the HDF5 file, [xarray]
This project is in cooperation with the Incorporated Research Institutes of Seismology, the U.S. Geological Survey, and other collaborators. Facilities of the IRIS Consortium are supported by the National Science Foundation’s Seismological Facilities for the Advancement of Geoscience (SAGE) Award under Cooperative Support Agreement EAR-1851048. USGS is partially funded through the Community for Data Integration and IMAGe through the Minerals Resources Program.


* **Version**: 0.4.0
* **Version**: 0.4.1
* **Free software**: MIT license
* **Documentation**: https://mth5.readthedocs.io.
* **Examples**: Click the `Binder` badge above and Jupyter Notebook examples are in **docs/examples/notebooks**
2 changes: 1 addition & 1 deletion docs/README.rst
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ MTH5 uses `h5py <https://www.h5py.org/>`_ to interact with the HDF5 file, `xarra

This project is in cooperation with the Incorporated Research Institutes of Seismology, the U.S. Geological Survey, and other collaborators. Facilities of the IRIS Consortium are supported by the National Science Foundation’s Seismological Facilities for the Advancement of Geoscience (SAGE) Award under Cooperative Support Agreement EAR-1851048. USGS is partially funded through the Community for Data Integration and IMAGe through the Minerals Resources Program.

* **Version**: 0.4.0
* **Version**: 0.4.1
* **Free software**: MIT license
* **Documentation**: `<https://mth5.readthedocs.io>`_.
* **Examples**: Click the `Binder` badge above and Jupyter Notebook examples are in **docs/examples/notebooks**
2 changes: 1 addition & 1 deletion mth5/__init__.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@

__author__ = """Jared Peacock"""
__email__ = "jpeacock@usgs.gov"
__version__ = "0.4.0"
__version__ = "0.4.1"


# =============================================================================
19 changes: 16 additions & 3 deletions mth5/helpers.py
Original file line number Diff line number Diff line change
@@ -132,7 +132,9 @@ def get_tree(parent):
"""
lines = ["{0}:".format(parent.name), "=" * 20]
if not isinstance(parent, (h5py.File, h5py.Group)):
raise TypeError("Provided object is not a h5py.File or h5py.Group " "object")
raise TypeError(
"Provided object is not a h5py.File or h5py.Group " "object"
)

def fancy_print(name, obj):
# lines.append(name)
@@ -141,10 +143,14 @@ def fancy_print(name, obj):

if isinstance(obj, h5py.Group):
lines.append(f"{spacing}|- Group: {group_name}")
lines.append("{0}{1}".format(spacing, (len(group_name) + 10) * "-"))
lines.append(
"{0}{1}".format(spacing, (len(group_name) + 10) * "-")
)
elif isinstance(obj, h5py.Dataset):
lines.append(f"{spacing}--> Dataset: {group_name}")
lines.append("{0}{1}".format(spacing, (len(group_name) + 15) * "."))
lines.append(
"{0}{1}".format(spacing, (len(group_name) + 15) * ".")
)

# lines.append(parent.name)
parent.visititems(fancy_print)
@@ -223,6 +229,7 @@ def from_numpy_type(value):

if value is None:
return "none"

# For now turn references into a generic string
if isinstance(value, h5py.h5r.Reference):
value = str(value)
@@ -239,6 +246,12 @@ def from_numpy_type(value):
np.float_,
np.bool_,
np.complex_,
np.intp,
type(np.int_),
type(np.float_),
type(np.bool_),
type(np.complex_),
type(np.intp),
),
):
return value
52 changes: 34 additions & 18 deletions mth5/io/lemi/lemi424.py
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
from mt_metadata.timeseries import Station, Run, Electric, Magnetic, Auxiliary
from mt_metadata.utils.mttime import MTime


# =============================================================================
def lemi_date_parser(year, month, day, hour, minute, second):
"""
@@ -50,18 +51,22 @@ def lemi_date_parser(year, month, day, hour, minute, second):
:rtype: :class:`pandas.DateTime`
"""

return pd.to_datetime(
datetime(
int(year),
int(month),
int(day),
int(hour),
int(minute),
int(second),
)
dt_df = pd.DataFrame(
{
"year": year,
"month": month,
"day": day,
"hour": hour,
"minute": minute,
"second": second,
}
)

for key in ["year", "month", "day", "hour", "minute", "second"]:
dt_df[key] = dt_df[key].astype(int)

return pd.to_datetime(dt_df)


def lemi_position_parser(position):
"""
@@ -262,7 +267,6 @@ def __add__(self, other):
new.data = pd.concat([new.data, other.data])
return new
elif isinstance(other, pd.DataFrame):

if not other.columns != self.data.columns:
raise ValueError("DataFrame columns are not the same.")
new = LEMI424()
@@ -346,14 +350,18 @@ def end(self):
def latitude(self):
"""median latitude where data have been collected in the LEMI424 file"""
if self._has_data():

return self.data.latitude.median() * self.data.lat_hemisphere.median()
return (
self.data.latitude.median() * self.data.lat_hemisphere.median()
)

@property
def longitude(self):
"""median longitude where data have been collected in the LEMI424 file"""
if self._has_data():
return self.data.longitude.median() * self.data.lon_hemisphere.median()
return (
self.data.longitude.median()
* self.data.lon_hemisphere.median()
)

@property
def elevation(self):
@@ -474,7 +482,9 @@ def read(self, fn=None, fast=True):
freq="1000000000N",
)
if time_index.size != data.shape[0]:
raise ValueError("Missing a time stamp use read with fast=False")
raise ValueError(
"Missing a time stamp use read with fast=False"
)
data.index = time_index
self.data = data
return
@@ -516,7 +526,9 @@ def read(self, fn=None, fast=True):

self.data = pd.concat(dfs)
et = MTime().now()
self.logger.debug(f"Reading {self.fn.name} took {et - st:.2f} seconds")
self.logger.debug(
f"Reading {self.fn.name} took {et - st:.2f} seconds"
)
else:
st = MTime().now()
self.data = pd.read_csv(
@@ -544,7 +556,9 @@ def read(self, fn=None, fast=True):
index_col="date",
)
et = MTime().now()
self.logger.debug(f"Reading {self.fn.name} took {et - st:.2f} seconds")
self.logger.debug(
f"Reading {self.fn.name} took {et - st:.2f} seconds"
)

def read_metadata(self):
"""
@@ -603,7 +617,9 @@ def to_run_ts(self, fn=None, e_channels=["e1", "e2"]):
ch_list = []

for comp in (
["bx", "by", "bz"] + e_channels + ["temperature_e", "temperature_h"]
["bx", "by", "bz"]
+ e_channels
+ ["temperature_e", "temperature_h"]
):
if comp[0] in ["h", "b"]:
ch = ChannelTS("magnetic")
Binary file modified requirements_dev.txt
Binary file not shown.
8 changes: 1 addition & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -10,15 +10,9 @@
history = history_file.read()
requirements = [
"h5py",
"matplotlib",
"numpy",
"obspy",
"pandas<=1.5.3",
"pyyaml",
"scipy",
"xarray",
"mt_metadata",
"loguru",
]


@@ -58,6 +52,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/kujaku11/mth5",
version="0.4.0",
version="0.4.1",
zip_safe=False,
)

0 comments on commit f4d3b05

Please sign in to comment.