Changes between Version 9 and Version 10 of Documentation/UserGuide/StudyNetCDF


Ignore:
Timestamp:
2020-02-28T14:35:36+01:00 (4 years ago)
Author:
bguenet
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/UserGuide/StudyNetCDF

    v9 v10  
    55Last revision: 2020/02/28, B. Guenet [[BR]] 
    66 
    7  
    8 The quickest way of all to look at NetCDF files is to use '''ncview''', i.e.: 
    9  
    10 {{{ 
    11 ncview myJob_20060101_20061231_1M_sechiba_history.nc 
    12 }}} 
    13  
    14 Unfortunately the ncview application can be a little unstable (at least on my system anyway). 
    15  
    16 '''ncdump''' is more flexible, and is a great way to look at header information: 
     7== nco == 
     8 
     9 
     10nco is a very powerful tool to print data, modify variable names, concatenate, etc on netcdf file. A detailled documentation can be found here http://nco.sourceforge.net/ 
     11We will just summarize here some of the most useful nco commands often used in the orchidee context. 
     12 
     13 * '''ncdump'''  
     14This command print all the informations stored in your netcdf file. Some prefix can extract only the information you need. 
     15 
     16   * To look at header information: 
    1717 
    1818{{{ 
     
    2020}}} 
    2121 
    22 or, for example to extract one column of data in a tabulated text format (here for 'fluxlat', the latent heat flux): 
    23  
    24  
    25 {{{ 
    26 ncdump -v fluxlat -f fortran -n fluxlat myJob_20060101_20061231_1M_sechiba_history.nc > myJob_fluxlat.cdl 
    27 }}} 
    28  
    29  
    30 But there's a really useful script that can be used in '''IDL''' to import all of the data series at once, without having to spend time writing scripts to define input arrays first. First of all, download [http://aos.princeton.edu/WWWPUBLIC/PROFS/pom_gfdex/idl_lib/cdf2idl.pro cdf2idl.pro], compile it within IDL and then input the following: 
    31  
    32 {{{ 
    33  
    34 cdf2idl, '/home/rest_of_the_path/myJob_20060101_20061231_1M_sechiba_history.nc' 
    35  
    36 @myJob_20060101_20061231_1M_sechiba_history.idl 
    37 }}} 
    38  
    39 And then you have all of your variables automatically imported, each into arrays of an appropriate size, and they can be quickly plotted, e.g: 
    40  
    41  
    42 {{{ 
    43 plot, tstep, tair(0,0,0,*) 
    44 }}} 
    45  
    46 (remember that IDL by default defines arrays as starting from 0, instead of from 1) 
    47  
    48 '''ncks''': If you would like to remove a certain time series from a netcdf file (for instance, in this example, all data from 'temp_atmos_pres' in the file jamescdf.nc for which the height dimension is 20) with the output written to jamestest.nc 
     22   * To extract one variable (here for 'fluxlat', the latent heat flux) 
     23 
     24{{{ 
     25ncdump -v fluxlat myJob_20060101_20061231_1M_sechiba_history.nc  
     26}}} 
     27 
     28   * To extract one variable and show them in a tabulated way (here for 'fluxlat', the latent heat flux) 
     29 
     30{{{ 
     31ncdump -v fluxlat -f fortran -n fluxlat myJob_20060101_20061231_1M_sechiba_history.nc  
     32}}} 
     33 
     34 * '''ncrename'''  
     35 
     36This command change the name of a given variable/dimension depending on the prefix you are using 
     37 
     38   * To rename a variable within the file (here for 'fluxlat', the latent heat flux) 
     39{{{ 
     40ncrename -v fluxlat,latent_heat_flux myJob_20060101_20061231_1M_sechiba_history.nc  
     41}}} 
     42 
     43   * To rename a variable a creating a new file (here for 'fluxlat', the latent heat flux) 
     44{{{ 
     45ncrename -v fluxlat,latent_heat_flux myJob_20060101_20061231_1M_sechiba_history.nc mynewfile.nc 
     46}}} 
     47 
     48   * To rename a dimension within the file (here for 'lon', the longitude) 
     49{{{ 
     50ncrename -d lon,longitude myJob_20060101_20061231_1M_sechiba_history.nc  
     51}}} 
     52 
     53   * To rename a variable a creating a new file (here for 'lon', the longitude) 
     54{{{ 
     55ncrename -d lon,longitude myJob_20060101_20061231_1M_sechiba_history.nc mynewfile.nc 
     56}}} 
     57 
     58  * '''ncks'''  
     59 
     60If you would like to remove a certain time series from a netcdf file (for instance, in this example, all data from 'temp_atmos_pres' in the file jamescdf.nc for which the height dimension is 20) with the output written to jamestest.nc 
    4961 
    5062{{{ 
    5163ncks -H -d height,20 -d temp_atmos_pres,: jamescdf.nc jamestest.nc 
    5264}}} 
     65 
     66 * '''ncap2'''  
     67 
     68The most powerful and quickly evolving tool from the nco set of functions 
     69 
     70search what you are looking on this growing list of answers [[http://sourceforge.net/search/index.php?words=&sort=posted_date&sortdir=desc&offset=0&group_id=3331&type_of_search=forums|forum nco]] 
     71 
     72A simple example showing different capacities (creation of a variable, use of a mask, call to an attribute, count the total and the size of the field (we can restrict this operation to a dimension as shown on the second line) 
     73 
     74{{{ 
     75 ncap2 -O -s 'missing_flag[$y,$x]=0;where(t2m_daily!=t2m_daily@missing_value) missing_flag=1;missing_count=float(missing_flag.total())/missing_flag.size();print(missing_count)' stomate_restart.nc  ~/foo.nc 
     76 ncap2 -O -s 'missing_flag[$y,$x]=0;where(t2m_daily!=t2m_daily@missing_value) missing_flag=1;missing_count=float(missing_flag.total($x))/missing_flag.size($x);print(missing_count)' stomate_restart.nc  ~/foo.nc 
     77}}} 
     78 
     79 
     80 
    5381 
    5482 
     
    72100}}} 
    73101 
    74  
    75  
    76 == ncap2 == 
    77  
    78 The most powerful and quickly evolving tool from the nco set of functions 
    79  
    80 See the file of exemples : {{:reunions_orchidee:ncap2.pdf| ncap2 file}} or search what you are looking on this growing list of answers [[http://sourceforge.net/search/index.php?words=&sort=posted_date&sortdir=desc&offset=0&group_id=3331&type_of_search=forums|forum nco]] 
    81  
    82 A simple exemple showing different capacities (creation of a variable, use of a mask, call to an attribute, count the total and the size of the field (we can restrict this operation to a dimension as shown on the second line) 
    83  
    84 <code> 
    85  ncap2 -O -s 'missing_flag[$y,$x]=0;where(t2m_daily!=t2m_daily@missing_value) missing_flag=1;missing_count=float(missing_flag.total())/missing_flag.size();print(missing_count)' stomate_restart.nc  ~/foo.nc 
    86  ncap2 -O -s 'missing_flag[$y,$x]=0;where(t2m_daily!=t2m_daily@missing_value) missing_flag=1;missing_count=float(missing_flag.total($x))/missing_flag.size($x);print(missing_count)' stomate_restart.nc  ~/foo.nc 
    87 </code> 
    88102 
    89103 
     
    180194</code> 
    181195 
    182  
     196== ncview: a quick alternative == 
     197The quickest way of all to look at NetCDF files and to quickly plot some outputs is to use ncview: 
     198 
     199{{{ 
     200ncview myJob_20060101_20061231_1M_sechiba_history.nc 
     201}}} 
     202 
     203Unfortunately the ncview application can be sometimes a little unstable.