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

Last change on this file since 1411 was 1406, checked in by lfita, 8 years ago

Adding:

`curve_section': Function to provide a section of a file following a given curve

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