comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: How to handle gaps in plot?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: How to handle gaps in plot? [message #45104] Fri, 12 August 2005 21:16 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"caitouer" <caitouer@yahoo.com> writes:
> Thanks for your quick reply. It is true that it is easy when you have
> filled the gap with some values. However, I am trying to figure out
> how to plot when you do not fill the gap. Here is an example:
>
> X (time):[1,2,3,5,6,7,10,11,12,19,20,21,22,23,24]
> ;Hourly data in one day. There are several gaps in the data
> ;array. You do not know when you will have gap nor
> ; how large the gap is. The actual data is not so regular and
> ;huge. So it is not practical to fill the data.
>
> Y (some values):
> [1.1,0.9,1.3,1.6,2.1,0.7,2.3,0.1,0.3,0.6,0.9,1.4,1.3,1.7,1.8 ]
> ; these are the measurements you take at above time.
>
> Then when you type:
> plot,x,y
> There will have lines between the intervals. However, these lines are
> meaningless.

I have a routine called GTISEG which groups data points into segments.
With that routine, it is up to you to decide how big of a time
separation is a gap.

Once you have the time segments, you can do a FOR loop and plot each
segment separately, i.e. use WHERE to find the points in each segment,
and then OPLOT those points onto your graph.

Craig

GTISEG can be found here:
http://cow.physics.wisc.edu/~craigm/idl/arrays.html

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: How to handle gaps in plot? [message #45113 is a reply to message #45104] Thu, 11 August 2005 23:13 Go to previous messageGo to next message
peter.albert@gmx.de is currently offline  peter.albert@gmx.de
Messages: 108
Registered: July 2005
Senior Member
Hi,

if you know a priori what the "good" interval should be, i.e. a
threshhold for intervals between x values that marks gaps, you could
identify those gaps and plot from one gap to the other using, please
forgive me, evil for loops.

In your example, this threshhold would be 1 (hour), and the example
code would look like this:

IDL> interval = 1
IDL> x=[1,2,3,5,6,7,10,11,12,19,20,21,22,23,24]
IDL> y= [1.1,0.9,1.3,1.6,2.1,0.7,2.3,0.1,0.3,0.6,0.9,1.4,1.3,1.7,1.8 ]
IDL> gap=[-1,where(shift(x, -1)-x ne interval, n)]
IDL> plot, x, y, /nodata
IDL> for i=0,n-1 do oplot, x[gap[i]+1:gap[i+1]], y[gap[i]+1:gap[i+1]],
psym=-4

with the "shift" and "where" command I am checking where the interval
between adjacent x values exceeds the threshhold. The values in the
variable gap always give the last index of one connected x interval, so
in the following oplot command I am plotting from gap[i]+1 to gap[i+1].
Therefore we need the -1 as the first element in gap.

Best regards,

Peter
Re: How to handle gaps in plot? [message #45118 is a reply to message #45113] Thu, 11 August 2005 09:40 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
caitouer wrote:
> Thanks for your quick reply. It is true that it is easy when you have
> filled the gap with some values. However, I am trying to figure out
> how to plot when you do not fill the gap. Here is an example:
>
> X (time):[1,2,3,5,6,7,10,11,12,19,20,21,22,23,24]
> ;Hourly data in one day. There are several gaps in the data
> ;array. You do not know when you will have gap nor
> ; how large the gap is. The actual data is not so regular and
> ;huge. So it is not practical to fill the data.
>
> Y (some values):
> [1.1,0.9,1.3,1.6,2.1,0.7,2.3,0.1,0.3,0.6,0.9,1.4,1.3,1.7,1.8 ]
> ; these are the measurements you take at above time.
>
> Then when you type:
> plot,x,y
> There will have lines between the intervals. However, these lines are
> meaningless.
>
> I just want know if we plot the valid intervals only without those
> extra lines.

Ahh... so you don't actually have invalid data in these gaps, just irregularly spaced data. The
simplest solution is to use the PSYM keyword to plot just symbols and no connecting lines at all
(since the lines between the regular, hourly data are also meaningless... at least depending on the
variabiliy of your data).

Another option would be to create a regularly spaced array of x-data (based on yout x(time) data),
copy in the y-data to a simialrly spaced array and fill the y-data gaps with !values.d_nan. E.g.

IDL> x=dindgen(20)
IDL> y=dindgen(20)
IDL> y[5:8]=!values.d_nan
IDL> plot, x, y

Insty-gap in the data plot.

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: How to handle gaps in plot? [message #45120 is a reply to message #45118] Thu, 11 August 2005 09:06 Go to previous messageGo to next message
caitouer is currently offline  caitouer
Messages: 21
Registered: June 2005
Junior Member
Thanks for your quick reply. It is true that it is easy when you have
filled the gap with some values. However, I am trying to figure out
how to plot when you do not fill the gap. Here is an example:

X (time):[1,2,3,5,6,7,10,11,12,19,20,21,22,23,24]
;Hourly data in one day. There are several gaps in the data
;array. You do not know when you will have gap nor
; how large the gap is. The actual data is not so regular and
;huge. So it is not practical to fill the data.

Y (some values):
[1.1,0.9,1.3,1.6,2.1,0.7,2.3,0.1,0.3,0.6,0.9,1.4,1.3,1.7,1.8 ]
; these are the measurements you take at above time.

Then when you type:
plot,x,y
There will have lines between the intervals. However, these lines are
meaningless.

I just want know if we plot the valid intervals only without those
extra lines.

Thanks,
Caitouer
Re: How to handle gaps in plot? [message #45123 is a reply to message #45120] Thu, 11 August 2005 08:14 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
caitouer wrote:
> Hi, everyone,
> I have a question about gaps in data array. Normally when there are
> gaps in data array, people would fill the gap with extraordinary large
> or small number. Then when you use plot, IDL will detect gap
> automatically and will not connect two intervals when data is
> available. However, sometimes the data format is not so friendly. For
> example, the data file is not filled with extraordinary large or small
> number. You do not know when you have gap and how large the gap is.
> Even worse, the time is irregular. Is there a easy way to plot the
> valid data only?

Well, it's easy to find the valid data, e.g. for given MIN_VALUE and MAX_VALUE parameters for your
dependent data,

Idx = WHERE( YData GT MIN_VALUE AND YData LT MAX_VALUE, Count )
IF ( Count GT 0 ) THEN $
PLOT, XData[Idx], YData[Idx] $
ELSE $
MESSAGE, 'No valid data!'

Is this the sort of thing you mean?

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Re: How to handle gaps in plot? [message #45214 is a reply to message #45104] Mon, 22 August 2005 12:20 Go to previous message
caitouer is currently offline  caitouer
Messages: 21
Registered: June 2005
Junior Member
Sorry to reply late. :)
Thanks, Craig. This is exactly what I need. Originally I calculated the
time step one element by one element and also check if this gap is
larger than the interval I set. It takes forever to plot. The GTISEG
routine saves me a lot of computer time.
However, if we just want to plot the valid data, I agree with Peter and
Paul. We can use PSM to plot out those valid data only.
Thank all of you again to help me to figure this problem out.
Caitouer
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Speeding Up Oracle DataBase Access with IDL DataMiner
Next Topic: Re: Check if a point is inside a polygon mesh

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 06:30:59 PDT 2025

Total time taken to generate the page: 0.02620 seconds