Skip to content

Commit

Permalink
coords_size and range methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadtourei committed Mar 27, 2024
1 parent 2da1e43 commit 62ee497
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion dascore/core/coordmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def shape(self):

@property
def size(self):
"""Return the shape of the dimensions."""
"""Return the size of the patch data matrix."""
return np.prod(self.shape)

def validate_data(self, data):
Expand Down Expand Up @@ -945,6 +945,24 @@ def get_array(self, coord_name) -> np.ndarray:
"""Return the coordinate values as a numpy array."""
return np.array(self.get_coord(coord_name))

def coords_size(self, coord_name):
"""Return the coordinate size."""
# a better name for this function? (size is already taken)
# returning self.shape[self.coord_name] would be more efficient since
# we have already defined shape as a property?
return len(self.get_coord(coord_name))

Check warning on line 953 in dascore/core/coordmanager.py

View check run for this annotation

Codecov / codecov/patch

dascore/core/coordmanager.py#L953

Added line #L953 was not covered by tests

def range(self, coord_name):
"""Return the coordinate scaler value (e.g., number of seconds)."""
# not sure if we want to go with the "range" name.
if coord_name == "time":
sampling_interval = self.attrs["time_step"] / np.timedelta64(1, "s")
sec_max = self.attrs["time_max"] / np.timedelta64(1, "s")
sec_min = self.attrs["time_min"] / np.timedelta64(1, "s")
return sec_max - sec_min + sampling_interval

Check warning on line 962 in dascore/core/coordmanager.py

View check run for this annotation

Codecov / codecov/patch

dascore/core/coordmanager.py#L958-L962

Added lines #L958 - L962 were not covered by tests
else:
return self.coords_size(coord_name)

Check warning on line 964 in dascore/core/coordmanager.py

View check run for this annotation

Codecov / codecov/patch

dascore/core/coordmanager.py#L964

Added line #L964 was not covered by tests


def get_coord_manager(
coords: Mapping[str, BaseCoord | np.ndarray] | CoordManager | None = None,
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/patch.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ A single file can be loaded like this:
import dascore as dc
from dascore.utils.downloader import fetch
# first we download an example data file. You can replace
# this with the path to your file.
# here we download an example data file. You can replace
# the next line with the path to your file.
path = fetch("terra15_das_1_trimmed.hdf5")
# then we get the first patch in the spool
Expand Down

0 comments on commit 62ee497

Please sign in to comment.