Under the hood¶
Disk Models¶
Model Handling¶
You should define the model with the ModelSersic()
class :
from galpak import GalPaK3D, ModelSersic
mymodel = ModelSersic(flux_profile='exponential',rotation_curve='tanh',redshift=1.0)
gk = GalPaK3D('GalPaK_cube_1101_from_paper.fits',model=mymodel)
And print(gk.model)
should yield
Note
The galpak save()
method will save a file model.txt
If the model is saved into a model.txt file, one can use :
from galpak import GalPaK3D
gk = GalPaK3D('GalPaK_cube_1101_from_paper.fits',model='model.txt')
The file model.txt should be like :
Base Model Class¶
Instruments¶
GalPaK uses a virtual Instrument
to convolve the simulation cubes and check against observed data.
As each instrument has its own tweaks and quirks (both hardware and atmospheric),
you can provide an instrument to GalPaK3D
,
the default one being MUSE
in Wide Field Mode :
The spectral characteristics (pixel cdelt, etc.) are re-calibrated using the Cube’s header when you instantiate GalPaK.
Pay attention in defining most appropriate values for the seeing or psf_fwhm(“)
– psf_ba if not round – and lsf_fwhm (in units of cube) parameters.
All of them by default use the gaussian PSF GaussianPointSpreadFunction
.
Instruments handling¶
You should define the instrument as :
from galpak import GalPaK3D, MUSE, GaussianPointSpreadFunction
mypsf = GaussianPointSpreadFunction(fwhm=0.7,pa=0,ba=1)
myinstr = MUSE(psf=mypsf,lsf=None)
gk = GalPaK3D('GalPaK_cube_1101_from_paper.fits',instrument=myinstr)
And print(gk.instrument)
should yield
Note
The galpak save
method will save a file instrument.txt
If the instrument is saved into a instrument.txt file, one can use :
from galpak import GalPaK3D
gk = GalPaK3D('GalPaK_cube_1101_from_paper.fits',instrument='instrument.txt')
The file instrument.txt should be like :
Note
Both instrument.txt and model.txt can be combined in a single config file
Instruments supported¶
- ALMA
set lsf_fwhm to 1 cdelt (default) or less or use NoLineSpreadFunction
- SINFONI (J250, H250 and K250 modes)
SINFOJ250, SINFOH250, SINFOK250 :
- from galpak import run, SINFOK250
gk = run(‘my_sinfok250_cube.fits’, instrument=SINFOK250())
- MUSE (WFM and NFW modes)
default lsf_fwhm is 2.67 Angstrom
- KMOS
default xy_step is 0.2 arcsecs
- HARMONI
use the syntax HARMONI(pixscale=30)
OSIRIS
MANGA (soon)
Note
The default Instrument values will be overridden by the cube header info (CRPIX, CDELT etc.) if present.
Base Instrument Class¶
Hyperspectral Cube¶
This class is a very simple (understand : not fully-featured nor exhaustive) model of a hyperspectral cube.
Note
This class is not fully formed yet and its API may evolve as it moves to its own module.
Important
A description of the parameter meaning can be found here
Description¶
A GalaxyParameters
object gp
is merely a glorified numpy.ndarray
with convenience accessors and mutators :
Warning
the velocity_dispersion parameter is NOT the total dispersion. This parameter is akin to a turbulent term. It is added in quadrature to the dispersions due to the disk model and to the thickness. See Cresci et al. 2009, Genzel et al. 2011, and Bouche et al. 2015
You still can access the parameters like an indexed array
assert gp.x == gp[0] # true
assert gp.y == gp[1] # true
# ...
assert gp.sigma0 == gp[9] # true
You may instantiate a GalaxyParameters
object like so
from galpak import GalaxyParameters
gp = GalaxyParameters(z=0.65)
gp.x = 5.
assert gp.z == 0.65 # true
assert gp.x == 5. # true
Warning
An undefined value in GalaxyParameters
will be nan
, not None
assert math.isnan(gp.pa) # true
assert gp.pa is None # false
Getting the Wavelength¶
The z
attribute in a GalaxyParameter
is in pixels,
you may want the value in the physical unit specified in your Cube’s header.
To that effect, you may use the wavelength_of
method of the HyperspectralCube
:
from galpak import GalPaK3D
gk = GalPaK3D('my_muse_cube.fits')
gk.run_mcmc()
wavelength = gk.cube.wavelength_of(gk.galaxy.z)
MCMC¶
GalPaK3D allows the user to select several samplers for the MCMC as described in the
run_mcmc
method which has the following options:
- mcmc_method: ‘galpak’ [default] | ‘emcee_walkers’| ‘emcee_MH’ | ‘dynesty’ | ‘multinest’
- The MCMC method.
galpak: for the original MCMC algorithm using Cauchy proposal distribution
emcee_MH: emcee v2.x classic MH; no longer supported
emcee_walkers: emcee v3.x multi-Walkers algorithms with Moves
dynesty: unsupported
multinest: still experimental
pymc3: to be implemented
- mcmc_sampling:
galpak: ‘Cauchy’ [default] | ‘Normal’ | ‘AdaptiveCauchy’
emcee_walkers: ‘walkers’ [default] | ‘walkersCauchy’ | ‘DE’ | ‘Snooker’ | ‘Cauchy’ | ‘Normal’
multinest: None
pymc3: to be implemented
The proposal sampling methods
GalPaK3D uses an internal MCMC
class which extend the galpak class.
This can be used to call its likelihood such as:
li = gk(params)
using a self.__call__()
method which returns the lnprob
Here is a full example:
import galpak
gk=galpak.GalPaK3D('data/input/GalPaK_cube_1101_from_paper.fits',model=galpak.DefaultModel())
p=gk.model.Parameters()
params=p.from_ndarray([15,15,15,1e-16,5,60,90,1,100,10])
li=gk(params)
You can always check that the log-likelihood is finite :
print(li)
-16117.55742040931
If it is not finite, this is probably caused by the priors when the parameter values are outside the min and max boundaries.
Point Spread Functions¶
GalPaK provides the two most common PSF : Gaussian and Moffat.
You may use them as the psf
argument of the Instrument, as described here.
All instruments use this PSF model by default, with their own configuration :
In order to furthermore customize the PSF you want to use, you can create your own PSF class and use it in the instrument, it simply needs to implement the following interface :
Line Spread Functions¶
GalPaK provides two LSFs : Gaussian and MUSE. These are used to extrude the 2D PSF image into 3D, right before its application in Fourier space.
You may use them as the lsf
argument of the Instrument
,
as described here.
All instruments use this LSF model by default, with their own configuration :
This LSF requires the mpdaf module, specifically mpdaf.MUSE.LSF.
As this LSF is optional, you must explicitly tell your instrument to use it when you want to.
In order to further customize the LSF you want to use, you can create your own LSF class and use it in the instrument, it simply needs to implement the following interface :