-
Notifications
You must be signed in to change notification settings - Fork 10
Process creating NcML file aggregating netCDF files #97
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
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c77917f
first version of ncml test
huard 03474d3
fixed conflicts
huard d983caa
merge
huard ad7e490
fixed bugs
huard 61224ae
added test. Removed duplicate process after rename
huard 36f8f71
codacy
huard a906c5d
added process to convert file url to dap url.
huard 555e43e
added nc_to_dap to list of processes
huard 1ef269f
fix typo
huard 75fb64b
added nc_to_dap to test_caps
huard 5478c36
added support for NcML format. requires PR #515 in pywps to be merged
huard a471dad
tests for ncml pass
huard 2cac214
code quality fixes
huard 1f948a0
pep8
huard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from pywps import Process | ||
| from pywps import ComplexInput, ComplexOutput, FORMATS | ||
| from pywps.app.Common import Metadata | ||
| from pywps import configuration | ||
| import logging | ||
|
|
||
|
|
||
| LOGGER = logging.getLogger("PYWPS") | ||
|
|
||
| # This needs some more thoughts before going live to decide how the WPS server should be configured to communicate | ||
| # with the DAP server. | ||
|
|
||
|
|
||
| class NcToDap(Process): | ||
| def __init__(self): | ||
| inputs = [ | ||
| ComplexInput('resource', "NetCDF file", | ||
| abstract="Link to NetCDF or NcML file on this server", | ||
| supported_formats=[FORMATS.NETCDF, ], # FORMATS.NCML], to become available in PyWPS 4.2.5 | ||
| min_occurs=1, | ||
| max_occurs=1) | ||
| ] | ||
| outputs = [ | ||
| ComplexOutput('dap', 'DAP url', | ||
| as_reference=True, | ||
| supported_formats=[FORMATS.DODS]), | ||
| ] | ||
|
|
||
| super(NcToDap, self).__init__( | ||
| self._handler, | ||
| identifier='nc_to_dap', | ||
| title="Convert file URL to DAP URL", | ||
| abstract="Return Data Access Protocol link to a netCDF or NcML file.", | ||
| version="1", | ||
| metadata=[ | ||
| Metadata('User Guide', 'http://emu.readthedocs.io/en/latest/'), | ||
| ], | ||
| inputs=inputs, | ||
| outputs=outputs, | ||
| store_supported=True, | ||
| status_supported=True) | ||
|
|
||
| @staticmethod | ||
| def _handler(self, request, response): | ||
| url = request.inputs['resource'][0].url | ||
|
|
||
| # Write response | ||
| file_server = configuration.CONFIG.get("server", "outputurl") | ||
| dap_server = configuration.CONFIG.get("dap", "outputurl") | ||
|
|
||
| response.outputs["dap"].url = url.replace(file_server, dap_server) | ||
|
|
||
| return response | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import os | ||
| import xarray.tests.test_dataset as td | ||
| from pywps import Process | ||
| from pywps import ComplexOutput, FORMATS | ||
| from pywps.app.Common import Metadata | ||
| import logging | ||
|
|
||
|
|
||
| LOGGER = logging.getLogger("PYWPS") | ||
|
|
||
|
|
||
| class NcMLAgg(Process): | ||
| def __init__(self): | ||
| inputs = [] | ||
| outputs = [ | ||
| ComplexOutput('d1', 'NetCDF file 1', | ||
| as_reference=True, | ||
| supported_formats=[FORMATS.NETCDF]), | ||
| ComplexOutput('d2', 'NetCDF file 2', | ||
| as_reference=True, | ||
| supported_formats=[FORMATS.NETCDF]), | ||
| ComplexOutput('ncml', 'NcML aggregation', | ||
| as_reference=True, | ||
| supported_formats=[FORMATS.DODS]), # FORMATS.NCML To become available in PyWPS 4.2.5 | ||
| ] | ||
|
|
||
| super(NcMLAgg, self).__init__( | ||
| self._handler, | ||
| identifier='ncml', | ||
| title="Test NcML THREDDS capability", | ||
| abstract="Return links to an NcML file aggregating netCDF files with moving time units.", | ||
| version="1", | ||
| metadata=[ | ||
| Metadata('User Guide', 'http://emu.readthedocs.io/en/latest/'), | ||
| ], | ||
| inputs=inputs, | ||
| outputs=outputs, | ||
| store_supported=True, | ||
| status_supported=True) | ||
|
|
||
| def _handler(self, request, response): | ||
|
|
||
| # Create test datasets | ||
| d1, d2, _ = td.create_append_test_data() | ||
|
|
||
| # Save datasets to disk | ||
| d1fn = os.path.join(self.workdir, "d1.nc") | ||
| d2fn = os.path.join(self.workdir, "d2.nc") | ||
|
|
||
| d1.to_netcdf(d1fn) | ||
| d2.to_netcdf(d2fn) | ||
|
|
||
| # Create NcML aggregation | ||
| ncml = """ | ||
| <netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2"> | ||
| <aggregation dimName="time" type="joinExisting"> | ||
| <scan location="." suffix=".nc" subdirs="false"/> | ||
| </aggregation> | ||
| </netcdf> | ||
| """ | ||
|
|
||
| # Write response | ||
| response.outputs["d1"].file = d1fn | ||
| response.outputs["d2"].file = d2fn | ||
|
|
||
| response.outputs['ncml'].data = ncml | ||
|
|
||
| return response |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ click | |
| psutil | ||
| defusedxml | ||
| geomet | ||
| netCDF4 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import pytest | ||
|
|
||
| from pywps import Service | ||
| from pywps.tests import assert_response_success | ||
|
|
||
| from .common import client_for, get_output | ||
| from emu.processes.wps_nc_to_dap import NcToDap | ||
| from emu.processes.wps_output_formats import OutputFormats | ||
|
|
||
|
|
||
| @pytest.mark.skip | ||
| def test_wps_nc_to_dap(): | ||
| # Create netCDF file on server | ||
| client = client_for(Service(processes=[OutputFormats()])) | ||
| resp = client.get( | ||
| service='WPS', request='Execute', version='1.0.0', | ||
| identifier='output_formats',) | ||
| nc_url = get_output(resp.xml)['netcdf'] | ||
|
|
||
| # Convert to DAP link | ||
| client = client_for(Service(processes=[NcToDap()])) | ||
| datainputs = "resource=@xlink:href={0}".format(nc_url) | ||
| resp = client.get( | ||
| service='wps', request='execute', version='1.0.0', | ||
| identifier='nc_to_dap', | ||
| datainputs=datainputs) | ||
| assert_response_success(resp) | ||
| assert 'dodsC' in get_output(resp.xml)['dap'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import pytest | ||
|
|
||
| from pywps import Service | ||
| from pywps.tests import assert_response_success | ||
| from emu.processes.wps_ncml import NcMLAgg | ||
| from .common import client_for, CFG_FILE | ||
| from owslib.wps import WPSExecution | ||
|
|
||
|
|
||
| @pytest.mark.online | ||
| def test_wps_ncml(): | ||
|
|
||
| client = client_for(Service(processes=[NcMLAgg()], cfgfiles=CFG_FILE)) | ||
|
|
||
| resp = client.get( | ||
| service='wps', request='execute', version='1.0.0', | ||
| identifier='ncml') | ||
|
|
||
| assert_response_success(resp) | ||
|
|
||
| ex = WPSExecution() | ||
| ex.parseResponse(resp.xml) | ||
| d1, d2, d3 = ex.processOutputs | ||
| ncml = d3.retrieveData() | ||
| assert ncml.strip().startswith("<") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.