diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b9a2b52..006461b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,51 +16,73 @@ jobs: with: fetch-depth: 0 - - name: Cache Linux/macOS (x86) Conda environment - if: ${{ runner.os != 'Windows' }} - uses: actions/cache@v3 - env: - # Increase this value to reset cache if ci/environment.yml has not changed - CACHE_NUMBER: 0 - with: - path: ~/conda_pkgs_dir - key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment-py${{ matrix.python-version }}.yml') }} + # - name: Cache Linux/macOS (x86) Conda environment + # if: ${{ runner.os != 'Windows' }} + # uses: actions/cache@v3 + # env: + # # Increase this value to reset cache if ci/environment.yml has not changed + # CACHE_NUMBER: 0 + # with: + # path: ~/conda_pkgs_dir + # key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment-py${{ matrix.python-version }}.yml') }} - - name: Cache Windows Conda environment - if: ${{ runner.os == 'Windows' }} - uses: actions/cache@v3 - env: - # Increase this value to reset cache if ci/environment.yml has not changed - CACHE_NUMBER: 0 - with: - path: ~/conda_pkgs_dir - key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment-py${{ matrix.python-version }}-win.yml') }} + # - name: Cache Windows Conda environment + # if: ${{ runner.os == 'Windows' }} + # uses: actions/cache@v3 + # env: + # # Increase this value to reset cache if ci/environment.yml has not changed + # CACHE_NUMBER: 0 + # with: + # path: ~/conda_pkgs_dir + # key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('ci/environment-py${{ matrix.python-version }}-win.yml') }} - - name: Build and activate Linux/macOS Conda environment + - name: Setup Linux/macOS Micromamba Python ${{ matrix.python-version }} if: ${{ runner.os != 'Windows' }} - uses: conda-incubator/setup-miniconda@v2 + uses: mamba-org/setup-micromamba@v1 with: - miniforge-variant: Mambaforge - python-version: ${{ matrix.python-version }} - channels: conda-forge, defaults # These need to be specified to use mamba - channel-priority: true + init-shell: bash + create-args: >- + python=${{ matrix.python-version }} --channel conda-forge environment-file: ci/environment-py${{ matrix.python-version }}.yml + cache-environment: true + post-cleanup: 'all' - activate-environment: test-env-mac-unix - use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! - - - name: Build and activate Windows Conda environment + - name: Setup Windows Micromamba Python ${{ matrix.python-version }} if: ${{ runner.os == 'Windows' }} - uses: conda-incubator/setup-miniconda@v2 + uses: mamba-org/setup-micromamba@v1 with: - miniforge-variant: Mambaforge - python-version: ${{ matrix.python-version }} - channels: conda-forge, defaults # These need to be specified to use mamba - channel-priority: true + init-shell: bash + create-args: >- + python=${{ matrix.python-version }} --channel conda-forge environment-file: ci/environment-py${{ matrix.python-version }}-win.yml + cache-environment: true + post-cleanup: 'all' + + # - name: Build and activate Linux/macOS Conda environment + # if: ${{ runner.os != 'Windows' }} + # uses: conda-incubator/setup-miniconda@v2 + # with: + # miniforge-variant: Mambaforge + # python-version: ${{ matrix.python-version }} + # channels: conda-forge, defaults # These need to be specified to use mamba + # channel-priority: true + # environment-file: ci/environment-py${{ matrix.python-version }}.yml + + # activate-environment: test-env-mac-unix + # use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! + + # - name: Build and activate Windows Conda environment + # if: ${{ runner.os == 'Windows' }} + # uses: conda-incubator/setup-miniconda@v2 + # with: + # miniforge-variant: Mambaforge + # python-version: ${{ matrix.python-version }} + # channels: conda-forge, defaults # These need to be specified to use mamba + # channel-priority: true + # environment-file: ci/environment-py${{ matrix.python-version }}-win.yml - activate-environment: test-env-win - use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! + # activate-environment: test-env-win + # use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! - name: Install package in environment shell: bash -l {0} diff --git a/tests/make_test_datasets.py b/tests/make_test_datasets.py index 914af1a..5674960 100644 --- a/tests/make_test_datasets.py +++ b/tests/make_test_datasets.py @@ -54,8 +54,6 @@ def make_test_datasets(): } ) dds["profile"] = df - - ## surface drifter ## example_loc1 = ds.sel(eta_rho=20, xi_rho=10).isel(s_rho=-1) @@ -69,9 +67,7 @@ def make_test_datasets(): ) npts = len(times) - lons = np.linspace( - float(example_loc1.lon_rho), float(example_loc2.lon_rho), npts - ) + lons = np.linspace(float(example_loc1.lon_rho), float(example_loc2.lon_rho), npts) lats = [float(example_loc1.lat_rho)] * npts depths = [0] * npts @@ -95,7 +91,6 @@ def make_test_datasets(): df["salinity"] = salt dds["trajectory"] = df - ## CTD transect ## example_loc1 = ds.sel(eta_rho=20, xi_rho=10) example_loc2 = ds.sel(eta_rho=20, xi_rho=15) @@ -214,8 +209,6 @@ def make_test_datasets(): dsd["salt"] = (("date_time", "depths"), salt.T) dds["timeSeriesProfile"] = dsd - - # HF Radar example_area = ds.sel(eta_rho=slice(20, 25), xi_rho=slice(10, 15)).isel( ocean_time=0, s_rho=-1 diff --git a/tests/test_datasets.py b/tests/test_datasets.py index 99279c0..b04fcf4 100644 --- a/tests/test_datasets.py +++ b/tests/test_datasets.py @@ -4,14 +4,14 @@ from unittest import TestCase -import extract_model as em import numpy as np import pandas as pd import xarray as xr import xroms -from .make_test_datasets import make_test_datasets +import extract_model as em +from .make_test_datasets import make_test_datasets project_name = "tests" @@ -28,15 +28,14 @@ def test_timeSeries_temp(): interpolate_horizontal = True vertical_interp = False grid = None - extrap=False + extrap = False horizontal_interp_code = "delaunay" - mask=None - locstream=False - locstreamT=False - locstreamZ=False + mask = None + locstream = False + locstreamT = False + locstreamZ = False use_projection = False - - + data = dds[featuretype] lons = np.unique(data["lon"].values) lats = np.unique(data["lat"].values) @@ -45,7 +44,7 @@ def test_timeSeries_temp(): Z = None iZ = -1 iT = None - + select_kwargs = dict( longitude=lons, latitude=lats, @@ -69,11 +68,11 @@ def test_timeSeries_temp(): xgcm_grid=grid, return_info=True, ) - + dsactual, out_kwargs = em.select(ds[key_variable], **select_kwargs) if hasattr(dsactual, "chunks"): dsactual = dsactual.load() - + expname = f"tests/test_results/{featuretype}_{key_variable}_horinterp_{horizontal_interp_code}.nc" # # previously saved with: # dsactual.to_netcdf(expname) @@ -89,15 +88,14 @@ def test_timeSeries_zeta(): interpolate_horizontal = False vertical_interp = False grid = None - extrap=False + extrap = False horizontal_interp_code = "delaunay" - mask=None - locstream=False - locstreamT=False - locstreamZ=False + mask = None + locstream = False + locstreamT = False + locstreamZ = False use_projection = False - - + data = dds[featuretype] lons = data["lon"].values lats = data["lat"].values @@ -106,7 +104,7 @@ def test_timeSeries_zeta(): Z = None iZ = None iT = None - + select_kwargs = dict( longitude=lons, latitude=lats, @@ -130,11 +128,11 @@ def test_timeSeries_zeta(): xgcm_grid=grid, return_info=True, ) - + dsactual, out_kwargs = em.select(ds[key_variable], **select_kwargs) if hasattr(dsactual, "chunks"): dsactual = dsactual.load() - + expname = f"tests/test_results/{featuretype}_{key_variable}_horinterp_{interpolate_horizontal}.nc" # # previously saved with: # dsactual.to_netcdf(expname) @@ -148,31 +146,30 @@ def test_profile(): interpolate_horizontal = False vertical_interp = True ds = xroms.datasets.fetch_ROMS_example_full_grid() - ds, xgrid = xroms.roms_dataset(ds, include_cell_volume=False, include_3D_metrics=True) + ds, xgrid = xroms.roms_dataset( + ds, include_cell_volume=False, include_3D_metrics=True + ) grid = xgrid - extrap=False + extrap = False horizontal_interp_code = "delaunay" - mask=None - locstream=False - locstreamT=False - locstreamZ=False + mask = None + locstream = False + locstreamT = False + locstreamZ = False use_projection = False - - + data = dds[featuretype] lons = data["lon"].values lats = data["lat"].values if locstreamT: T = [pd.Timestamp(date) for date in data["date_time"].values] else: - T = [ - pd.Timestamp(date) for date in np.unique(data["date_time"].values) - ] + T = [pd.Timestamp(date) for date in np.unique(data["date_time"].values)] Z = data["depth"].values # Z = None iZ = None iT = None - + select_kwargs = dict( longitude=lons, latitude=lats, @@ -196,11 +193,11 @@ def test_profile(): xgcm_grid=grid, return_info=True, ) - + dsactual, out_kwargs = em.select(ds[key_variable], **select_kwargs) if hasattr(dsactual, "chunks"): dsactual = dsactual.load() - + expname = f"tests/test_results/{featuretype}_{key_variable}_horinterp_{interpolate_horizontal}.nc" # # previously saved with: # dsactual.to_netcdf(expname) @@ -214,31 +211,30 @@ def test_timeSeriesProfile(): interpolate_horizontal = False vertical_interp = True ds = xroms.datasets.fetch_ROMS_example_full_grid() - ds, xgrid = xroms.roms_dataset(ds, include_cell_volume=False, include_3D_metrics=True) + ds, xgrid = xroms.roms_dataset( + ds, include_cell_volume=False, include_3D_metrics=True + ) grid = xgrid - extrap=False + extrap = False horizontal_interp_code = "delaunay" - mask=None - locstream=False - locstreamT=False - locstreamZ=False + mask = None + locstream = False + locstreamT = False + locstreamZ = False use_projection = False - - + data = dds[featuretype] lons = data["lon"].values lats = data["lat"].values if locstreamT: T = [pd.Timestamp(date) for date in data["date_time"].values] else: - T = [ - pd.Timestamp(date) for date in np.unique(data["date_time"].values) - ] + T = [pd.Timestamp(date) for date in np.unique(data["date_time"].values)] Z = data["depths"].values # Z = None iZ = None iT = None - + select_kwargs = dict( longitude=lons, latitude=lats, @@ -262,11 +258,11 @@ def test_timeSeriesProfile(): xgcm_grid=grid, return_info=True, ) - + dsactual, out_kwargs = em.select(ds[key_variable], **select_kwargs) if hasattr(dsactual, "chunks"): dsactual = dsactual.load() - + expname = f"tests/test_results/{featuretype}_{key_variable}_horinterp_{interpolate_horizontal}.nc" # # previously saved with: # dsactual.to_netcdf(expname) @@ -281,29 +277,26 @@ def test_trajectory(): interpolate_horizontal = True vertical_interp = False grid = None - extrap=False + extrap = False horizontal_interp_code = "delaunay" - mask=None - locstream=True - locstreamT=True - locstreamZ=False + mask = None + locstream = True + locstreamT = True + locstreamZ = False use_projection = False - - + data = dds[featuretype] lons = data["lons"].values lats = data["lats"].values if locstreamT: T = [pd.Timestamp(date) for date in data["date_time"].values] else: - T = [ - pd.Timestamp(date) for date in np.unique(data["date_time"].values) - ] + T = [pd.Timestamp(date) for date in np.unique(data["date_time"].values)] # Z = np.unique(data["depth"].values) Z = None iZ = -1 iT = None - + select_kwargs = dict( longitude=lons, latitude=lats, @@ -327,11 +320,11 @@ def test_trajectory(): xgcm_grid=grid, return_info=True, ) - + dsactual, out_kwargs = em.select(ds[key_variable], **select_kwargs) if hasattr(dsactual, "chunks"): dsactual = dsactual.load() - + expname = f"tests/test_results/{featuretype}_{key_variable}_horinterp_{interpolate_horizontal}.nc" # # previously saved with: # dsactual.to_netcdf(expname) @@ -346,31 +339,30 @@ def test_trajectoryProfile(): interpolate_horizontal = True vertical_interp = True ds = xroms.datasets.fetch_ROMS_example_full_grid() - ds, xgrid = xroms.roms_dataset(ds, include_cell_volume=False, include_3D_metrics=True) + ds, xgrid = xroms.roms_dataset( + ds, include_cell_volume=False, include_3D_metrics=True + ) grid = xgrid - extrap=False + extrap = False horizontal_interp_code = "delaunay" - mask=None - locstream=True - locstreamT=True - locstreamZ=True + mask = None + locstream = True + locstreamT = True + locstreamZ = True use_projection = False - - + data = dds[featuretype] lons = data["lons"].values lats = data["lats"].values if locstreamT: T = [pd.Timestamp(date) for date in data["date_time"].values] else: - T = [ - pd.Timestamp(date) for date in np.unique(data["date_time"].values) - ] + T = [pd.Timestamp(date) for date in np.unique(data["date_time"].values)] Z = np.unique(data["depth"].values) # Z = None iZ = None iT = None - + select_kwargs = dict( longitude=lons, latitude=lats, @@ -394,11 +386,11 @@ def test_trajectoryProfile(): xgcm_grid=grid, return_info=True, ) - + dsactual, out_kwargs = em.select(ds[key_variable], **select_kwargs) if hasattr(dsactual, "chunks"): dsactual = dsactual.load() - + expname = f"tests/test_results/{featuretype}_{key_variable}_horinterp_{interpolate_horizontal}.nc" # # previously saved with: # dsactual.to_netcdf(expname) @@ -412,17 +404,18 @@ def test_grid(): interpolate_horizontal = True vertical_interp = False ds = xroms.datasets.fetch_ROMS_example_full_grid() - ds, xgrid = xroms.roms_dataset(ds, include_cell_volume=False, include_3D_metrics=False) + ds, xgrid = xroms.roms_dataset( + ds, include_cell_volume=False, include_3D_metrics=False + ) grid = None - extrap=False + extrap = False horizontal_interp_code = "xesmf" - mask=None - locstream=False - locstreamT=False - locstreamZ=False + mask = None + locstream = False + locstreamT = False + locstreamZ = False use_projection = False - - + data = dds[featuretype] lons = data["lon_rho"].values lats = data["lat_rho"].values @@ -431,7 +424,7 @@ def test_grid(): Z = None iZ = -1 iT = None - + select_kwargs = dict( longitude=lons, latitude=lats, @@ -455,19 +448,16 @@ def test_grid(): xgcm_grid=grid, return_info=True, ) - + dsactual, out_kwargs = em.select(ds[key_variable], **select_kwargs) if hasattr(dsactual, "chunks"): dsactual = dsactual.load() - + expname = f"tests/test_results/{featuretype}_{key_variable}_horinterp_{horizontal_interp_code}.nc" # # previously saved with: # dsactual.to_netcdf(expname) dsexpected = xr.open_dataset(expname) - dsexpected = dsexpected.assign_coords({"s_rho": dsexpected["s_rho"], - "ocean_time": dsexpected["ocean_time"]})[key_variable] + dsexpected = dsexpected.assign_coords( + {"s_rho": dsexpected["s_rho"], "ocean_time": dsexpected["ocean_time"]} + )[key_variable] assert dsexpected.equals(dsactual.astype(dsexpected.dtype)) - - - -