Re: Reading from netcdf files within NCL again - with more information

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Aug 23 2013 - 15:26:51 MDT

Hi Helen,

Andy did respond to your message, but I think the message was only sent to ncl-talk.

I will repeat some of what Andy already suggested, and add a second suggestion.

First, to read just the first of the 10 outputs, you can use index subscripting. Copying from
Andy's original response, it might look like this:

  PS = fi->PS(0,:,:)
  U = fi->U(0,:,:,:)
Indexing in NCL starts at 0, so index 0 is the first model output.

My second suggestion will be to use "addfiles". This allows you to read in
the variables across all 50 files without having to loop. I don't know if this
is what you want, because you didn't say what the different files represent.

But, just in case this is helpful, then you can do this:

fi = addfiles (diri+fili, "r")
U = fi[:]->U

Then "U" will still be a 4D array, but it will now be a 500 x 50 x 192 x 288 array,
because NCL contentates the leftmost dimension across all 50 files. This
is called "cat" mode.

If you do this, and use the "join" mode instead:

  fi = addfiles (diri+fili, "r")
  ListSetType(fi, "join")
  U = fi[:]->U

Then "U" will be a 5D array, dimensioned 50 x 10 x 50 x 192 x 288.

This second method may be better for you, if you indeed want that first timestep.
You can now dimension "U" with:

  U = fi[:]->U(:,0,:,:,:)

and "U" will be 50 x 50 x 192 x 288, where the leftmost dimension represents
the 50 different files, and the other dimensions represent lev x lat lon.

--Mary

On Aug 23, 2013, at 2:35 PM, Helen Parish <hparish@ess.ucla.edu> wrote:

> I am resending this message with more information as I am told it may
> be difficult to know what the variables look like. I include a
> printVarSummary(U), printVarSummary(PS), and printVarSummary(lat) at
> the end if my question below. I am also told that Andy Mai may have
> responded to my post, but I did not receive that reply for some
> reason. Perhaps Andy could reply again if possible ?. Also, anyone
> else who has any ideas about how to do this.
>
> Thanks,
> Helen.
>
> I am trying to read data from 50 netcdf files. Within each of these
> netcdf files there are 10 model outputs (from the CAM model). I would
> like to read in the variables from only the first of the 10 outputs in
> each netcdf file. I am wondering if there is a way to do this kind of
> read within NCL ?. I have been using lines like these within my script
> to read variables from all the files :
>
> do nf = 0, nfili-1
>
> fi = addfile (diri+fili(nf), "r")
>
> PS = fi->PS
> U = fi->U
> lat = fi->lat
>
> end do
>
> However, this reads in all of the 10 outputs within the file.
>
> Does anyone know how to read in just one of the 10 outputs from each
> of the 50 files ?.
>
> Thanks,
> Helen.
>
> Variable: U
> Type: float
> Total Size: 110592000 bytes
> 27648000 values
> Number of Dimensions: 4
> Dimensions and sizes: [time | 10] x [lev | 50] x [lat | 192] x [lon |
> 288]
> Coordinates:
> time: [37333.33333333334..37438.33333333334]
> lev: [0.03554912016..91942.93428213599]
> lat: [ -90.. 90]
> lon: [ 0..358.75]
> Number Of Attributes: 3
> cell_methods : time: mean
> long_name : Zonal wind
> units : m/s
>
> Variable: PS
> Type: float
> Total Size: 2211840 bytes
> 552960 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 10] x [lat | 192] x [lon | 288]
> Coordinates:
> time: [37333.33333333334..37438.33333333334]
> lat: [ -90.. 90]
> lon: [ 0..358.75]
> Number Of Attributes: 3
> cell_methods : time: mean
> long_name : Surface pressure
> units : Pa
>
> Variable: lat
> Type: double
> Total Size: 1536 bytes
> 192 values
> Number of Dimensions: 1
> Dimensions and sizes: [lat | 192]
> Coordinates:
> lat: [ -90.. 90]
> Number Of Attributes: 2
> units : degrees_north
> long_name : latitude
>
> _______________________________________________
> 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 Fri Aug 23 15:27:02 2013

This archive was generated by hypermail 2.1.8 : Fri Aug 30 2013 - 14:04:57 MDT