[Thread Prev][Thread Next][Index]

Re: [ferret_users] insert data into variable at certain time step



Hi Fabian,
                          I am making an assumption from ur mail else this may not work.
1) you are initially listing data to an ascii file  from netcdf using ferret ( I guess so as you say
crashes or complains about the missing
values ***** in the text file.)

 To solve this you need to set  the variable as bad with a specific number
set var/bad= -999.999 temp
list/file=temp.dat/format=(f10.4)/nohead  temp

2) Then while reading you read  variable as temp to ferret and then
set var/bad=-999.999 temp

this will tell ferret that there are missing values in the data.
Hope this helps
sjo

On Thu, Jun 25, 2009 at 11:32 PM, Fabian Lienert <cccma-student-003@xxxxxxxx> wrote:
Hi Ferret crowd,

The script below works fine if there are no missing values. Since I started
computing lagged correlations for SST, a netcdf dataset with missing values,
the troubles started. Ferret crashes when reading an ASCII file with missing
values. Adding different format options when writing and reading text file like list/form=comma didn't help, Fferret either crashes or complains about the missing
values ***** in the text file.

So I tried writing the 2d field 'correl' in the repeat loop into a netcdf file
using save/append/file="temp.nc"/clobber correl[g=sst[d=2]] without success.
Correl does not have a time axis, so correl is not appended but overwritten.
Using just save/append/file="temp.nc" or adding and increasing /l=1 does not help either.
I also tried to define different time axis for correl like the following, without success.
def axis/t=1:3:1 lagx; def grid/like=sst[d=2,l=1]/t=lagx glag; correl[g=glag]

The only fix I could come up with was the following:
let max_lag = 1
repeat/range=`-1*max_lag`:`max_lag`:1/name=lag (let q = some_ts[l=@shf:`lag`]; let p = sst[d=2]; go variance;\
           let lagcorr = correl + 0*sst[d=2,l=`lag+max_lag+1`];\
            save/append/file="temp.nc"/clobber lagcorr;\
            cancel var correl; cancel var q; cancel var p; cancel memory )

Cheers,
Fabian


Fabian Lienert wrote:
Thanks very much Mick,

I tested the commands. There should be an append option while writing
the ASCII file in order not to overwrite the previous one.
So for people finding this useful, below is the corrected version.

Cheers,
Fabian


use my_data  !(the original xyt dataset containing "myvar")
spawn touch temp.file
repeat/range=1:5/name=lag ( ... define and compute the lagged correlation variable "correl" from "myvar"  ;\
  list/nohead/file=temp.file/form=(f12.5)/append correl )
def axis/t=1:5:1 lagx
def grid/like=myvar[d=1]/t=lagx glag
file/form=free/g=glag/ord=xyt/var=mylagvar temp.file
set var/title="Lagged Correlations" mylagvar
! now you can plot or use them ... or use ferret to write them to a netCDF file then discard temp.file
save/file=MyLaggedResults.nc mylagvar


mick spillane wrote:
Hi Fabian,
  Unlike some other languages, what you are doing in Ferret is setting up the algebraic quantities to compute something, until you use or write the variable you define, it doesn't exist as a number. Your situation is a case like this -- for each lag the definition is changing so it is best to write out the results for each lag to a file, then read them back later.
  The most elegant way would be to write to a netCDF file, one time slice (lag) at a time.  But, unless the x-y grid is huge, I typically write to an ASCII file (one value per record) then define the appropriate grid and read it back. It would go something like this:

use my_data  !(the original xyt dataset containing "myvar")
spawn touch temp.file
repeat/range=1:5/name=lag ( ... define and compute the lagged correlation variable "correl" from "myvar"  ;\
   list/nohead/file=temp.file/form=(f12.5) correl )
def axis/t=1:5:1 lagx
def grid/like=myvar[d=1]/t=lagx glag
file/form=free/g=glag/ord=xyt/var=mylagvar temp.file
set var/title="Lagged Correlations" mylagvar
! now you can plot or use them ... or use ferret to write them to a netCDF file then discard temp.file
save/file=MyLaggedResults.nc mylagvar

Things to note:
1) ";\" continues the repeat statement to the next line
2)  the build up lag-by-lag of the results file
3) I just typed this in without doing a demo -- there may be typos but I hope the gist is clear

Hope it helps,
Mick
PS Look in the user guide for the slice-by-slice construction of a netCDF file if you like to be more elegant
-------
Fabian Lienert wrote:
Hi Ferreters,

Simple question, couldn't find an answer so far.
In a repeat loop, I am calculating lagged cross correlations:

yes? repeat/range = 1:5:1/Name=lag (let q = timeseries[d=1,i=1,l=@shf:`lag`]; \
        let p = 3dvariable[d=2]; go variance;\
All I want to do is to insert a 2-d field (correl) into a 3-d variable (x,y,t) at each time step inside the repeat loop, something like the following.
        let lag_corr/l=`lag` = correl)

In other programming languages this is easily done by filling an array:
for (t in 1:5) {
   lag_corr[,,t] = correl(t)
}

I am using FERRET v6.1 on Ubuntu Linux.

Any help appreciated,
Fabian





--
Fabian Lienert                  |  Canadian Centre for Climate Modelling and Analysis
PhD Student                     |  Meteorological Service of Canada
phone: +1(250)721-7211          |  University of Victoria
cccma-student-003@xxxxxxxx      |  P.O. Box 1700
http://www.cccma.bc.ec.gc.ca    |  Victoria, BC,  V8W 2Y2, Canada



--
**********************************************************************************
Sudheer Joseph                                                                  
Scientist                                                                                    
Indian National Centre for Ocean Information Services (INCOIS)    
Ocean Valley, Post Box No# 21,
IDA Jeedimetla P.O.                  
Hyderabad, Ranga Reddy District - 500 055
Andhra Pradesh, India.
TEl:+91-40-23044600(R),Tel:+91-9440832534(Mobile)
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O)
E-mail:sjo@xxxxxxxxxxxxxx; sudheer.joseph@xxxxxxxxx;  sjo@xxxxxxxxxxxxx.
Web- http://oppamthadathil.tripod.com
          --------------* ---------------
"The ultimate measure of a man is
not where he stands in moments of
comfort and convenience, but where
he stands at times of challenge and
controversy."
                       Martin Luther King, Jr.

[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement