Skip to content

Commit 829a5ec

Browse files
authored
Fixed custom output command not rendering correctly. Convert config and output paths to absolute paths. (#360)
1 parent e60d704 commit 829a5ec

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ History
77
* Upgraded `owslib` to `>=0.29.1`. (PR #358)
88
* All operations that open NetCDF files or DAP links accept an `engine` argument. The default for all of these is `h5netcdf`. (PR #358)
99
* Added `pydap` as an alternate backend for opening DAP links. (PR #358)
10+
* Fixed buggy CustomOutput command
11+
* Make sure config and output paths are absolute
1012

1113
Internal changes
1214
^^^^^^^^^^^^^^^^

docs/notebooks/time_series_analysis.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"cell_type": "markdown",
6060
"metadata": {},
6161
"source": [
62-
"The base flow index needs as input arguments the link to a NetCDF file storing the stream flow time series, the name of the stream flow variable, and the frequency at which the index is computed (`YS`: yearly, `QS-DEC`: seasonally)."
62+
"The base flow index needs as input arguments a DataArray storing the stream flow time series, and the frequency at which the index is computed (`YS`: yearly, `QS-DEC`: seasonally)."
6363
]
6464
},
6565
{

ravenpy/config/commands.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class EvaluationPeriod(LineCommand):
163163
end: dt.date
164164

165165

166-
class CustomOutput(FlatCommand):
166+
class CustomOutput(LineCommand):
167167
"""
168168
Create custom output file to track a single variable, parameter or forcing function over time at a number of
169169
basins, HRUs, or across the watershed.
@@ -796,7 +796,10 @@ def from_nc(
796796
forcings.difference_update(data)
797797

798798
if len(data) == 0:
799-
raise ValueError("No data found in netCDF files.")
799+
raise ValueError(
800+
"No data found in netCDF files. Check that variable names follow CF conventions, "
801+
"or if not, provide `alt_names` mapping Raven data types to variable names."
802+
)
800803

801804
# Default Gauge name
802805
attrs["name"] = attrs.get("name", f"Gauge_{idx}")

ravenpy/config/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def nc_specs(
6060
else:
6161
raise ValueError("NetCDF file not found.")
6262

63-
if isinstance(alt_names, str):
63+
if alt_names is None:
64+
alt_names = ()
65+
elif isinstance(alt_names, str):
6466
alt_names = (alt_names,)
6567

6668
attrs = {

ravenpy/ravenpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ def run(
283283
)
284284

285285
# Confirm configdir exists
286-
configdir = Path(configdir)
286+
configdir = Path(configdir).absolute()
287287
if not configdir.exists():
288288
raise OSError("Workdir should include configuration files.")
289289

290290
# Create outputdir
291291
outputdir = Path(outputdir or "output")
292292
if not outputdir.is_absolute():
293-
outputdir = configdir / outputdir
293+
outputdir = (configdir / outputdir).absolute()
294294

295295
if overwrite and outputdir.exists():
296296
shutil.rmtree(str(outputdir))

ravenpy/utilities/coords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def units_transform(source, target, context="hydro"):
120120
context : str, optional
121121
Context of unit conversion. Default: "hydro".
122122
"""
123-
from xclim.core.units import convert_units_to, units
123+
from xclim.core.units import convert_units_to
124124

125125
b = convert_units_to(0 * source, target, context)
126126
a = convert_units_to(1 * source, target, context) - b

tests/test_commands.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@
99

1010
from ravenpy.config import commands as rc
1111
from ravenpy.config import options as o
12-
from ravenpy.config.base import RV
12+
from ravenpy.config.base import RV, optfield
1313

1414
salmon_land_hru_1 = dict(
1515
area=4250.6, elevation=843.0, latitude=54.4848, longitude=-123.3659, hru_type="land"
1616
)
1717

1818

19+
def test_custom_ouputs():
20+
class Test(RV):
21+
co: Sequence[rc.CustomOutput] = optfield(alias="CustomOutput")
22+
23+
co = rc.CustomOutput(
24+
time_per="YEARLY",
25+
stat="AVERAGE",
26+
variable="PRECIP",
27+
space_agg="ENTIRE_WATERSHED",
28+
)
29+
assert (
30+
Test(co=[co]).to_rv().strip()
31+
== ":CustomOutput YEARLY AVERAGE PRECIP ENTIRE_WATERSHED"
32+
)
33+
34+
1935
def test_evaluation_metrics():
2036
class Test(RV):
2137
em: Sequence[o.EvaluationMetrics] = Field(

0 commit comments

Comments
 (0)