Skip to content

Commit

Permalink
Merge pull request #29 from NOAA-PSL/hotfix-indextest
Browse files Browse the repository at this point in the history
dap error so remove loading from dap
  • Loading branch information
chiaweh2 authored May 1, 2024
2 parents aa18d32 + ec76eda commit 757ad27
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tests/test_mom6_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
The location option is implemented due to the conftest.py
"""

import pytest
import numpy as np
from mom6.mom6_module import mom6_indexes
from mom6.mom6_module.mom6_io import MOM6Historical
Expand All @@ -33,25 +33,25 @@ def test_gulf_stream_index(location):
ds_test = MOM6Historical('ssh','hist_run/','static/','raw',location).get_all()
ds_test = ds_test.rename({'geolon':'lon','geolat':'lat'})
elif location == 'opendap':
ds_test = MOM6Historical('ssh','hist_run/','static/','raw',location).get_all()
ds_test = ds_test.isel(time=slice(0,24)).load()
ds_test = ds_test.rename({'geolon':'lon','geolat':'lat'})
try:
ds_test = MOM6Historical(var='ssh',source=location).get_all()
except OSError :
pytest.fail('OSError is raised when access OPeNDAP data')
else :
raise ValueError(
f'the input --location={location} '+
'does not exist. Please put "local" or "opendap".'
)

mom_gfi = mom6_indexes.GulfStreamIndex(ds_test,'ssh')
ds_gs = mom_gfi.generate_index()

if location == 'local':
mom_gfi = mom6_indexes.GulfStreamIndex(ds_test,'ssh')
ds_gs = mom_gfi.generate_index()
# whole dataset examination
assert np.abs(np.abs(ds_gs.gulf_stream_index).sum().compute().data - 264.06818) < 1e-5
assert np.abs(ds_gs.gulf_stream_index.max().compute().data - 2.5614245) < 1e-6
assert np.abs(ds_gs.gulf_stream_index.min().compute().data - -2.5407326) < 1e-6
elif location == 'opendap':
# only two years of data
assert np.abs(np.abs(ds_gs.gulf_stream_index).sum().compute().data - 20.642387) < 1e-5
assert np.abs(ds_gs.gulf_stream_index.max().compute().data - 1.7084963) < 1e-6
assert np.abs(ds_gs.gulf_stream_index.min().compute().data - -1.7084963) < 1e-6

# elif location == 'opendap':
# # only two years of data
# assert np.abs(np.abs(ds_gs.gulf_stream_index).sum().compute().data - 20.642387) < 1e-5
# assert np.abs(ds_gs.gulf_stream_index.max().compute().data - 1.7084963) < 1e-6
# assert np.abs(ds_gs.gulf_stream_index.min().compute().data - -1.7084963) < 1e-6

0 comments on commit 757ad27

Please sign in to comment.