-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASA user's guide to common operations in spectral-cube #15
CASA user's guide to common operations in spectral-cube #15
Conversation
The install on binder is failing. Will need to revise the build files |
Build still not working. Seem like:
|
…via conda; go back to pip install
Yay! CASA is finally working on binder! Here's what ended up being required for the install:
Other things to note:
|
…o specify different requirements for each tutorial
Ready once radio-astro-tools/spectral-cube#680 is merged. |
ran locally, and... something's amiss?
The Gaussian shapes are different, but they look like they evaluated to be the same |
Yeah, they're within ~1/5 of a pixel (1 pixel = 1" here). I wasn't able to get these to agree any better, but I agree that they seem to be evaluated almost the same. I can add a note about this in the notebook. |
I think these are too different. I'm concerned now. |
The difference is with the underlying image being fit. CASA seems to only be able to cutout odd-sized chunks and is dealing with masking differently. |
the odd-size chunk issue can be solved with The remaining difference might be that astropy masks pixels (ignores them), casa doesn't |
nope, my idea is wrong. You've manually set bad pixels to zero. So what is CASA doing? |
the difference is in the fitter, verified by astropy-fitting the CASA data: ia.open(outfilename)
casa_mom0 = ia.getchunk().squeeze().T
ia.close()
p_gauss2D = fit_p(p_init_gauss2D, xx, yy, casa_mom0*u.K*u.km/u.s) it gives the same result as astropy-fitting the spectral-cube data |
This MWE works as expected: import numpy as np
import shutil
import os
from casatools import image; ia = image()
from casatasks import imfit
from astropy.modeling.models import Gaussian2D
from astropy.modeling.fitting import LevMarLSQFitter
from astropy import units as u
FWHM2SIGMA = (8*np.log(2))**0.5
mod = Gaussian2D(amplitude=1.5, x_mean=15, y_mean=17, x_stddev=3.2, y_stddev=1.5, theta=45*u.deg)
yy,xx = np.indices([64,64])
modim = mod(xx,yy)
if os.path.exists('test_gauss.image'):
shutil.rmtree('test_gauss.image')
ia.fromarray(outfile='test_gauss.image', pixels=modim.T)
spatfit_casa = imfit('test_gauss.image')
g_casa_spatfit = Gaussian2D(amplitude=spatfit_casa['results']['component0']['peak']['value'],
x_mean=spatfit_casa['results']['component0']['pixelcoords'][0],
y_mean=spatfit_casa['results']['component0']['pixelcoords'][1],
y_stddev=spatfit_casa['results']['component0']['shape']['majoraxis']['value'] / FWHM2SIGMA / 60,
x_stddev=spatfit_casa['results']['component0']['shape']['minoraxis']['value'] / FWHM2SIGMA / 60,
theta=spatfit_casa['results']['component0']['shape']['positionangle']['value'] * u.deg
)
print(g_casa_spatfit, mod) |
MWE with noise: import numpy as np
import shutil
import os
from casatools import image; ia = image()
from casatasks import imfit
from astropy.modeling.models import Gaussian2D
from astropy.modeling.fitting import LevMarLSQFitter
from astropy import units as u
FWHM2SIGMA = (8*np.log(2))**0.5
mod = Gaussian2D(amplitude=1.5, x_mean=15, y_mean=17, x_stddev=3.2, y_stddev=1.5, theta=45*u.deg)
yy,xx = np.indices([64,64])
np.random.seed(12345)
noise = np.random.randn(64,64) / 2
modim = mod(xx,yy) + noise
if os.path.exists('test_gauss.image'):
shutil.rmtree('test_gauss.image')
ia.fromarray(outfile='test_gauss.image', pixels=modim.T)
ia.close()
spatfit_casa = imfit('test_gauss.image')
g_casa_spatfit = Gaussian2D(amplitude=spatfit_casa['results']['component0']['peak']['value'],
x_mean=spatfit_casa['results']['component0']['pixelcoords'][0],
y_mean=spatfit_casa['results']['component0']['pixelcoords'][1],
y_stddev=spatfit_casa['results']['component0']['shape']['majoraxis']['value'] / FWHM2SIGMA / 60,
x_stddev=spatfit_casa['results']['component0']['shape']['minoraxis']['value'] / FWHM2SIGMA / 60,
theta=spatfit_casa['results']['component0']['shape']['positionangle']['value'] * u.deg
)
fitter = LevMarLSQFitter()
pguess_astropy = Gaussian2D(amplitude=2, x_mean=16, y_mean=16, x_stddev=2, y_stddev=2, theta=0*u.deg)
pfit_astropy = fitter(pguess_astropy, xx, yy, modim)
print(f"CASA: {g_casa_spatfit}\n\n Astropy: {pfit_astropy}\n\n input:{mod}") |
@keflavich -- thanks for digging into the fitting problem. Also not due to imfit doing something with the beam size. Deleting the beam in the CASA moment 0 image makes no difference.
|
Also no difference for adding the same initial guesses to the CASA fit that we're using for the astropy fit:
|
Can it be something to do with the masks? I tried masking out the data in the astropy fit (your version doesn't mask out the data - suggest modifying so that it does; set |
…ded a general explanation for the conversion from pix to ang scales for arb. theta
Closing the loop on the fit discrepancies and @keflavich's MWEs:
I've also cleaned up the box selections in CASA to use @keflavich -- Mind having one last look through the spatial fitting? The key addition is handling the pix -> ang scale conversion. There's a bit of confusion with the |
@keflavich Good to squash and merge (the first few commits included the cell outputs in the nb) |
Split out tutorial initially in #11. Depends on pending PR radio-astro-tools/spectral-cube#665.
Temporary binder link:
Link to main repo is in the README.