In [ ]:
from birdy import WPSClient
import os
from datetime import datetime
from wps_tools.testing import get_target_url
from netCDF4 import Dataset
from rvic.core.config import read_config
from importlib.resources import files
# Ensure we are in the working directory with access to the data
while os.path.basename(os.getcwd()) != "osprey":
os.chdir('../')
In [ ]:
# NBVAL_IGNORE_OUTPUT
url = get_target_url("osprey")
print(f"Using osprey on {url}")
Using osprey on https://marble-dev01.pcic.uvic.ca/twitcher/ows/proxy/osprey/wps
In [ ]:
osprey = WPSClient(url)
Help for individual processes can be diplayed using the ? command (ex. bird.process?).¶
In [ ]:
# NBVAL_IGNORE_OUTPUT
osprey.convert?
Signature: osprey.convert( uhs_files=None, station_file=None, domain=None, config_file=None, loglevel='INFO', ) Docstring: A simple conversion utility to provide users with the ability to convert old routing model setups into RVIC parameters. Parameters ---------- loglevel : {'CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'}string Logging level uhs_files : ComplexData:mimetype:`text/plain` Path to UHS file station_file : ComplexData:mimetype:`text/plain` Path to stations file domain : ComplexData:mimetype:`application/x-netcdf`, :mimetype:`application/x-ogc-dods` Path to CESM complaint domain file config_file : ComplexData:mimetype:`text/cfg` Path to input configuration file for Convert process Returns ------- output : ComplexData:mimetype:`application/x-netcdf` Output Netcdf File File: ~/python-sprint/py-repos/osprey/</home/quintins/.cache/pypoetry/virtualenvs/osprey-ZXncEVFc-py3.12/lib/python3.12/site-packages/birdy/client/base.py-0> Type: method
We can use the docstring to ensure we provide the appropriate parameters.¶
In [ ]:
# run convert
output = osprey.convert(
uhs_files = str((files("tests") / "data/samples/sample.uh_s2").resolve()),
station_file = str((files("tests") / "data/samples/station_file.txt").resolve()),
domain = str((files("tests") / "data/samples/sample_routing_domain.nc").resolve()),
config_file = str((files("tests") / "data/configs/convert.cfg").resolve()),
)
Use asobj=True
to get the dataset from the output file.
In [ ]:
output_data = output.get(asobj=True)[0]
Once the process has completed we can extract the results and ensure it is what we expected.¶
In [ ]:
input_config = read_config("tests/data/configs/convert.cfg")
# Expected output metadata determined from the input configuration file
expected = {
"title": "RVIC parameter file",
"year": datetime.now().strftime("%Y"),
"month": datetime.now().strftime("%b"),
"day": datetime.now().strftime("%d"),
"RvicUHFile": "unknown",
"RvicFdrFile": "unknown",
}
In [ ]:
# Metadata of the output of RVIC convert module
metadata = {
"title": output_data.title,
"year": output_data.history.split()[5],
"month": output_data.history.split()[2],
"day": output_data.history.split()[3].zfill(2),
"RvicUHFile": output_data.RvicUHFile,
"RvicFdrFile": output_data.RvicFdrFile,
}
assert metadata == expected