{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import json\n", "import logging\n", "logger = logging.getLogger(__name__)\n", "logger.setLevel(logging.DEBUG)\n", "with open('../processes/wps_matlab_processes.json') as f:\n", " processes = json.load(f)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 111 }, { "cell_type": "code", "collapsed": false, "input": [ "import pywps" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 112 }, { "cell_type": "code", "collapsed": false, "input": [ "geoformats = [\n", " {'mimeType': 'text/plain', 'encoding': 'UTF-8'},\n", " {'mimeType': 'application/xml', 'schema': 'http://schemas.opengis.net/gml/2.1.2/feature.xsd', 'encoding': 'UTF-8'},\n", " {'mimeType': 'application/json'}\n", " ]\n" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 113 }, { "cell_type": "code", "collapsed": false, "input": [ "class MatlabWPSProcess(pywps.Process.WPSProcess):\n", " def execute(self):\n", " logger.info(\"Passing everything to Matlab\")\n", " logger.debug(\"Identifier: {}\".format(self.identifier))\n", " for input in self.inputs:\n", " logger.debug(\"Input: {}=>{}\".format(input, self.getInputValue(input)))" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 120 }, { "cell_type": "code", "collapsed": false, "input": [ "wpsprocesses = []\n", "for process in processes:\n", " wpsprocess = MatlabWPSProcess(identifier=process['identifier'])\n", " for key, value in process['inputs'].items():\n", " if value['type'] in ['point', 'linestring', 'polygon', 'geometrycollection', 'multilinestring', 'multipoint', 'multipolygon']:\n", " wpsprocess.addComplexInput(identifier=key, title=key, formats=geoformats)\n", " elif '/' in value['type']:\n", " wpsprocess.addComplexInput(identifier=key, title=key, formats=[{'mimeType': value['type']}])\n", " else:\n", " logger.warn('Unexpected type for process: {}, identifier: {}, type: {}'.format(process['identifier'], key, value['type']))\n", " for key, value in process['outputs'].items():\n", " if value['type'] in ['point', 'linestring', 'polygon', 'geometrycollection', 'multilinestring', 'multipoint', 'multipolygon']:\n", " wpsprocess.addComplexOutput(identifier=key, title=key, formats=geoformats)\n", " elif '/' in value['type']:\n", " wpsprocess.addComplexOutput(identifier=key, title=key, formats=[{'mimeType': value['type']}])\n", " else:\n", " logger.warn('Unexpected type for process: {}, identifier: {}, type: {}'.format(process['identifier'], key, value['type']))\n", " wpsprocesses.append(wpsprocess)\n", " " ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 121 }, { "cell_type": "code", "collapsed": false, "input": [ "p0 = wpsprocesses[0]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 122 }, { "cell_type": "code", "collapsed": false, "input": [ "location = p0.inputs['location']\n", "location.format['mimetype']='text/plain'\n", "location.setValue({'value': 'POINT(3 1)'})\n" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 123 }, { "cell_type": "code", "collapsed": false, "input": [ "p0.execute()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "INFO:__main__:Passing everything to Matlab\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "DEBUG:__main__:Identifier: tide_analysis\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "DEBUG:__main__:Input: location=>./pywpsInputz1ApD2\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "DEBUG:__main__:Input: timeseries=>None\n" ] } ], "prompt_number": 124 }, { "cell_type": "code", "collapsed": false, "input": [ "!ls" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "matlabwps example.ipynb pywpsInput0dHFxC pywpsInputFIr7Dm pywpsInputOqR2Aw pywpsInputr_23KR pywpsInputyz6SZ4 pywpsInputz1ApD2\r\n", "matlabwps example.py\t pywpsInputc20mkW pywpsInputgwf34n pywpsInputot3bl4 pywpsInputX7SmIy pywpsInputYZdVU3 pywpsInputZvxKn6\r\n" ] } ], "prompt_number": 125 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }