source: lmdz_wrf/trunk/tools/nc_var.py @ 1489

Last change on this file since 1489 was 1484, checked in by lfita, 8 years ago

Adding:

`lonlat_polygon': Function to define a lon/lat region giving the coordinates of the vertexs of a given polygon

  • Property svn:executable set to *
File size: 28.7 KB
Line 
1#!/usr/bin/python
2# Python to manage netCDF files.
3# From L. Fita work in different places: CCRC (Australia), LMD (France)
4# More information at: http://www.xn--llusfb-5va.cat/python/PyNCplot
5#
6# pyNCplot and its component nc_var.py comes with ABSOLUTELY NO WARRANTY.
7# This work is licendes under a Creative Commons
8#   Attribution-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-sa/4.0)
9#
10
11## e.g. # nc_var.py -o lonlat_polygon -f wrfout_d01_1995-01-01_00:00:00 -S star.dat -v XLONG,XLAT
12
13## e.g. ccrc468-17 # ./nc_var.py -v time -f 123/CCRC_NARCliM_Sydney_All_1990-1999_pr10max.nc -o out -S 1:-1
14## e.g. ccrc468-17 # ./nc_var.py -v prac -f xyz/CCRC_NARCliM_Sydney_DAM_1990-1999_prac.nc -o mname -S pluja
15## e.g. ccrc468-17 # ./nc_var.py -v lluis -f CCRC_NARCliM_Sydney_MOM_1990-1999_prac.nc -o addref -S 'prac:standard_name@lluis_variable:long_name@test variable lluis:units@m s-1:0.'
16## e.g. ccrc468-17 # ./nc_var.py -v lluis66 -f ~/UNSW-CCRC-WRF/tools/python/CCRC_NARCliM_Sydney_MOM_1990-1999_prac.nc -o addattr -S 'comment|Lluis Fita-123456'
17## e.g. ccrc468-17 # ./nc_var.py -v lluis66 -f ~/UNSW-CCRC-WRF/tools/python/CCRC_NARCliM_Sydney_MOM_1990-1999_prac.nc -o rmvattr -S 'comment'
18## e.g. acuna # ./nc_var.py -f /d4/lflmd/etudes/WRF_LMDZ/WaquaL/WRF/control/wrfout/wrfout_d01_1979-12-01_00:00:00 -o checkallvars -S 'DateStrLen,Time,soil_layers_stag,bottom_top_stag,bottom_top,west_east_stag,west_east,south_north,south_north_stag:-3,1,2,2,2,-2,-2,-2,-2'
19## e.g. foudre # nc_var.py -f ~/etudes/WRF_LMDZ/tests/wrf_input/AR40.0/wrfout_d01_1979-01-01_00\:00\:00 -o checkallvars -S 'bottom_top_plus1,num_orchidee_soil_levels,lmdz_ksoil_types,DIM0009,DateStrLen,Time,soil_layers_stag,bottom_top_stag,bottom_top,west_east_stag,west_east,south_north,south_north_stag:2,0,0,1,-3,1,2,2,2,-2,-2,-2,-2'
20## e.g. # nc_var.py -o field_stats -f ~/etudes/domains/Polynesie/geo_em.d03.nc -S full -v HGT_M
21## e.g. # nc_var.py -o filter_2dim -S '80,y,x,lon,lat' -f 'tahiti_5m_ll.grd' -v 'z'
22## e.g. # nc_var.py -o selvar -f /home/lluis/PY/met_em.d01.1979-01-01_00:00:00.nc -S 'west_east@XLONG_M,south_north@XLAT_M,num_metgrid_levels@int,Time@Times' -v TT,UU,VV,SKINTEMP
23## e.g. # nc_var.py -o 'Partialmap_Entiremap' -f carteveg5km.nc -S 'longitude,latitude,std,5000.,Goode,Goode_5km.nc' -v vegetation_map
24## e.g. # nc_var.py -o subbasin -f routing.nc -S Caceres,-57.75,-16.25,left
25## e.g. # nc_var.py -o computevar_model -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S hurs
26## e.g. # nc_var.py -o model_characteristics -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S WRF
27## e.g. # nc_var.py -o WRF_toCF -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S XLONG:XLAT:19491201000000:minutes
28## e.g. # nc_var.py -o cleaning_varsfile -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S T2,XLONG,XLAT,Times
29## e.g. # nc_var.py -o LMDZ_toCF -f LMDZ/AR40/vas_histins_1-1.nc -S 'minutes!since!1949-12-01!00:00:00'
30## e.g. # nc_var.py -o CDO_toCF -f LMDZ/AR40/hfss_reproj-histins.nc
31## e.g. # nc_var.py -o pinterp -f wrfout_d01_2001-11-11_00\:00\:00 -S 100000.:97500.:95000.:92500.:90000.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:5000.:2500.:1000.:500.:250.,1,0 -v WRFt,WRFrh
32## e.g. # nc_var.py -o pinterp -f /media/ExtDiskC_ext4/DATA/etudes/WRF_LMDZ/WaquaL_highres/short_copies/LMDZ/AR40/histins_19790101000000-19790304000000_short.nc -S 100000.:97500.:95000.:92500.:90000.:85000.:80000.:75000.:70000.:65000.:60000.:55000.:50000.:45000.:40000.:35000.:30000.:25000.:20000.:15000.:10000.:5000.:2500.:1000.:500.:250.,1,0 -v temp,ovap
33## e.g. # nc_var.py -o reproject -f analysis/LMDZ/AR40/hurs_histins.nc -S 'lon,lat,analysis/WRF/current/hurs_wrfout.nc,lon,lat,npp,time@time' -v hurs
34## e.g. # nc_var.py -o field_stats_dim -f /home/lluis/PY/wrfout_d01_2001-11-11_00:00:00 -S 'full,None,None,west_east,XLONG,False' -v 'T2'
35## e.g. # nc_var.py -o compute_opersvarsfiles -S 'west_east|XLONG|-1;south_north|XLAT|-1;Time|Times|3@add|wrfout_d01_2001-11-11_00:00:00|T2%west_east|XLONG|-1;south_north|XLAT|-1;Time|Times|3@subc,273.15|wrfout_d01_2001-11-11_00:00:00|None' -v 'tempC,air!temperature,C'
36## e.g. # nc_var.py -o compute_opersvarsfiles -S 'lon|lon|-1;lat|lat|-1;time_counter|time_counter|-1@forwrdderiv,1,1,2|/ccc/store/cont003/gen7593/fitaborl/etudes/DynamicoESM/aquaplanet/AR40/19800101000000-19810101000000/histday.nc|t2m' -v 'tasderiv,x-derivative|of|air|temperature,K
37## e.g. # nc_var.py -o getvars_tofile -S soils_param_Zobler_textXIOS.nc -f soils_param_colorXIOS.nc -v 'soiltext,soiltexttypes'
38## e.g. # nc_var.py -o addVar -S 'lon,lat|mask@mask@1|f' -f new_ORCHIDEE_13PFTmap_2010_cmpi6_LUH2v2h.nc -v mask
39## e.g. # nc_var.py -o setvar_nc -S 'new_ORCHIDEE_13PFTmap_2010_cmpi6_LUH2v2h.nc,maxvegetfrac,veget;0' -f new_ORCHIDEE_13PFTmap_2010_cmpi6_LUH2v2h.nc -v mask
40## e.g. $ nc_var.py -o VarVal_FillValue -S '0.,eq,std' -f new_lai2D.nc -v LAI
41## e.g. # nc_var.py -o rm_FillValue -f new_ORCHIDEE_13PFTmap_2010_cmpi6_LUH2v2h.nc -S 0 -v mask
42## e.g. # nc_var.py -o curve_section -f /home/lluis/PY/test.nc -S 'gridline,x,y,8.,8.,16.,16.,32' -v all
43
44from optparse import OptionParser
45import numpy as np
46from netCDF4 import Dataset as NetCDFFile
47import os
48import re
49import nc_var_tools as ncvar
50# Using 'generic_tools.py'
51import generic_tools as gen
52
53# addVar: Operation to add a new variable in a file using exisintg dimensions
54# addvals: Function to add values to a given variable at a given dimension
55# CDO_toCF: Function to pass a CDO output file to CF-conventions
56# chdimname: Changing the name of the dimension
57# changevartype: Function to change the type of a variable (when possible)
58# checkallvars: Function to check all variables of a file
59# checkAllValues: Function to check for variables with along all their dimensions with the same value in a file
60# checkNaNs: Function to check for NaN values over all variables in a file
61# chgtimestep: Function to change the values of a given time-step of a variable inside a netCDF for values from a nother file
62# chvarname: Changing the name of the variable
63# cleaning_varsfile: Function to keep a list of varibales from a file
64# compute_deaccum: Function to compute deaccum: deaccumulation of a variable (VAR[t+1]-VAR[t])
65# compute_opersvarsfiles: Function to compute opersvarfiles: operation of variables from different files
66# compute_opervaralltime: Function to compute opervaralltime: operation of variable successible allover the time-steps
67# compute_opervartimes: Function to compute opervartimes: operation of variable for a given sub-set of time-steps
68# compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory
69# computevar_model: Function to provide the way to compute a CF-variable providing its name
70# curve_section: Function to provide a section of a file following a given curve
71# DatesFiles: Function to find different time values on a series of WRF files in a folder
72# DataSetSection: Function to get a section (values along a dimension) of a given data-set
73# DataSetSection_multidims: Function to get a section (values along multiple dimensions) of a given data-set
74# DataSetSection_multivars: Function to get a section (values along multiple variables) of a given data-set
75# DYNAMICO_toCF: Function to pass a DYNAMICO original file to CF-conventions
76# dimToUnlimited: Operation to create an unlimited dimension from an existing one
77# dimVar_creation: Function to add a 1D variable with the size of a given dimension in a file
78# fattradd: Adding attributes from a reference file
79# fdimadd: Adding dimension from another reference file
80# fgaddattr: Adding global attributes from a reference file
81# field_stats: Function to retrieve statistics from a field
82# field_stats_dim: Function to retrieve statistics from a field along dimensions
83# file_creation: Operation to create a file with one variable with a given set of dimensions
84# file_oper_alongdims: Function to operate a file along different dimensions of a variable
85# filter_2dim: Function to filter along 2 dimensions (moving grid-box means of a given size) values of the netCDF file
86# flipdim: flips the value following one dimension
87# fvaradd: Adding variable (and all its attributes and dimensions) from a reference file to a file
88# gaddattrk: Add a global attribute to a netCDF caring about the type. Removes previous attribute if it exist
89# gaddattr: Add a global attribute to a netCDF. Removes previous attribute if it exist
90# get_attribute: Function to get an attribute from a netCDF file
91# get_namelist_vars: Function to get namelist-like  values ([varname] = [value])
92# get_Variables: Function to get a list of variables from an existing file
93# getvalues_lonlat: Function to retrieve the values from the closest grid point to a set of longitude, latitude values
94# getvars_tofile: Function to get variables from a file and pass them to another one
95# grattr: Function to read a global atribute
96# grmattr: Removing a global attribute
97# idims: Give all the dimensions names of a file
98# igattrs: Give all the global attributes of a file
99# increaseDimvar: Function to increase with 1 dimension an existing variable within a netcdf file. Values of
100#   the variable will be repeated along the new dimension
101# isgattrs: Give a single global attribute of a file and its type
102# isvattrs: Give a single attribute of a variable
103# ivars: Give all the variable names of a file
104# ivattrs: Give all the attributes of a variable and its type
105# LMDZ_toCF: Function to pass a LMDZ original file to CF-conventions
106# lonlat_polygon: Function to define a lon/lat region giving the coordinates of the vertexs of a given polygon
107# maskvar: Function to mask a variable using a mask. It is assumed that mask[...,dimM,dimJ,dimK] and
108# model_characteristics: Function to provide major characterisitcs of a given model output
109# mthDYNAMICO_toCF: Function to pass a mthDYNAMICO original file to CF-conventions
110# ncreplace: Function to replace something from a netCDF file
111# ncstepdiff: Function to compute differencies between time-steps (deacumulate) a netCDF file
112# netcdf_concatenation: Function to concatenate netCDF files for a given set of variables
113# netcdf_fold_concatenation: Function to concatenate netCDF files in a given folder for a given set of variables
114# netcdf_fold_concatenation_HMT: Function to concatenate netCDF files in a given folder for a given set of variables
115#   giving Header, Middle, Tail for the name files
116# reproject: Function to reproject values to another one
117# rm_FillValue: Operation to remove the _FillValue from a variable inside a netCDF file
118# Partialmap_Entiremap: Function to transform from a partial global map (e.g.: only land points) to an entire one
119#   Coincidence of points is done throughout a first guess from fractions of the total domain of search
120# Partialmap_EntiremapFor: Function to transform from a partial global map (e.g.: only land points) to an entire one
121#   using Fortran code Coincidence of points is done throughout a first guess from fractions of the total domain of search
122# Partialmap_EntiremapForExact: Function to transform from a partial global map (e.g.: only land points) to an entire
123#   one using Fortran code with exact location Coincidence of points is done throughout a first guess from fractions of
124#   the total domain of search
125# pinterp: Function to vertically interpolate using subroutines from the p_interp.F90 NCAR program
126# remapnn: Function to remap to the nearest neightbor a variable using projection from another file
127# seasmean: Function to compute the seasonal mean of a variable
128# sellonlatbox: Function to select a lotlan box from a data-set
129# sellonlatlevbox: Function to select a lotlan box and a given level from a data-set
130# selvar: Function to select a series of variables from a netcdf file. Variables with
131# setvar_asciivalues: Function to set de values of a variable with an ASCII file (common Fortran-like format)
132# setvar_nc: Operation to set values of a variable from values of an other one
133# sorttimesmat: Function to sort the time values of a given file
134# spacemean: Function to retrieve a space mean series from a multidimensional variable of a file
135# SpatialWeightedMean: Function to compute the spatial mean using weights from a netCDF file
136# statcompare_files: Python script to statistically compare two different files
137# subbasin: Function to retrieve the subbasin (all the sub-flows untila a given lon,lat)
138# submns: Function to retrieve a series of months from a file
139# subyrs: Function to retrieve a series of years from a file
140# TimeInf: Function to print all the information from the variable time
141# time_reset: Function to re-set the time axis of a file
142# TimeSplitmat: Function to transform a file with CFtimes to a matrix [Nyear,Nmonth,Nday,Nhour,Nminute,Nsecond]
143# timemean: Function to retrieve a time mean series from a multidimensional variable of a file
144# valmod: Function to modify the value of a variable
145# valmod_dim: Function to modify the value of a variable at a given dimension and value
146# varaddattrk: Add an attribute to a variable caring about the type
147# varaddattr: Add an attribute to a variable. Removes previous attribute if it exists
148# varaddref: Function to add a variable in an existing file copying characteristics from an existing one
149# var_creation: Operation to create a new variable in a file with a given set of dimensions
150# varout: Function when we want to output variable values
151# varrmattr: Removing an attribute from a variable
152# varrm: Removing a variable from a file
153# VarVal_FillValue: Function to transform a given value from a given variable to _FillValue in a netCDF file
154# vrattr: Function to remove an atribute from a variable
155# WRF_d0Nref: Function for the generation of an extra WRF domain from a given one
156# WRF_CFlonlat_creation: Function to add a CF-convention longitude/latitude variables in a WRF file
157# WRF_CFtime_creation: Function to add a CF-convention time unit in a WRF file
158# WRF_CFxtime_creation: Function to add a CF-convention time unit in a WRF file using variable 'XTIME'
159# WRF_toCF: Function to pass a WRF original file to CF-conventions
160
161operations=['addVar', 'addvals', 'CDO_toCF', 'chdimname', 'changevartype',           \
162  'checkallvars', 'checkAllValues', 'checkNaNs',                                     \
163  'chgtimestep', 'chvarname', 'cleaning_varsfile', 'compute_deaccum',                \
164  'compute_opersvarsfiles',                                                          \
165  'compute_opervaralltime', 'compute_opervartimes', 'compute_tevolboxtraj',          \
166  'computevar_model', 'curve_section', 'DatesFiles',                                 \
167  'DataSetSection', 'DataSetSection_multidims', 'DataSetSection_multivars',          \
168  'DYNAMICO_toCF', 'dimToUnlimited', 'dimVar_creation',                              \
169  'fattradd',                                                                        \
170  'fdimadd', 'fgaddattr', 'field_stats', 'field_stats_dim', 'file_creation',         \
171  'file_oper_alongdims', 'filter_2dim',                                              \
172  'flipdim', 'fvaradd', 'gaddattrk', 'gaddattr', 'get_attribute',                    \
173  'get_namelist_vars', 'get_Variables',                                              \
174  'getvalues_lonlat', 'getvars_tofile', 'grattr',                                    \
175  'grmattr', 'idims', 'igattrs', 'increaseDimvar', 'isgattrs',                       \
176  'isvattrs', 'ivars', 'ivattrs', 'LMDZ_toCF', 'lonlat_polygon', 'maskvar',          \
177  'model_characteristics',                                                           \
178  'mthDYNAMICO_toCF', 'ncreplace', 'ncstepdiff', 'netcdf_concatenation',             \
179  'netcdf_fold_concatenation',                                                       \
180  'netcdf_fold_concatenation_HMT', 'reproject', 'Partialmap_Entiremap',              \
181  'Partialmap_EntiremapFor', 'Partialmap_EntiremapForExact',                         \
182  'pinterp', 'remapnn', 'rm_FillValue',                                              \
183  'seasmean', 'sellonlatbox', 'sellonlatlevbox', 'selvar', 'setvar_asciivalues',     \
184  'setvar_nc', 'sorttimesmat', 'spacemean', 'SpatialWeightedMean',                   \
185  'statcompare_files',                                                               \
186  'subbasin', 'submns', 'subyrs', 'TimeInf', 'time_reset',                           \
187  'TimeSplitmat', 'timemean', 'valmod', 'valmod_dim','varaddattrk', 'varaddattr',    \
188  'varaddref',                                                                       \
189  'var_creation', 'varout', 'varoutold', 'varrmattr', 'varrm', 'VarVal_FillValue',   \
190  'vrattr', 'WRF_d0Nref',                                                            \
191  'WRF_CFlonlat_creation', 'WRF_CFtime_creation', 'WRF_CFxtime_creation',            \
192  'list_operations', 'WRF_toCF']
193
194### Options
195##string_operation="operation to make: " + '\n' + " out, output values -S inidim1,[inidim2,...]:enddim1,[enddim2,...]"
196string_operation="""operation to make:
197  addgattr, add a new global attribute: addatr -S [attrname]|[attrvalue]
198  addvattr, add a new attribute to any given variable: addatr -S [attrname]|[attrvalue]
199  addref, add a new variable with dimension and attributes from an already existing 'variable ref' in the file and -S [variable ref]:[attr name]@[value]:[[attr2]@[value2], ...]:[value/file with values]  mname, modify name -S newname
200  checkallvalrs: Function to check all variables of a file: -S [dimn1],[[dimn2],...,[dimnN]]:[dim1],[[dim2],...,[dimN]]
201  mname, modify name -S newname
202  out, output values -S inidim1,[inidim2,...]:enddim1,[enddim2,...]
203  valmod, modifiy values of variable -S [modification]:
204     sumc,[constant]: add [constant] to variables values
205     subc,[constant]: substract [constant] to variables values
206     mulc,[constant]: multipy by [constant] to variables values
207     divc,[constant]: divide by [constant] to variables values
208  rmgattr, remove a global attribute: rmgattr -S [attrname]
209  rmvattr, remove an attribute to any given variable: rmvattr -S [attrname]
210"""
211
212#print string_operation
213
214operationnames = "'" + gen.numVector_String(operations, "', '") + "'"
215
216parser = OptionParser()
217parser.add_option("-f", "--netCDF_file", dest="ncfile", help="file to use", 
218  metavar="FILE")
219parser.add_option("-o", "--operation", type='choice', dest="operation", 
220  choices=operations, help="operation to make: " + operationnames, metavar="OPER")
221parser.add_option("-S", "--valueS", dest="values", 
222  help="values to use according to the operation (when applicable); '-h' specific help of the operation", metavar="VALUES")
223parser.add_option("-v", "--variable", dest="varname",
224  help="variable to use (when applicable)", metavar="VAR")
225
226(opts, args) = parser.parse_args()
227
228#if opts.help:
229#  parser.print_help()
230#  print string_operation
231#  sys.exit()
232
233#######    #######
234## MAIN
235    #######
236
237# Operations which file name is not a real file
238NotCheckingFile = ['DatesFiles', 'compute_opersvarsfiles', 'file_creation',          \
239  'list_operations',                                                                 \
240  'model_characteristics', 'netcdf_concatenation', 'netcdf_fold_concatenation',      \
241  'netcdf_fold_concatenation_HMT']
242
243####### ###### ##### #### ### ## #
244errormsg='ERROR -- error -- ERROR -- error'
245
246varn=opts.varname
247oper=opts.operation
248
249if opts.operation is None:
250    print errormsg
251    print '  No operation provided !!'
252    print "  an operation must be provided as '-o [operationname]' "
253    quit(-1)
254
255if opts.ncfile is not None and not os.path.isfile(opts.ncfile) and                   \
256  not gen.searchInlist(NotCheckingFile,oper):
257    print errormsg
258    print '  File ' + opts.ncfile + ' does not exist !!'
259    quit(-1)
260elif opts.ncfile is None and not gen.searchInlist(NotCheckingFile,oper) and          \
261  opts.values != 'h':
262    print errormsg
263    print '  No file provided !!'
264    print "  a file must be provided as '-f [filename]' "
265    quit(-1)
266
267if oper == 'addVar':
268    ncvar.addVar(opts.values, opts.ncfile, opts.varname)
269elif oper == 'addvals':
270    ncvar.addvals(opts.values, opts.ncfile, opts.varname)
271elif oper == 'CDO_toCF':
272    ncvar.CDO_toCF(opts.ncfile)
273elif oper == 'chdimname':
274    ncvar.chdimname(opts.values, opts.ncfile)
275elif oper == 'changevartype':
276    ncvar.changevartype(opts.values, opts.ncfile, opts.varname)
277elif oper == 'checkallvars':
278    ncvar.checkallvars(opts.values, opts.ncfile)
279elif oper == 'checkAllValues':
280    ncvar.checkAllValues(opts.values, opts.ncfile)
281elif oper == 'checkNaNs':
282    ncvar.checkNaNs(opts.values, opts.ncfile)
283elif oper == 'chgtimestep':
284    ncvar.chgtimestep(opts.values, opts.ncfile, opts.varname)
285elif oper == 'chvarname':
286    ncvar.chvarname(opts.values, opts.ncfile, opts.varname)
287elif oper == 'cleaning_varsfile':
288    ncvar.cleaning_varsfile(opts.values, opts.ncfile)
289elif oper == 'compute_deaccum':
290    ncvar.compute_deaccum(opts.values, opts.ncfile, opts.varname)
291elif oper == 'compute_opersvarsfiles':
292    ncvar.compute_opersvarsfiles(opts.values, opts.varname)
293elif oper == 'compute_opervaralltime':
294    ncvar.compute_opervaralltime(opts.values, opts.ncfile, opts.varname)
295elif oper == 'compute_opervartimes':
296    ncvar.compute_opervartimes(opts.values, opts.ncfile, opts.varname)
297elif oper == 'compute_tevolboxtraj':
298    ncvar.compute_tevolboxtraj(opts.values, opts.ncfile, opts.varname)
299elif oper == 'computevar_model':
300    ncvar.computevar_model(opts.values, opts.ncfile)
301elif oper == 'curve_section':
302    ncvar.curve_section(opts.values, opts.ncfile, opts.varname)
303elif oper == 'DataSetSection':
304    ncvar.DataSetSection(opts.values, opts.ncfile)
305elif oper == 'DataSetSection_multidims':
306    ncvar.DataSetSection_multidims(opts.values, opts.ncfile, opts.varname)
307elif oper == 'DataSetSection_multivars':
308    ncvar.DataSetSection_multivars(opts.values, opts.ncfile, opts.varname)
309elif oper == 'DatesFiles':
310    ncvar.DatesFiles(opts.values, opts.ncfile, opts.varname)
311elif oper == 'DYNAMICO_toCF':
312    ncvar.DYNAMICO_toCF(opts.values, opts.ncfile)
313elif oper == 'dimToUnlimited':
314    ncvar.dimToUnlimited(opts.values, opts.ncfile)
315elif oper == 'dimVar_creation':
316    ncvar.dimVar_creation(opts.values, opts.ncfile)
317elif oper == 'fattradd':
318    ncvar.fattradd(var, opts.values, opts.ncfile)
319elif oper == 'fdimadd':
320    ncvar.fdimadd(opts.values, opts.ncfile)
321elif oper == 'fgaddattr':
322    ncvar.fgaddattr(opts.values, opts.ncfile)
323elif oper == 'file_creation':
324    ncvar.file_creation(opts.values, opts.ncfile, opts.varname)
325elif oper == 'file_oper_alongdims':
326    ncvar.file_oper_alongdims(opts.values, opts.ncfile, opts.varname)
327elif oper == 'field_stats':
328    ncvar.field_stats(opts.values, opts.ncfile, opts.varname)
329elif oper == 'field_stats_dim':
330    ncvar.field_stats_dim(opts.values, opts.ncfile, opts.varname)
331elif oper == 'filter_2dim':
332    ncvar.filter_2dim(opts.values, opts.ncfile, opts.varname)
333elif oper == 'flipdim':
334    ncvar.flipdim(opts.values, opts.ncfile, opts.varname)
335elif oper == 'fvaradd':
336    ncvar.fvaradd(opts.values, opts.ncfile)
337elif oper == 'gaddattrk':
338    ncvar.gaddattrk(opts.values, opts.ncfile)
339elif oper == 'gaddattr':
340    ncvar.gaddattr(opts.values, opts.ncfile)
341elif oper == 'get_attribute':
342    ncvar.get_attribute(opts.values, opts.ncfile, opts.varname)
343elif oper == 'get_namelist_vars':
344    ncvar.get_namelist_vars(opts.values, opts.ncfile)
345elif oper == 'get_Variables':
346    ncvar.get_Variables(opts.values, opts.ncfile, opts.varname)
347elif oper == 'getvalues_lonlat':
348    ncvar.getvalues_lonlat(opts.values, opts.ncfile)
349elif oper == 'getvars_tofile':
350    ncvar.getvars_tofile(opts.values, opts.ncfile, opts.varname)
351elif oper == 'grattr':
352    ncvar.grattr(opts.values, opts.ncfile)
353elif oper == 'grmattr':
354    ncvar.grmattr(opts.values, opts.ncfile)
355elif oper == 'idims':
356    ncvar.idims(opts.ncfile)
357elif oper == 'igattrs':
358    ncvar.igattrs(opts.ncfile)
359elif oper == 'increaseDimvar':
360    ncvar.increaseDimvar(opts.values, opts.ncfile, opts.varname)
361elif oper == 'isgattrs':
362    ncvar.isgattrs(opts.values, opts.ncfile)
363elif oper == 'isvattrs':
364    ncvar.isvattrs(opts.values, opts.ncfile, opts.varname)
365elif oper == 'ivars':
366    ncvar.ivars(opts.ncfile)
367elif oper == 'ivattrs':
368    ncvar.ivattrs(opts.ncfile, opts.varname)
369elif oper == 'list_operations':
370# From: http://www.diveintopython.net/power_of_introspection/all_together.html
371    object = ncvar
372    for opern in operations:
373        if  opern != 'list_operations': 
374            print opern + '_______ ______ _____ ____ ___ __ _'
375            print getattr(object, opern).__doc__
376elif oper == 'LMDZ_toCF':
377    ncvar.LMDZ_toCF(opts.values, opts.ncfile)
378elif oper == 'lonlat_polygon':
379    ncvar.lonlat_polygon(opts.values, opts.ncfile, opts.varname)
380elif oper == 'maskvar':
381    ncvar.maskvar(opts.values, opts.ncfile, opts.varname)
382elif oper == 'model_characteristics':
383    ncvar.model_characteristics(opts.values, opts.ncfile)
384elif oper == 'mthDYNAMICO_toCF':
385    ncvar.mthDYNAMICO_toCF(opts.values, opts.ncfile)
386elif oper == 'ncreplace':
387    ncvar.ncreplace(opts.values, opts.ncfile, opts.varname)
388elif oper == 'ncstepdiff':
389    ncvar.ncstepdiff(opts.values, opts.ncfile, opts.varname)
390elif oper == 'netcdf_concatenation':
391    ncvar.netcdf_concatenation(opts.ncfile)
392elif oper == 'netcdf_fold_concatenation':
393    ncvar.netcdf_fold_concatenation(opts.values, opts.ncfile, opts.varname)
394elif oper == 'netcdf_fold_concatenation_HMT':
395    ncvar.netcdf_fold_concatenation_HMT(opts.values, opts.ncfile, opts.varname)
396elif oper == 'opersvarsfiles':
397    ncvar.compute_opersvarsfiles(opts.values, opts.varname)
398elif oper == 'pinterp':
399    ncvar.pinterp(opts.values, opts.ncfile, opts.varname)
400elif oper == 'remapnn':
401    ncvar.remapnn(opts.values, opts.ncfile, opts.varname)
402elif oper == 'Partialmap_Entiremap':
403    ncvar.Partialmap_Entiremap(opts.values, opts.ncfile, opts.varname)
404elif oper == 'Partialmap_EntiremapFor':
405    ncvar.Partialmap_EntiremapFor(opts.values, opts.ncfile, opts.varname)
406elif oper == 'Partialmap_EntiremapForExact':
407    ncvar.Partialmap_EntiremapForExact(opts.values, opts.ncfile, opts.varname)
408elif oper == 'reproject':
409    ncvar.reproject(opts.values, opts.ncfile, opts.varname)
410elif oper == 'rm_FillValue':
411    ncvar.rm_FillValue(opts.values, opts.ncfile, opts.varname)
412elif oper == 'seasmean':
413    ncvar.seasmean(timename, opts.ncfile, opts.varname)
414elif oper == 'sellonlatbox':
415    ncvar.sellonlatbox(opts.values, opts.ncfile, opts.varname)
416elif oper == 'sellonlatlevbox':
417    ncvar.sellonlatlevbox(opts.values, opts.ncfile, opts.varname)
418elif oper == 'selvar':
419    ncvar.selvar(opts.values, opts.ncfile, opts.varname)
420elif oper == 'setvar_asciivalues':
421    ncvar.setvar_asciivalues(opts.values, opts.ncfile, opts.varname)
422elif oper == 'setvar_nc':
423    ncvar.setvar_nc(opts.values, opts.ncfile, opts.varname)
424elif oper == 'sorttimesmat':
425    ncvar.sorttimesmat(opts.ncfile, opts.varname)
426elif oper == 'spacemean':
427    ncvar.spacemean(opts.ncfile, opts.varname)
428elif oper == 'SpatialWeightedMean':
429    ncvar.SpatialWeightedMean(opts.values, opts.ncfile, opts.varname)
430elif oper == 'statcompare_files':
431    ncvar.statcompare_files(opts.values)
432elif oper == 'subbasin':
433    ncvar.subbasin(opts.values, opts.ncfile)
434elif oper == 'submns':
435    ncvar.submns(opts.values, opts.ncfile, opts.varname)
436elif oper == 'subyrs':
437    ncvar.subyrs(opts.values, opts.ncfile, opts.varname)
438elif oper == 'TimeInf':
439    ncvar.TimeInf(opts.ncfile, opts.varname)
440elif oper == 'time_reset':
441    ncvar.time_reset(opts.values, opts.ncfile, opts.varname)
442elif oper == 'TimeSplitmat':
443    ncvar.TimeSplitmat(opts.values, opts.ncfile, opts.varname)
444elif oper == 'timemean':
445    ncvar.timemean(opts.values, opts.ncfile, opts.varname)
446elif oper == 'valmod':
447    ncvar.valmod(opts.values, opts.ncfile, opts.varname)
448elif oper == 'valmod_dim':
449    ncvar.valmod_dim(opts.values, opts.ncfile, opts.varname)
450elif oper == 'varaddattrk':
451    ncvar.varaddattrk(opts.values, opts.ncfile, opts.varname)
452elif oper == 'varaddattr':
453    ncvar.varaddattr(opts.values, opts.ncfile, opts.varname)
454elif oper == 'varaddref':
455    ncvar.varaddref(opts.values, opts.ncfile, opts.varname)
456elif oper == 'var_creation':
457    ncvar.var_creation(opts.values, opts.ncfile, opts.varname)
458elif oper == 'varout':
459    ncvar.varout(opts.values, opts.ncfile, opts.varname)
460elif oper == 'varoutold':
461    ncvar.varoutold(opts.values, opts.ncfile, opts.varname)
462elif oper == 'varrmattr':
463    ncvar.varrmattr(opts.values, opts.ncfile, opts.varname)
464elif oper == 'varrm':
465    ncvar.varrm(opts.ncfile, opts.varname)
466elif oper == 'VarVal_FillValue':
467    ncvar.VarVal_FillValue(opts.values, opts.ncfile, opts.varname)
468elif oper == 'vrattr':
469    ncvar.vrattr(opts.values, opts.ncfile, opts.varname)
470elif oper == 'WRF_d0Nref':
471    ncvar.WRF_d0Nref(opts.values, opts.ncfile)
472elif oper == 'WRF_CFlonlat_creation':
473    ncvar.WRF_CFlonlat_creation(opts.values, opts.ncfile, opts.varname)
474elif oper == 'WRF_CFtime_creation':
475    ncvar.WRF_CFtime_creation(opts.values, opts.ncfile, opts.varname)
476elif oper == 'WRF_CFxtime_creation':
477    ncvar.WRF_CFxtime_creation(opts.values, opts.ncfile, opts.varname)
478elif oper == 'WRF_toCF':
479    ncvar.WRF_toCF(opts.values, opts.ncfile)
480else:
481    print errormsg
482    print '   The operation ' + oper + ' is not ready !!'
483    print errormsg
484    quit()
Note: See TracBrowser for help on using the repository browser.