From 2d400db97c1e0f863519b8a6d3c835cb02612d91 Mon Sep 17 00:00:00 2001 From: rsignell-usgs Date: Fri, 18 Dec 2015 17:33:20 -0500 Subject: [PATCH 1/2] added display attribute --- yaml2ncml.egg-info/PKG-INFO | 141 ++++++++++++++++++++++++ yaml2ncml.egg-info/SOURCES.txt | 14 +++ yaml2ncml.egg-info/dependency_links.txt | 1 + yaml2ncml.egg-info/entry_points.txt | 3 + yaml2ncml.egg-info/not-zip-safe | 1 + yaml2ncml.egg-info/requires.txt | 3 + yaml2ncml.egg-info/top_level.txt | 1 + yaml2ncml/yaml2ncml.py | 76 +++++++++---- 8 files changed, 220 insertions(+), 20 deletions(-) create mode 100644 yaml2ncml.egg-info/PKG-INFO create mode 100644 yaml2ncml.egg-info/SOURCES.txt create mode 100644 yaml2ncml.egg-info/dependency_links.txt create mode 100644 yaml2ncml.egg-info/entry_points.txt create mode 100644 yaml2ncml.egg-info/not-zip-safe create mode 100644 yaml2ncml.egg-info/requires.txt create mode 100644 yaml2ncml.egg-info/top_level.txt diff --git a/yaml2ncml.egg-info/PKG-INFO b/yaml2ncml.egg-info/PKG-INFO new file mode 100644 index 0000000..fea3b08 --- /dev/null +++ b/yaml2ncml.egg-info/PKG-INFO @@ -0,0 +1,141 @@ +Metadata-Version: 1.1 +Name: yaml2ncml +Version: 0.1.0 +Summary: ncML aggregation from YAML specifications +Home-page: https://github.com/rsignell-usgs/yaml2ncml +Author: Rich Signell +Author-email: rsignell@usgs.gov +License: The MIT License (MIT) + +Copyright (c) 2015 Richard Signell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +Description: yaml2ncml + ========= + + NcML aggregation from YAML specifications. + + ``yaml2ncml`` is a command line tool to facilitate the creation of + `NcML + aggregation `__ + file for THREDDS servers. + + Install it using pip or conda. + + .. code:: bash + + pip install yaml2ncml + # or + conda install -c https://conda.binstar.org/ioos yaml2ncml + + The user must create a YAML config file (see the example below) and run: + + .. code:: bash + + yaml2ncml roms.yaml + + # or save the output + + yaml2ncml roms.yaml --output roms_aggregation.ncml + + roms.yaml + --------- + + .. code:: yaml + + dataset: + id: "USGS_COAWST_MVCO_CBLAST_Ripples_SWAN_40m" + + title: "USGS-CMG-COAWST Model: CBLAST2007 Ripples with SWAN-40m res" + + summary: "Simulation of hydrodynamics and bottom stress south of Marthas Vineyard, MA using the COAWST modeling system. These results are from the 40m inner nest of a four-level nested simulation." + + project: + - CMG_Portal + - Sandy_Portal + + creator: + email: nganju@usgs.gov + name: Neil Ganju + url: http://water.usgs.gov/fluxes + + publisher: + email: tkalra@usgs.gov + name: Tarandeep Kalra + url: http://www.usgs.gov + + contributor: + role: advisor + email: rsignell@usgs.gov + name: Rich Signell + url: http://profile.usgs.gov/rsignell + + + license: "The data may be used and redistributed for free but is not intended for legal use, since it may contain inaccuracies. Neither the data Contributor, nor the United States Government, nor any of their employees or contractors, makes any warranty, express or implied, including warranties of merchantability and fitness for a particular purpose, or assumes any legal liability for the accuracy, completeness, or usefulness, of this information." + + references: + - http://www.whoi.edu/science/AOPE/dept/CBLASTmain.html + - http://water.usgs.gov/fluxes/mvco.html + - doi:10.1029/2011JC007035 + + acknowledgements: + - USGS-CMGP + - NSF + + variables: + include: + - temp + - salt + + exclude: + - ubar + - vbar + + aggregation: + time_var: ocean_time + dir: Output + sample_file: test_nc4_0001.nc + pattern: .*test_nc4_[0-9]{4}\.nc$ + + + Notes on the YAML file: + + 1. The aggregation `dir:` is the directory where the data (e.g. NetCDF files) are located, relative to the directory where the NcML will be. In the above example, the NetCDF files are located in a subdirectory called "Output". If the NetCDF files will be in the same directory as the NcML file, specify `dir: '.'`. + + 2. Specify that all variables should appear in the aggregation (none excluded) like this: + + .. code:: yaml + + variables: + include: + - All + + exclude: + - None + + * First version + +Keywords: YAML,ncml +Platform: UNKNOWN +Classifier: Development Status :: 4 - Beta +Classifier: Programming Language :: Python :: 2.7 +Classifier: Programming Language :: Python :: 3.4 +Classifier: License :: OSI Approved :: MIT License diff --git a/yaml2ncml.egg-info/SOURCES.txt b/yaml2ncml.egg-info/SOURCES.txt new file mode 100644 index 0000000..7e0f727 --- /dev/null +++ b/yaml2ncml.egg-info/SOURCES.txt @@ -0,0 +1,14 @@ +CHANGES.txt +LICENSE.txt +MANIFEST.in +README.rst +requirements.txt +yaml2ncml/__init__.py +yaml2ncml/yaml2ncml.py +yaml2ncml.egg-info/PKG-INFO +yaml2ncml.egg-info/SOURCES.txt +yaml2ncml.egg-info/dependency_links.txt +yaml2ncml.egg-info/entry_points.txt +yaml2ncml.egg-info/not-zip-safe +yaml2ncml.egg-info/requires.txt +yaml2ncml.egg-info/top_level.txt \ No newline at end of file diff --git a/yaml2ncml.egg-info/dependency_links.txt b/yaml2ncml.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/yaml2ncml.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/yaml2ncml.egg-info/entry_points.txt b/yaml2ncml.egg-info/entry_points.txt new file mode 100644 index 0000000..5700cb5 --- /dev/null +++ b/yaml2ncml.egg-info/entry_points.txt @@ -0,0 +1,3 @@ +[console_scripts] +yaml2ncml = yaml2ncml.yaml2ncml:main + diff --git a/yaml2ncml.egg-info/not-zip-safe b/yaml2ncml.egg-info/not-zip-safe new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/yaml2ncml.egg-info/not-zip-safe @@ -0,0 +1 @@ + diff --git a/yaml2ncml.egg-info/requires.txt b/yaml2ncml.egg-info/requires.txt new file mode 100644 index 0000000..58fb62a --- /dev/null +++ b/yaml2ncml.egg-info/requires.txt @@ -0,0 +1,3 @@ +PyYAML +docopt +netCDF4 diff --git a/yaml2ncml.egg-info/top_level.txt b/yaml2ncml.egg-info/top_level.txt new file mode 100644 index 0000000..c9fc608 --- /dev/null +++ b/yaml2ncml.egg-info/top_level.txt @@ -0,0 +1 @@ +yaml2ncml diff --git a/yaml2ncml/yaml2ncml.py b/yaml2ncml/yaml2ncml.py index 316dd02..f3db429 100644 --- a/yaml2ncml/yaml2ncml.py +++ b/yaml2ncml/yaml2ncml.py @@ -84,32 +84,50 @@ def add_var_atts(text, a): # Get a list of all variables more than 1D. vars = [var for var, vart in ncv.items() if vart.ndim > 1] + + +# identify all the rho, u and v vars + + rho_vars = [var for var in vars if 'eta_rho' in + vart.dimensions and 'xi_rho' in vart.dimensions] + u_vars = [var for var in vars if 'eta_u' in + vart.dimensions and 'xi_u' in vart.dimensions] + v_vars = [var for var in vars if 'eta_v' in + vart.dimensions and 'xi_v' in vart.dimensions] + + vars_all = set(vars) vars_include = set(a['variables']['include']) vars_exclude = set(a['variables']['exclude']) - if a['variables']['exclude']: - vars = list(vars_all - vars_all.intersection(vars_exclude)) + +# include/exclude only variables that actually occur in variable list + + vars_include = vars_all.intersection(vars_include) + vars_exclude = vars_all.intersection(vars_exclude) + + + +# If there are variables excluded, exclude them and keep all rest. +# If no variables are excluded, take just the included variables +# If no variables are included or excluded, take all variables (leave +# list of variables unchanged) + + if vars_exclude: + vars_display = vars_all - vars_all.intersection(vars_exclude) else: - if a['variables']['include']: - vars = list(vars_all.intersection(vars_include)) - rho_vars = [var for var, vart in ncv.items() if 'eta_rho' in - vart.dimensions and 'xi_rho' in vart.dimensions] - u_vars = [var for var, vart in ncv.items() if 'eta_u' in - vart.dimensions and 'xi_u' in vart.dimensions] - v_vars = [var for var, vart in ncv.items() if 'eta_v' in - vart.dimensions and 'xi_v' in vart.dimensions] + if vars_include: + vars_display = vars_all.intersection(vars_include) + else: + vars_display = vars_all -# write standard_name for time coordinate variable - var = 'ocean_time' - if var in ncv.keys(): - try: - text += '\n\n'.format(var) - text += str_att('standard_name',cf[var]) - text += '\n\n' - except: - pass - +# remove some variables we never want (if they exist) + Tobc = set(['Tobc_in', 'Tobc_out']) + vars_display = vars_display - vars_display.intersection(Tobc) + vars_display = list(vars_display) + print vars_display + +# add the variable attributes: S-grid stuff, display=T|F, ... for var in vars: text += '\n'.format(var) try: @@ -117,6 +135,12 @@ def add_var_atts(text, a): except: pass text += str_att('grid','grid') + + if var in vars_display: + text += str_att('display','True') + else: + text += str_att('display','False') + text += str_att('content_coverage_type','modelResult') if var in rho_vars: text += str_att('location','face') @@ -125,6 +149,18 @@ def add_var_atts(text, a): elif var in v_vars: text += str_att('location','edge2') text += '\n\n' + +# write standard_name for time coordinate variable + var = 'ocean_time' + if var in ncv.keys(): + try: + text += '\n\n'.format(var) + text += str_att('standard_name',cf[var]) + text += '\n\n' + except: + pass + + return text def write_grid_var(text): From 5df8b913f0cc5b2fcd3cecbd90377081f2b2aaae Mon Sep 17 00:00:00 2001 From: rsignell-usgs Date: Fri, 18 Dec 2015 17:42:04 -0500 Subject: [PATCH 2/2] removed print --- .gitignore | 2 + yaml2ncml/tests/test6.ncml | 267 ++++++++++++++++++++++++------------- yaml2ncml/yaml2ncml.py | 1 - 3 files changed, 179 insertions(+), 91 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..52e4e61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.pyo diff --git a/yaml2ncml/tests/test6.ncml b/yaml2ncml/tests/test6.ncml index 4ed8e7d..94bab1e 100644 --- a/yaml2ncml/tests/test6.ncml +++ b/yaml2ncml/tests/test6.ncml @@ -19,422 +19,509 @@ + + + + + + - - + + + + + + - + + - + - + + - + + - + + - + + - + - + + - + + - + + - + + - + + - + - + + + - + + + - + + - + + - + - - + + - + + - + + - + + - + + - + + - + + - + + - + + + - + + - + + - + + - + + - + + - - + + - + + - + + - + + - + + - + + - + + - + + - + + - + - + + - + - + + - + - + + - + + + - + + - + + - + - + + - + + - + + - + - + + - + - + + - + + - + - + + + - + + - - + + - + + - + + - + - + + - + + - + + - + - + + - + + - + + - - + + + - + - - + + - + - + + + - - + + + - + + + - + + + - + + + + + + + + diff --git a/yaml2ncml/yaml2ncml.py b/yaml2ncml/yaml2ncml.py index f3db429..4eefd48 100644 --- a/yaml2ncml/yaml2ncml.py +++ b/yaml2ncml/yaml2ncml.py @@ -125,7 +125,6 @@ def add_var_atts(text, a): vars_display = vars_display - vars_display.intersection(Tobc) vars_display = list(vars_display) - print vars_display # add the variable attributes: S-grid stuff, display=T|F, ... for var in vars: