Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
----------
**kwargs : dict
Arguments to be passed to the `TPFModel` constructor, e.g.
`star_priors`.
Returns
-------
model : TPFModel object
Model with appropriate defaults for this Target Pixel File.
"""
from .prf import TPFModel, StarPrior, BackgroundPrior
from .prf import UniformPrior, GaussianPrior
# Set up the model
if 'star_priors' not in kwargs:
centr_col, centr_row = self.estimate_centroids()
star_priors = [StarPrior(col=GaussianPrior(mean=np.nanmedian(centr_col),
var=np.nanstd(centr_col)**2),
row=GaussianPrior(mean=np.nanmedian(centr_row),
var=np.nanstd(centr_row)**2),
flux=UniformPrior(lb=0.5*np.nanmax(self.flux[0]),
ub=2*np.nansum(self.flux[0]) + 1e-10),
targetid=self.targetid)]
kwargs['star_priors'] = star_priors
if 'prfmodel' not in kwargs:
kwargs['prfmodel'] = self.get_prf_model()
if 'background_prior' not in kwargs:
if np.all(np.isnan(self.flux_bkg)): # If TargetPixelFile has no background flux data
# Use the median of the lower half of flux as an estimate for flux_bkg
clipped_flux = np.ma.masked_where(self.flux > np.percentile(self.flux, 50),
self.flux)
flux_prior = GaussianPrior(mean=np.ma.median(clipped_flux),
var=np.ma.std(clipped_flux)**2)
star_priors = [StarPrior(col=GaussianPrior(mean=np.nanmedian(centr_col),
var=np.nanstd(centr_col)**2),
row=GaussianPrior(mean=np.nanmedian(centr_row),
var=np.nanstd(centr_row)**2),
flux=UniformPrior(lb=0.5*np.nanmax(self.flux[0]),
ub=2*np.nansum(self.flux[0]) + 1e-10),
targetid=self.targetid)]
kwargs['star_priors'] = star_priors
if 'prfmodel' not in kwargs:
kwargs['prfmodel'] = self.get_prf_model()
if 'background_prior' not in kwargs:
if np.all(np.isnan(self.flux_bkg)): # If TargetPixelFile has no background flux data
# Use the median of the lower half of flux as an estimate for flux_bkg
clipped_flux = np.ma.masked_where(self.flux > np.percentile(self.flux, 50),
self.flux)
flux_prior = GaussianPrior(mean=np.ma.median(clipped_flux),
var=np.ma.std(clipped_flux)**2)
else:
flux_prior = GaussianPrior(mean=np.nanmedian(self.flux_bkg),
var=np.nanstd(self.flux_bkg)**2)
kwargs['background_prior'] = BackgroundPrior(flux=flux_prior)
return TPFModel(**kwargs)
var=np.nanstd(centr_row)**2),
flux=UniformPrior(lb=0.5*np.nanmax(self.flux[0]),
ub=2*np.nansum(self.flux[0]) + 1e-10),
targetid=self.targetid)]
kwargs['star_priors'] = star_priors
if 'prfmodel' not in kwargs:
kwargs['prfmodel'] = self.get_prf_model()
if 'background_prior' not in kwargs:
if np.all(np.isnan(self.flux_bkg)): # If TargetPixelFile has no background flux data
# Use the median of the lower half of flux as an estimate for flux_bkg
clipped_flux = np.ma.masked_where(self.flux > np.percentile(self.flux, 50),
self.flux)
flux_prior = GaussianPrior(mean=np.ma.median(clipped_flux),
var=np.ma.std(clipped_flux)**2)
else:
flux_prior = GaussianPrior(mean=np.nanmedian(self.flux_bkg),
var=np.nanstd(self.flux_bkg)**2)
kwargs['background_prior'] = BackgroundPrior(flux=flux_prior)
return TPFModel(**kwargs)
Arguments to be passed to the `TPFModel` constructor, e.g.
`star_priors`.
Returns
-------
model : TPFModel object
Model with appropriate defaults for this Target Pixel File.
"""
from .prf import TPFModel, StarPrior, BackgroundPrior
from .prf import UniformPrior, GaussianPrior
# Set up the model
if 'star_priors' not in kwargs:
centr_col, centr_row = self.estimate_centroids()
star_priors = [StarPrior(col=GaussianPrior(mean=np.nanmedian(centr_col),
var=np.nanstd(centr_col)**2),
row=GaussianPrior(mean=np.nanmedian(centr_row),
var=np.nanstd(centr_row)**2),
flux=UniformPrior(lb=0.5*np.nanmax(self.flux[0]),
ub=2*np.nansum(self.flux[0]) + 1e-10),
targetid=self.targetid)]
kwargs['star_priors'] = star_priors
if 'prfmodel' not in kwargs:
kwargs['prfmodel'] = self.get_prf_model()
if 'background_prior' not in kwargs:
if np.all(np.isnan(self.flux_bkg)): # If TargetPixelFile has no background flux data
# Use the median of the lower half of flux as an estimate for flux_bkg
clipped_flux = np.ma.masked_where(self.flux > np.percentile(self.flux, 50),
self.flux)
flux_prior = GaussianPrior(mean=np.ma.median(clipped_flux),
var=np.ma.std(clipped_flux)**2)
else:
flux_prior = GaussianPrior(mean=np.nanmedian(self.flux_bkg),