Re: Specify a time for a variable

From: Ping Yang <pyang_at_nyahnyahspammersnyahnyah>
Date: Mon Oct 15 2012 - 16:36:34 MDT

Hi NCL,

I ended it up using the following code:
 Time = f1->time ; Times is of type character
  yyyymm=cd_calendar(Time,-1)
  tStrt=ind(yyyymm.eq.200001)
  tLast=ind(yyyymm.eq.201012)
  y1 = f1->precipitation(tStrt:tLast,{40.725},{-74.025})
  t = f1->time(tStrt:tLast)

to get the exactly time span.

Thank you so much for your prompt help.

Regards,

Ping

On Thu, Oct 11, 2012 at 6:15 PM, Alan Brammer <abrammer@albany.edu> wrote:

> Hi Ping,
> Was browsing the list and think this is a relatively straight froward
> answer, apologies if I missed something or this doesn't work.
>
> Your plotting line is just plotting the 0th to 5th time period of data.
> Essentially this line of code that actually plots has no relation to the
> variable YYYMM, except for the dimension size.
>
> plot_p(nt) = gsn_csm_contour_map_ce(pwks,x(nt,:,:),res)
>
>
> Also your file name and the attributes in the file seem to differ
> somewhat, the time coordinates in the file seem to fit a 30-minute interval
> as is the long_name of your variable. The below method will rewrite the
> time coordinates so that it works. If that is what is actually in the file.
>
> maybe see ->
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#CoordinateSubscripts
>
>
> ---------------------------------------------------------------------------------------------------------------
>
> a quick way to possibly make this work if you know you have monthly data
> from Jan 1970 -> Dec 1999 would be:
>
> time = todouble( ispan(0, 359, 1) ) ; Needs to
> be double to match up with time_to_plot below.
> time@units = "months since 1970-01-01 00:00:00"
>
> x!0 = "time"
> x&time = time
>
> YYYY = (/1970,1970,1980,1980,1990,1990/)
> MM = (/ 1, 7, 1, 7, 1, 7 /)
> tmax = dimsizes(YYYY)
>
> do nt=0,tmax-1
> time_to_plot = ut_inv_calendar(YYYY(nt), MM(nt), 01, 00, 00, 00,
> time@units, 0) ; this could be cd_inv_calendar in recent ncl versions
>
> res@gsnLeftString = "Monthly Total Precipitation"
> res@gsnRightString = YYYY(nt)+""+sprinti("%0.2i",MM(nt) ) ;
> didn't test this -> might fail.
> plot_x(nt) = gsn_csm_contour_map_ce(xwks,x({time_to_plot},:,:),res)
> plot_p(nt) = gsn_csm_contour_map_ce(pwks,x({time_to_plot},:,:),res)
>
>
> end do
>
>
>
>
>
>
> Alan.
>
>
>
> -------------------------------------
> Alan Brammer,
> PhD Student
>
> Department of Atmospheric and Environmental Sciences, University at
> Albany, SUNY, Albany, NY, 12222
>
> -------------------------------------
>
>
> On Oct 11, 2012, at 10:10 AM, Ping Yang <pyang@ccny.cuny.edu> wrote:
>
> Hi NCL,
>
> I have a similar question about how to specify a time for plotting,
> I used
>
> Here is the script content:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> begin
>
>
> ;Open the merged monthly file for plotting
> fili = "NEUS_Precipitation_HadGEM2-ESv3_30min_monthly1970-1999.nc"
> f = addfile(fili,"r")
> ; x = short2flt(f->precipitation)
> x = f->precipitation
> print("PRICP: min="+min(x)+" max="+max(x))
> printVarSummary(x)
>
> ; you can plot right now
> ;***************************************************
> ; Specify user desired yyyymm to be plotted
> ;***************************************************
> YYYYMM = (/190001,190007,198001,198007,199001,199007/)
> ;***************************************
> ; Replace the input time coordinate with the yyyymm
> ;***************************************
> ; x&time = f->yyyymm
> ;***************************************
> pwks = gsn_open_wks("ps","cru") ; open ps file
> xwks = gsn_open_wks("x11","cru") ; open x11 file
>
> gsn_define_colormap(pwks,"BlAqGrYeOrReVi200")
> gsn_define_colormap(xwks,"BlAqGrYeOrReVi200")
>
> plot_p = new (dimsizes(YYYYMM), graphic) ; create graphical array
> plot_x = new (dimsizes(YYYYMM), graphic) ; create graphical array
>
> res = True ; plot mods desired
> res@gsnDraw = False ; don't draw yet
> res@gsnFrame = False ; don't advance frame yet
>
> res@cnFillOn = True ; color contours
> res@cnLinesOn = False ; turn off contour lines
> res@cnFillMode = "RasterFill" ; Raster Mode
> res@cnInfoLabelOn = False
> res@cnLineLabelsOn = False
>
> res@cnLevelSelectionMode = "ManualLevels" ; set manual contour
> levels
> res@cnMinLevelValF = 0 ; set min contour level
> res@cnMaxLevelValF = 300 ; set max contour level
> res@cnLevelSpacingF = 10
>
> ;---This resource not needed in NCL V6.1.0
> res@gsnSpreadColors = True ; use full range of color map
>
> res@lbLabelBarOn = False ; turn off individual lb's
>
> res@gsnAddCyclic = False ; regional grid so not cyclic
> res@mpMinLatF = min(x&latitude)
> res@mpMaxLatF = max(x&latitude)
> res@mpMinLonF = min(x&longitude)
> res@mpMaxLonF = max(x&longitude)
>
> ; do nt = 0,dimsizes(YYYYMM)-1
> do nt = 0,5
> print("nt = " + nt)
> res@gsnLeftString = "Monthly Total Precipitation"
>
> res@gsnRightString = YYYYMM(nt)
> plot_x(nt) = gsn_csm_contour_map_ce(xwks,x(nt,:,:),res)
> plot_p(nt) = gsn_csm_contour_map_ce(pwks,x(nt,:,:),res)
> end do
>
> ;************************************************
> ; create panel plot
> ;************************************************
>
> resP = True ; modify the panel plot
> resP@txString = fili ; plot title
> resP@gsnMaximize = True ; make ps, eps, pdf, ...
> large
> resP@lbLabelAutoStride = True
> resP@gsnPanelLabelBar = True ; add common label bar
> gsn_panel(xwks,plot_x(0:5),(/3,2/),resP) ; now draw as one
> plot
> gsn_panel(pwks,plot_p(0:5),(/3,2/),resP) ; now draw as one
> plot
>
> end
>
> The problem is whatever I change the time
> In this example(I attached the script the data file in this email), I
> changed it to a wrong time:
> YYYYMM = (/190001,190007,198001,198007,199001,199007/)
>
> I used PrintSummary of the variable here:
> Variable: x
> Type: float
> Total Size: 1641600 bytes
> 410400 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 360] x [latitude | 30] x [longitude | 38]
> Coordinates:
> time: [ 30..10956]
> latitude: [35.25..49.75]
> longitude: [-83.75..-65.25]
> Number Of Attributes: 5
> long_name : Global, HadGEM2-ESv3 Precipitation (30min, DailyTS, 1970)
> Vv3
> standard_name : Precipitation
> _FillValue : -9999
> var_desc : Precipitation
> actual_range : ( 0, 400 )
>
> but the script still runs the same. Would you please help me on this?
>
> Ping
>
>
> _______________________________________________
> 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 Oct 15 16:36:52 2012

This archive was generated by hypermail 2.1.8 : Tue Oct 23 2012 - 11:10:04 MDT