Main Page | Report Page

 

  Computers Forum Index » Computer Languages (IDL-PVWAVE) » How to average every nth data?...

Author Message
go cats...
Posted: Thu Nov 04, 2010 5:53 pm
 
Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength data
350 0.001146
351 0.001176
352 0.001147
. .
. .
. .
2500 0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350 0.001150
353 0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim
 
Chris W...
Posted: Thu Nov 04, 2010 6:14 pm
 
On Nov 4, 12:53 pm, go cats <beardown... at (no spam) gmail.com> wrote:
Quote:
Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength    data
350             0.001146
351             0.001176
352             0.001147
  .                      .
  .                      .
  .                      .
2500           0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350            0.001150
353            0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim

put the data into separate arrays
then reform them

rw = reform(w, 3, n_elements(w)/3) ; make sure w has a multiple of 3
length
rd = reform(d, 3, n_elements(d)/3)

get the mean across the 1st dimension for the average
result_d = mean(rd,dimension = 1)
get the minimum across the wavelengths
result_w = min(rw, dimension = 1)


Chris
 
Bennett...
Posted: Thu Nov 04, 2010 7:24 pm
 
On Nov 4, 1:53 pm, go cats <beardown... at (no spam) gmail.com> wrote:
Quote:
Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength    data
350             0.001146
351             0.001176
352             0.001147
  .                      .
  .                      .
  .                      .
2500           0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350            0.001150
353            0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim

You can also do something like this.
x = indgen(50)
mean_1 = mean(x)
mean_2 = mean(x[0:*:2])
mean_3 = mean(x[0:*:3])

The third element in your indexing indicates a skipping parameter.
 
go cats...
Posted: Thu Nov 04, 2010 8:12 pm
 
On Nov 4, 1:14 pm, Chris W <cwood1... at (no spam) gmail.com> wrote:
Quote:
On Nov 4, 12:53 pm, go cats <beardown... at (no spam) gmail.com> wrote:





Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength    data
350             0.001146
351             0.001176
352             0.001147
  .                      .
  .                      .
  .                      .
2500           0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350            0.001150
353            0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim

put the data into separate arrays
then reform them

rw = reform(w, 3, n_elements(w)/3) ; make sure w has a multiple of 3
length
rd = reform(d, 3, n_elements(d)/3)

get the mean across the 1st dimension for the average
result_d = mean(rd,dimension = 1)
get the minimum across the wavelengths
result_w = min(rw, dimension = 1)

Chris- Hide quoted text -

- Show quoted text -

Thanks Chris,

That works perfectly.

Kim
 
go cats...
Posted: Thu Nov 04, 2010 8:13 pm
 
On Nov 4, 2:24 pm, Bennett <juggernau... at (no spam) gmail.com> wrote:
Quote:
On Nov 4, 1:53 pm, go cats <beardown... at (no spam) gmail.com> wrote:





Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength    data
350             0.001146
351             0.001176
352             0.001147
  .                      .
  .                      .
  .                      .
2500           0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350            0.001150
353            0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim

You can also do something like this.
x = indgen(50)
mean_1 = mean(x)
mean_2 = mean(x[0:*:2])
mean_3 = mean(x[0:*:3])

The third element in your indexing indicates a skipping parameter.- Hide quoted text -

- Show quoted text -

Bennet,

Thanks for the tips.

Kim
 
go cats...
Posted: Thu Nov 04, 2010 8:31 pm
 
On Nov 4, 1:14 pm, Chris W <cwood1... at (no spam) gmail.com> wrote:
Quote:
On Nov 4, 12:53 pm, go cats <beardown... at (no spam) gmail.com> wrote:





Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength    data
350             0.001146
351             0.001176
352             0.001147
  .                      .
  .                      .
  .                      .
2500           0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350            0.001150
353            0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim

put the data into separate arrays
then reform them

rw = reform(w, 3, n_elements(w)/3) ; make sure w has a multiple of 3
length
rd = reform(d, 3, n_elements(d)/3)

get the mean across the 1st dimension for the average
result_d = mean(rd,dimension = 1)
get the minimum across the wavelengths
result_w = min(rw, dimension = 1)

Chris- Hide quoted text -

- Show quoted text -

Hi Chris,

The "dimension" flag may not be used in the "mean" function.
wavelength sorting was successful, but only one (total) mean value was
calculated.
I am digging out what I did wrong.

Thanks,
Kim
 
chris...
Posted: Thu Nov 04, 2010 11:23 pm
 
On 4 Nov., 18:53, go cats <beardown... at (no spam) gmail.com> wrote:
Quote:
Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength    data
350             0.001146
351             0.001176
352             0.001147
  .                      .
  .                      .
  .                      .
2500           0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350            0.001150
353            0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim
Hi Kim,

you could also use this:

range=3
new_w = total(reform(w,range,n_elements(w)/range),1)/range

or if you have missing values:

missing=0
new_w = total(((rr=reform(w,range,n_elements(w)/range),1)))/total(rr
ne missing,1)

Cheers

CR
 
Michael Galloy...
Posted: Fri Nov 05, 2010 12:55 am
 
On 11/4/10 2:31 PM, go cats wrote:
Quote:
On Nov 4, 1:14 pm, Chris W<cwood1... at (no spam) gmail.com> wrote:
On Nov 4, 12:53 pm, go cats<beardown... at (no spam) gmail.com> wrote:





Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength data
350 0.001146
351 0.001176
352 0.001147
. .
. .
. .
2500 0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350 0.001150
353 0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim

put the data into separate arrays
then reform them

rw = reform(w, 3, n_elements(w)/3) ; make sure w has a multiple of 3
length
rd = reform(d, 3, n_elements(d)/3)

get the mean across the 1st dimension for the average
result_d = mean(rd,dimension = 1)
get the minimum across the wavelengths
result_w = min(rw, dimension = 1)

Chris- Hide quoted text -

- Show quoted text -

Hi Chris,

The "dimension" flag may not be used in the "mean" function.
wavelength sorting was successful, but only one (total) mean value was
calculated.
I am digging out what I did wrong.

Thanks,
Kim

IDL 8.0 added the DIMENSION keyword for MEAN.

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
 
go cats...
Posted: Fri Nov 05, 2010 3:09 pm
 
On Nov 5, 8:54 am, Jeremy Bailin <astroco... at (no spam) gmail.com> wrote:
Quote:
On Nov 4, 4:55 pm, Michael Galloy <mgal... at (no spam) gmail.com> wrote:





On 11/4/10 2:31 PM, go cats wrote:

On Nov 4, 1:14 pm, Chris W<cwood1... at (no spam) gmail.com>  wrote:
On Nov 4, 12:53 pm, go cats<beardown... at (no spam) gmail.com>  wrote:

Dear Gurus,

Hope someone will help me how to figure this out.
I've been keep trying to do some spectral resampling (just simple
average) with ASD data.
ASD data is a two dimensional array;

wavelength    data
350             0.001146
351             0.001176
352             0.001147
   .                      .
   .                      .
   .                      .
2500           0.0004311

What I've been trying to do is averaging every nth data values and
rewrite into a new array.
For example, if I want to average every 3rd data values, the resulting
array will be

350            0.001150
353            0.001147
and so on.

MS excel seems to be able to handle it, but it wouldn't be a good idea
for processing several hundres files.

I really appreciate if someone could give me tip(s).

Thanks,
Kim

put the data into separate arrays
then reform them

rw = reform(w, 3, n_elements(w)/3) ; make sure w has a multiple of 3
length
rd = reform(d, 3, n_elements(d)/3)

get the mean across the 1st dimension for the average
result_d = mean(rd,dimension = 1)
get the minimum across the wavelengths
result_w = min(rw, dimension = 1)

Chris- Hide quoted text -

- Show quoted text -

Hi Chris,

The "dimension" flag may not be used in the "mean" function.
wavelength sorting was successful, but only one (total) mean value was
calculated.
I am digging out what I did wrong.

Thanks,
Kim

IDL 8.0 added the DIMENSION keyword for MEAN.

Mike
--www.michaelgalloy.com
Research Mathematician
Tech-X Corporation

If you're on pre-8, you can use the modifications of the intrinsic
routines here:

http://web.astroconst.org/jbiu/#MOMENTDIMEN

-Jeremy.- Hide quoted text -

- Show quoted text -

Hi all,

Thank you all for your invaulable tips and code examples.

Kim
 
 
Page 1 of 1    
All times are GMT
The time now is Wed Apr 16, 2014 11:00 pm