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

Home » Public Forums » archive » Re: help on creating a mean array of data
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: help on creating a mean array of data [message #45949] Mon, 24 October 2005 11:09
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
pimpk24@hotmail.com wrote:
> perhaps my original post was a little misleading and oversimplified.
> but what iam dealing with are several large '.dat' file in which there
> are multiple columns and number of rows of data varies with each file.
> Also each 'day' of data is not physcially seperated. perhaps this is
> better this is a better representation:
>
> temp1a dewp1a pressure1a *where 1,2,3 etc represent data at
> different levels in
> temp2a dewp2a pressure2a the atmosphere and a,b,c etc
> represent different days
> temp3a dewp3a pressure 3a
> temp1b dewp2b pressure 1b
> temp2b dewp2b pressure 2b
> temp3b dewp3b pressure 3b


> the number of columns of data in each file is standard but the number
> of columns is not known and can vary.

Ummm. Did you mean the # of *rows* can vary? Or do you mean that there
can be any number of columns between files, but within a file the # of
columns is fixed? I'm assuming you mean rows...

> Hence would i still be able to
> use the matrix approach you described along with something like a
> 'while(eof)' loop? Or should i take an altogether different approach?

Both would work. You can use the FILE_LINES function to determine the #
of rows and then use the matrix approach. Or you can used a while (not
eof()) loop and process the file line by line. I generally do the
former when my data is arranged logically in the file, or the latter
when data is "mixed-up" and I want to re-arrange it in memory.

In your case, I would probably use the while loop and calculate the mean
as I was reading in data.


-Rick
Re: help on creating a mean array of data [message #45981 is a reply to message #45949] Fri, 21 October 2005 11:11 Go to previous message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
pimpk24@hotmail.com wrote:
> hello, iam very new to idl and would appreciate any help anyone could
> give on performing the following task:
>
> I have a large array of data which is meteorological data from multiple
> days. The data for each day is consistent (i.e. same amount) and i need
> a program that can average each kind of data
>
> For example, I have something like the following:
>
> day a :
> temp-1
> temp-2
> temp-3
>
> day b :
> temp-1
> temp-2
> temp-3
>
>
>
>
> and I need the following:
>
> day a+b:
> temp-1
> temp-2
> temp-3
>
>
> thanks for any feedback
>

If you have one array which looks like

t = [dayA_t1, dayA_t2, dayA_t3, dayB_t1, dayB_t2, dayB_t3]

you can do the following

;; turn array into a 2-dimensional array with one day per row
;; and one temperature per column
t = reform(t, n_temps, n_days, /overwrite)

;; calculate daily average for each temperature. total(.., 2)
;; will sum over the 2nd dimension (sum up all days),
;; then divide by the number of days.
t_avg = total(t, 2) / n_days


Good luck,
Benjamin
Re: help on creating a mean array of data [message #45982 is a reply to message #45981] Fri, 21 October 2005 11:13 Go to previous message
news.qwest.net is currently offline  news.qwest.net
Messages: 137
Registered: September 2005
Senior Member
<pimpk24@hotmail.com> wrote in message
news:1129917339.727669.218770@g49g2000cwa.googlegroups.com.. .
> hello, iam very new to idl and would appreciate any help anyone could
> give on performing the following task:
>
> I have a large array of data which is meteorological data from multiple
> days. The data for each day is consistent (i.e. same amount) and i need
> a program that can average each kind of data

Simple case:
meanab = (daya+dayb)/2

Also a more general approach that you can apply to an arbitrary
amount of data is as follows: it uses total().

Arrays are rows in idl, so transpose them into columns,
and concatenate.
Make a matrix of data. Arrays are rows in idl, so transpose them
into columns, and concatenate.
IDL> matrix = [transpose(a),transpose(b)]
then total along the rows
IDL> sum = total(matrix,1)
then divide by the number of columns
IDL> ncol = (size(matrix,/dim))[0]
where I've taken the first element of the array returned by size()
IDL> meanab = sum/ncol

For more than 2 days, you can concatenate many rows into the array "matrix".
There are many other ways as well. You may want to look into the rebin()
function.

Cheers,
bob
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to display both wavenumber & wavelength (Z-profile window) in ENVI
Next Topic: Re: Problem: Opening a 20-30MB sized ShapeFile

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

Current Time: Wed Oct 08 15:10:57 PDT 2025

Total time taken to generate the page: 0.00445 seconds