Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _non_iterative(self, sma, step, linear, geometry, sclip, nclip,
integrmode):
sample = EllipseSample(self.image, sma, astep=step, sclip=sclip,
nclip=nclip, linear_growth=linear,
geometry=geometry, integrmode=integrmode)
sample.update()
# build isophote without iterating with an EllipseFitter
isophote = Isophote(sample, 0, True, stop_code=4)
return isophote
sample.update()
# see if any abnormal (or unusual) conditions warrant
# the change to non-iterative mode, or go-inwards mode.
proceed, lexceed = self._check_conditions(
sample, maxgerr, going_inwards, lexceed)
if not proceed:
sample.update()
return Isophote(sample, iter+1, True, -1)
# Got to the maximum number of iterations. Return with
# code 2, and handle it as a valid isophote. Use the
# best fit sample instead of the current one.
minimum_amplitude_sample.update()
return Isophote(minimum_amplitude_sample, maxit, True, 2)
# The extract() method returns sampled values as a 2-d numpy array
# with the following structure:
# values[0] = 1-d array with angles
# values[1] = 1-d array with radii
# values[2] = 1-d array with intensity
values = sample.extract()
# Fit harmonic coefficients. Failure in fitting is
# a fatal error; terminate immediately with sample
# marked as invalid.
try:
coeffs = fit_first_and_second_harmonics(values[0], values[2])
except Exception as e:
log.info(e)
return Isophote(sample, iter+1, False, 3)
coeffs = coeffs[0]
# largest harmonic in absolute value drives the correction.
largest_harmonic_index = np.argmax(np.abs(coeffs[1:]))
largest_harmonic = coeffs[1:][largest_harmonic_index]
# see if the amplitude decreased; if yes, keep the
# corresponding sample for eventual later use.
if abs(largest_harmonic) < minimum_amplitude_value:
minimum_amplitude_value = abs(largest_harmonic)
minimum_amplitude_sample = sample
# check if converged
model = first_and_second_harmonic_function(values[0], coeffs)
residual = values[2] - model
# to be like the geometry of the index-th isophote
# in list.
isophote.fix_geometry(isophote_list[index])
# force new extraction of raw data, since
# geometry changed.
isophote.sample.values = None
isophote.sample.update()
# we take the opportunity to change an eventual
# negative stop code to its' positive equivalent.
code = (5 if isophote.stop_code < 0 else isophote.stop_code)
# build new instance so it can have its attributes
# populated from the updated sample attributes.
new_isophote = Isophote(isophote.sample, isophote.niter,
isophote.valid, code)
# add new isophote to list
isophote_list.append(new_isophote)
# corresponding sample for eventual later use.
if abs(largest_harmonic) < minimum_amplitude_value:
minimum_amplitude_value = abs(largest_harmonic)
minimum_amplitude_sample = sample
# check if converged
model = first_and_second_harmonic_function(values[0], coeffs)
residual = values[2] - model
if ((conver * sample.sector_area * np.std(residual))
> np.abs(largest_harmonic)):
# Got a valid solution. But before returning, ensure
# that a minimum of iterations has run.
if iter >= minit-1:
sample.update()
return Isophote(sample, iter+1, True, 0)
# it may not have converged yet, but the sample contains too
# many invalid data points: return.
if sample.actual_points < (sample.total_points * fflag):
# when too many data points were flagged, return the
# best fit sample instead of the current one.
minimum_amplitude_sample.update()
return Isophote(minimum_amplitude_sample, iter+1, True, 1)
# pick appropriate corrector code.
corrector = _correctors[largest_harmonic_index]
# generate *NEW* EllipseSample instance with corrected
# parameter. Note that this instance is still devoid of other
# information besides its geometry. It needs to be explicitly
# updated for computations to proceed. We have to build a new
def to_table(self):
"""
Return the main isophote parameters as an astropy
`~astropy.table.QTable`.
Returns
-------
result : `~astropy.table.QTable`
An astropy `~astropy.table.QTable` containing the main
isophote paramters.
"""
return _isophote_list_to_table([self])
class CentralPixel(Isophote):
"""
Specialized Isophote class for the galaxy central pixel.
This class holds only a single intensity value at the central
position. Thus, most of its attributes are hardcoded to `None` or a
default value when appropriate.
Parameters
----------
sample : `~photutils.utils.EllipseSample` instance
The sample information.
"""
def __init__(self, sample):
self.sample = sample
self.niter = 0
if ((conver * sample.sector_area * np.std(residual))
> np.abs(largest_harmonic)):
# Got a valid solution. But before returning, ensure
# that a minimum of iterations has run.
if iter >= minit-1:
sample.update()
return Isophote(sample, iter+1, True, 0)
# it may not have converged yet, but the sample contains too
# many invalid data points: return.
if sample.actual_points < (sample.total_points * fflag):
# when too many data points were flagged, return the
# best fit sample instead of the current one.
minimum_amplitude_sample.update()
return Isophote(minimum_amplitude_sample, iter+1, True, 1)
# pick appropriate corrector code.
corrector = _correctors[largest_harmonic_index]
# generate *NEW* EllipseSample instance with corrected
# parameter. Note that this instance is still devoid of other
# information besides its geometry. It needs to be explicitly
# updated for computations to proceed. We have to build a new
# EllipseSample instance every time because of the lazy
# extraction process used by EllipseSample code. To minimize
# the number of calls to the area integrators, we pay a
# (hopefully smaller) price here, by having multiple calls to
# the EllipseSample constructor.
sample = corrector.correct(sample, largest_harmonic)
sample.update()