|
| 1 | +import os |
| 2 | +import xarray.tests.test_dataset as td |
| 3 | +from pywps import Process |
| 4 | +from pywps import ComplexOutput, FORMATS |
| 5 | +from pywps.app.Common import Metadata |
| 6 | +import logging |
| 7 | + |
| 8 | + |
| 9 | +LOGGER = logging.getLogger("PYWPS") |
| 10 | + |
| 11 | + |
| 12 | +class NcMLAgg(Process): |
| 13 | + def __init__(self): |
| 14 | + inputs = [] |
| 15 | + outputs = [ |
| 16 | + ComplexOutput('d1', 'NetCDF file 1', |
| 17 | + as_reference=True, |
| 18 | + supported_formats=[FORMATS.NETCDF]), |
| 19 | + ComplexOutput('d2', 'NetCDF file 2', |
| 20 | + as_reference=True, |
| 21 | + supported_formats=[FORMATS.NETCDF]), |
| 22 | + ComplexOutput('ncml', 'NcML aggregation', |
| 23 | + as_reference=True, |
| 24 | + supported_formats=[FORMATS.DODS]), # FORMATS.NCML To become available in PyWPS 4.2.5 |
| 25 | + ] |
| 26 | + |
| 27 | + super(NcMLAgg, self).__init__( |
| 28 | + self._handler, |
| 29 | + identifier='ncml', |
| 30 | + title="Test NcML THREDDS capability", |
| 31 | + abstract="Return links to an NcML file aggregating netCDF files with moving time units.", |
| 32 | + version="1", |
| 33 | + metadata=[ |
| 34 | + Metadata('User Guide', 'http://emu.readthedocs.io/en/latest/'), |
| 35 | + ], |
| 36 | + inputs=inputs, |
| 37 | + outputs=outputs, |
| 38 | + store_supported=True, |
| 39 | + status_supported=True) |
| 40 | + |
| 41 | + def _handler(self, request, response): |
| 42 | + |
| 43 | + # Create test datasets |
| 44 | + d1, d2, _ = td.create_append_test_data() |
| 45 | + |
| 46 | + # Save datasets to disk |
| 47 | + d1fn = os.path.join(self.workdir, "d1.nc") |
| 48 | + d2fn = os.path.join(self.workdir, "d2.nc") |
| 49 | + |
| 50 | + d1.to_netcdf(d1fn) |
| 51 | + d2.to_netcdf(d2fn) |
| 52 | + |
| 53 | + # Create NcML aggregation |
| 54 | + ncml = """ |
| 55 | + <netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"> |
| 56 | + <aggregation dimName="time" type="joinExisting"> |
| 57 | + <scan location="." suffix=".nc" subdirs="false"/> |
| 58 | + </aggregation> |
| 59 | + </netcdf> |
| 60 | + """ |
| 61 | + |
| 62 | + # Write response |
| 63 | + response.outputs["d1"].file = d1fn |
| 64 | + response.outputs["d2"].file = d2fn |
| 65 | + |
| 66 | + response.outputs['ncml'].data = ncml |
| 67 | + |
| 68 | + return response |
0 commit comments