Re: plotting irregular data

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 06 2012 - 09:33:44 MDT

Hi Basit,
An expert user came up with a possible solution for you:

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

d = asciiread("timedata.asc",-1,"float")
nentries = dimsizes(d) / 7

; create time dimension with units of "seconds since 2006/06/01" -- could be generalized to generate the units string based on the time of the first entry in the data
dn = onedtond(d,(/nentries,7/))

; start at the beginning of the first day

dni = tointeger(dn(:,0:5))

time_start = tointeger(cd_inv_calendar(2000 + dni(0,2),dni(0,1),dni(0,0),0,0,0,"seconds since 2006/06/01",0))
time_coords = tointeger(cd_inv_calendar(2000 + dni(:,2),dni(:,1),dni(:,0),dni(:,3),dni(:,4),dni(:,5),"seconds since 2006/06/01",0))

data = dn(:,6)

; following not really needed
;data!0 = "time"
;data&time = time_coords

; create an axis of 2 days ( should use the last time value to make this general)

time_span = 48 * 60 * 60
; stride of four hours in units of seconds
time_vals = ispan(time_start, time_start + time_span, 4 * 60 * 60)

res = True
res@tmXBMode = "explicit"
res@tmXBValues = time_vals
res@tmXBLabels = ((time_vals - time_start) / (60 * 60)) % 24 ; converting to hours from midnight for the labels only
res@xyMarkLineMode = "MarkLines"

wks = gsn_open_wks("x11","test")
plot = gsn_csm_xy(wks,time_coords,data,res)

Note that you will likely want to modify time_span to take into account
the number of days you are reading in, as right now it is set to span 2
days (=48hrs).
Adam

On 06/05/2012 03:28 AM, BasitAli Khan wrote:
> Hi all,
>
> I have an observational dataset and I want to plot a simple xy plot
> with time dimension on x-axis (snippet copied below). The problem is
> that the time is irregular and discontinuous. For example the
> interval between two time steps varies, in the same way there is no
> data between 16:55:18 of the first day and 6:28:28 hours of the
> following day. I believed my best bet would have been time_axis_label
> function. Unfortunately that also does not work correctly for these
> kind of data or probably I don't know how to use it correctly this
> dataset although time_axis_label works fine for my wrfoutput.
>
> What I want is to plot the data on the exact time (hour, minutes,
> second) on a monotonically increasing and equally spaced time stamp on
> x-axis. For example on x-axis want the time as "00 04 08 12 16 20 00
> 04 08 12 16 20 00". In excel its probably 5 minutes job.
> Unfortunately I don't know the right functions/method to do the same.
> Also there are no example available for such cases. I will greatly
> appreciate if somebody could help me in this.
>
>
> Date(dd-mm-yy) Time(hh:mm:ss) AOT_1640
> 1/6/06 6:28:35 0.036782
> 1/6/06 6:34:59 0.036322
> 1/6/06 6:43:04 0.03453
> 1/6/06 6:52:34 0.03479
> 1/6/06 6:54:02 0.035196
> 1/6/06 6:55:50 0.033874
> 1/6/06 7:01:09 0.03577
> 1/6/06 7:07:15 0.034593
> 1/6/06 7:15:53 0.036877
> 1/6/06 7:21:05 0.036782
> 1/6/06 7:22:32 0.037556
> 1/6/06 7:31:56 0.038561
> 1/6/06 7:43:23 0.039798
> 1/6/06 7:57:24 0.040178
> 1/6/06 8:25:50 0.042576
> 1/6/06 8:56:23 0.049657
> 1/6/06 9:11:21 0.05025
> 1/6/06 9:26:23 0.05384
> 1/6/06 10:35:19 0.064918
> 1/6/06 10:56:21 0.065833
> 1/6/06 11:11:23 0.064025
> 1/6/06 12:26:27 0.056221
> 1/6/06 13:35:30 0.060246
> 1/6/06 13:56:24 0.08178
> 1/6/06 14:26:26 0.100734
> 1/6/06 14:35:29 0.092645
> 1/6/06 14:41:21 0.099116
> 1/6/06 15:26:23 0.118793
> 1/6/06 15:41:25 0.114984
> 1/6/06 15:56:21 0.120402
> 1/6/06 16:11:23 0.122496
> 1/6/06 16:26:24 0.148276
> 1/6/06 16:31:32 0.151355
> 1/6/06 16:55:18 0.165673
> 2/6/06 6:28:28 0.170047
> 2/6/06 6:34:51 0.17144
> 2/6/06 6:55:41 0.166282
> 2/6/06 7:01:02 0.163973
> 2/6/06 7:15:45 0.164671
> 2/6/06 7:20:53 0.166546
> 2/6/06 7:31:48 0.173329
> 2/6/06 7:43:15 0.164972
> 2/6/06 7:57:20 0.170174
> 2/6/06 8:35:15 0.159429
> 2/6/06 8:41:31 0.155072
> 2/6/06 8:56:31 0.166109
> 2/6/06 9:11:33 0.17149
> 2/6/06 9:26:31 0.163605
> 2/6/06 11:41:34 0.148113
> 2/6/06 13:41:33 0.189807
> 2/6/06 13:56:33 0.177184
> 2/6/06 14:11:35 0.170119
> 2/6/06 14:41:32 0.166909
> 2/6/06 15:41:33 0.187572
> 2/6/06 16:26:31 0.201749
> 2/6/06 16:55:42 0.208505
> 2/6/06 17:38:55 0.237899
> 2/6/06 17:57:21 0.261323
> 2/6/06 18:02:06 0.272931
>
>
>
>
>
>
>
>
> Thanks and best regards,
> ----
>
> Basit A. Khan, Ph.D.
>
> Postdoctoral Research Fellow
>
> Division of Physical Sciences & Engineering
>
> Office# 3204, Level 3, Building 1,
>
> King Abdullah University of Science & Technology
>
> 4700 King Abdullah Blvd, Box 2753, Thuwal 23955 --6900,
>
> Kingdom of Saudi Arabia.
>
> Office: +966(0)2 808 0276, Mobile: +966(0)5 0860 3617
>
> E-mail: basitali.khan@kaust.edu.sa <mailto:basitali.khan@kaust.edu.sa>
>
> Skype name: basit.a.khan
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
______________________________________________________________
Adam Phillips                                asphilli@ucar.edu
NCAR/Climate and Global Dynamics Division       (303) 497-1726
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jun 6 09:33:57 2012

This archive was generated by hypermail 2.1.8 : Wed Jun 06 2012 - 15:17:44 MDT