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 | ## e.g. # nc_var.py -o WRF_to_newCF -f wrfout_d01_1995-01-01_00\:00\:00 -S 'XLONG:XLAT:Times:19491201000000:minutes' -v QVAPOR,T2,Q2 |
---|
19 | ## e.g. # nc_var.py -o reconstruct_matrix_from_vector -f cruncep_halfdeg_1958.nc -S 'nav_lon:nav_lat:-90.:-7.:-67.:15.:latlon:0.5:0.5:0.05' -v all |
---|
20 | ## e.g. # nc_var.py -o nc_var.py -o CFmorzization -S 'X|west_east|XLONG,Y|south_north|XLAT,T|Time|WRFtime,Z|bottom_top|ZNU:GlobalAttr1995.inf:proj1995.inf' -f ~/PY/wrfout_d01_1995-01-01_00\:00\:00 -v QFX@instantaneous@None |
---|
21 | ## e.g.# nc_var.py -o CFmorzization -S 'X|west_east|XLONG,Y|south_north|XLAT,T|Time|WRFtime,Z|bottom_top|ZNU:GlobalAttr1995.inf:proj1995.inf' -f ~/PY/wrfout_d01_1995-01-01_00\:00\:00 -v 'RAINC@time:!accumulation@WRFtime_bnds|h|3' |
---|
22 | ## e.g. # nc_var.py -o dimrm -S removevar -f wrfout_d01_1995-01-01_00:00:00 -v west_east |
---|
23 | ## e.g. # nc_var.py -o ifile -f ../PY/wrfout_d01_1995-01-01_00:00:00 |
---|
24 | ## e.g. # nc_var.py -o splitfile_dim -S bottom_top:ZNU:QVAPOR_ZNU:.4f -v QVAPOR,XLONG,XLAT,Times -f ~/PY/wrfout_d01_1995-01-01_00:00:00 |
---|
25 | ## e.g. # nc_var.py -o itime -S WRFtime -f ../PY/wrfout_d01_1995-01-01_00:00:00 -v Times |
---|
26 | ## e.g. # nc_var.py -o get_point -S 'XLONG:XLAT:Time|0' -f /home/lluis/PY/wrfout_d01_1995-01-01_00:00:00 -v -45.,-30. |
---|
27 | ## e.g. # nc_var.py -o get_time -S '1422759600;seconds!since!1949-12-01!00:00:00' -f /home/lluis/PY/wrfout_d01_1995-01-01_00:00:00 -v WRFtime |
---|
28 | ## e.g. # nc_var.py -o join_singlestation_obsfiles -S 'obs/sfc_CAM:OBSnetcdf' -v all |
---|
29 | ## e.g. # nc_var.py -o join_sounding_obsfiles -S .:UWyoming_snd_1 -v all |
---|
30 | ## e.g. # nc_var.py -o timemean -f selvar_new.nc -S 2:XLONG,XLAT -v T2 |
---|
31 | ## e.g. # nc_var.py -o netcdf_fold_slice_concatenation_HMT -S south_north|168:south_north_stag|169:west_east|196:west_east_stag|197,control,Time,WRFtime -v all -f wrfout,d01,00 |
---|
32 | |
---|
33 | ## e.g. ccrc468-17 # ./nc_var.py -v time -f 123/CCRC_NARCliM_Sydney_All_1990-1999_pr10max.nc -o out -S 1:-1 |
---|
34 | ## e.g. ccrc468-17 # ./nc_var.py -v prac -f xyz/CCRC_NARCliM_Sydney_DAM_1990-1999_prac.nc -o mname -S pluja |
---|
35 | ## 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.' |
---|
36 | ## 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' |
---|
37 | ## 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' |
---|
38 | ## 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' |
---|
39 | ## 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' |
---|
40 | ## e.g. # nc_var.py -o field_stats -f ~/etudes/domains/Polynesie/geo_em.d03.nc -S full -v HGT_M |
---|
41 | ## e.g. # nc_var.py -o filter_2dim -S '80,y,x,lon,lat' -f 'tahiti_5m_ll.grd' -v 'z' |
---|
42 | ## 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 |
---|
43 | ## e.g. # nc_var.py -o 'Partialmap_Entiremap' -f carteveg5km.nc -S 'longitude,latitude,std,5000.,Goode,Goode_5km.nc' -v vegetation_map |
---|
44 | ## e.g. # nc_var.py -o subbasin -f routing.nc -S Caceres,-57.75,-16.25,left |
---|
45 | ## e.g. # nc_var.py -o computevar_model -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S hurs |
---|
46 | ## e.g. # nc_var.py -o model_characteristics -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S WRF |
---|
47 | ## e.g. # nc_var.py -o WRF_toCF -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S XLONG:XLAT:19491201000000:minutes |
---|
48 | ## e.g. # nc_var.py -o cleaning_varsfile -f ~/PY/wrfout_d01_2001-11-11_00:00:00 -S T2,XLONG,XLAT,Times |
---|
49 | ## 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' |
---|
50 | ## e.g. # nc_var.py -o CDO_toCF -f LMDZ/AR40/hfss_reproj-histins.nc |
---|
51 | ## 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 |
---|
52 | ## 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 |
---|
53 | ## 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 |
---|
54 | ## 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' |
---|
55 | ## 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' |
---|
56 | ## 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 |
---|
57 | ## e.g. # nc_var.py -o getvars_tofile -S soils_param_Zobler_textXIOS.nc -f soils_param_colorXIOS.nc -v 'soiltext,soiltexttypes' |
---|
58 | ## e.g. # nc_var.py -o addVar -S 'lon,lat|mask@mask@1|f' -f new_ORCHIDEE_13PFTmap_2010_cmpi6_LUH2v2h.nc -v mask |
---|
59 | ## 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 |
---|
60 | ## e.g. $ nc_var.py -o VarVal_FillValue -S '0.,eq,std' -f new_lai2D.nc -v LAI |
---|
61 | ## e.g. # nc_var.py -o rm_FillValue -f new_ORCHIDEE_13PFTmap_2010_cmpi6_LUH2v2h.nc -S 0 -v mask |
---|
62 | ## 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 |
---|
63 | ## e.g. # nc_var.py -o merge_files -S 'plev|plev,time|time:merged.nc' -f 'ncobs/AliceSprings/snd_94326_198201-198201.nc,ncobs/AliceSprings/snd_94326_198202-198202.nc' -v 'plev,time' |
---|
64 | ## e.g. # nc_var.py -o temporal_stats -S 'Time:WRFtime:day@1@min,LTday@-3@1@min,agghour@1@mean:bottom_top@ZNU,south_north@XLAT,west_east@XLONG' -f wrfout_d01_1995-01-01_00:00:00 -v T2,Q2 |
---|
65 | ## e.g. # nc_var.py -o retrieve_stations -f wrfout_d01_1995-01-01_00:00:00 -S 'tmin_percentiles.nc:stname:None:stlon:stlat:None:nearest:west_east:XLONG:south_north:XLAT:HGT:Time:WRFtime' -v T2,QVAPOR |
---|
66 | ## e.g. # nc_var.py -o compute_slice2Dstats -S 'XLAT,-63.,19.,2.,HGT,250.,7000.,500.,Time|Times:west_east|XLONG:south_north|XLAT' -f wrfout_d01_1995-01-01_00:00:00 -v T2,Q2 |
---|
67 | ## e.g. # nc_var.py -o same_deltasign -f wrfout_d01_1995-01-01_00:00:00 -S 'Time:0|south_north:60|west_east:-1' -v T2,Q2,XLAT,XLONG |
---|
68 | ## e.g. # nc_var.py -o compute_slices_stats -S 'XLONG,-74.,-36.,4.;XLAT,-62.,18.,2.;HGT,500.,7000.,500.@Time|Times:west_east|XLONG:south_north|XLAT@Time' -f wrfout_d01_1995-01-01_00:00:00 -v T2,Q2 |
---|
69 | ## e.g. # nc_var.py -o dimrename -f /media/lluis/ExtDiskC_ext3/DATA/estudios/FPS_Alps/additional/IOP/select/out_irene/simcdx_vars_cape_120lev_cdxwrf2.nc -S Time -v time0 |
---|
70 | ## e.g. # nc_var.py -o area_weighted -f 'reference_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1,get_data.nc:lon;lon;lon_bnds;-1;lat;lat;lat_bnds;-1' -S 'yes:min,max,mean,stddev,count' -v ct_values,xband_values,box_values,mosaic_values |
---|
71 | ## e.g. # nc_var.py -o area_weighted -f '/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA150k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1,/media/lluis/ExtDiskC_ext4/bkup/llamp/estudios/dominios/SA50k/geo_em.d01.nc:west_east;XLONG_M;WRFxbnds;-1;south_north;XLAT_M;WRFybnds;-1' -S 'no:mean' -v HGT_M |
---|
72 | ## e.g. # nc_var.py -o compute_slices_stats_areaweighted -S 'XLONG,-74.,-36.4,4.;XLAT,-63.,19.,4.;HGT,500.,7000.,500.@Time|WRFtime:west_east|XLONG:south_north|XLAT@Time@west_east|lon_bnds,south_north|lat_bnds@XLONG|lat_bnds;lon_bnds,XLAT|lat_bnds;lon_bnds@Time' -f wrfout_bnds.nc -v T2,U10,V10,Q2 |
---|
73 | ## e.g. # nc_var.py -o compute_slices_stats_areaweighted -S 'lat,-63.,19.,2.;orog,500.,7000.,500.;rangefaces,fixed,-2.5|-0.5,-0.5|0.5,0.5|2.5@time|time:lon|lon:lat|lat@time@lon|lon_bnds,lat|lat_bnds@lon|lon_bnds,lat|lat_bnds@lat,lon@time' -f /media/lluis/ExtDiskC_ext3/DATA/estudios/Andes/DATA/concatenated/historical/tasmin/tasmin_Amon_ACCESS1-0_historical_r1i1p1_185001-200512_Andes_19600101000000-19900101000000.nc -v tasmin |
---|
74 | ## e.g. # nc_var.py -o except_fillValue -S 'orog:range,500.,7000.:None' -f /home/lluis/estudios/Andes/cmip_data/fx/orog_fx_ACCESS1-0_historical_r0i0p0.nc -v 'all' |
---|
75 | ## e.g. # nc_var.py -o usefile_compute_slices_stats_areaweighted -S 'compute_slices_stats_areaweighted.nc@XLAT_M-HGT_M-rangefaces@Time|WRFtime:west_east|XLONG_M:south_north|XLAT_M:land_cat|INTrange@Time,land_cat' -f 'geo_em.d01.nc' -v 'LANDUSEF' |
---|
76 | ## e.g. # nc_var.py -o compress_data -S 'XLAND:Time|0:single,1:X|west_east|XLONG,Y|south_north|XLAT' -f wrfout_d01_1995-01-01_00:00:00 -v T2,LU_INDEX,Times |
---|
77 | ## e.g. # nc_var.py -o CFfile_creation -S 'lon|360,lat|180,time|None@20:global' -v 'tas#time;lat;lon#f#None,time#time#f8#units|seconds!since!1949-12-01!00:00:00|S' -f newCF.nc |
---|
78 | ## e.g. # nc_var.py -o CFfile_fixTime -f tasmin_Amon_BNU-ESM_historical_r1i1p1_185001-200512_lonlatbox.nc -S 'setCalendar;setRefDate,19491201000000' -v time |
---|
79 | ## e.g. # nc_var.py -o fill_varNCfile -S 'random,0.,10.' -f CFtest.nc -v tas |
---|
80 | ## e.g. # python nc_var.py -o statcompare_files -f '/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00,/home/lluis/PY/wrfout_d01_1995-01-01_00:00:00' -S 'diffstats,None,yes' -v 'T2,U10,QVAPOR:T2,U10,QVAPOR' |
---|
81 | |
---|
82 | |
---|
83 | from optparse import OptionParser |
---|
84 | import numpy as np |
---|
85 | from netCDF4 import Dataset as NetCDFFile |
---|
86 | import os |
---|
87 | import re |
---|
88 | import nc_var_tools as ncvar |
---|
89 | # Using 'generic_tools.py' |
---|
90 | import generic_tools as gen |
---|
91 | |
---|
92 | # addDim: Operation to add a new dimension in a file |
---|
93 | # addVar: Operation to add a new variable in a file using exisintg dimensions |
---|
94 | # addvals: Function to add values to a given variable at a given dimension |
---|
95 | # area_weighted: Function to provide an area weighted statistics within two different values |
---|
96 | # of matrices assuming regular lon/lat projections without taking into account Earth's curvature |
---|
97 | # CDO_toCF: Function to pass a CDO output file to CF-conventions |
---|
98 | # CFfile_creation: Operation to create a file folowing CF-conventions |
---|
99 | # CFfile_fixTime: Operation to fix a netCDF file with a time axis folowing CF-conventions, but |
---|
100 | # with a wrong set-up following a set of available operations |
---|
101 | # CFmorzization: Function to provide a CF-compilation version of a variable within a file |
---|
102 | # chdimname: Changing the name of the dimension |
---|
103 | # changevartype: Function to change the type of a variable (when possible) |
---|
104 | # checkallvars: Function to check all variables of a file |
---|
105 | # checkAllValues: Function to check for variables with along all their dimensions with the same value in a file |
---|
106 | # checkNaNs: Function to check for NaN values over all variables in a file |
---|
107 | # chgtimestep: Function to change the values of a given time-step of a variable inside a netCDF for values from a nother file |
---|
108 | # chvarname: Changing the name of the variable |
---|
109 | # cleaning_varsfile: Function to keep a list of varibales from a file |
---|
110 | # compress_data: Function to compress (only provide values for a criteria) the values of a 2D |
---|
111 | # file following a given criteria from one of its variables |
---|
112 | # compute_deaccum: Function to compute deaccum: deaccumulation of a variable (VAR[t+1]-VAR[t]) |
---|
113 | # compute_opersvarsfiles: Function to compute opersvarfiles: operation of variables from different files |
---|
114 | # compute_opervaralltime: Function to compute opervaralltime: operation of variable successible allover the time-steps |
---|
115 | # compute_opervartimes: Function to compute opervartimes: operation of variable for a given sub-set of time-steps |
---|
116 | # compute_slices_stats: Function to compute stats of variables of a file splitting variables by |
---|
117 | # slices along sets of ranges for a series of variables |
---|
118 | # compute_slices_stats_areaweighted: Function to compute stats of variables of a file splitting variables by |
---|
119 | # slices along sets of ranges for a series of variables weighting by the area |
---|
120 | # covered by each grid (defined as polygon) within the slice |
---|
121 | # compute_slice2Dstats: Function to compute stats of variables of a file following slices along 2 variables |
---|
122 | # compute_tevolboxtraj: Function to compute tevolboxtraj: temporal evolution at a given point along a box following a trajectory |
---|
123 | # computevar_model: Function to provide the way to compute a CF-variable providing its name |
---|
124 | # curve_section: Function to provide a section of a file following a given curve |
---|
125 | # DatesFiles: Function to find different time values on a series of WRF files in a folder |
---|
126 | # DataSetSection: Function to get a section (values along a dimension) of a given data-set |
---|
127 | # DataSetSection_multidims: Function to get a section (values along multiple dimensions) of a given data-set |
---|
128 | # DataSetSection_multivars: Function to get a section (values along multiple variables) of a given data-set |
---|
129 | # DYNAMICO_toCF: Function to pass a DYNAMICO original file to CF-conventions |
---|
130 | # dimrename: Renaming a dimension from a file |
---|
131 | # dimrm: Removing a dimension from a file |
---|
132 | # dimToUnlimited: Operation to create an unlimited dimension from an existing one |
---|
133 | # dimVar_creation: Function to add a 1D variable with the size of a given dimension in a file |
---|
134 | # except_fillValue: Function to fill a file with fill_Value except a given value of a variable |
---|
135 | # fattradd: Adding attributes from a reference file |
---|
136 | # fdimadd: Adding dimension from another reference file |
---|
137 | # fgaddattr: Adding global attributes from a reference file |
---|
138 | # field_stats: Function to retrieve statistics from a field |
---|
139 | # field_stats_dim: Function to retrieve statistics from a field along dimensions |
---|
140 | # file_creation: Operation to create a file with one variable with a given set of dimensions |
---|
141 | # file_oper_alongdims: Function to operate a file along different dimensions of a variable |
---|
142 | # fill_varNCfile: Function to fill up a variable from a netCDF file |
---|
143 | # filter_2dim: Function to filter along 2 dimensions (moving grid-box means of a given size) values of the netCDF file |
---|
144 | # flipdim: flips the value following one dimension |
---|
145 | # fvaradd: Adding variable (and all its attributes and dimensions) from a reference file to a file |
---|
146 | # gaddattrk: Add a global attribute to a netCDF caring about the type. Removes previous attribute if it exist |
---|
147 | # gaddattr: Add a global attribute to a netCDF. Removes previous attribute if it exist |
---|
148 | # get_attribute: Function to get an attribute from a netCDF file |
---|
149 | # get_point: Function to provide the closest grid point to a given lat,lon |
---|
150 | # get_time: Function to provide the closest time-step to a given time |
---|
151 | # get_namelist_vars: Function to get namelist-like values ([varname] = [value]) |
---|
152 | # get_Variables: Function to get a list of variables from an existing file |
---|
153 | # getvalues_lonlat: Function to retrieve the values from the closest grid point to a set of longitude, latitude values |
---|
154 | # getvars_tofile: Function to get variables from a file and pass them to another one |
---|
155 | # grattr: Function to read a global atribute |
---|
156 | # grmattr: Removing a global attribute |
---|
157 | # idims: Give all the dimensions names of a file |
---|
158 | # ifile: Function to provide some information from a given file |
---|
159 | # igattrs: Give all the global attributes of a file |
---|
160 | # increaseDimvar: Function to increase with 1 dimension an existing variable within a netcdf file. Values of |
---|
161 | # the variable will be repeated along the new dimension |
---|
162 | # isgattrs: Give a single global attribute of a file and its type |
---|
163 | # isvattrs: Give a single attribute of a variable |
---|
164 | # itime: Function to provide information of the time from a netCDF file |
---|
165 | # ivars: Give all the variable names of a file |
---|
166 | # ivattrs: Give all the attributes of a variable and its type |
---|
167 | # join_singlestation_obsfiles: Function to join files from 'single-station' |
---|
168 | # `create_OBSnetcdf.py' script to create a single file |
---|
169 | # join_sounding_obsfiles: Function to join 1D variables from files generated by |
---|
170 | # `UWyoming_snd_nc.py' script to create a single file |
---|
171 | # LMDZ_toCF: Function to pass a LMDZ original file to CF-conventions |
---|
172 | # lonlat_polygon: Function to define a lon/lat region giving the coordinates of the vertexs of a given polygon |
---|
173 | # 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) |
---|
174 | # merge_files: Function to merge variables from two files |
---|
175 | # model_characteristics: Function to provide major characterisitcs of a given model output |
---|
176 | # mthDYNAMICO_toCF: Function to pass a mthDYNAMICO original file to CF-conventions |
---|
177 | # ncreplace: Function to replace something from a netCDF file |
---|
178 | # ncstepdiff: Function to compute differencies between time-steps (deacumulate) a netCDF file |
---|
179 | # netcdf_concatenation: Function to concatenate netCDF files for a given set of variables |
---|
180 | # netcdf_fold_concatenation: Function to concatenate netCDF files in a given folder for a given set of variables |
---|
181 | # netcdf_fold_slice_concatenation_HMT: Function to concatenate netCDF files in a given folder for a given slice and |
---|
182 | # for a given set of variables giving Header, Middle, Tail for the name files |
---|
183 | # netcdf_fold_concatenation_HMT: Function to concatenate netCDF files in a given folder for a given set of variables |
---|
184 | # giving Header, Middle, Tail for the name files |
---|
185 | # reconstruct_matrix_from_vector: Function to reconstruct a 2D matrix from a pair of syncronized vectors with the positions on x and y coordinates |
---|
186 | # reproject: Function to reproject values to another one |
---|
187 | # rm_FillValue: Operation to remove the _FillValue from a variable inside a netCDF file |
---|
188 | # Partialmap_Entiremap: Function to transform from a partial global map (e.g.: only land points) to an entire one |
---|
189 | # Coincidence of points is done throughout a first guess from fractions of the total domain of search |
---|
190 | # Partialmap_EntiremapFor: Function to transform from a partial global map (e.g.: only land points) to an entire one |
---|
191 | # using Fortran code Coincidence of points is done throughout a first guess from fractions of the total domain of search |
---|
192 | # Partialmap_EntiremapForExact: Function to transform from a partial global map (e.g.: only land points) to an entire |
---|
193 | # one using Fortran code with exact location Coincidence of points is done throughout a first guess from fractions of |
---|
194 | # the total domain of search |
---|
195 | # pinterp: Function to vertically interpolate using subroutines from the p_interp.F90 NCAR program |
---|
196 | # remapnn: Function to remap to the nearest neightbor a variable using projection from another file |
---|
197 | # retrieve_stations: Function to retrieve temporal values at given stations provided by a secondary netcdf |
---|
198 | # same_deltasign: Function to determine if a given series of 1D values share the same sign of |
---|
199 | # increase/decrease between consecutive values |
---|
200 | # seasmean: Function to compute the seasonal mean of a variable |
---|
201 | # sellonlatbox: Function to select a lotlan box from a data-set |
---|
202 | # sellonlatlevbox: Function to select a lotlan box and a given level from a data-set |
---|
203 | # selvar: Function to select a series of variables from a netcdf file. Variables with |
---|
204 | # setvar_asciivalues: Function to set de values of a variable with an ASCII file (common Fortran-like format) |
---|
205 | # setvar_nc: Operation to set values of a variable from values of an other one |
---|
206 | # sorttimesmat: Function to sort the time values of a given file |
---|
207 | # spacemean: Function to retrieve a space mean series from a multidimensional variable of a file |
---|
208 | # SpatialWeightedMean: Function to compute the spatial mean using weights from a netCDF file |
---|
209 | # splitfile_dim: Function to split a file along a given dimension with a new file for each different value along the dimension (assuming resultant vardim of rank-1) |
---|
210 | # statcompare_files: Python script to statistically compare two different files |
---|
211 | # subbasin: Function to retrieve the subbasin (all the sub-flows untila a given lon,lat) |
---|
212 | # submns: Function to retrieve a series of months from a file |
---|
213 | # subyrs: Function to retrieve a series of years from a file |
---|
214 | # temporal_stats: Function to compute temporal statistics. Rank of the variables are |
---|
215 | # preserved along other non-temporal dimensions |
---|
216 | # TimeInf: Function to print all the information from the variable time |
---|
217 | # time_reset: Function to re-set the time axis of a file |
---|
218 | # TimeSplitmat: Function to transform a file with CFtimes to a matrix [Nyear,Nmonth,Nday,Nhour,Nminute,Nsecond] |
---|
219 | # timemean: Function to retrieve a time mean series from a multidimensional variable of a file |
---|
220 | # usefile_compute_slices_stats_areaweighted: Function to compute stats of variables of |
---|
221 | # a file splitting variables by slices along sets of ranges for a series of |
---|
222 | # variables weighting by the area covered by each grid (defined as polygon) within |
---|
223 | # the slice using pre-calculated area-weights from an existing file |
---|
224 | # valmod: Function to modify the value of a variable |
---|
225 | # valmod_dim: Function to modify the value of a variable at a given dimension and value |
---|
226 | # varaddattrk: Add an attribute to a variable caring about the type |
---|
227 | # varaddattr: Add an attribute to a variable. Removes previous attribute if it exists |
---|
228 | # varaddref: Function to add a variable in an existing file copying characteristics from an existing one |
---|
229 | # var_creation: Operation to create a new variable in a file with a given set of dimensions |
---|
230 | # varout: Function when we want to output variable values |
---|
231 | # varrmattr: Removing an attribute from a variable |
---|
232 | # varrm: Removing a variable from a file |
---|
233 | # VarVal_FillValue: Function to transform a given value from a given variable to _FillValue in a netCDF file |
---|
234 | # vrattr: Function to remove an atribute from a variable |
---|
235 | # WRF_d0Nref: Function for the generation of an extra WRF domain from a given one |
---|
236 | # WRF_CFlonlat_creation: Function to add a CF-convention longitude/latitude variables in a WRF file |
---|
237 | # WRF_CFtime_creation: Function to add a CF-convention time unit in a WRF file |
---|
238 | # WRF_CFxtime_creation: Function to add a CF-convention time unit in a WRF file using variable 'XTIME' |
---|
239 | # WRF_toCF: Function to pass a WRF original file to CF-conventions |
---|
240 | # WRF_to_newCF: Function to pass a WRF original file to new CF-conventions file |
---|
241 | |
---|
242 | operations=['addDim', 'addVar', 'addvals', 'area_weighted', 'CDO_toCF', \ |
---|
243 | 'CFfile_creation', 'CFfile_fixTime', 'CFmorzization', 'chdimname', \ |
---|
244 | 'changevartype', 'checkallvars', 'checkAllValues', 'checkNaNs', \ |
---|
245 | 'chgtimestep', 'chvarname', 'cleaning_varsfile', 'compress_data', \ |
---|
246 | 'compute_deaccum', 'compute_opersvarsfiles', \ |
---|
247 | 'compute_opervaralltime', 'compute_opervartimes', 'compute_slices_stats', \ |
---|
248 | 'compute_slices_stats_areaweighted', 'compute_slice2Dstats', \ |
---|
249 | 'compute_tevolboxtraj', \ |
---|
250 | 'computevar_model', 'curve_section', 'DatesFiles', \ |
---|
251 | 'DataSetSection', 'DataSetSection_multidims', 'DataSetSection_multivars', \ |
---|
252 | 'DYNAMICO_toCF', 'dimrename', 'dimrm', 'dimToUnlimited', 'dimVar_creation', \ |
---|
253 | 'except_fillValue', 'fattradd', \ |
---|
254 | 'fdimadd', 'fgaddattr', 'field_stats', 'field_stats_dim', 'file_creation', \ |
---|
255 | 'file_oper_alongdims', 'fill_varNCfile', 'filter_2dim', \ |
---|
256 | 'flipdim', 'fvaradd', 'gaddattrk', 'gaddattr', 'get_attribute', \ |
---|
257 | 'get_point', 'get_time', 'get_namelist_vars', 'get_Variables', \ |
---|
258 | 'getvalues_lonlat', 'getvars_tofile', 'grattr', \ |
---|
259 | 'grmattr', 'idims', 'ifile', 'igattrs', 'increaseDimvar', 'isgattrs', \ |
---|
260 | 'isvattrs', 'itime', 'ivars', 'ivattrs', 'join_singlestation_obsfiles', \ |
---|
261 | 'join_sounding_obsfiles', 'LMDZ_toCF', 'lonlat_polygon', 'maskvar', \ |
---|
262 | 'merge_files', 'model_characteristics', \ |
---|
263 | 'mthDYNAMICO_toCF', 'ncreplace', 'ncstepdiff', 'netcdf_concatenation', \ |
---|
264 | 'netcdf_fold_concatenation', \ |
---|
265 | 'netcdf_fold_concatenation_HMT', 'netcdf_fold_slice_concatenation_HMT', \ |
---|
266 | 'reproject', 'Partialmap_Entiremap', \ |
---|
267 | 'Partialmap_EntiremapFor', 'Partialmap_EntiremapForExact', \ |
---|
268 | 'pinterp', 'reconstruct_matrix_from_vector', 'remapnn', 'retrieve_stations', \ |
---|
269 | 'rm_FillValue', 'same_deltasign', \ |
---|
270 | 'seasmean', 'sellonlatbox', 'sellonlatlevbox', 'selvar', 'setvar_asciivalues', \ |
---|
271 | 'setvar_nc', 'sorttimesmat', 'spacemean', 'SpatialWeightedMean', \ |
---|
272 | 'splitfile_dim', 'statcompare_files', \ |
---|
273 | 'subbasin', 'submns', 'subyrs', 'temporal_stats', 'TimeInf', 'time_reset', \ |
---|
274 | 'TimeSplitmat', 'timemean', 'usefile_compute_slices_stats_areaweighted', \ |
---|
275 | 'valmod', 'valmod_dim','varaddattrk', 'varaddattr', \ |
---|
276 | 'varaddref', \ |
---|
277 | 'var_creation', 'varout', 'varoutold', 'varrmattr', 'varrm', 'VarVal_FillValue', \ |
---|
278 | 'vrattr', 'WRF_d0Nref', \ |
---|
279 | 'WRF_CFlonlat_creation', 'WRF_CFtime_creation', 'WRF_CFxtime_creation', \ |
---|
280 | 'list_operations', 'WRF_toCF', 'WRF_to_newCF'] |
---|
281 | |
---|
282 | ### Options |
---|
283 | ##string_operation="operation to make: " + '\n' + " out, output values -S inidim1,[inidim2,...]:enddim1,[enddim2,...]" |
---|
284 | string_operation="""operation to make: |
---|
285 | addgattr, add a new global attribute: addatr -S [attrname]|[attrvalue] |
---|
286 | addvattr, add a new attribute to any given variable: addatr -S [attrname]|[attrvalue] |
---|
287 | 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 |
---|
288 | checkallvalrs: Function to check all variables of a file: -S [dimn1],[[dimn2],...,[dimnN]]:[dim1],[[dim2],...,[dimN]] |
---|
289 | mname, modify name -S newname |
---|
290 | out, output values -S inidim1,[inidim2,...]:enddim1,[enddim2,...] |
---|
291 | valmod, modifiy values of variable -S [modification]: |
---|
292 | sumc,[constant]: add [constant] to variables values |
---|
293 | subc,[constant]: substract [constant] to variables values |
---|
294 | mulc,[constant]: multipy by [constant] to variables values |
---|
295 | divc,[constant]: divide by [constant] to variables values |
---|
296 | rmgattr, remove a global attribute: rmgattr -S [attrname] |
---|
297 | rmvattr, remove an attribute to any given variable: rmvattr -S [attrname] |
---|
298 | """ |
---|
299 | |
---|
300 | #print string_operation |
---|
301 | |
---|
302 | operationnames = "'" + gen.numVector_String(operations, "', '") + "'" |
---|
303 | |
---|
304 | parser = OptionParser() |
---|
305 | parser.add_option("-f", "--netCDF_file", dest="ncfile", help="file to use", |
---|
306 | metavar="FILE") |
---|
307 | parser.add_option("-o", "--operation", type='choice', dest="operation", |
---|
308 | choices=operations, help="operation to make: " + operationnames, metavar="OPER") |
---|
309 | parser.add_option("-S", "--valueS", dest="values", |
---|
310 | help="values to use according to the operation (when applicable); '-h' specific help of the operation", metavar="VALUES") |
---|
311 | parser.add_option("-v", "--variable", dest="varname", |
---|
312 | help="variable to use (when applicable)", metavar="VAR") |
---|
313 | |
---|
314 | (opts, args) = parser.parse_args() |
---|
315 | |
---|
316 | #if opts.help: |
---|
317 | # parser.print_help() |
---|
318 | # print string_operation |
---|
319 | # sys.exit() |
---|
320 | |
---|
321 | ####### ####### |
---|
322 | ## MAIN |
---|
323 | ####### |
---|
324 | |
---|
325 | # Operations which file name is not a real file |
---|
326 | NotCheckingFile = ['area_weighted', 'CFfile_creation','DatesFiles', \ |
---|
327 | 'compute_opersvarsfiles', 'file_creation', \ |
---|
328 | 'join_singlestation_obsfiles', 'join_sounding_obsfiles', 'list_operations', \ |
---|
329 | 'merge_files', \ |
---|
330 | 'model_characteristics', 'netcdf_concatenation', 'netcdf_fold_concatenation', \ |
---|
331 | 'netcdf_fold_concatenation_HMT', 'netcdf_fold_slice_concatenation_HMT', \ |
---|
332 | 'statcompare_files'] |
---|
333 | |
---|
334 | ####### ###### ##### #### ### ## # |
---|
335 | errormsg='ERROR -- error -- ERROR -- error' |
---|
336 | |
---|
337 | varn=opts.varname |
---|
338 | oper=opts.operation |
---|
339 | |
---|
340 | if opts.operation is None: |
---|
341 | print errormsg |
---|
342 | print ' No operation provided !!' |
---|
343 | print " an operation must be provided as '-o [operationname]' " |
---|
344 | quit(-1) |
---|
345 | |
---|
346 | if opts.ncfile is not None and not os.path.isfile(opts.ncfile) and \ |
---|
347 | not gen.searchInlist(NotCheckingFile,oper) and opts.ncfile != 'h': |
---|
348 | print errormsg |
---|
349 | print " File '" + opts.ncfile + "' does not exist !!" |
---|
350 | quit(-1) |
---|
351 | elif opts.ncfile is None and not gen.searchInlist(NotCheckingFile,oper) and \ |
---|
352 | opts.values != 'h': |
---|
353 | print errormsg |
---|
354 | print ' No file provided !!' |
---|
355 | print " a file must be provided as '-f [filename]' " |
---|
356 | quit(-1) |
---|
357 | |
---|
358 | if oper == 'addDim': |
---|
359 | ncvar.addDim(opts.values, opts.ncfile, opts.varname) |
---|
360 | elif oper == 'addVar': |
---|
361 | ncvar.addVar(opts.values, opts.ncfile, opts.varname) |
---|
362 | elif oper == 'addvals': |
---|
363 | ncvar.addvals(opts.values, opts.ncfile, opts.varname) |
---|
364 | elif oper == 'area_weighted': |
---|
365 | ncvar.area_weighted(opts.values, opts.ncfile, opts.varname) |
---|
366 | elif oper == 'CDO_toCF': |
---|
367 | ncvar.CDO_toCF(opts.ncfile) |
---|
368 | elif oper == 'CFfile_creation': |
---|
369 | ncvar.CFfile_creation(opts.values, opts.ncfile, opts.varname) |
---|
370 | elif oper == 'CFfile_fixTime': |
---|
371 | ncvar.CFfile_fixTime(opts.values, opts.ncfile, opts.varname) |
---|
372 | elif oper == 'CFmorzization': |
---|
373 | ncvar.CFmorzization(opts.values, opts.ncfile, opts.varname) |
---|
374 | elif oper == 'chdimname': |
---|
375 | ncvar.chdimname(opts.values, opts.ncfile) |
---|
376 | elif oper == 'changevartype': |
---|
377 | ncvar.changevartype(opts.values, opts.ncfile, opts.varname) |
---|
378 | elif oper == 'checkallvars': |
---|
379 | ncvar.checkallvars(opts.values, opts.ncfile) |
---|
380 | elif oper == 'checkAllValues': |
---|
381 | ncvar.checkAllValues(opts.values, opts.ncfile) |
---|
382 | elif oper == 'checkNaNs': |
---|
383 | ncvar.checkNaNs(opts.values, opts.ncfile) |
---|
384 | elif oper == 'chgtimestep': |
---|
385 | ncvar.chgtimestep(opts.values, opts.ncfile, opts.varname) |
---|
386 | elif oper == 'chvarname': |
---|
387 | ncvar.chvarname(opts.values, opts.ncfile, opts.varname) |
---|
388 | elif oper == 'cleaning_varsfile': |
---|
389 | ncvar.cleaning_varsfile(opts.values, opts.ncfile) |
---|
390 | elif oper == 'compress_data': |
---|
391 | ncvar.compress_data(opts.values, opts.ncfile, opts.varname) |
---|
392 | elif oper == 'compute_deaccum': |
---|
393 | ncvar.compute_deaccum(opts.values, opts.ncfile, opts.varname) |
---|
394 | elif oper == 'compute_opersvarsfiles': |
---|
395 | ncvar.compute_opersvarsfiles(opts.values, opts.varname) |
---|
396 | elif oper == 'compute_opervaralltime': |
---|
397 | ncvar.compute_opervaralltime(opts.values, opts.ncfile, opts.varname) |
---|
398 | elif oper == 'compute_opervartimes': |
---|
399 | ncvar.compute_opervartimes(opts.values, opts.ncfile, opts.varname) |
---|
400 | elif oper == 'compute_slices_stats': |
---|
401 | ncvar.compute_slices_stats(opts.values, opts.ncfile, opts.varname) |
---|
402 | elif oper == 'compute_slices_stats_areaweighted': |
---|
403 | ncvar.compute_slices_stats_areaweighted(opts.values, opts.ncfile, opts.varname) |
---|
404 | elif oper == 'compute_slice2Dstats': |
---|
405 | ncvar.compute_slice2Dstats(opts.values, opts.ncfile, opts.varname) |
---|
406 | elif oper == 'compute_tevolboxtraj': |
---|
407 | ncvar.compute_tevolboxtraj(opts.values, opts.ncfile, opts.varname) |
---|
408 | elif oper == 'computevar_model': |
---|
409 | ncvar.computevar_model(opts.values, opts.ncfile) |
---|
410 | elif oper == 'curve_section': |
---|
411 | ncvar.curve_section(opts.values, opts.ncfile, opts.varname) |
---|
412 | elif oper == 'DataSetSection': |
---|
413 | ncvar.DataSetSection(opts.values, opts.ncfile) |
---|
414 | elif oper == 'DataSetSection_multidims': |
---|
415 | ncvar.DataSetSection_multidims(opts.values, opts.ncfile, opts.varname) |
---|
416 | elif oper == 'DataSetSection_multivars': |
---|
417 | ncvar.DataSetSection_multivars(opts.values, opts.ncfile, opts.varname) |
---|
418 | elif oper == 'DatesFiles': |
---|
419 | ncvar.DatesFiles(opts.values, opts.ncfile, opts.varname) |
---|
420 | elif oper == 'DYNAMICO_toCF': |
---|
421 | ncvar.DYNAMICO_toCF(opts.values, opts.ncfile) |
---|
422 | elif oper == 'dimrename': |
---|
423 | ncvar.dimrename(opts.ncfile, opts.values, opts.varname) |
---|
424 | elif oper == 'dimrm': |
---|
425 | ncvar.dimrm(opts.ncfile, opts.values, opts.varname) |
---|
426 | elif oper == 'dimToUnlimited': |
---|
427 | ncvar.dimToUnlimited(opts.values, opts.ncfile) |
---|
428 | elif oper == 'dimVar_creation': |
---|
429 | ncvar.dimVar_creation(opts.values, opts.ncfile) |
---|
430 | elif oper == 'except_fillValue': |
---|
431 | ncvar.except_fillValue(opts.values, opts.ncfile, opts.varname) |
---|
432 | elif oper == 'fattradd': |
---|
433 | ncvar.fattradd(var, opts.values, opts.ncfile) |
---|
434 | elif oper == 'fdimadd': |
---|
435 | ncvar.fdimadd(opts.values, opts.ncfile) |
---|
436 | elif oper == 'fgaddattr': |
---|
437 | ncvar.fgaddattr(opts.values, opts.ncfile) |
---|
438 | elif oper == 'file_creation': |
---|
439 | ncvar.file_creation(opts.values, opts.ncfile, opts.varname) |
---|
440 | elif oper == 'file_oper_alongdims': |
---|
441 | ncvar.file_oper_alongdims(opts.values, opts.ncfile, opts.varname) |
---|
442 | elif oper == 'field_stats': |
---|
443 | ncvar.field_stats(opts.values, opts.ncfile, opts.varname) |
---|
444 | elif oper == 'field_stats_dim': |
---|
445 | ncvar.field_stats_dim(opts.values, opts.ncfile, opts.varname) |
---|
446 | elif oper == 'fill_varNCfile': |
---|
447 | ncvar.fill_varNCfile(opts.values, opts.ncfile, opts.varname) |
---|
448 | elif oper == 'filter_2dim': |
---|
449 | ncvar.filter_2dim(opts.values, opts.ncfile, opts.varname) |
---|
450 | elif oper == 'flipdim': |
---|
451 | ncvar.flipdim(opts.values, opts.ncfile, opts.varname) |
---|
452 | elif oper == 'fvaradd': |
---|
453 | ncvar.fvaradd(opts.values, opts.ncfile) |
---|
454 | elif oper == 'gaddattrk': |
---|
455 | ncvar.gaddattrk(opts.values, opts.ncfile) |
---|
456 | elif oper == 'gaddattr': |
---|
457 | ncvar.gaddattr(opts.values, opts.ncfile) |
---|
458 | elif oper == 'get_attribute': |
---|
459 | ncvar.get_attribute(opts.values, opts.ncfile, opts.varname) |
---|
460 | elif oper == 'get_namelist_vars': |
---|
461 | ncvar.get_namelist_vars(opts.values, opts.ncfile) |
---|
462 | elif oper == 'get_point': |
---|
463 | ncvar.get_point(opts.values, opts.ncfile, opts.varname) |
---|
464 | elif oper == 'get_time': |
---|
465 | ncvar.get_time(opts.values, opts.ncfile, opts.varname) |
---|
466 | elif oper == 'get_Variables': |
---|
467 | ncvar.get_Variables(opts.values, opts.ncfile, opts.varname) |
---|
468 | elif oper == 'getvalues_lonlat': |
---|
469 | ncvar.getvalues_lonlat(opts.values, opts.ncfile) |
---|
470 | elif oper == 'getvars_tofile': |
---|
471 | ncvar.getvars_tofile(opts.values, opts.ncfile, opts.varname) |
---|
472 | elif oper == 'grattr': |
---|
473 | ncvar.grattr(opts.values, opts.ncfile) |
---|
474 | elif oper == 'grmattr': |
---|
475 | ncvar.grmattr(opts.values, opts.ncfile) |
---|
476 | elif oper == 'idims': |
---|
477 | ncvar.idims(opts.ncfile) |
---|
478 | elif oper == 'ifile': |
---|
479 | ncvar.ifile(opts.ncfile) |
---|
480 | elif oper == 'igattrs': |
---|
481 | ncvar.igattrs(opts.ncfile) |
---|
482 | elif oper == 'increaseDimvar': |
---|
483 | ncvar.increaseDimvar(opts.values, opts.ncfile, opts.varname) |
---|
484 | elif oper == 'isgattrs': |
---|
485 | ncvar.isgattrs(opts.values, opts.ncfile) |
---|
486 | elif oper == 'isvattrs': |
---|
487 | ncvar.isvattrs(opts.values, opts.ncfile, opts.varname) |
---|
488 | elif oper == 'itime': |
---|
489 | ncvar.itime(opts.values, opts.ncfile, opts.varname) |
---|
490 | elif oper == 'ivars': |
---|
491 | ncvar.ivars(opts.ncfile) |
---|
492 | elif oper == 'ivattrs': |
---|
493 | ncvar.ivattrs(opts.ncfile, opts.varname) |
---|
494 | elif oper == 'join_singlestation_obsfiles': |
---|
495 | ncvar.join_singlestation_obsfiles(opts.values, opts.varname) |
---|
496 | elif oper == 'join_sounding_obsfiles': |
---|
497 | ncvar.join_sounding_obsfiles(opts.values, opts.varname) |
---|
498 | elif oper == 'list_operations': |
---|
499 | # From: http://www.diveintopython.net/power_of_introspection/all_together.html |
---|
500 | object = ncvar |
---|
501 | for opern in operations: |
---|
502 | if opern != 'list_operations': |
---|
503 | print opern + '_______ ______ _____ ____ ___ __ _' |
---|
504 | print getattr(object, opern).__doc__ |
---|
505 | elif oper == 'LMDZ_toCF': |
---|
506 | ncvar.LMDZ_toCF(opts.values, opts.ncfile) |
---|
507 | elif oper == 'lonlat_polygon': |
---|
508 | ncvar.lonlat_polygon(opts.values, opts.ncfile, opts.varname) |
---|
509 | elif oper == 'maskvar': |
---|
510 | ncvar.maskvar(opts.values, opts.ncfile, opts.varname) |
---|
511 | elif oper == 'merge_files': |
---|
512 | ncvar.merge_files(opts.values, opts.ncfile, opts.varname) |
---|
513 | elif oper == 'model_characteristics': |
---|
514 | ncvar.model_characteristics(opts.values, opts.ncfile) |
---|
515 | elif oper == 'mthDYNAMICO_toCF': |
---|
516 | ncvar.mthDYNAMICO_toCF(opts.values, opts.ncfile) |
---|
517 | elif oper == 'ncreplace': |
---|
518 | ncvar.ncreplace(opts.values, opts.ncfile, opts.varname) |
---|
519 | elif oper == 'ncstepdiff': |
---|
520 | ncvar.ncstepdiff(opts.values, opts.ncfile, opts.varname) |
---|
521 | elif oper == 'netcdf_concatenation': |
---|
522 | ncvar.netcdf_concatenation(opts.ncfile) |
---|
523 | elif oper == 'netcdf_fold_concatenation': |
---|
524 | ncvar.netcdf_fold_concatenation(opts.values, opts.ncfile, opts.varname) |
---|
525 | elif oper == 'netcdf_fold_concatenation_HMT': |
---|
526 | ncvar.netcdf_fold_concatenation_HMT(opts.values, opts.ncfile, opts.varname) |
---|
527 | elif oper == 'netcdf_fold_slice_concatenation_HMT': |
---|
528 | ncvar.netcdf_fold_slice_concatenation_HMT(opts.values, opts.ncfile, opts.varname) |
---|
529 | elif oper == 'opersvarsfiles': |
---|
530 | ncvar.compute_opersvarsfiles(opts.values, opts.varname) |
---|
531 | elif oper == 'pinterp': |
---|
532 | ncvar.pinterp(opts.values, opts.ncfile, opts.varname) |
---|
533 | elif oper == 'remapnn': |
---|
534 | ncvar.remapnn(opts.values, opts.ncfile, opts.varname) |
---|
535 | elif oper == 'Partialmap_Entiremap': |
---|
536 | ncvar.Partialmap_Entiremap(opts.values, opts.ncfile, opts.varname) |
---|
537 | elif oper == 'Partialmap_EntiremapFor': |
---|
538 | ncvar.Partialmap_EntiremapFor(opts.values, opts.ncfile, opts.varname) |
---|
539 | elif oper == 'Partialmap_EntiremapForExact': |
---|
540 | ncvar.Partialmap_EntiremapForExact(opts.values, opts.ncfile, opts.varname) |
---|
541 | elif oper == 'reconstruct_matrix_from_vector': |
---|
542 | ncvar.reconstruct_matrix_from_vector(opts.values, opts.ncfile, opts.varname) |
---|
543 | elif oper == 'reproject': |
---|
544 | ncvar.reproject(opts.values, opts.ncfile, opts.varname) |
---|
545 | elif oper == 'retrieve_stations': |
---|
546 | ncvar.retrieve_stations(opts.values, opts.ncfile, opts.varname) |
---|
547 | elif oper == 'rm_FillValue': |
---|
548 | ncvar.rm_FillValue(opts.values, opts.ncfile, opts.varname) |
---|
549 | elif oper == 'same_deltasign': |
---|
550 | ncvar.same_deltasign(opts.values, opts.ncfile, opts.varname) |
---|
551 | elif oper == 'seasmean': |
---|
552 | ncvar.seasmean(timename, opts.ncfile, opts.varname) |
---|
553 | elif oper == 'sellonlatbox': |
---|
554 | ncvar.sellonlatbox(opts.values, opts.ncfile, opts.varname) |
---|
555 | elif oper == 'sellonlatlevbox': |
---|
556 | ncvar.sellonlatlevbox(opts.values, opts.ncfile, opts.varname) |
---|
557 | elif oper == 'selvar': |
---|
558 | ncvar.selvar(opts.values, opts.ncfile, opts.varname) |
---|
559 | elif oper == 'setvar_asciivalues': |
---|
560 | ncvar.setvar_asciivalues(opts.values, opts.ncfile, opts.varname) |
---|
561 | elif oper == 'setvar_nc': |
---|
562 | ncvar.setvar_nc(opts.values, opts.ncfile, opts.varname) |
---|
563 | elif oper == 'sorttimesmat': |
---|
564 | ncvar.sorttimesmat(opts.ncfile, opts.varname) |
---|
565 | elif oper == 'spacemean': |
---|
566 | ncvar.spacemean(opts.ncfile, opts.varname) |
---|
567 | elif oper == 'SpatialWeightedMean': |
---|
568 | ncvar.SpatialWeightedMean(opts.values, opts.ncfile, opts.varname) |
---|
569 | elif oper == 'splitfile_dim': |
---|
570 | ncvar.splitfile_dim(opts.values, opts.ncfile, opts.varname) |
---|
571 | elif oper == 'statcompare_files': |
---|
572 | ncvar.statcompare_files(opts.values, opts.ncfile, opts.varname) |
---|
573 | elif oper == 'subbasin': |
---|
574 | ncvar.subbasin(opts.values, opts.ncfile) |
---|
575 | elif oper == 'submns': |
---|
576 | ncvar.submns(opts.values, opts.ncfile, opts.varname) |
---|
577 | elif oper == 'subyrs': |
---|
578 | ncvar.subyrs(opts.values, opts.ncfile, opts.varname) |
---|
579 | elif oper == 'temporal_stats': |
---|
580 | ncvar.temporal_stats(opts.values, opts.ncfile, opts.varname) |
---|
581 | elif oper == 'TimeInf': |
---|
582 | ncvar.TimeInf(opts.ncfile, opts.varname) |
---|
583 | elif oper == 'time_reset': |
---|
584 | ncvar.time_reset(opts.values, opts.ncfile, opts.varname) |
---|
585 | elif oper == 'TimeSplitmat': |
---|
586 | ncvar.TimeSplitmat(opts.values, opts.ncfile, opts.varname) |
---|
587 | elif oper == 'timemean': |
---|
588 | ncvar.timemean(opts.values, opts.ncfile, opts.varname) |
---|
589 | elif oper == 'usefile_compute_slices_stats_areaweighted': |
---|
590 | ncvar.usefile_compute_slices_stats_areaweighted(opts.values, opts.ncfile, \ |
---|
591 | opts.varname) |
---|
592 | elif oper == 'valmod': |
---|
593 | ncvar.valmod(opts.values, opts.ncfile, opts.varname) |
---|
594 | elif oper == 'valmod_dim': |
---|
595 | ncvar.valmod_dim(opts.values, opts.ncfile, opts.varname) |
---|
596 | elif oper == 'varaddattrk': |
---|
597 | ncvar.varaddattrk(opts.values, opts.ncfile, opts.varname) |
---|
598 | elif oper == 'varaddattr': |
---|
599 | ncvar.varaddattr(opts.values, opts.ncfile, opts.varname) |
---|
600 | elif oper == 'varaddref': |
---|
601 | ncvar.varaddref(opts.values, opts.ncfile, opts.varname) |
---|
602 | elif oper == 'var_creation': |
---|
603 | ncvar.var_creation(opts.values, opts.ncfile, opts.varname) |
---|
604 | elif oper == 'varout': |
---|
605 | ncvar.varout(opts.values, opts.ncfile, opts.varname) |
---|
606 | elif oper == 'varoutold': |
---|
607 | ncvar.varoutold(opts.values, opts.ncfile, opts.varname) |
---|
608 | elif oper == 'varrmattr': |
---|
609 | ncvar.varrmattr(opts.values, opts.ncfile, opts.varname) |
---|
610 | elif oper == 'varrm': |
---|
611 | ncvar.varrm(opts.ncfile, opts.varname) |
---|
612 | elif oper == 'VarVal_FillValue': |
---|
613 | ncvar.VarVal_FillValue(opts.values, opts.ncfile, opts.varname) |
---|
614 | elif oper == 'vrattr': |
---|
615 | ncvar.vrattr(opts.values, opts.ncfile, opts.varname) |
---|
616 | elif oper == 'WRF_d0Nref': |
---|
617 | ncvar.WRF_d0Nref(opts.values, opts.ncfile) |
---|
618 | elif oper == 'WRF_CFlonlat_creation': |
---|
619 | ncvar.WRF_CFlonlat_creation(opts.values, opts.ncfile, opts.varname) |
---|
620 | elif oper == 'WRF_CFtime_creation': |
---|
621 | ncvar.WRF_CFtime_creation(opts.values, opts.ncfile, opts.varname) |
---|
622 | elif oper == 'WRF_CFxtime_creation': |
---|
623 | ncvar.WRF_CFxtime_creation(opts.values, opts.ncfile, opts.varname) |
---|
624 | elif oper == 'WRF_toCF': |
---|
625 | ncvar.WRF_toCF(opts.values, opts.ncfile) |
---|
626 | elif oper == 'WRF_to_newCF': |
---|
627 | ncvar.WRF_to_newCF(opts.values, opts.ncfile, opts.varname) |
---|
628 | else: |
---|
629 | print errormsg |
---|
630 | print ' The operation ' + oper + ' is not ready !!' |
---|
631 | print errormsg |
---|
632 | quit() |
---|