[AstroPy] JointFitter help

Nadezhda Dencheva dencheva at stsci.edu
Thu Feb 5 08:45:13 EST 2015


Hi Brandon,

Thanks for posting.
You are right, this is a use case for the JointFitter but there's a bug.
I'll see if this can be easily fixed.

Nadia
________________________________
From: astropy-bounces at scipy.org [astropy-bounces at scipy.org] on behalf of Paul Kuin [npkuin at gmail.com]
Sent: Wednesday, February 04, 2015 4:21 PM
To: Astronomical Python mailing list
Subject: Re: [AstroPy] JointFitter help

to quickly get a centroid, you can also use a simple weighted mean

I think it is like,

say z(x,y) is the value of the pixel,
posx = sum(x*z(x,y))/sum(x)
posy = sum(y*z(x,y))/sum(y)

On Wed, Feb 4, 2015 at 7:22 PM, Brandon Swift <bjswift at gmail.com<mailto:bjswift at gmail.com>> wrote:
Sure thing, Nadia. In case you/someone else doesn't know, a regular digital camera has an alternating color filter pattern over the CMOS detectors like this http://en.wikipedia.org/wiki/Bayer_filter. I am trying to take a picture of a point-like source that has contrast to the surrounding background, and nail down the centroid of that as well (and as fast) as I reasonably can. I figure that using the raw pixel data instead of using the demosaiced and otherwise-processed JPEG that normally comes out the back end of the camera will help.

So, yes, I'm trying to fit a 2D gaussian to R, G, and B channels simultaneously, each of which has their own checkerboard-like mask, like in the attached image/below.

[cid:ii_i5r2nc7y1_14b55eefcafaac02]
​
When doing the gaussian fit, the x/y_mean should be tied together between the 3 channels, and the x/y_stddev and theta should also be tied (to within chromatic effects of the lens), but the amplitude of each channel should be allowed to be different. Which all sounds very much like the example use-case described in the docstring of the JointFitter class!

I had moderate success with fitting individual channels (convergence was sometimes flaky) and was about to try writing a custom 'Gaussian2Dx3' model class when I ran across JointFItter and thought it seemed like it would do nicely. Right now, I'm doing something like this, which isn't working right because I don't know how the inputs need to go but I've been trying to guess from the source code and errors generated:

--------------------------------------------------------------------------------------------------------
## Define reasonable ranges for the fitting parameters (data centered at 0,0 pixel)
gaussbounds = {'amplitude': [0.2, 0.8],  'x_mean':    [-2.0, 2.0],  'y_mean':    [-2.0, 2.0], 'x_stddev':  [0.2, 1.5], 'y_stddev':  [0.2, 1.5]}

## Create a model instance for each channel
gaussR = models.Gaussian2D(0.5, 0.0, 0.0, 0.4, 0.4, bounds=gaussbounds)
gaussG = models.Gaussian2D(0.5, 0.0, 0.0, 0.4, 0.4, bounds=gaussbounds)
gaussB = models.Gaussian2D(0.5, 0.0, 0.0, 0.4, 0.4, bounds=gaussbounds)

## Trying to get these other inputs structured correctly to make JointFitter.__init__()
## complete smoothly.
jointpars = {'gaussR':   [gaussR.x_mean, gaussR.y_mean, gaussR.x_stddev, gaussR.y_stddev, gaussR.theta],
             'gaussG':   [gaussG.x_mean, gaussG.y_mean, gaussG.x_stddev, gaussG.y_stddev, gaussG.theta],
             'gaussB':   [gaussB.x_mean, gaussB.y_mean, gaussB.x_stddev, gaussB.y_stddev, gaussB.theta] }
initvals = [0.0, 0.0, 0.4, 0.4, 0.0]

## Here's what I'm feeding it, finally. I'm out of ideas!
jointRGB = fitting.JointFitter({'gaussR':gaussR, 'gaussG':gaussG, 'gaussB':gaussB}, jointpars, initvals)
--------------------------------------------------------------------------------------------------------

Anyway, many thanks in advance for the help! Cheers,
Brandon



> Date: Wed, 4 Feb 2015 14:38:44 +0000
> From: Nadezhda Dencheva <dencheva at stsci.edu<mailto:dencheva at stsci.edu>>
> Subject: Re: [AstroPy] JointFitter help
>
> Hi Brandon,
>
> Can you explain a bit more how you are doing the fitting?
> It sounds like you are fitting a 2D Gaussian but I'm not sure what the data is?
> What are the inputs to each model?
>
> Cheers,
> Nadia

_______________________________________________
AstroPy mailing list
AstroPy at scipy.org<mailto:AstroPy at scipy.org>
http://mail.scipy.org/mailman/listinfo/astropy




--

* * * * * * * * http://www.mssl.ucl.ac.uk/~npmk/ * * * *
Dr. N.P.M. Kuin      (n.kuin at ucl.ac.uk<mailto:n.kuin at ucl.ac.uk>)
phone +44-(0)1483 (prefix) -204927 (work)
mobile +44(0)7806985366  skype ID: npkuin
Mullard Space Science Laboratory  – University College London  –
Holmbury St Mary – Dorking – Surrey RH5 6NT–  U.K.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150205/ccfafa4e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rgbspot.png
Type: image/png
Size: 1980 bytes
Desc: rgbspot.png
URL: <http://mail.python.org/pipermail/astropy/attachments/20150205/ccfafa4e/attachment.png>


More information about the AstroPy mailing list