Skip to content

Commit

Permalink
Modification of masking using regionmask 3D instead of 2D (#144)
Browse files Browse the repository at this point in the history
Modification of regions2D masking function using regionmask's 3D mask function instead of it's 2D function, and subsequent modifications to the 2d-to-3d and 3d-to-2d helper API functions.

Additionally, modified setup to more closely match that of Echopype.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Wu-Jung Lee <[email protected]>
Co-authored-by: Don Setiawan <[email protected]>
  • Loading branch information
4 people authored Oct 2, 2023
1 parent ae1e8c2 commit b7d67d0
Show file tree
Hide file tree
Showing 21 changed files with 755 additions and 460 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
# Check for updates once a week
interval: 'weekly'
104 changes: 104 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Publish archives to PyPI and TestPyPI using GitHub Actions
name: Publish to PyPI
on: [workflow_dispatch]
jobs:

build-artifact:

name: Build echoregions package
runs-on: ubuntu-20.04
if: github.repository == 'OSOceanAcoustics/echoregions'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# fetch all history so that setuptools-scm works
fetch-depth: 0

- name: Set up Python
uses: actions/[email protected]
with:
python-version: 3.9

- name: Install dependencies
run: python -m pip install setuptools wheel

# This step is only necessary for testing purposes and for TestPyPI
- name: Fix up version string for TestPyPI
if: ${{ !startsWith(github.ref, 'refs/tags') }}
run: |
# Change setuptools-scm local_scheme to "no-local-version" so the
# local part of the version isn't included, making the version string
# compatible with PyPI.
sed --in-place "s/node-and-date/no-local-version/g" pyproject.toml
- name: Build source and wheel distributions
run: |
python setup.py sdist bdist_wheel
echo ""
echo "Generated files:"
ls -lh dist/
- uses: actions/upload-artifact@v3
with:
name: releases
path: dist

test-built-dist:

name: Test echoregions package
needs: build-artifact
runs-on: ubuntu-20.04
permissions:
contents: read
id-token: write
steps:
- uses: actions/[email protected]
name: Install Python
with:
python-version: 3.9
- uses: actions/download-artifact@v3
with:
name: releases
path: dist

- name: List contents of built dist
run: |
ls -ltrh
ls -ltrh dist
- name: Publish to Test PyPI
uses: pypa/[email protected]
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
skip-existing: true

- name: Check pypi packages
run: |
sleep 3
python -m pip install --upgrade pip
echo "=== Testing wheel file ==="
# Install wheel to get dependencies and check import
python -m pip install --extra-index-url https://test.pypi.org/simple --upgrade --pre echoregions
python -c "import echoregions;"
echo "=== Done testing wheel file ==="
echo "=== Testing source tar file ==="
# Install tar gz and check import
python -m pip uninstall --yes echoregions
python -m pip install --extra-index-url https://test.pypi.org/simple --upgrade --pre --no-binary=:all: echoregions
python -c "import echoregions;"
echo "=== Done testing source tar file ==="
publish-pypi:
name: Push echoregions to production pypi
needs: test-built-dist
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: releases
path: dist
- name: Publish to PyPI
uses: pypa/[email protected]
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ repos:
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions _echoregions_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.1.dev348+ga480450.d20231002"
4 changes: 3 additions & 1 deletion echoregions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
that contain the majority of the functionality within echoregions.
"""

from _echoregions_version import version as __version__ # noqa

from .core import read_evl, read_evr
from .utils.api import convert_mask_2d_to_3d, convert_mask_3d_to_2d

__all__ = ["read_evl", "read_evr", "convert_mask_2d_to_3d", "convert_mask_3d_to_2d"]
__all__ = ["read_evl", "read_evr", "convert_mask_2d_to_3d", "convert_mask_3d_to_2d"] # noqa
8 changes: 3 additions & 5 deletions echoregions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
from .regions2d.regions2d import Regions2D


def read_evr(
filepath: str, min_depth: float = None, max_depth: float = None
) -> Regions2D:
def read_evr(filepath: str, min_depth: float = 0.0, max_depth: float = 1000.0) -> Regions2D:
"""Read an EVR file into a Regions2D object.
Parameters
----------
filepath : str, Path object
A valid path to an EVR file
min_depth : float, default ``None``
min_depth : float, default 0
Depth value in meters to set -9999.99 depth edges to.
max_depth : float, default ``None``
max_depth : float, default 1000
Depth value in meters to set 9999.99 depth edges to.
Returns
Expand Down
19 changes: 5 additions & 14 deletions echoregions/lines/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def __init__(self, input_file: str, nan_depth_value: float = None):
self.data = parse_line_file(input_file)
self.output_file = []

self._nan_depth_value = (
None # Set to replace -10000.99 depth values with (EVL only)
)
self._nan_depth_value = None # Set to replace -10000.99 depth values with (EVL only)
self._nan_depth_value = nan_depth_value

def __iter__(self) -> Iterable:
Expand Down Expand Up @@ -67,9 +65,7 @@ def to_csv(self, save_path: bool = None) -> None:
path to save the CSV file to
"""
# Check if the save directory is safe
save_path = validate_path(
save_path=save_path, input_file=self.input_file, ext=".csv"
)
save_path = validate_path(save_path=save_path, input_file=self.input_file, ext=".csv")
# Reorder columns and export to csv
self.data.to_csv(save_path, index=False)
self.output_file.append(save_path)
Expand All @@ -88,9 +84,7 @@ def to_json(self, save_path: str = None, pretty: bool = True, **kwargs) -> None:
keyword arguments passed into `parse_file`
"""
# Check if the save directory is safe
save_path = validate_path(
save_path=save_path, input_file=self.input_file, ext=".json"
)
save_path = validate_path(save_path=save_path, input_file=self.input_file, ext=".json")
indent = 4 if pretty else None

# Save the entire parsed EVR dictionary as a JSON file
Expand Down Expand Up @@ -176,8 +170,7 @@ def mask(self, da_Sv: DataArray, method: str = "nearest", limit_area: str = None

if not isinstance(da_Sv, DataArray):
raise TypeError(
"Input da_Sv must be of type DataArray. da_Sv was instead"
f" of type {type(da_Sv)}"
"Input da_Sv must be of type DataArray. da_Sv was instead" f" of type {type(da_Sv)}"
)

def filter_bottom(bottom, start_date, end_date):
Expand Down Expand Up @@ -264,9 +257,7 @@ def filter_bottom(bottom, start_date, end_date):
print(e)

# convert to data array for bottom
bottom_da = bottom_interpolated[
"depth"
].to_xarray() # .rename({'index':'ping_time'})
bottom_da = bottom_interpolated["depth"].to_xarray() # .rename({'index':'ping_time'})
bottom_da = bottom_da.rename({"time": "ping_time"})

# create a data array of depths
Expand Down
Loading

0 comments on commit b7d67d0

Please sign in to comment.