Changes between Initial Version and Version 1 of HowTo_nco_netcdf


Ignore:
Timestamp:
2014-11-21T11:20:36+01:00 (10 years ago)
Author:
zpoussi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowTo_nco_netcdf

    v1 v1  
     1 
     2== Manual == 
     3Please have a look at if you want to make some operations on netcdf files : http://nco.sourceforge.net/#Definition 
     4 
     5The manual can be downloaded as a pdf : http://nco.sourceforge.net/nco.pdf 
     6 
     7You may have a look at one of the associated forum if you encounter some problems when using it. 
     8http://sourceforge.net/projects/nco/forums/forum/9830 
     9 
     10== Consulting netcdf files on a dods server == 
     11 
     12For netcdf files available on an OpenDAP/DODS server, one can see the format by adding .dds at the end of the file. 
     13Exemple : [[http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/database/climato/CRU_precipitation.nc.dds]] 
     14 
     15More explanation on [[http://docs.opendap.org/index.php/QuickStart]] and [[http://www.opendap.org/pub/dods/ps-docs/guide.pdf]] 
     16 
     17== Spécific note for the dods in Jussieu == 
     18 
     19to activate the dods fonctionnality, one should use the URL : [[http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/]] rather than [[http://dods.ipsl.jussieu.fr/]] 
     20 
     21For exemple, to see the characteristics of the CRU precipitation file : 
     22[[http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/database/climato/CRU_precipitation.nc.dds]] 
     23 
     24Or to get a subset of it : 
     25[[http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/database/climato/CRU_precipitation.nc.html]] 
     26 
     27 
     28More info on [[http://wiki.ipsl.jussieu.fr/wiki_ipsl/ServeurDODSintro]] 
     29 
     30== Example of use == 
     31 
     32== commande NetCDF Arithmetic Processor ncap == 
     33 
     34<code> 
     35   ncap -s "C_tot=VEGET_MAX*(CARBON_PASSIVE+CARBON_ACTIVE+LITTER);C_tot@missing_value=CARBON_PASSIVE@missing_value" soilc_af2002.nc my_soilc_af2002.nc 
     36</code> 
     37 
     38== commande ncrcat == 
     39 
     40concatenate the variables file_{23..32}.nc changing 2 digits on the number by step of 1 
     41 
     42<code> 
     43   ncrcat -n 10,2,1 file_23.nc file_global.nc 
     44</code> 
     45 
     46== commande ncwa == 
     47 
     48calculate the mean over various dimensions. 
     49 
     50== commande ncatted == 
     51 
     52o, meaning Overwrite (other possible options : a c d m ) a global attribute entitled nbyear which is a double d (other possible options : f d l s c b) 
     53 
     54<code> 
     55   ncatted -O -a nbyear,global,o,d,$ny stomate_forcing_all.nc 
     56</code> 
     57 
     58 
     59Pour modifier rapidement l'année de départ (!attention aux calendriers grégoriens pour lesquels on n'a pas le droit de procéder de la sorte!!!), c'est time_counter:units qui est interprété par ferret et non time_counter:origin. Cf /home/orchidee01/pbrender/ORCHIDEE/MERGE_PP/AGOUFOU_SPINUP_PP/SPINUP_COMPLET_v3/change_date   
     60 
     61<code> 
     62   #!/bin/bash 
     63   ncrcat -O run_100?/stomate_history.nc MA_Ago_stomate_history.nc  
     64  
     65   n_or=$( ncdump -h MA_Ago_stomate_history.nc |grep time_origin| grep -m 1 -o -E \".*\"|sed "s/2005/$[2005-109]/"|sed 's/"//g')  
     66   n_unit=$( ncdump -h MA_Ago_stomate_history.nc |grep time_counter:units| grep -m 1 -o -E \".*\"|sed "s/2005/$[2005-109]/"|sed 's/"//g')  
     67  
     68   ncatted -O -a time_origin,time_counter,o,c,"${n_or}" MA_Ago_stomate_history.nc  
     69   ncatted -O -a units,time_counter,o,c,"${n_unit}" MA_Ago_stomate_history.nc  
     70</code> 
     71 
     72== sélection d'une partie d'un fichier netcdf == 
     73 
     74<code> 
     75   ncks -d tstep,0,17519 wankame_gapfilled.nc wankama_gapfilled_2005.nc 
     76</code> 
     77 
     78== conversion to ascii and reverse == 
     79 
     80pour rapide examen de la structure 
     81 
     82<code>  
     83   ncdump -c 
     84</code> 
     85 
     86pour l'extraction ascii d'une variable 
     87 
     88<code> 
     89   ncdump -v temp -f fortran -n name > output.cdl 
     90</code> 
     91 
     92pour récupérer un fichier netcdf à partir de la fraction extraite 
     93 
     94<code> 
     95   ncgen -b -o my_new_name output.cdl 
     96</code> 
     97 
     98utile aussi quand on rencontre un problème sur une commande par exemple ncatted. Ie pour faire des corrections à la main ! 
     99 
     100== ncview == 
     101 
     102<code> 
     103   ncview 
     104</code> 
     105 
     106Installation : 
     107<code> 
     108   sudo apt-get install xorg-dev netcdfg-dev 
     109   ./configure --x-libraries=/usr/lib 
     110   make 
     111   sudo make install 
     112</code> 
     113 
     114voir aussi cdat et vcdat comme utilitaires de visualisation rapide 
     115 
     116== ncap2 == 
     117 
     118<code> 
     119   ncap2 -O -v -s 'gpp_moy=(GPP*VEGET_MAX).avg($PFT)' stomate_history.nc my_history.nc 
     120</code> 
     121 
     122voir exemples de commandes sur : http://nco.sourceforge.net/ncap2.in 
     123 
     124== ncpdq == 
     125 
     126ncpdq makes it possible to concatenate files along any dimension, not just the record dimension. First, use ncpdq to convert the dimension to be concatenated (i.e., extended with data from other files) into the record dimension. As a concrete example, say that files x_01.nc, x_02.nc, ... x_10.nc contain time-evolving datasets from spatially adjacent regions. The time and spatial coordinates are time and x, respectively. Initially the record dimension is time. Our goal is to create a single file that contains joins all the spatially adjacent regions into one single time-evolving dataset. 
     127 
     128<code> 
     129   for idx in 01 02 03 04 05 06 07 08 09 10; do # Bourne Shell 
     130   ncpdq -a x,time x_${idx}.nc foo_${idx}.nc # Make x record dimension 
     131   done 
     132   ncrcat foo_??.nc out.nc       # Concatenate along x 
     133   ncpdq -a time,x out.nc out.nc # Revert to time as record dimension 
     134</code> 
     135 
     136---- 
     137 
     138[[reunions_orchidee:cdo_netcdf|Page dedicated to the cdo function]]