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

Home » Public Forums » archive » Re: How to average every nth 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: How to average every nth data? [message #73371] Fri, 05 November 2010 08:09
beardown911 is currently offline  beardown911
Messages: 21
Registered: March 2007
Junior Member
On Nov 5, 8:54 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Nov 4, 4:55 pm, Michael Galloy <mgal...@gmail.com> wrote:
>
>
>
>
>
>> On 11/4/10 2:31 PM, go cats wrote:
>
>>> On Nov 4, 1:14 pm, Chris W<cwood1...@gmail.com>  wrote:
>>>> On Nov 4, 12:53 pm, go cats<beardown...@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
Re: How to average every nth data? [message #73378 is a reply to message #73371] Fri, 05 November 2010 06:54 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Nov 4, 4:55 pm, Michael Galloy <mgal...@gmail.com> wrote:
> On 11/4/10 2:31 PM, go cats wrote:
>
>
>
>
>
>
>
>
>
>> On Nov 4, 1:14 pm, Chris W<cwood1...@gmail.com>  wrote:
>>> On Nov 4, 12:53 pm, go cats<beardown...@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.
Re: How to average every nth data? [message #73383 is a reply to message #73378] Thu, 04 November 2010 16:23 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
On 4 Nov., 18:53, go cats <beardown...@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
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
Re: How to average every nth data? [message #73389 is a reply to message #73383] Thu, 04 November 2010 13:55 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 11/4/10 2:31 PM, go cats wrote:
> On Nov 4, 1:14 pm, Chris W<cwood1...@gmail.com> wrote:
>> On Nov 4, 12:53 pm, go cats<beardown...@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
Re: How to average every nth data? [message #73390 is a reply to message #73389] Thu, 04 November 2010 13:31 Go to previous message
beardown911 is currently offline  beardown911
Messages: 21
Registered: March 2007
Junior Member
On Nov 4, 1:14 pm, Chris W <cwood1...@gmail.com> wrote:
> On Nov 4, 12:53 pm, go cats <beardown...@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
Re: How to average every nth data? [message #73391 is a reply to message #73390] Thu, 04 November 2010 13:13 Go to previous message
beardown911 is currently offline  beardown911
Messages: 21
Registered: March 2007
Junior Member
On Nov 4, 2:24 pm, Bennett <juggernau...@gmail.com> wrote:
> On Nov 4, 1:53 pm, go cats <beardown...@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
Re: How to average every nth data? [message #73392 is a reply to message #73391] Thu, 04 November 2010 13:12 Go to previous message
beardown911 is currently offline  beardown911
Messages: 21
Registered: March 2007
Junior Member
On Nov 4, 1:14 pm, Chris W <cwood1...@gmail.com> wrote:
> On Nov 4, 12:53 pm, go cats <beardown...@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
Re: How to average every nth data? [message #73395 is a reply to message #73392] Thu, 04 November 2010 12:24 Go to previous message
Juggernaut is currently offline  Juggernaut
Messages: 83
Registered: June 2008
Member
On Nov 4, 1:53 pm, go cats <beardown...@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.
Re: How to average every nth data? [message #73399 is a reply to message #73395] Thu, 04 November 2010 11:14 Go to previous message
Chris W is currently offline  Chris W
Messages: 12
Registered: May 2007
Junior Member
On Nov 4, 12:53 pm, go cats <beardown...@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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: SPAWN and strings
Next Topic: Re: SPAWN and strings

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

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

Total time taken to generate the page: 0.00666 seconds