[ncl-talk] NCL Creating Time Series Plots
Karin Meier-Fleischer
meier-fleischer at dkrz.de
Fri Feb 2 08:38:47 MST 2018
Hi Stuart,
have a look at
http://ncl.ucar.edu/Document/Functions/Built-in/cd_calendar.shtml
and how to use the string dates as the explicit labels
http://ncl.ucar.edu/Applications/Scripts/tm_2.ncl
-Karin
Am 02.02.18 um 15:51 schrieb Smith, Stuart via ncl-talk:
>
> Good morning Adam,
>
> I wanted to follow up with some revisions to my script in case others
> wanted to use it, though there are still improvements to be made.
> Listed below is a script that reads in a list of NetCDF files and
> joins them together to create a time series plot.
>
> A time variable is defined, although all values are 0. This is
> something I wish to improve in the script, and have it print out dates
> instead of 0 values as shown below. If you have any suggestions on
> improvments to be made please let me know. Thank you for your time.
>
> Current Print Output of data at time
>
>
>
> Goal to print output of data at time
>
> (0) 0
>
> (1) 0
>
> (2) 0
>
> (3) 0
>
> (4) 0
>
> (5) 0
>
> (6) 0
>
> (7) 0
>
>
>
> (0) 2009-03-01
>
> (1) 2009-03-02
>
> (2) 2009-03-03
>
> (3) 2009-03-04
>
> (4) 2009-03-05
>
> (5) 2009-03-06
>
> (6) 2009-03-07
>
> (7) 2009-03-08
>
> ;Time series plotting script
>
> begin
>
> ;Go to directory of interest
>
> diri =
> "/scratch/conte/s/smit1770/RRB_Test_Simulation/RedRiver/OUTPUT_8x6.1hr_2018/SURFACEMODEL/200903/"
>
> ;list names of all of the files and add ful file path
>
> fils = systemfunc("ls "+diri+"*.d01.nc")
>
> ;print(fils) ; make sure the desired files are listed in the correct order
>
> ;read in all files
>
> a = addfiles(fils,"r")
>
> ListSetType (a, "join")
>
> data = a[:]->vic_lake_depth_inst
>
> data at time=a[:]->time
>
> ;print(data) ;prints data values
>
> ;print(data at time); prints variable time, but all values are 0.
>
> ;printVarSummary(data) ; examine data array. Result is [ncl_join |
> 31] x [north_south | 32] x [east_west | 45]
>
> data_aa = wgt_areaave(data,1.,1.,0) ; Not applying any area-weight
> to the data
>
> ;print(data_aa)
>
> wks = gsn_open_wks("png","timeseries")
>
> resplot = True
>
> restick = True
>
> restick at ttmValues= (/(/2009,3,1/),(/2009,3,15/),(/2009,3,31/)/)
>
> resplot at tiMainString = "March Water Depth";title name
>
> plot = gsn_csm_xy(wks,ispan(0,dimsizes(data at time)-1,1),data_aa,resplot)
>
> end
>
> Regards,
>
> -Stuart
>
> *From:*Adam Phillips [mailto:asphilli at ucar.edu]
> *Sent:* Tuesday, January 23, 2018 2:12 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,
>
> 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
> <mailto: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 <http://d01.nc>")
>
> fils = systemfunc("ls "+diri+"*.d01.nc <http://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
> <mailto:asphilli at ucar.edu>]
> *Sent:* Thursday, January 18, 2018 12:32 PM
> *To:* Smith, Stuart <smit1770 at purdue.edu <mailto:smit1770 at purdue.edu>>
> *Cc:* Ncl-talk <ncl-talk at ucar.edu <mailto: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 <http://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 <mailto: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 <http://200903250000.d01.nc>,
> 200903260000.d01.nc <http://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 <mailto: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/
> <http://www.cgd.ucar.edu/staff/asphilli/> 303-497-1726
> <tel:%28303%29%20497-1726>
>
>
>
> --
>
> Adam Phillips
>
> Associate Scientist, Climate and Global Dynamics Laboratory, NCAR
>
> www.cgd.ucar.edu/staff/asphilli/
> <http://www.cgd.ucar.edu/staff/asphilli/> 303-497-1726
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180202/7dd8e69d/attachment-0001.html>
More information about the ncl-talk
mailing list