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

Last change on this file since 1531 was 1497, checked in by lfita, 8 years ago

Adding example lines

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