[Thread Prev][Thread Next][Index]

Re: [ferret_users] question about replace a value on a grid



Hi Steve,

Thanks for your reply. The technique works.  Thanks!

Liya

Steve Hankin wrote:
Hi Liya,

In case you are a newcomer to Ferret I'll mention that as a general rule Ferret style prefers that you do not alter the original file. Instead use the LET command with an IF clause to define a new variable based on the file variable, but having the corrections you want. Then use the new LET-defined variable instead of the original for whatever your analysis and visualization needs are.

If you really do want to edit the file, though, it is just a small addition to the above strategy. You use the SET VARIABLE/NAME (http://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/commands-reference/SET#_VPINDEXENTRY_1760) as you see below. Note that the technique is elegant if you have a block of values to change through a systematic algorithm; it is clumsy if you have a collection of individual replacements.

Here's a very quick example session that replaces the single value of "sst" at i=50,j=50,l=5

    * *create a test file for experimentation*
      yes? use coads_climatology
      yes? save/file=my_edit_test.nc sst

    * *open the file and replace one value in it*
      yes? use my_edit_test
      yes? show data
           currently SET data sets:
          1> ./my_edit_test.nc  (default)
name title I J K L SST SEA SURFACE TEMPERATURE 1:180 1:90 ... 1:12 yes? list sst[i=50,j=50,l=5]
                   VARIABLE : SEA SURFACE TEMPERATURE (Deg C)
                   FILENAME : my_edit_test.nc
                   LONGITUDE: 119E
                   LATITUDE : 9N
                   TIME     : 16-MAY 23:56
                29.67
      yes? set var/name=old_sst sst
      yes? show data
           currently SET data sets:
          1> ./my_edit_test.nc  (default)
name title I J K L OLD_SST SEA SURFACE TEMPERATURE 1:180 1:90 ... 1:12 yes? let sst = IF i eq 50 AND j eq 50 AND l eq 5 then 999 else
      old_sst
      yes? save/append/file=my_edit_test.nc sst[i=50,j=50,l=5]
       LISTing to file my_edit_test.nc
      yes? q

    * *confirm that the change has been made
      *yes? use my_edit_test.nc
      yes? list sst[i=50,j=50,l=5]
                   VARIABLE : SEA SURFACE TEMPERATURE (Deg C)
                   FILENAME : my_edit_test.nc
                   LONGITUDE: 119E
                   LATITUDE : 9N
                   TIME     : 16-MAY 23:56
                999.0

You might check the email archives to see if there is more detail on this subject (http://ferret.pmel.noaa.gov/Ferret/email-users-group).
    - Steve

====================================

On 3/21/2011 1:03 PM, Liya Jin wrote:
Dear Ferreters,

There is a data file (sst.nc) like this:

(ncdump -h sst.nc)

dimensions:
      x = 182 ;
      y = 149 ;
      deptht = 31 ;
      time = UNLIMITED ; // (73 currently)
variables:
      float nav_lon(y, x) ;
              nav_lon:long_name = "Longitude" ;
              nav_lon:units = "degrees_east" ;
              nav_lon:standard_name = "longitude" ;
      float nav_lat(y, x) ;
              nav_lat:long_name = "Latitude" ;
              nav_lat:units = "degrees_north" ;
              nav_lat:standard_name = "latitude" ;
      float deptht(deptht) ;
              deptht:long_name = "Vertical T levels" ;
              deptht:units = "m" ;
      double time(time) ;
              time:units = "days since 999-01-03 12:00" ;
    float sosstsst(time, y, x) ;
              sosstsst:long_name = "Sea Surface temperature" ;
              sosstsst:units = "C" ;
              sosstsst:coordinates = "nav_lon nav_lat" ;
              sosstsst:valid_min = 1.00000002004088e+20 ;
              sosstsst:valid_max = -1.00000002004088e+20 ;
              sosstsst:short_name = "sosstsst" ;
              sosstsst:online_operation = "ave(x)" ;
              sosstsst:interval_operation = 5760. ;
              sosstsst:interval_write = 432000. ;

I would like to replace the values of some grids of the variable (sosstsst) with new values, e.g., replace sosstsst(time, 88,160) with sosstsst(time, 89,160), or with the interpolated values of surrounding grids (e.g., (sosstsst(time, 89,160)+sosstsst(time, 90,160))/2). Then the sosstsst(time, 88,160) will have a new value in sst.nc.

How can I do this with Ferret? Thanks for your help!

Regards,
Liya



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement