[Thread Prev][Thread Next][Index]

Re: [ferret_users] add (degenerate) axis to variable



Hi Andy,

NCO is often a really good answer, and of course you could do all of this with NCO. 

But since we're on the topic, maybe I can finish it off from the Ferret point of view.  (By the way, look for "timestamp" in the Ferret documentation.)

If your time axis is defined as a calendar time axis with recognized time units and timesteps defined terms of dates, it should automatically be marked as the record axis when saved to a netCDF file. 


! open dataset containing SST, and define the time axis.

use my_xy_data.nc
define axis/t=1-jan-2020:1-jan-2020:1/units=days tax

! A variable with value 0 on the time axis.

let timestamp = 0*t[gt=tax]

! Rename the file variable, so we can keep the original name in the new file

set variable/name=sst_in sst

! Define the variable with the original name, units, and title, and
! adding the time axis to the grid.  tax is the record axis.

let/like=sst_in sst = sst_in + timestamp
save/clobber/file=new_xyt_data.nc sst


A pretty common thing is for someone to create a set of files files containing for example a single month per file, but the variables in the files have no time axis.  The time information might be in an attribute somewhere or be indicated only by the filename.  The framework above can be used to define a a time axis for the whole  time range and then apply the appropriate timestep to each file. 

There is much discussion of monthly time axes in the documentation, regularly-spaced axes, true monthly axes, and so on.  See the "DEFINE" section of the manual.  Here I'll show how this goes using a regularly spaced axis.


! Define a monthly axis and a timestamp variable, 0 at all the timesteps.

define axis/t=1-jan-2020:31-jul-2022:1
/t0=1-jan-2000/units=month/edges tmonth
let timestamp = 0*t[gt=tmonth]

! Open the files one by one, add the timestep variable, and then write out the
! correct single timestep for this dataset to a new file.

use data_01_2020.nc

set variable/name=sst_in sst

let/like=sst_in sst = sst_in + timestamp
save/clobber/file=data_01_2020_fixed.nc sst[L=1]
cancel data/all

use data_02_2020.nc
set variable/name=sst_in sst
let/like=sst_in sst = sst_in + timestamp
save/clobber/file=data_02_2020_fixed.nc sst[L=2]
cancel data/all

...


Now, you can use a time aggregation to work with the set of files as a virtual timeseries dataset, see https://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/commands-reference/DEFINE#_define_data_agg


! new session


let file_list = SPAWN ("ls -1 data_*fixed.nc")

tseries sst_months = file_list

show data       ! sst in dataset sst_months will have a time axis
show grid sst   ! the time axis is tmonth




On 4/1/2021 10:12 AM, Andy Jacobson wrote:
Just FYI, NCO makes this extremely easy:

ncks -O --mk_rec_dmn time ${infile} ${outfile}

-Andy

On 3/31/21 7:17 PM, Andy Jacobson wrote:
That works! Thanks, Ansley. Now...is there some magic that I can use to designate my new time axis as the record (unlimited) dimension?

Best,

Andy

On 3/31/21 6:59 PM, Ansley Manke wrote:
Hi Andy,

You can add a variable on the desired time axis with a value of 0 everywhere.  This uses the idea of "conformability <https://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/variables-xpressions/XPRESSIONS#_VPINDEXENTRY_300>" - the principals that govern how variables created from on unlike grids can be combined.

so,

yes? let/like=temp temp_new = temp + 0*t[gt=t1]

Ansley

On 3/31/2021 10:35 AM, Andy Jacobson wrote:
Yes, I tried [...gt=t1@asn] syntax. Ferret didn't complain, but it didn't output that time axis either.

Thanks,

Andy

On 3/31/21 10:44 AM, Satyesh Ghetiya wrote:
Have you tried giving that time axis to variable by GT ? -->
let your variable is Temp and time axis name is T1, then -->
let Temp_new=Temp[gt=T1]

^ This should work.

On Wed, Mar 31, 2021 at 10:04 PM Andy Jacobson <andy.jacobson@xxxxxxxx <mailto:andy.jacobson@xxxxxxxx>> wrote:

    Howdy,

    I have a 2-d variable (lat, lon) that I read from a well-formatted netCDF file. This represents one month out of a time series of many such files. I'd like to add a time axis to this variable. I've defined my single-point time axis, but I can't figure out how to convince ferret to add this time axis to my variable. Normally I'd do this in NCO but I'd like to stay in ferret this time. Is there some reshape trickery involved?

    Thanks,

    Andy

    --     Andy Jacobson
andy.jacobson@xxxxxxxx <mailto:andy.jacobson@xxxxxxxx>

    NOAA Global Monitoring Laboratory
    325 Broadway R/GMD1
    Boulder, Colorado 80305

    303/497-4916



G Satyesh,
India





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

Privacy Policy | Disclaimer | Accessibility Statement