Menu

How to replace some values of a variable?

chuck b
2011-05-16
2015-12-18
  • chuck b

    chuck b - 2011-05-16

    Greetings,
    How do I change some values of a particular variable in a bunch of my netcdf files?
    Any advice would be greatly appreciated.  Here's what I wish to do:

    Change variable "zaxis = 1, 2, 3;" to "zaxis = 0.3, 0.6, 0.9;" for the file below:


    netcdf filex {
    dimensions:
            two = 2 ;
            three = 3 ;
            time = UNLIMITED ; // (15 currently)
            xaxis = 1320 ;
            yaxis = 1482 ;
            zaxis = 3 ;
            zip2 = 1117087 ;
            zip3 = 5587693 ;
    variables:
            int zaxis(zaxis) ;
                    zaxis:long_name = "coordinate variables of zaxis" ;
                    zaxis:units = "sigma_level" ;
                    zaxis:figure = "na" ;
                    zaxis:positive = "down" ;

    zaxis = 1, 2, 3 ;


    I  tried the following command but the command unexpectedly changed other things in my file.  For example, some dimensions got deleted; zaxis variable got deleted.

    %  ncap -s 'zaxis=.33;zaxis=.66;zaxis=.99' filex.nc  x.nc

    I got:

    netcdf x {
    dimensions:
            time = UNLIMITED ; // (15 currently)
            xaxis = 1320 ;
            yaxis = 1482 ;
            zaxis = 3 ;
    variables:
            double zaxis ;

    zaxis = 0.33 ;


    Thanks.
    -chk

     
  • Charlie Zender

    Charlie Zender - 2011-05-16

    Use ncap2. Both of these should work:

    ncap2 -s 'zaxis/=3.3333333' filex.nc x.nc
    ncap2 -s 'zaxis(:)={0.33,0.66,0.99}' filex.nc x.nc

    cz

     
    • Jim Noel

      Jim Noel - 2015-12-18

      So I am trying to change the value of dimension lat and lon in two files to be the same.

      dimensions:
      time = UNLIMITED; // (1 currently)
      lat = 73;
      lon = 144;

      dimensions:
      time = UNLIMITED;   // (1 currently)
      lat = 92;
      lon = 192;
      
      I want both to be the same values of 92,192
      
       
      • Charlie Zender

        Charlie Zender - 2015-12-18

        Clarify how/whether you want to regrid, extrapolate, leave empty the values of the associated coordinates and data fields.
        cz

         
  • chuck b

    chuck b - 2011-05-18

    Many thanks, Charlie.
    -chk

     
  • Emanuele

    Emanuele - 2014-08-29

    Hi, I have the same problem.
    I would like to replace all the null values ​​with a "zero" value:

    from


    netcdf current {
    dimensions:
    ...
    ...
    variables
    float current (lon, lat, time)
    ...
    ...

    current:
    , , , , 1, , , , , , , 3, , , 25, , , , , _


    in

    current:
    0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 25, 0, 0, 0,......

    thanks
    Emanuele

     

    Last edit: Emanuele 2014-08-29
  • Charlie Zender

    Charlie Zender - 2014-08-29

    ncap2 where() syntax can do this:
    http://nco.sf.net/nco.html#where
    cz

     

Log in to post a comment.

MongoDB Logo MongoDB