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

Home » Public Forums » archive » Re: REGRESS and sky background
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: REGRESS and sky background [message #71648] Tue, 06 July 2010 12:50
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jul 6, 9:18 am, wlandsman <wlands...@gmail.com> wrote:
> On Jul 5, 8:06 pm, Gray <grayliketheco...@gmail.com> wrote:
>
>> Here's my general algorithm; I actually use a different mean clipping
>> routine, but astrolib's MEANCLIP gives the same (unwanted) results.
>> Take a look and tell me what you think.  Thanks!
>
> Some possibly useful thoughts.
>
> 1.   I don't understand this line
>
>      abc += [ab,c]
>
> On each iteration you are removing outliers and redoing the
> regression.   But you don't want to add the newly determined
> parameters to the old ones - I think you want a simple equality in the
> above statement.
>
> 2.  REGRESS has a lot of keywords -- STATUS, SIGMA, CHISQ -- to help
> assess the quality of the solution.   I would monitor these to see if
>
> 3.  Henry Freudenreich wrote code for a similar problem -- check out
> robust_planefit.pro and supporting procedures inhttp://idlastro.gsfc.nasa.gov/ftp/contrib/freudenreich/
>
> --Wayne

Robust_planefit looks like it may be exactly what I need, so I will
give it a try! Thanks :)
Re: REGRESS and sky background [message #71649 is a reply to message #71648] Tue, 06 July 2010 12:49 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jul 6, 9:19 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Jul 5, 8:06 pm, Gray <grayliketheco...@gmail.com> wrote:
>
>
>
>
>
>> Hi all,
>
>> I'm baffled with how one of my programs is acting, and would love some
>> insight, if there is any to be had.
>
>> The routine is designed to fit the sky background image (in my case, a
>> 128x128 subdivision of a larger astronomical image) to a plane (Ax+By
>> +C) using REGRESS.  My subdivisions are small enough that I think a
>> plane is a pretty good approximation; the idea is to do a 3.5-sigma
>> mean clip to remove sources, then regress the sky pixels to a plane
>> and subtract the plane, and iterate until the fitted plane reaches 0.
>> The problem is that it seems the slope of the background increases
>> with increasing iterations, which it theoretically should not do.
>
>> Here's my general algorithm; I actually use a different mean clipping
>> routine, but astrolib's MEANCLIP gives the same (unwanted) results.
>> Take a look and tell me what you think.  Thanks!
>
>> --Gray
>
>> FUNCTION find_skybg, image, sigma
>>   img = image
>>   s = size(img,/dim)
>>   lx = rebin(indgen(s[0]),s[0],s[1])    ;x and y coordinates
>>   ly = rebin(indgen(1,s[1]),s[0],s[1]) ;to construct bg plane
>>   abc = fltarr(3)
>>   iter = 0
>>   repeat begin
>>     meanclip, img, m, subs=clips, clipsig=3.5 ;don't care about mean,
>> just clips
>>     xy = array_indices(s,clips,/dim)
>>     ab = reform(regress(xy,img[clips],const=c))
>>     sigma = stddev(img[clips])
>>     abc += [ab,c]
>>     bg = ab[0]*lx+ab[1]*ly+c
>>     img -= bg
>>     iter++
>>   endrep until (iter ge 10 or total([ab,c]/abc le 0.02) eq 3)
>>   background = abc[0]*lx+abc[1]*ly+abc[2]
>>   return, background
>> endfor
>
> Not sure... I just tested it out on an image with stars and a
> background gradient and it worked exactly as expected. What fraction
> of the image is making it through the sigma clipping? I could see it
> being unstable if that fraction is sufficiently small. Is that
> fraction reasonably stable from iteration to iteration? Maybe there
> are an unusual number of pixels right around 3.5sigma, whose inclusion
> or exclusion makes a big change to the solution?
>
> -Jeremy.

Most of the points, usually around 85%. I've tried varying the clip
sigma, and it doesn't seem to matter...
Re: REGRESS and sky background [message #71655 is a reply to message #71649] Tue, 06 July 2010 07:51 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
> 1.   I don't understand this line
>
>      abc += [ab,c]
>
> On each iteration you are removing outliers and redoing the
> regression.   But you don't want to add the newly determined
> parameters to the old ones - I think you want a simple equality in the
> above statement.

No, that's correct. It works because the image gets the background
determined at the previous iteration subtracted at each step... so the
solution to get from the original coordinates to the new plane is the
sum of the planes determined at each iteration.

-Jeremy.
Re: REGRESS and sky background [message #71656 is a reply to message #71655] Tue, 06 July 2010 06:19 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Jul 5, 8:06 pm, Gray <grayliketheco...@gmail.com> wrote:
> Hi all,
>
> I'm baffled with how one of my programs is acting, and would love some
> insight, if there is any to be had.
>
> The routine is designed to fit the sky background image (in my case, a
> 128x128 subdivision of a larger astronomical image) to a plane (Ax+By
> +C) using REGRESS.  My subdivisions are small enough that I think a
> plane is a pretty good approximation; the idea is to do a 3.5-sigma
> mean clip to remove sources, then regress the sky pixels to a plane
> and subtract the plane, and iterate until the fitted plane reaches 0.
> The problem is that it seems the slope of the background increases
> with increasing iterations, which it theoretically should not do.
>
> Here's my general algorithm; I actually use a different mean clipping
> routine, but astrolib's MEANCLIP gives the same (unwanted) results.
> Take a look and tell me what you think.  Thanks!
>
> --Gray
>
> FUNCTION find_skybg, image, sigma
>   img = image
>   s = size(img,/dim)
>   lx = rebin(indgen(s[0]),s[0],s[1])    ;x and y coordinates
>   ly = rebin(indgen(1,s[1]),s[0],s[1]) ;to construct bg plane
>   abc = fltarr(3)
>   iter = 0
>   repeat begin
>     meanclip, img, m, subs=clips, clipsig=3.5 ;don't care about mean,
> just clips
>     xy = array_indices(s,clips,/dim)
>     ab = reform(regress(xy,img[clips],const=c))
>     sigma = stddev(img[clips])
>     abc += [ab,c]
>     bg = ab[0]*lx+ab[1]*ly+c
>     img -= bg
>     iter++
>   endrep until (iter ge 10 or total([ab,c]/abc le 0.02) eq 3)
>   background = abc[0]*lx+abc[1]*ly+abc[2]
>   return, background
> endfor

Not sure... I just tested it out on an image with stars and a
background gradient and it worked exactly as expected. What fraction
of the image is making it through the sigma clipping? I could see it
being unstable if that fraction is sufficiently small. Is that
fraction reasonably stable from iteration to iteration? Maybe there
are an unusual number of pixels right around 3.5sigma, whose inclusion
or exclusion makes a big change to the solution?

-Jeremy.
Re: REGRESS and sky background [message #71657 is a reply to message #71656] Tue, 06 July 2010 06:18 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Jul 5, 8:06 pm, Gray <grayliketheco...@gmail.com> wrote:

> Here's my general algorithm; I actually use a different mean clipping
> routine, but astrolib's MEANCLIP gives the same (unwanted) results.
> Take a look and tell me what you think.  Thanks!

Some possibly useful thoughts.

1. I don't understand this line

    abc += [ab,c]

On each iteration you are removing outliers and redoing the
regression. But you don't want to add the newly determined
parameters to the old ones - I think you want a simple equality in the
above statement.

2. REGRESS has a lot of keywords -- STATUS, SIGMA, CHISQ -- to help
assess the quality of the solution. I would monitor these to see if

3. Henry Freudenreich wrote code for a similar problem -- check out
robust_planefit.pro and supporting procedures in
http://idlastro.gsfc.nasa.gov/ftp/contrib/freudenreich/

--Wayne
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Padding arrays - vector subscripts not working
Next Topic: Subtracting a single variable from an array

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

Current Time: Wed Oct 08 15:33:38 PDT 2025

Total time taken to generate the page: 0.00449 seconds