Skip to content

Commit

Permalink
Merge pull request #56 from CSHS-CWRA/fix-55
Browse files Browse the repository at this point in the history
Added simple test with DAP link to demo failure
  • Loading branch information
huard authored Apr 8, 2021
2 parents a3d5a3c + 2e229c3 commit f369c29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ravenpy/models/importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,13 @@ def _check_gridcell_in_proximity_of_shape(

class NcDataImporter:
def __init__(self, fns):
self.fns = map(Path, fns)
self.fns = fns
self.attrs = {}
self._extract_nc_attrs(self.fns)

def _extract_nc_attrs(self, fns):
for fn in fns:
if ".nc" in fn.suffix:
if Path(fn).suffix.startswith(".nc"):
with xr.open_dataset(fn) as ds:
# Check if any alternate variable name is in the file.
for var, alt_names in rv.alternate_nc_names.items():
Expand Down
23 changes: 22 additions & 1 deletion tests/test_emulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import os
import tempfile
import zipfile
from dataclasses import replace
from pathlib import Path

import numpy as np
import pytest
import xarray as xr
from dataclasses import replace

from ravenpy.models import (
GR4JCN,
Expand Down Expand Up @@ -44,6 +44,9 @@
"raven-gr4j-cemaneige/Salmon-River-Near-Prince-George_meteo_daily.nc"
)

# Link to THREDDS Data Server netCDF testdata
TDS = "https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/testdata/raven"


@pytest.fixture
def input2d(tmpdir):
Expand Down Expand Up @@ -647,6 +650,24 @@ def test_parallel_basins(self, input2d):
z = zipfile.ZipFile(model.outputs["rv_config"])
assert len(z.filelist) == 10

@pytest.mark.online
def test_dap(self):
"""Test Raven with DAP link instead of local netCDF file."""
model = GR4JCN()
config = dict(
start_date=dt.datetime(2000, 1, 1),
end_date=dt.datetime(2002, 1, 1),
run_name="test",
name="Salmon",
hrus=(GR4JCN.LandHRU(**salmon_land_hru_1),),
params=model.params(0.529, -3.396, 407.29, 1.072, 16.9, 0.947),
)

ts = (
f"{TDS}/raven-gr4j-cemaneige/Salmon-River-Near-Prince-George_meteo_daily.nc"
)
model(ts, **config)


class TestGR4JCN_OST:
def test_simple(self):
Expand Down

0 comments on commit f369c29

Please sign in to comment.