Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: convert Path to str. update notebook #114

Merged
merged 5 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Configuration
APP_ROOT := $(abspath $(lastword $(MAKEFILE_LIST))/..)
APP_NAME := finch
FINCH_WPS_URL := http://localhost:5000

# end of configuration

Expand Down Expand Up @@ -105,7 +106,7 @@ test: check_conda
test-notebooks:
@echo "Running notebook-based tests"
@bash -c "curl -L https://github.com/Ouranosinc/PAVICS-e2e-workflow-tests/raw/master/notebooks/output-sanitize.cfg --output $(CURDIR)/docs/source/output_sanitize.cfg --silent"
@bash -c "FINCH_WPS_URL=$(FINCH_WPS_URL) pytest --nbval $(CURDIR)/docs/source/notebooks/ --sanitize-with $(CURDIR)/docs/source/output_sanitize.cfg --ignore $(CURDIR)/docs/source/notebooks/.ipynb_checkpoints"
@bash -c "env FINCH_WPS_URL=$(FINCH_WPS_URL) pytest --nbval --verbose $(CURDIR)/docs/source/notebooks/ --sanitize-with $(CURDIR)/docs/source/output_sanitize.cfg --ignore $(CURDIR)/docs/source/notebooks/.ipynb_checkpoints"

.PHONY: test-all
test-all:
Expand Down
197 changes: 46 additions & 151 deletions docs/source/notebooks/finch-usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Finch usage\n",
"\n",
"Finch is a WPS server for climate indicators, but also has a few utilities to facilitate data handling. To get started, first instantiate the client. "
"Finch is a WPS server for climate indicators, but also has a few utilities to facilitate data handling. To get started, first instantiate the client. Here, the client will try to connect to a local or remote finch instance, depending on whether the environment variable `FINCH_WPS_URL` is defined."
]
},
{
Expand All @@ -28,25 +28,45 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The list of available processes can be displayed using the help function, as well as details about individual processes. "
"\n",
"The list of available processes can be displayed using the magic ? command (`wps?`). Similarly, help about any individual process is available using ? or the `help` command. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"wps?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on method frost_days in module birdy.client.base:\n",
"\n",
"frost_days(tasmin=None, freq='YS') method of birdy.client.base.WPSClient instance\n",
" Number of days where daily minimum temperatures are below 0.\n",
" \n",
" Parameters\n",
" ----------\n",
" tasmin : ComplexData:mimetype:`application/x-netcdf`, :mimetype:`application/x-ogc-dods`\n",
" NetCDF Files or archive (tar/zip) containing netCDF files.\n",
" freq : {'YS', 'MS', 'QS-DEC', 'AS-JUL'}string\n",
" Resampling frequency\n",
" \n",
" Returns\n",
" -------\n",
" output_netcdf : ComplexData:mimetype:`application/x-netcdf`\n",
" The indicator values computed on the original input grid.\n",
" output_log : ComplexData:mimetype:`text/plain`\n",
" Collected logs during process run.\n",
" ref : ComplexData:mimetype:`application/metalink+xml; version=4.0`\n",
" Metalink file storing all references to output files.\n",
"\n"
]
}
],
"source": [
"wps.frost_days?"
"help(wps.frost_days)"
]
},
{
Expand All @@ -62,7 +82,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -72,145 +92,43 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ProcessSucceeded\n",
"frost_daysResponse(\n",
" output_netcdf='https://pavics.ouranos.ca/wpsoutputs/e8afbb04-42d3-11ea-9531-0242ac12000b/frost-days_SRES-A2-experiment_20460101-20650101.nc',\n",
" output_log='https://pavics.ouranos.ca/wpsoutputs/e8afbb04-42d3-11ea-9531-0242ac12000b/log.txt',\n",
" ref='https://pavics.ouranos.ca/wpsoutputs/e8afbb04-42d3-11ea-9531-0242ac12000b/input.meta4'\n",
")\n"
"Process status: ProcessSucceeded\n",
"Link to process output: http://localhost:5000/outputs/11ed156e-6897-11ea-b7ed-b052162515fb/frost-days_SRES-A2-experiment_20460101-20650101.nc\n"
]
}
],
"source": [
"print(resp.status)\n",
"out = resp.get()\n",
"print(out)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `get` method returns a `NamedTuple` object with all the WPS outputs, either as references to files or actual content. To copy the file to the local disk, you can use the `getOutput` method. "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"resp.getOutput('/tmp/out.nc')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre>&lt;xarray.Dataset&gt;\n",
"Dimensions: (lat: 6, lon: 7, time: 20)\n",
"Coordinates:\n",
" height float64 ...\n",
" * time (time) object 2046-01-01 00:00:00 ... 2065-01-01 00:00:00\n",
" * lat (lat) float64 42.68 46.39 50.1 53.81 57.52 61.23\n",
" * lon (lon) float64 281.2 285.0 288.8 292.5 296.2 300.0 303.8\n",
"Data variables:\n",
" frost_days (time, lat, lon) timedelta64[ns] ...\n",
"Attributes:\n",
" comment: Spinup: restart files from end of experiment 20...\n",
" title: MIUB model output prepared for IPCC Fourth Ass...\n",
" cmor_version: 0.96\n",
" institution: Canadian Centre for Climate Services (CCCS)\n",
" source: ECHO-G(1999): atmosphere: ECHAM4 (T30L19) with ...\n",
" contact: Canadian Centre for Climate Services\n",
" references: ECHAM4: E. Roeckner et al., 1996, The atmospher...\n",
" experiment_id: SRES A2 experiment\n",
" realization: 1\n",
" directory: /ipcc/sresa2/atm/da/\n",
" table_id: Table A2 (17 November 2004)\n",
" calendar: 360_day\n",
" project_id: IPCC Fourth Assessment\n",
" Conventions: CF-1.0\n",
" id: pcmdi.ipcc4.miub_echo_g.sresa2.run1.atm.da\n",
" history: Mon Aug 1 11:43:58 2011: ncks -4 -L 7 -d lat,4...\n",
" NCO: 4.0.9\n",
" climateindex_package_id: https://github.com/Ouranosinc/xclim\n",
" product: derived climate index\n",
" institute_id: CCCS</pre>"
],
"text/plain": [
"<xarray.Dataset>\n",
"Dimensions: (lat: 6, lon: 7, time: 20)\n",
"Coordinates:\n",
" height float64 ...\n",
" * time (time) object 2046-01-01 00:00:00 ... 2065-01-01 00:00:00\n",
" * lat (lat) float64 42.68 46.39 50.1 53.81 57.52 61.23\n",
" * lon (lon) float64 281.2 285.0 288.8 292.5 296.2 300.0 303.8\n",
"Data variables:\n",
" frost_days (time, lat, lon) timedelta64[ns] ...\n",
"Attributes:\n",
" comment: Spinup: restart files from end of experiment 20...\n",
" title: MIUB model output prepared for IPCC Fourth Ass...\n",
" cmor_version: 0.96\n",
" institution: Canadian Centre for Climate Services (CCCS)\n",
" source: ECHO-G(1999): atmosphere: ECHAM4 (T30L19) with ...\n",
" contact: Canadian Centre for Climate Services\n",
" references: ECHAM4: E. Roeckner et al., 1996, The atmospher...\n",
" experiment_id: SRES A2 experiment\n",
" realization: 1\n",
" directory: /ipcc/sresa2/atm/da/\n",
" table_id: Table A2 (17 November 2004)\n",
" calendar: 360_day\n",
" project_id: IPCC Fourth Assessment\n",
" Conventions: CF-1.0\n",
" id: pcmdi.ipcc4.miub_echo_g.sresa2.run1.atm.da\n",
" history: Mon Aug 1 11:43:58 2011: ncks -4 -L 7 -d lat,4...\n",
" NCO: 4.0.9\n",
" climateindex_package_id: https://github.com/Ouranosinc/xclim\n",
" product: derived climate index\n",
" institute_id: CCCS"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import xarray as xr\n",
"xr.open_dataset('/tmp/out.nc')"
"print(\"Process status: \", resp.status)\n",
"urls = resp.get()\n",
"print(\"Link to process output: \", urls.output_netcdf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The birdy client offers a quicker way to download and open the files automatically using `asobj=True`, as long as the file format is known to birdy. "
"The `get` method returns a `NamedTuple` object with all the WPS outputs, either as references to files or actual content. To copy the file to the local disk, you can use the `getOutput` method, but birdy's get function has a more user-friendly solution. Setting the `asobj` argument to True will directly download all the output files and return outputs as python objects. "
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"ds, log, metalink = resp.get(asobj=True)"
"out = resp.get(asobj=True)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -280,36 +198,13 @@
" institute_id: CCCS"
]
},
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Computing the output netcdf\n",
"Processing file 0 of 1\n",
"[ ] | 0% Done\n",
"[###############] | 100% Done\n",
"Processing finished successfully\n",
"\n"
]
}
],
"source": [
"# NBVAL_IGNORE_OUTPUT\n",
"print(log)"
"out.output_netcdf"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions finch/processes/wps_xclim_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def _log(message, percentage):

metalink = make_metalink_output(self, output_files)

response.outputs["output_netcdf"].file = output_files[0]
response.outputs["output_log"].file = log_file_path(self)
response.outputs["output_netcdf"].file = str(output_files[0])
response.outputs["output_log"].file = str(log_file_path(self))
response.outputs["ref"].data = metalink.xml

write_log(self, "Processing finished successfully", process_step="done")
Expand Down