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

Last change on this file since 1361 was 1360, checked in by lfita, 8 years ago

Adding `getvars_tofile': Function to get variables from a file and pass them to another one

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