{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Simple WPS Profile with optional func decorator" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pywps import ComplexInput, ComplexOutput, FORMATS, Format\n", "from pywps import Process" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "esgf_api_test_a_input = ComplexInput(\n", " 'test_a', 'Test A ESGF API Param',\n", " supported_formats=[FORMATS.JSON],\n", ")\n", "\n", "esgf_api_test_b_input = ComplexInput(\n", " 'test_b', 'Test B ESGF API Param',\n", " supported_formats=[FORMATS.JSON],\n", ")\n", "\n", "esgf_api_inputs = [esgf_api_test_a_input, esgf_api_test_b_input]\n", "\n", "\n", "def esgf_api(F):\n", " def wrapper(self):\n", " F(self)\n", " self.profile.append('ESGF-API')\n", " self.inputs.extend(esgf_api_inputs)\n", " return wrapper" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Use input parameters from esgf_api profile" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class EmuSubsetSimple(Process):\n", " def __init__(self):\n", " domain = ComplexInput(\n", " 'domain', 'domain',\n", " abstract=\"\",\n", " supported_formats=[FORMATS.JSON],\n", " min_occurs=0, max_occurs=1)\n", " inputs = [domain, ]\n", " # extend by esgf api profile\n", " inputs.extend(esgf_api_inputs)\n", " outputs = [\n", " ComplexOutput(\n", " 'output', 'Output',\n", " as_reference=True,\n", " supported_formats=[FORMATS.NETCDF], ), ]\n", " \n", " super(EmuSubsetSimple, self).__init__(\n", " self._handler,\n", " identifier='Emu.subset',\n", " title='xarray.subset',\n", " abstract=\"subset netcdf files\",\n", " version='1',\n", " inputs=inputs,\n", " outputs=outputs,\n", " store_supported=True,\n", " status_supported=True)\n", " \n", " def _handler(self, request, response):\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = EmuSubsetSimple()\n", "for inpt in p.inputs:\n", " print(inpt.title)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Use esgf_api decorator" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class EmuSubsetDecorated(Process):\n", " # use esgf_api decorator to extend wps inputs behind the scences\n", " @esgf_api \n", " def __init__(self):\n", " domain = ComplexInput(\n", " 'domain', 'domain',\n", " abstract=\"\",\n", " supported_formats=[FORMATS.JSON],\n", " min_occurs=0, max_occurs=1)\n", " inputs = [domain]\n", " outputs = [\n", " ComplexOutput(\n", " 'output', 'Output',\n", " as_reference=True,\n", " supported_formats=[FORMATS.NETCDF], ), ]\n", " \n", " super(EmuSubsetDecorated, self).__init__(\n", " self._handler,\n", " identifier='Emu.subset',\n", " title='xarray.subset',\n", " abstract=\"subset netcdf files\",\n", " version='1',\n", " inputs=inputs,\n", " outputs=outputs,\n", " store_supported=True,\n", " status_supported=True)\n", " \n", " def _handler(self, request, response):\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p = EmuSubsetDecorated()\n", "for inpt in p.inputs:\n", " print(inpt.title)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p.profile" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }