[Thread Prev][Thread Next][Index]

Re: [ferret_users] reading ascii data ?



thanks a lot Ansley Manke, for the help and your valuable time for me.
I could manage the drawings to my satisfaction.
I just worked the *.jnl file attached here with all ur suggestions. Please feel free to
correct the same and make it available for all who wants it.
___________________
! irregular grid (slanting, curvi-linear coordinate) plotting exercise.
! with ascii data. ferret reads data easily, if data is written as below:
!c do k=1,ks !(for 3D... depth levels)
! do j=1,jm !( latitudes)
! do i=1,im !( longitudes)
! write() lon(i,j),lat(i,j),sal(i,j)
!c write() lon(i,j),lat(i,j),depth,sal(i,j,k) ! for 3D
! enddo
! defining the grid size
let im=500 ! no of longitudes points (not longitude values)
let jm=396 ! no. of lalitude points (not latitude vales)
define axis/x=1:500:1 xindex
define axis/y=1:396:1 yindex
!for 3D
! define axis/z/depth/units=meters zdepth={1,5,10,...,100..} !set of depths
!OR
! define axis/z=0:1000:50/depth/units=meters zdepth !regular- spaced depths
!defining grid
define grid/x=xindex/y=yindex index_grid ! for 2D
! define grid/x=xindex/y=yindex/z=zdepth xyz_grid ! for 3D
!defining the data file, one can skip any 'n' no of header line by /skip=n
file/grid=index_grid/var="lon,lat,sal" rew.dat ! for 2D!
! file/grid=xyz_grid/var="lon,lat,depth,sal" filnam.dat ! for 3D
!set up units for lon, lat, sal
set variable/units=degrees_east lon
set variable/units=degrees_north lat
set variable/bad=-999/units=ppm sal
!plotting
set window/aspect=0.55:axis
shade sal,lon,lat ! this is a raster plot - each grid box is a 4-sided shape
fill sal,lon,lat ! this is a filled color contour plot.
!for 3D
! shade/z=0 sal,lon,lat ! this is for raster plot for depth z=0mts
! fill/z=50,sal,lon,lat ! for filed color contour plot for depth z=50mts
! ! one can choose /k=5 for 5th depth level
!saving file in netCDF format
SAVE/file=filname.nc sal,lon,lat
!(for 3D: sal,lon[k=1],lat[k=1])

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----Original Message-----
From: Ansley Manke <Ansley.B.Manke@xxxxxxxx>
To: Srinivas Chamarthi <schamarthi1@xxxxxx>
Sent: Tue, 11 Aug 2009 5:06 am
Subject: Re: [ferret_users] reading ascii data ?

Hi -
Let's work this out and then we can report the answer back to the Users List so that it is there for others to learn from and to find if they have the same question later on.

Ferret assumes that in ascii data, i varies fastest, then j, then k.  So it would be easier if your data were written out using these loops:

for given layer (2D)

do j=1,jm  (latitude)
do i=1,im  (longitude)
........ lon(i,j),lat(i,j),u(i,j)
enddo

and for 3D

do k=1,ks
do j=1,jm  (latitude)
do i=1,im  (longitude)
........ lon,(i,j),lat(i,j),depth,u(i,j,k)
enddo

If you can re-do your data using the above code, everything will be quite easy. You can set up Ferret to read your file like this:

First try just a 2D case, or read just the first depth of a 3D case.  If your data is in a file called file.dat, you can read your data like this.  (If there are any header lines on the file, then use FILE/SKIP=n/grid=   where n is the number of records to skip.)
yes? ! Fill in the correct values for your data here:
yes? let im = 15
yes? let jm = 22

yes? define axis/x=1:`im`:1 xindex
yes? define axis/y=1:`jm`:1 yindex

yes? define grid/x=xindex/y=yindex  index_grid

yes? file/grid=index_grid/var="lon,lat,u"  file.dat   ! Open the file (add /skip=4 to skip 4 records)

yes? ! Set up units for lon, lat, and u
yes? set variable/units=degrees_east lon    ! Longitude in degrees_east
yes? set variable/units=degrees_north lat   ! Latitude in degrees_north
yes? set variable/units="m/s" u          ! Units for the variable u will be in the plot labels

yes? shade u, lon, lat    ! This is a raster plot - each grid box is a 4-sided shape
yes? pause

yes? fill u, lon, lat   ! This is a filled color contour plot.
If you specify degrees for the units of Longitude and Latitude, these are assumed to be in degrees longitude east and degrees latitude north.  If you find that your plot is being shown in the wrong part of the world, you might need to define the units differently, or perhaps multiply the values of longitude or latitude by -1.  We can figure this out later if we need to.

Now, try the 3D case.  If the Z values are depth, then you add a /depth qualifier to the axis definition, so that Z is shown as depth. Here you probably know the depths in meters.  I will show how you could define a depth axis from a set of numbers, and also how you could set up the depth axis if it's just a regularly-spaced axis.  I am assuming that the depths are constant over the grid, that is each depth level is the same at all of the longitude,latitude locations.
yes? ! Fill in the correct values here:
yes? let im = 15
yes? let jm = 22

yes? define axis/x=1:`im`:1 xindex
yes? define axis/y=1:`jm`:1 yindex

yes?  ! Use ONE of these kinds of axis definitions, with the numbers changed to reflect your data:

yes? define axis/z/depth/units=meters zdepth = {0,5,10,20,40,100,200,400,600,1000}  ! A set of depths yes? define axis/z=0:1000:50/depth/units=meters zdepth   ! a regularly-spaced set of depths

yes? define grid/x=xindex/y=yindex/z=zdepth  xyz_grid

yes? file/grid=xyz_grid/var="lon,lat,depth,u"  file.dat    ! If you need to, add /SKIP=n

yes? ! Set up units for lon, lat, and u
yes? set variable/units=degrees_east lon    ! Longitude in degrees_east
yes? set variable/units=degrees_north lat   ! Latitude in degrees_north
yes? set variable/units="m/s" u          ! Units for the variable u will be in the plot labels

yes? shade/z=0 u, lon, lat    ! This is a raster plot - each grid box is a 4-sided shape
yes? pause

yes? fill/z=0 u, lon, lat   ! This is a filled color contour plot.

To see the data at a particular depth you can choose /Z=20 for 20 meters, or  /K=5  for the 5th depth.


Finally, once you have your data read into Ferret, you might write it out in netCDF format, which Ferret can then read back in using just one command. After the FILE command above, do something like this. Choose any filename, and use the extension   .nc

       yes? SAVE/file=u_velocity.nc  u, lon[k=1], lat[k=1]

The depths will be saved as a coordinate axis, so you don't need to list depth in the command. The longitudes and latitudes are the same at all depths, so you don't want to write them out for all depths, only for one.

Now, next time you want to work with this data, the Ferret commands are very simple:
yes? use u_velocity.nc
yes? shade/z=100 u, lon, lat   
--------------------------------------------------------------------------
Srinivas Chamarthi wrote:
Thanks a lot. U have just released all the steam of anxiety.
Yeah... the data is generated from a fortran statement as below

for given layer (2D)

do i=1,im  (longitude)
do j=1,jm  (latitude)
........ lon(i,j),lat(i,j),u(i,j)
enddo

and for 3D

do i=1,im  (longitude)
do j=1,jm  (latitude)
do k=1,ks
........ lon,(i,j),lat(i,j),depth,u(i,j,k)
enddo

i generally use this data in plotting in tecplot with some headers

--------------------------------------------------------

-----Original Message-----
From: Ansley Manke <Ansley.B.Manke@xxxxxxxx>
To: Srinivas Chamarthi <schamarthi1@xxxxxx>
Cc: oar.pmel.ferret_users@xxxxxxxx
Sent: Fri, 7 Aug 2009 10:35 pm
Subject: Re: [ferret_users] reading ascii data ?

Hi Chamarthi,
How are the longitudes and latitudes arranged in your input file? One method as others have suggested is to interpolate the data onto a regular grid, but if we can work out how to read the longitude and latitude locations into a 2-dimensional grid, and the data field onto the correct 3-dimensional grid, then you could visualize the data on the curvilinear grid without regridding it.

For plotting data on the curvilinear grid, Ferret expects that the longitudes and latitudes, as well as the data field are arranged on a grid in X and Y where X and Y are just index values 1 to M and 1 to N, so that after opening the file and defining the grid correctly, you could do a SHOW DATA command, and see something like this:
yes? show data
    1> /home/porter/ansley/data.dat  (default)
 name     title          I         J         K         L
 LON     Longitude      1:180     1:173     ...       ...
 LAT     Latitude       1:180     1:173     ...       ...
 TEMP    Temperature    1:180     1:173    1:19       ...
You would open your data file, if possible following the examples found in the Ferret Users Guide by following the index entry "ASCII data: reading, examples", and then the command to make the plot would be a FILL or SHADE command such as
yes? FILL/Z=0 temp, lon, lat
Then the plot will show both the data, and the shape of the curvilinear grid.

If you need help reading your data, please send more information showing the format of your ASCII file.

Ansley

---------------------------------------------------------------------
Srinivas Chamarthi wrote:
hello everybody!
I am new to ferret but attracted to its features. The user-friendly nature of the user groups
and the moderators kindness is welcoming.

I have a problem with curvilinear coordinate grid. I am having the data in 3D space, but the grid is 
curvilinear and its southern boundary is from 40E-120E but the northern boundary is 60E-85E. It
looks like a trapezium.
Many (not here on user group) have suggested to treat each lat-log position as a profile and interpolate
these profiles onto a regular grid. I am finding it a little difficult and also the data is not reproduced
to my satisfaction. I do not know what the command is doing and what algorithm it is using etc.

Can some one working with this type of problem help me out to draw the plots?!

thanks in advance.
Chamarthi

[Thread Prev][Thread Next][Index]

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

Privacy Policy | Disclaimer | Accessibility Statement