[ncl-talk] Creating Time Series Graphs: Plotting Specific Time Periods
Mary Haley
haley at ucar.edu
Tue Mar 20 13:06:15 MDT 2018
Hi Stuart,
You can use cd_calendar to convert the time array to an N x 6 array where
the 6 represents year, month, day, hour, minute, and second. Once you have
this, you can get the indexes where all the months equal to 3, and use this
to subset your data before plotting:
date = cd_calendar(f->T,0) ; returns N x 6 array
ind_subset = ind(date(:,1).eq.3) ; Grab indexes where the month is equal
to March
;---Use indexes to subset data
avg_data_subset = avg_data(ind_subset)
time_subset = time(ind_subset)
. . .
plot = gsn_csm_xy(wks,time_subset,avg_data_subset,resplot)
I've attached a modified version of your script.
Note that I also am using wgt_areaave_Wrap (instead of wgt_areaave),
which retains metadata. This is not critical in your case, but it can be
useful for plotting and other things.
--Mary
On Mon, Mar 19, 2018 at 12:23 PM, Smith, Stuart <smit1770 at purdue.edu> wrote:
> Hello,
>
>
>
> Listed below is a plotting script that plots the time varying spatial
> average of a variable of interest (in this example it is surface water area
> ). The x-axis plots number of days since (2009/1/1), but I would like to
> improve my graph to plot a specific month (March), instead of all of the
> values. I have tried editing my NCL resources, but have not been able to
> properly extract the time period of interest.
>
>
>
> Could I please have assistance, on converting and plotting specific time
> periods? I have attached sample data if needed for clarification. Thank you
> for your time.
>
>
>
> Regards,
>
>
>
> -Stuart
>
>
>
>
>
>
>
>
>
> begin
>
>
>
> ;Go to directory of interest
>
>
>
> ;diri = "/scratch/conte/s/smit1770/TempStorage"
>
>
>
>
>
> fili = "/scratch/conte/s/smit1770/TempStorage/surf_area.nc"
>
> ;print(fili) ; make sure the desired files are listed in the correct
> order
>
>
>
> ; read in all files
>
>
>
> f = addfile(fili,"r")
>
>
>
> ;Set variable of interest
>
> data = f->surf_area
>
> ;fix the mismatched _FillValue to properly recogonize the missing values
> after they are read in
>
> data at _FillValue := todouble (data at missing_value)
>
>
>
> ;data at lat2d = f->Y ;-- 2D latitudes
>
> ;data at lon2d = f->X ;-- 2D longitudes
>
> data at time= f->T ;--2D time
>
> ;m=(/45.4375,48.9375/)
>
> ;n=(/-99.5625,-94.0625/)
>
>
>
>
>
>
>
>
>
> ;printVarSummary(data)
>
>
>
>
>
>
>
> avg_data = wgt_areaave(data,1.,1.,0)
>
>
>
> ;print(data)
>
> wks = gsn_open_wks("png","VIC_timeseries")
>
>
>
> ;set resources
>
> resplot = True
>
> restick = True
>
> restick at ttFormat = "%d"
>
> restick at ttmValues= (/(/2009,3,1/),(/2009,3,15/),(/2009,3,31/)/)
>
>
>
>
>
>
>
> resplot at tiMainString = "Lake Area (m^2)";title name
>
>
>
> ;time_axis_labels( data at time,resplot,restick)
>
>
>
>
>
> plot = gsn_csm_xy(wks,data at time,avg_data,resplot)
>
>
>
>
>
> end
>
> _______________________________________________
> 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/20180320/d73d2085/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VIC_timeseries.png
Type: image/png
Size: 71317 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180320/d73d2085/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot_surf.ncl
Type: application/octet-stream
Size: 1271 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180320/d73d2085/attachment.obj>
More information about the ncl-talk
mailing list