Re: converting 2D array to 3D array

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 09 2012 - 16:01:57 MDT

On Apr 9, 2012, at 3:01 PM, juki juki wrote:

> Mary, thanks for reply. The enclosed data are (101 x 3) x 406 that mean: first hour has 101 x 406 array, the second hours (row 102th..202) has 101 x 406 array and soon..

Actually, by that description, it sounds like your data is ordered 3 x 101 x 406. The rightmost dimension is the fastest varying dimension.

>
> Is it possible to save re-ordered 3D data to ASCII file or must be in netcdf?

You can write the data to either an ASCII file or a NetCDF file. asciiwrite writes one data value per line, which is not very useful. write_matrix writes only 2D arrays to a file.

I would use a combination of sprintf, sprinti, and asciiwrite in order to create the lines of data I wanted to write. You can see an example at:

http://www.ncl.ucar.edu/Applications/o-ascii.shtml

But, I have to ask, in what format would you want your ASCII data? I think it's better to store it in NetCDF. Most plotting and analysis tools in our line of business should recognize NetCDF.

> Another question, is it possible by ncl to produce a volumetric plot ? I want to make a 3D map plot from this data. Thus, I can see the distribution of the data in 3D map/plot (lat-long-time).

You might want to look into Vapor for this: http://www.vapor.ucar.edu/

--Mary

>
> From the enclosed data, time (year, month, day, hour) is located at 1st to 4th column, 5th column to end = data. Thanks again for such helps.
>
> JukY
>
>
>
>
>
> From: Mary Haley <haley@ucar.edu>
> To: juki juki <juky_emc2@yahoo.com>
> Cc: "ncl-talk@ucar.edu" <ncl-talk@ucar.edu>
> Sent: Monday, April 9, 2012 8:54 PM
> Subject: Re: converting 2D array to 3D array
>
> Juky,
>
> You enclosed a data file, but you didn't indicate how the data are written to this file, so I'm not sure how to read it in.
>
> You can go from a 2D array to a 3D array by using a combination of ndtooned, onedtond, and possibly reordering commands.
>
> I'm not sure how your 303 x 406 array is ordered with regard to the "3" and the "101" values. It depends on how it is laid out. That is, is it laid out as (3x101) x 406, or as (101x3) x 406?
>
> If it is (3x101) x 406, then you could do something like:
>
> ;---Convert from 303 x 406 to 3 x 101 x 406
> data3d = onedtond(ndtooned(data2d),(/3,101,406/))
>
> ;---Reorder to 101 x 406 x 3
> data3d!0 = "dim0"
> data3d!1 = "dim1"
> data3d!2 = "dim2"
> data3d_reorder = data3d( dim1 | :, dim2 | :, dim0 | :)
>
> ;---Check the results
> printVarSummary(data3d_reorder)
>
>
> If it's (101x3) x 406:
>
> ;---Convert from 303 x 406 to 101 x 3 x 406
> data3d = onedtond(ndtooned(data2d),(/101,3,406/))
>
> ;---Reorder to 101 x 406 x 3
> data3d!0 = "dim0"
> data3d!1 = "dim1"
> data3d!2 = "dim2"
> data3d_reorder = data3d( dim0 | :, dim2 | :, dim1 | :)
>
> ;---Check the results
> printVarSummary(data3d_reorder)
>
> I used "dim0", "dim1" as examples here, but you should use whatever names are appropriate for your data's dimensions, like "lat", "lon", "time", etc.
>
> --Mary
>
> On Apr 6, 2012, at 3:19 AM, juki juki wrote:
>
> > Hi all,
> >
> > I would like to convert 2D to 3D array and save it as ascii file (txt file). Enclosed file is an example. This file is from 3 hours observation(hourly) for latitude -10:10 and longitude 70:160E. I want to convert this 2D (303 x 406) to become 3D (101 x 406x 3) and save it to ascii file or if it is not possible to binary file. I think, almost all of NCAR data like OLR is 3D array format, but in nc file, how to produce it for text file or binary file using ncl language ? Thanks for sharing....
> >
> > JuKy
> >
> >
> >
> >
> > <200111.txt>_______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 9 16:02:08 2012

This archive was generated by hypermail 2.1.8 : Fri Apr 13 2012 - 13:37:52 MDT