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