[ncl-talk] NCL Creating Time Series Plots

Adam Phillips asphilli at ucar.edu
Tue Jan 23 12:12:15 MST 2018


Hi Stuart,
Always remember to include ncl-talk in your reply, so that others can
follow along and/or learn from the conversation in the future via the
archives.

You sent along a printVarSummary of data:

Variable: data

Type: float

Total Size: 178560 bytes

            44640 values

Number of Dimensions: 2

Dimensions and sizes:   [north_south | 992] x [east_west | 45]

Coordinates:

Number Of Attributes: 9

  units :       m

  standard_name :       vic_lake_depth

  long_name :   vic_lake_depth

  scale_factor :         1

  add_offset :   0

  missing_value :       -9999

  _FillValue :  -9999

  vmin :        -1e+15
  vmax :        1e+15

It looks to me that NCL is concatenating your first dimension when the data
is read in via addfiles, and thus indicates that each data file does not
have a time dimension as part of the vic_lake_depth_inst variable. By
default, addfiles will cat the leftmost dimension of all input files. But
it can also be used to join the files together creating a new leftmost
dimension. See example #2 here:
https://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml

Try this:

 a = addfiles(fils,"r")

ListSetType (a, "join")

 data = a[:]->vic_lake_depth_inst

printVarSummary(data)

Your data should now be read in correctly.

If you have any further questions please reply to the ncl-talk list.
Adam


On Fri, Jan 19, 2018 at 3:27 PM, Smith, Stuart <smit1770 at purdue.edu> wrote:

> Good afternoon Adam,
>
>
>
> Thank you for the input. I’ve learned a lot. In the example you provided,
> “data” was assumed to have the variable time with the depth of water. In my
> .nc files depth of water and time are not named in the same dimension.
>
>
>
> As a result I get the following message, “fatal:(time) is not a named
> dimension in variable (data). “  I tried to adjust the script by assigning
> a time variable to the defined data variable as shown below.  However, this
> was unsuccessful. Any advice? Thank you for your time.
>
>
>
> begin
>
>
>
> diri = "/scratch/conte/s/smit1770/RRB_Test_Simulation/RedRiver/
> OUTPUT_8x6.1hr_2018/SURFACEMODEL/200903/"
>
>
>
> ;fils = systemfunc("ls *.d01.nc")
>
> fils = systemfunc("ls "+diri+"*.d01.nc")
>
>
>
> ;print(fils)   ; make sure the desired files are listed in the correct
> order
>
>
>
>  a = addfiles(fils,"r")
>
>    data = a[:]->vic_lake_depth_inst
>
>    data at time=a[:]->time
>
>    ;time = a[:]->time    ; assuming variable name is Depth_of_water
>
>    ;print(time)
>
>    ;print(data)
>
>    print(data&time)   ; check that the times read in are correct
>
>    ;printVarSummary(data)    ; examine data array
>
>
>
>    data_aa = wgt_areaave(data,1.,1.,0)   ; Not applying any area-weight to
> the data
>
>
>
>    wks = gsn_open_wks("png","timeseries")
>
>
>
>    res = True
>
>    res at tmXBMode          = "Explicit"              ; explicit labels
>
>    res at tmXBValues        = time                       ; location of
> labels
>
>    res at tmXBLabels        = "Test"                ; labels themselves
>
>    res at tmLabelAutoStride = True                    ; nice stride on labels
>
>    res at tiMainString      = "Explicit axis labeling"; title
>
>
>
>
>
>   ;plot = gsn_csm_xy(wks,ispan(0,dimsizes(data&time)-1,1,data_aa,res)
>
>   plot = gsn_csm_xy(wks,ispan(0,dimsizes(data&time)-1,1),data_aa,res)
>
>
>
>
>
> end
>
>
>
> Regards,
>
>
>
> -Stuart
>
>
>
> *From:* Adam Phillips [mailto:asphilli at ucar.edu]
> *Sent:* Thursday, January 18, 2018 12:32 PM
> *To:* Smith, Stuart <smit1770 at purdue.edu>
> *Cc:* Ncl-talk <ncl-talk at ucar.edu>
> *Subject:* Re: [ncl-talk] NCL Creating Time Series Plots
>
>
>
> Hi Stuart,
>
> If the files are sequentially named, you can use addfiles to read all the
> files at once:
>
>
>
> begin
>
>    fils = systemfunc("ls *.d01.nc")
>
>    print(fils)   ; make sure the desired files are listed in the correct
> order
>
>    a = addfiles(fils,"r")
>
>    data = a[:]->Depth_of_water    ; assuming variable name is
> Depth_of_water
>
>    print(data&time)   ; check that the times read in are correct
>
>    printVarSummary(data)    ; examine data array
>
>
>
>    data_aa = wgt_areaave(data,1.,1.,0)   ; Not applying any area-weight to
> the data
>
>
>
>    wks = gsn_open_wks("png","timeseries")
>
>
>
>    res = True
>
>    ...   ; set desired resources here
>
>
>
>   plot = gsn_csm_xy(wks,ispan(0,dimsizes(data&time)-1,1,data_aa,res)
>
> end
>
>
>
> Note:
>
> 1 - Make sure that the results from systemfunc list the files that you
> want to read in in the correct order.
>
> 2 - You may very well want to area weight the data, and this may have to
> be done by hand as I do not believe a function exists that can do that on
> an array with 2-dimensional latitudes/longitudes.
>
> 3 - There are lots of different resources that can be set for timeseries,
> specifically for the tickmarks. Review the examples here:
>
> http://www.ncl.ucar.edu/Applications/xy.shtml
>
> http://www.ncl.ucar.edu/Applications/time_labels.shtml
>
> http://www.ncl.ucar.edu/Applications/tickmarks.shtml
>
>
>
> Hope that helps. If you have any further questions please respond to the
> ncl-talk email list.
>
> Adam
>
>
>
>
>
>
>
>
>
>
>
> On Wed, Jan 17, 2018 at 2:24 PM, Smith, Stuart via ncl-talk <
> ncl-talk at ucar.edu> wrote:
>
> Good afternoon,
>
>
>
> My name is Stuart, and I am research assistant at Purdue University.. I
> tried using the serach ncl-talk archives, but received a “URL Not Found”
> message.
>
>
>
> I am wanting to learn about generating time series plots with .nc files.
> The .nc files I have are daily timesteps (200903250000.d01.nc,
> 200903260000.d01.nc). I would like to plot the .nc files as a spatially
> averaged(ex. Depth of water)  time series plot for an entire month.
>
>
>
> The dimension of time is 1,  as to be expected. The dimension of the
> variable of interest is 2 [north_south|32] x [east_west |45]. My goal would
> be to calculate the average value over this area, and plot it with the
> appropriate day to create the time series.
>
>
>
> Could you please provide some examples of how this problem has been solved
> in the past? Thank you for your time.
>
>
>
> Regards,
>
>
>
> -Stuart
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
>
> --
>
> Adam Phillips
>
> Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
>
> www.cgd.ucar.edu/staff/asphilli/   303-497-1726 <(303)%20497-1726>
>
>
>



-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180123/ccb9ad86/attachment.html>


More information about the ncl-talk mailing list