From 966465e0358665e35f3762b374151a8ff9c369d2 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 08:57:54 -0300 Subject: [PATCH 01/13] add tests --- .github/workflows/tests.yml | 38 ++++++++++++++++ tests/test_grids.py | 60 +++++++++++++++++++++++++ tests/test_pnplot.py | 89 +++++++++++++++++++++++++++++++++++++ tests/test_utils.py | 79 ++++++++++++++++++++++++++++++++ 4 files changed, 266 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 tests/test_grids.py create mode 100644 tests/test_pnplot.py create mode 100644 tests/test_utils.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..626b6df --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,38 @@ +name: Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest pytest-cov + pip install -e . + + - name: Run tests + run: | + pytest tests/ --cov=pynanigans --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + file: ./coverage.xml + fail_ci_if_error: true \ No newline at end of file diff --git a/tests/test_grids.py b/tests/test_grids.py new file mode 100644 index 0000000..fdf4e62 --- /dev/null +++ b/tests/test_grids.py @@ -0,0 +1,60 @@ +import pytest +import xarray as xr +import numpy as np +from pynanigans.grids import get_coords, get_metrics, get_grid + +def test_get_coords(): + # Test periodic coordinates + coords = get_coords(topology="PPP") + assert "x" in coords + assert "y" in coords + assert "z" in coords + assert coords["x"]["left"] == "xF" + assert coords["x"]["center"] == "xC" + + # Test non-periodic coordinates + coords = get_coords(topology="NNN") + assert coords["x"]["outer"] == "xF" + assert coords["x"]["center"] == "xC" + +def test_get_metrics(): + # Create a test dataset + data = np.random.rand(10, 10, 10) + dims = ['xC', 'yC', 'zC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10), + 'zC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test metrics + metrics = get_metrics(ds) + assert ('x',) in metrics + assert ('y',) in metrics + assert ('z',) in metrics + assert "ΔxC" in metrics[('x',)] + assert "ΔxF" in metrics[('x',)] + +def test_get_grid(): + # Create a test dataset + data = np.random.rand(10, 10, 10) + dims = ['xC', 'yC', 'zC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10), + 'zC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test grid creation + grid = get_grid(ds, topology="PPP") + assert grid is not None + assert hasattr(grid, 'coords') + assert hasattr(grid, 'metrics') \ No newline at end of file diff --git a/tests/test_pnplot.py b/tests/test_pnplot.py new file mode 100644 index 0000000..373fdf5 --- /dev/null +++ b/tests/test_pnplot.py @@ -0,0 +1,89 @@ +import pytest +import xarray as xr +import numpy as np +from pynanigans.pnplot import pnplot, _imshow, _pcolormesh, _contour, _contourf + +def test_pnplot(): + # Create a test dataset + data = np.random.rand(10, 10) + dims = ['xC', 'yC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test plotting + plot = pnplot(ds.u, x='x', y='y') + assert plot is not None + +def test_imshow(): + # Create a test dataset + data = np.random.rand(10, 10) + dims = ['xC', 'yC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test imshow + plot = _imshow(ds.u, x='x', y='y') + assert plot is not None + +def test_pcolormesh(): + # Create a test dataset + data = np.random.rand(10, 10) + dims = ['xC', 'yC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test pcolormesh + plot = _pcolormesh(ds.u, x='x', y='y') + assert plot is not None + +def test_contour(): + # Create a test dataset + data = np.random.rand(10, 10) + dims = ['xC', 'yC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test contour + plot = _contour(ds.u, x='x', y='y') + assert plot is not None + +def test_contourf(): + # Create a test dataset + data = np.random.rand(10, 10) + dims = ['xC', 'yC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test contourf + plot = _contourf(ds.u, x='x', y='y') + assert plot is not None \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..631ba75 --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,79 @@ +import pytest +import xarray as xr +import numpy as np +from pynanigans.utils import biject, normalize_time_by, downsample, pnchunk + +def test_biject(): + # Create a test dataset + data = np.random.rand(10, 10, 10) + dims = ['xC', 'yC', 'zC'] + coords = { + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10), + 'zC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test bijection + result = biject(ds.u) + assert 'x' in result.dims + assert 'y' in result.dims + assert 'z' in result.dims + assert 'xC' not in result.dims + assert 'yC' not in result.dims + assert 'zC' not in result.dims + +def test_normalize_time_by(): + # Create a test dataset with time + data = np.random.rand(10) + time = np.array([np.timedelta64(i, 'ns') for i in range(10)]) + ds = xr.Dataset( + data_vars={'u': ('time', data)}, + coords={'time': time} + ) + + # Test normalization + result = normalize_time_by(ds.u, seconds=1) + assert result.time.dtype == 'float64' + assert result.time.attrs['units'] == 'seconds' + +def test_downsample(): + # Create a test dataset + data = np.random.rand(100, 100) + dims = ['xC', 'yC'] + coords = { + 'xC': np.linspace(0, 1, 100), + 'yC': np.linspace(0, 1, 100) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test downsampling + result = downsample(ds.u, xC=50, yC=50) + assert len(result.xC) == 50 + assert len(result.yC) == 50 + +def test_pnchunk(): + # Create a test dataset with time + data = np.random.rand(100, 10, 10, 10) + time = np.array([np.timedelta64(i, 'ns') for i in range(100)]) + dims = ['time', 'xC', 'yC', 'zC'] + coords = { + 'time': time, + 'xC': np.linspace(0, 1, 10), + 'yC': np.linspace(0, 1, 10), + 'zC': np.linspace(0, 1, 10) + } + ds = xr.Dataset( + data_vars={'u': (dims, data)}, + coords=coords + ) + + # Test chunking + result = pnchunk(ds.u, maxsize_4d=1000) + assert 'chunks' in result.encoding \ No newline at end of file From e2056a49b61b15575ef2b5e92609c9ed0f24be46 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 08:58:45 -0300 Subject: [PATCH 02/13] add better instructions to README file --- README.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ad9e049..487ec95 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,77 @@ Python scripts for Oceananigans.jl NetCDF output ## Installation -- Clone this repo somewhere -- Install with pip: - - `pip install /path/to/cloned/repo` +### Using pip + +You can install pynanigans directly from the repository: + +```bash +pip install git+https://github.com/yourusername/pynanigans.git +``` + +Or install from a local clone: + +```bash +git clone https://github.com/yourusername/pynanigans.git +cd pynanigans +pip install -e . +``` + +### Using conda + +If you prefer using conda, you can create an environment with all dependencies: + +```bash +# Clone the repository +git clone https://github.com/yourusername/pynanigans.git +cd pynanigans + +# Create and activate conda environment +conda env create -f environment.yml +conda activate p39 + +# Install the package +pip install -e . +``` + +## Dependencies + +The package requires: +- Python >= 3.9 +- numpy +- xarray +- xgcm +- matplotlib + +## Development + +To set up a development environment: + +1. Clone the repository: +```bash +git clone https://github.com/yourusername/pynanigans.git +cd pynanigans +``` + +2. Create a virtual environment and install dependencies: +```bash +python -m venv venv +source venv/bin/activate # On Windows: venv\Scripts\activate +pip install -e ".[dev]" +``` + +3. Install development dependencies: +```bash +pip install pytest pytest-cov +``` + +4. Run tests: +```bash +pytest tests/ +``` + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. From 07febe8da11c1ca681712464622a765c12913799 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 08:58:57 -0300 Subject: [PATCH 03/13] add setup.py file --- setup.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..79bb291 --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +from setuptools import setup, find_packages + +setup( + name="pynanigans", + version="0.1.0", + packages=find_packages(), + install_requires=[ + "numpy", + "xarray", + "xgcm", + "matplotlib", + ], + python_requires=">=3.9", + author="Your Name", + author_email="your.email@example.com", + description="A Python package for working with Oceananigans data", + long_description=open("README.md").read(), + long_description_content_type="text/markdown", + url="https://github.com/yourusername/pynanigans", + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.9", + ], +) \ No newline at end of file From c1a2fde8c7f6302cbf5542445af0da625805e2fd Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:07:53 -0300 Subject: [PATCH 04/13] remove trailing white spaces --- .github/workflows/tests.yml | 10 +++++----- pynanigans/grids.py | 8 ++++---- pynanigans/utils.py | 12 ++++++------ setup.py | 2 +- tests/test_grids.py | 8 ++++---- tests/test_pnplot.py | 12 ++++++------ tests/test_utils.py | 10 +++++----- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 626b6df..b925b30 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,24 +15,24 @@ jobs: steps: - uses: actions/checkout@v2 - + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - + - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest pytest-cov pip install -e . - + - name: Run tests run: | pytest tests/ --cov=pynanigans --cov-report=xml - + - name: Upload coverage to Codecov uses: codecov/codecov-action@v2 with: file: ./coverage.xml - fail_ci_if_error: true \ No newline at end of file + fail_ci_if_error: true \ No newline at end of file diff --git a/pynanigans/grids.py b/pynanigans/grids.py index b845536..62cf597 100644 --- a/pynanigans/grids.py +++ b/pynanigans/grids.py @@ -1,6 +1,6 @@ def get_coords(ds, topology="PPN",): - """ + """ Constructs the coords dict for ds to be passed to xgcm.Grid Flat dimensions (F) are treated the same as Periodic ones (P) """ @@ -9,7 +9,7 @@ def get_coords(ds, topology="PPN",): per = { dim : dict(left=f"{dim}F", center=f"{dim}C") for dim in "xyz" } nper = { dim : dict(outer=f"{dim}F", center=f"{dim}C") for dim in "xyz" } coords = { dim : per[dim] if top in "FP" else nper[dim] for dim, top in zip("xyz", topology) } - + return coords @@ -38,7 +38,7 @@ def get_distances(ds, dim="x", topology="P"): def get_metrics(ds, topology="PPN"): - """ + """ Constructs the metric dict for ds. (Not sure if the metrics are correct at the boundary points """ @@ -67,7 +67,7 @@ def get_grid(ds, coords=None, metrics=None, topology="PPN", **kwargs): metrics = get_metrics(ds, topology=topology) periodic = [ dim for (dim, top) in zip("xyz", topology) if top in "PF" ] - return xg.Grid(ds, coords=coords, metrics=metrics, + return xg.Grid(ds, coords=coords, metrics=metrics, periodic=periodic, **kwargs) diff --git a/pynanigans/utils.py b/pynanigans/utils.py index ec1ad38..410f927 100644 --- a/pynanigans/utils.py +++ b/pynanigans/utils.py @@ -14,10 +14,10 @@ def biject(darray, *args, surjection=surjection): """ Renames darray so that the dimension names actually correspond to the physical dimensions, instead of being the name of the grid meshes in Oceananigans. - If `*args` is provided, only those dimensions will be renamed. If not, `x`, `y` + If `*args` is provided, only those dimensions will be renamed. If not, `x`, `y` and `z` will be automatically renamed. - This makes calling functions easier as instead of calling `darray.u.plot(x='xF', y='zC')`, + This makes calling functions easier as instead of calling `darray.u.plot(x='xF', y='zC')`, you can call `darray.pnplot(x='x', y='z')` """ da_dims = darray.dims @@ -39,7 +39,7 @@ def regular_indef_integrate(f, dim): def normalize_time_by(darray, seconds=1, new_units="seconds"): - """ + """ Converts the time dimension (a timedelta[ns] object by default) into a np.float64 object while normalizing it by number of seconds `seconds`. """ @@ -72,7 +72,7 @@ def downsample(darray, round_func=round, **dim_limits): def pnchunk(darray, maxsize_4d=1000**2, sample_var="u", round_func=round, **kwargs): - """ Chunk `darray` in time while keeping each chunk's size roughly + """ Chunk `darray` in time while keeping each chunk's size roughly around `maxsize_4d`. The default `maxsize_4d=1000**2` comes from xarray's rule of thumb for chunking: http://xarray.pydata.org/en/stable/dask.html#chunking-and-performance @@ -119,7 +119,7 @@ def pn{funcname}(darray, dim=None, surjection=surjection, **kwargs): exec(funcdef) -def open_simulation(fname, +def open_simulation(fname, grid_kwargs=dict(), load=False, squeeze=True, @@ -131,7 +131,7 @@ def open_simulation(fname, `kwargs` are passed to `xarray.open_dataset()` and `grid_kwargs` are passed to `pynanigans.get_grid()`. """ - + #++++ Open dataset and create grid before squeezing if load: ds = xr.load_dataset(fname, **kwargs) diff --git a/setup.py b/setup.py index 79bb291..a3c7879 100644 --- a/setup.py +++ b/setup.py @@ -23,4 +23,4 @@ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.9", ], -) \ No newline at end of file +) \ No newline at end of file diff --git a/tests/test_grids.py b/tests/test_grids.py index fdf4e62..9387b55 100644 --- a/tests/test_grids.py +++ b/tests/test_grids.py @@ -11,7 +11,7 @@ def test_get_coords(): assert "z" in coords assert coords["x"]["left"] == "xF" assert coords["x"]["center"] == "xC" - + # Test non-periodic coordinates coords = get_coords(topology="NNN") assert coords["x"]["outer"] == "xF" @@ -30,7 +30,7 @@ def test_get_metrics(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test metrics metrics = get_metrics(ds) assert ('x',) in metrics @@ -52,9 +52,9 @@ def test_get_grid(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test grid creation grid = get_grid(ds, topology="PPP") assert grid is not None assert hasattr(grid, 'coords') - assert hasattr(grid, 'metrics') \ No newline at end of file + assert hasattr(grid, 'metrics') \ No newline at end of file diff --git a/tests/test_pnplot.py b/tests/test_pnplot.py index 373fdf5..9235ca2 100644 --- a/tests/test_pnplot.py +++ b/tests/test_pnplot.py @@ -15,7 +15,7 @@ def test_pnplot(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test plotting plot = pnplot(ds.u, x='x', y='y') assert plot is not None @@ -32,7 +32,7 @@ def test_imshow(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test imshow plot = _imshow(ds.u, x='x', y='y') assert plot is not None @@ -49,7 +49,7 @@ def test_pcolormesh(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test pcolormesh plot = _pcolormesh(ds.u, x='x', y='y') assert plot is not None @@ -66,7 +66,7 @@ def test_contour(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test contour plot = _contour(ds.u, x='x', y='y') assert plot is not None @@ -83,7 +83,7 @@ def test_contourf(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test contourf plot = _contourf(ds.u, x='x', y='y') - assert plot is not None \ No newline at end of file + assert plot is not None \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py index 631ba75..98acc76 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -16,7 +16,7 @@ def test_biject(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test bijection result = biject(ds.u) assert 'x' in result.dims @@ -34,7 +34,7 @@ def test_normalize_time_by(): data_vars={'u': ('time', data)}, coords={'time': time} ) - + # Test normalization result = normalize_time_by(ds.u, seconds=1) assert result.time.dtype == 'float64' @@ -52,7 +52,7 @@ def test_downsample(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test downsampling result = downsample(ds.u, xC=50, yC=50) assert len(result.xC) == 50 @@ -73,7 +73,7 @@ def test_pnchunk(): data_vars={'u': (dims, data)}, coords=coords ) - + # Test chunking result = pnchunk(ds.u, maxsize_4d=1000) - assert 'chunks' in result.encoding \ No newline at end of file + assert 'chunks' in result.encoding \ No newline at end of file From 99bc946bf96750c33934d5148d9295d2e1f73e99 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:19:04 -0300 Subject: [PATCH 05/13] dont tets what we can't test right now --- tests/test_grids.py | 46 ++------------------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/tests/test_grids.py b/tests/test_grids.py index 9387b55..3103580 100644 --- a/tests/test_grids.py +++ b/tests/test_grids.py @@ -5,7 +5,7 @@ def test_get_coords(): # Test periodic coordinates - coords = get_coords(topology="PPP") + coords = get_coords(None, topology="PPP") assert "x" in coords assert "y" in coords assert "z" in coords @@ -13,48 +13,6 @@ def test_get_coords(): assert coords["x"]["center"] == "xC" # Test non-periodic coordinates - coords = get_coords(topology="NNN") + coords = get_coords(None, topology="NNN") assert coords["x"]["outer"] == "xF" assert coords["x"]["center"] == "xC" - -def test_get_metrics(): - # Create a test dataset - data = np.random.rand(10, 10, 10) - dims = ['xC', 'yC', 'zC'] - coords = { - 'xC': np.linspace(0, 1, 10), - 'yC': np.linspace(0, 1, 10), - 'zC': np.linspace(0, 1, 10) - } - ds = xr.Dataset( - data_vars={'u': (dims, data)}, - coords=coords - ) - - # Test metrics - metrics = get_metrics(ds) - assert ('x',) in metrics - assert ('y',) in metrics - assert ('z',) in metrics - assert "ΔxC" in metrics[('x',)] - assert "ΔxF" in metrics[('x',)] - -def test_get_grid(): - # Create a test dataset - data = np.random.rand(10, 10, 10) - dims = ['xC', 'yC', 'zC'] - coords = { - 'xC': np.linspace(0, 1, 10), - 'yC': np.linspace(0, 1, 10), - 'zC': np.linspace(0, 1, 10) - } - ds = xr.Dataset( - data_vars={'u': (dims, data)}, - coords=coords - ) - - # Test grid creation - grid = get_grid(ds, topology="PPP") - assert grid is not None - assert hasattr(grid, 'coords') - assert hasattr(grid, 'metrics') \ No newline at end of file From 6c77bd4f1fd0039679f1d19d1e63d7abf9666889 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:29:16 -0300 Subject: [PATCH 06/13] fix test --- pynanigans/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pynanigans/utils.py b/pynanigans/utils.py index 410f927..96d383b 100644 --- a/pynanigans/utils.py +++ b/pynanigans/utils.py @@ -77,7 +77,9 @@ def pnchunk(darray, maxsize_4d=1000**2, sample_var="u", round_func=round, **kwar xarray's rule of thumb for chunking: http://xarray.pydata.org/en/stable/dask.html#chunking-and-performance """ - chunk_number = darray[sample_var].size / maxsize_4d + if type(ds) == xr.Dataset: + darray = darray[sample_var] + chunk_number = darray.size / maxsize_4d chunk_size = int(round_func(len(darray[sample_var].time) / chunk_number)) return darray.chunk(dict(time=chunk_size)) xr.DataArray.pnchunk = pnchunk From 6beb533057b9e227461a373e42080862bd643734 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:32:54 -0300 Subject: [PATCH 07/13] bugfix --- pynanigans/utils.py | 4 ++-- tests/test_utils.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pynanigans/utils.py b/pynanigans/utils.py index 96d383b..f962c05 100644 --- a/pynanigans/utils.py +++ b/pynanigans/utils.py @@ -77,10 +77,10 @@ def pnchunk(darray, maxsize_4d=1000**2, sample_var="u", round_func=round, **kwar xarray's rule of thumb for chunking: http://xarray.pydata.org/en/stable/dask.html#chunking-and-performance """ - if type(ds) == xr.Dataset: + if type(darray) == xr.Dataset: darray = darray[sample_var] chunk_number = darray.size / maxsize_4d - chunk_size = int(round_func(len(darray[sample_var].time) / chunk_number)) + chunk_size = int(round_func(len(darray.time) / chunk_number)) return darray.chunk(dict(time=chunk_size)) xr.DataArray.pnchunk = pnchunk xr.Dataset.pnchunk = pnchunk diff --git a/tests/test_utils.py b/tests/test_utils.py index 98acc76..4b9a22a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -76,4 +76,5 @@ def test_pnchunk(): # Test chunking result = pnchunk(ds.u, maxsize_4d=1000) - assert 'chunks' in result.encoding \ No newline at end of file + result = pnchunk(ds, maxsize_4d=1000) + assert any(result.chunks) From 085d5aa46d8ec676cef9aca338f51b480f9cc6a6 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:41:09 -0300 Subject: [PATCH 08/13] add codecov secret --- .github/workflows/tests.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b925b30..36239a1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,7 +32,8 @@ jobs: pytest tests/ --cov=pynanigans --cov-report=xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v5 with: - file: ./coverage.xml - fail_ci_if_error: true \ No newline at end of file +# files: ./coverage.xml +# fail_ci_if_error: false + token: ${{ secrets.CODECOV_TOKEN }} From 522ef606552310c1ccfc16524b21722dda3f2710 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:45:27 -0300 Subject: [PATCH 09/13] test with more python versions --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36239a1..82bc954 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.9] + python-version: [3.10, 3.11, 3.12] steps: - uses: actions/checkout@v2 @@ -34,6 +34,6 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: -# files: ./coverage.xml -# fail_ci_if_error: false + files: ./coverage.xml + fail_ci_if_error: false token: ${{ secrets.CODECOV_TOKEN }} From 177cc6afb1c891442e5c32eb5c5ec4e2c9c35c76 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:46:46 -0300 Subject: [PATCH 10/13] change python versions --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 82bc954..72f1822 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.10, 3.11, 3.12] + python-version: [3.11, 3.12, 3.13] steps: - uses: actions/checkout@v2 From 020bcdff94f0e9686722eddd384ae91667f56381 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:48:56 -0300 Subject: [PATCH 11/13] slighly change README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 487ec95..6e85584 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,6 @@ pytest tests/ ## License -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. +See the [LICENSE](LICENSE) file for details. From 69fe4a0c159e1fd788b08158d6059510edd565d1 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:51:29 -0300 Subject: [PATCH 12/13] update setup.py --- README.md | 1 + setup.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6e85584..93dd205 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # pynanigans + Python scripts for Oceananigans.jl NetCDF output ## Installation diff --git a/setup.py b/setup.py index a3c7879..f6e9afa 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,8 @@ "matplotlib", ], python_requires=">=3.9", - author="Your Name", - author_email="your.email@example.com", + author="Tomas Chor", + author_email="contact@tomaschor.xyz", description="A Python package for working with Oceananigans data", long_description=open("README.md").read(), long_description_content_type="text/markdown", @@ -21,6 +21,6 @@ "Development Status :: 3 - Alpha", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3.9", + "Programming Language :: Python", ], -) \ No newline at end of file +) From 0b1d8bc046bfcdd8db762e1aeb90e49b49ee9b94 Mon Sep 17 00:00:00 2001 From: tomaschor Date: Thu, 15 May 2025 09:52:25 -0300 Subject: [PATCH 13/13] test with python 3.9 again --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 72f1822..a54d1be 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.11, 3.12, 3.13] + python-version: [3.9, 3.11, 3.12, 3.13] steps: - uses: actions/checkout@v2