nodes: 0, module; 1, function_definition; 2, function_name:fit_image; 3, parameters; 4, comment:# This parameter list is quite large and should in principle be; 5, comment:# simplified by re-distributing these controls to somewhere else.; 6, comment:# We keep this design though because it better mimics the flat; 7, comment:# architecture used in the original STSDAS task `ellipse`.; 8, block; 9, identifier:self; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, default_parameter; 16, default_parameter; 17, default_parameter; 18, default_parameter; 19, default_parameter; 20, default_parameter; 21, default_parameter; 22, default_parameter; 23, default_parameter; 24, expression_statement; 25, comment:# multiple fitted isophotes will be stored here; 26, expression_statement; 27, comment:# get starting sma from appropriate source: keyword parameter,; 28, comment:# internal EllipseGeometry instance, or fixed default value.; 29, if_statement; 30, comment:# first, go from initial sma outwards until; 31, comment:# hitting one of several stopping criteria.; 32, expression_statement; 33, expression_statement; 34, while_statement; 35, comment:# reset sma so as to go inwards.; 36, expression_statement; 37, expression_statement; 38, comment:# now, go from initial sma inwards towards center.; 39, while_statement; 40, comment:# if user asked for minsma=0, extract special isophote there; 41, if_statement; 42, comment:# sort list of isophotes according to sma; 43, expression_statement; 44, return_statement; 45, identifier:sma0; 46, None; 47, identifier:minsma; 48, float:0.; 49, identifier:maxsma; 50, None; 51, identifier:step; 52, float:0.1; 53, identifier:conver; 54, identifier:DEFAULT_CONVERGENCE; 55, identifier:minit; 56, identifier:DEFAULT_MINIT; 57, identifier:maxit; 58, identifier:DEFAULT_MAXIT; 59, identifier:fflag; 60, identifier:DEFAULT_FFLAG; 61, identifier:maxgerr; 62, identifier:DEFAULT_MAXGERR; 63, identifier:sclip; 64, float:3.; 65, identifier:nclip; 66, integer:0; 67, identifier:integrmode; 68, identifier:BILINEAR; 69, identifier:linear; 70, False; 71, identifier:maxrit; 72, None; 73, comment:"""
          Fit multiple isophotes to the image array.
  
          This method loops over each value of the semimajor axis (sma)
          length (constructed from the input parameters), fitting a single
          isophote at each sma.  The entire set of isophotes is returned
          in an `~photutils.isophote.IsophoteList` instance.
  
          Parameters
          ----------
          sma0 : float, optional
              The starting value for the semimajor axis length (pixels).
              This value must not be the minimum or maximum semimajor axis
              length, but something in between. The algorithm can't start
              from the very center of the galaxy image because the
              modelling of elliptical isophotes on that region is poor and
              it will diverge very easily if not tied to other previously
              fit isophotes. It can't start from the maximum value either
              because the maximum is not known beforehand, depending on
              signal-to-noise. The ``sma0`` value should be selected such
              that the corresponding isophote has a good signal-to-noise
              ratio and a clearly defined geometry. If set to `None` (the
              default), one of two actions will be taken:  if a
              `~photutils.isophote.EllipseGeometry` instance was input to
              the `~photutils.isophote.Ellipse` constructor, its ``sma``
              value will be used.  Otherwise, a default value of 10. will
              be used.
          minsma : float, optional
              The minimum value for the semimajor axis length (pixels).
              The default is 0.
          maxsma : float or `None`, optional
              The maximum value for the semimajor axis length (pixels).
              When set to `None` (default), the algorithm will increase
              the semimajor axis until one of several conditions will
              cause it to stop and revert to fit ellipses with sma <
              ``sma0``.
          step : float, optional
              The step value used to grow/shrink the semimajor axis length
              (pixels if ``linear=True``, or a relative value if
              ``linear=False``). See the ``linear`` parameter.  The
              default is 0.1.
          conver : float, optional
              The main convergence criterion. Iterations stop when the
              largest harmonic amplitude becomes smaller (in absolute
              value) than ``conver`` times the harmonic fit rms.  The
              default is 0.05.
          minit : int, optional
              The minimum number of iterations to perform. A minimum of 10
              (the default) iterations guarantees that, on average, 2
              iterations will be available for fitting each independent
              parameter (the four harmonic amplitudes and the intensity
              level). For the first isophote, the minimum number of
              iterations is 2 * ``minit`` to ensure that, even departing
              from not-so-good initial values, the algorithm has a better
              chance to converge to a sensible solution.
          maxit : int, optional
              The maximum number of iterations to perform.  The default is
              50.
          fflag : float, optional
              The acceptable fraction of flagged data points in the
              sample.  If the actual fraction of valid data points is
              smaller than this, the iterations will stop and the current
              `~photutils.isophote.Isophote` will be returned.  Flagged
              data points are points that either lie outside the image
              frame, are masked, or were rejected by sigma-clipping.  The
              default is 0.7.
          maxgerr : float, optional
              The maximum acceptable relative error in the local radial
              intensity gradient. This is the main control for preventing
              ellipses to grow to regions of too low signal-to-noise
              ratio.  It specifies the maximum acceptable relative error
              in the local radial intensity gradient.  `Busko (1996; ASPC
              101, 139)
              <http://adsabs.harvard.edu/abs/1996ASPC..101..139B>`_ showed
              that the fitting precision relates to that relative error.
              The usual behavior of the gradient relative error is to
              increase with semimajor axis, being larger in outer, fainter
              regions of a galaxy image.  In the current implementation,
              the ``maxgerr`` criterion is triggered only when two
              consecutive isophotes exceed the value specified by the
              parameter. This prevents premature stopping caused by
              contamination such as stars and HII regions.
  
              A number of actions may happen when the gradient error
              exceeds ``maxgerr`` (or becomes non-significant and is set
              to `None`).  If the maximum semimajor axis specified by
              ``maxsma`` is set to `None`, semimajor axis growth is
              stopped and the algorithm proceeds inwards to the galaxy
              center. If ``maxsma`` is set to some finite value, and this
              value is larger than the current semimajor axis length, the
              algorithm enters non-iterative mode and proceeds outwards
              until reaching ``maxsma``.  The default is 0.5.
          sclip : float, optional
              The sigma-clip sigma value.  The default is 3.0.
          nclip : int, optional
              The number of sigma-clip interations.  The default is 0,
              which means sigma-clipping is skipped.
          integrmode : {'bilinear', 'nearest_neighbor', 'mean', 'median'}, optional
              The area integration mode.  The default is 'bilinear'.
          linear : bool, optional
              The semimajor axis growing/shrinking mode. If `False`
              (default), the geometric growing mode is chosen, thus the
              semimajor axis length is increased by a factor of (1. +
              ``step``), and the process is repeated until either the
              semimajor axis value reaches the value of parameter
              ``maxsma``, or the last fitted ellipse has more than a given
              fraction of its sampled points flagged out (see ``fflag``).
              The process then resumes from the first fitted ellipse (at
              ``sma0``) inwards, in steps of (1./(1. + ``step``)), until
              the semimajor axis length reaches the value ``minsma``. In
              case of linear growing, the increment or decrement value is
              given directly by ``step`` in pixels.  If ``maxsma`` is set
              to `None`, the semimajor axis will grow until a low
              signal-to-noise criterion is met. See ``maxgerr``.
          maxrit : float or `None`, optional
              The maximum value of semimajor axis to perform an actual
              fit.  Whenever the current semimajor axis length is larger
              than ``maxrit``, the isophotes will be extracted using the
              current geometry, without being fitted.  This non-iterative
              mode may be useful for sampling regions of very low surface
              brightness, where the algorithm may become unstable and
              unable to recover reliable geometry information.
              Non-iterative mode can also be entered automatically
              whenever the ellipticity exceeds 1.0 or the ellipse center
              crosses the image boundaries.  If `None` (default), then no
              maximum value is used.
  
          Returns
          -------
          result : `~photutils.isophote.IsophoteList` instance
              A list-like object of `~photutils.isophote.Isophote`
              instances, sorted by increasing semimajor axis length.
          """; 74, assignment; 75, not_operator; 76, block; 77, else_clause; 78, assignment; 79, assignment; 80, True; 81, comment:# first isophote runs longer; 82, block; 83, assignment; 84, assignment; 85, True; 86, block; 87, comparison_operator:minsma == 0.0; 88, block; 89, call; 90, call; 91, identifier:isophote_list; 92, list; 93, identifier:sma0; 94, if_statement; 95, block; 96, identifier:noiter; 97, False; 98, identifier:first_isophote; 99, True; 100, expression_statement; 101, expression_statement; 102, expression_statement; 103, comment:# check for failed fit.; 104, if_statement; 105, comment:# reset variable from the actual list, since the last; 106, comment:# `isophote` instance may no longer be OK.; 107, expression_statement; 108, comment:# update sma. If exceeded user-defined; 109, comment:# maximum, bail out from this loop.; 110, expression_statement; 111, if_statement; 112, identifier:first_isophote; 113, subscript; 114, pattern_list; 115, call; 116, expression_statement; 117, comment:# if abnormal condition, fix isophote but keep going.; 118, if_statement; 119, comment:# reset variable from the actual list, since the last; 120, comment:# `isophote` instance may no longer be OK.; 121, expression_statement; 122, comment:# figure out next sma; if exceeded user-defined; 123, comment:# minimum, or too small, bail out from this loop; 124, expression_statement; 125, if_statement; 126, identifier:minsma; 127, float:0.0; 128, expression_statement; 129, attribute; 130, argument_list; 131, identifier:IsophoteList; 132, argument_list; 133, attribute; 134, block; 135, else_clause; 136, expression_statement; 137, assignment; 138, assignment; 139, assignment; 140, parenthesized_expression; 141, comment:# in case the fit failed right at the outset, return an; 142, comment:# empty list. This is the usual case when the user; 143, comment:# provides initial guesses that are too way off to enable; 144, comment:# the fitting algorithm to find any meaningful solution.; 145, block; 146, assignment; 147, assignment; 148, boolean_operator; 149, block; 150, identifier:isophote_list; 151, integer:0; 152, identifier:sma; 153, identifier:step; 154, attribute; 155, argument_list; 156, assignment; 157, comparison_operator:isophote.stop_code < 0; 158, block; 159, assignment; 160, assignment; 161, comparison_operator:sma <= max(minsma, 0.5); 162, block; 163, assignment; 164, identifier:isophote_list; 165, identifier:sort; 166, identifier:isophote_list; 167, identifier:self; 168, identifier:_geometry; 169, expression_statement; 170, block; 171, assignment; 172, identifier:minit_a; 173, conditional_expression:2 * minit if first_isophote else minit; 174, identifier:first_isophote; 175, False; 176, identifier:isophote; 177, call; 178, boolean_operator; 179, if_statement; 180, expression_statement; 181, comment:# get last isophote from the actual list, since the last; 182, comment:# `isophote` instance in this context may no longer be OK.; 183, expression_statement; 184, comment:# if two consecutive isophotes failed to fit,; 185, comment:# shut off iterative mode. Or, bail out and; 186, comment:# change to go inwards.; 187, if_statement; 188, identifier:isophote; 189, subscript; 190, identifier:sma; 191, call; 192, identifier:maxsma; 193, comparison_operator:sma >= maxsma; 194, break_statement; 195, attribute; 196, identifier:reset_sma; 197, identifier:step; 198, identifier:isophote; 199, call; 200, attribute; 201, integer:0; 202, expression_statement; 203, identifier:isophote; 204, subscript; 205, identifier:sma; 206, call; 207, identifier:sma; 208, call; 209, break_statement; 210, identifier:isophote; 211, call; 212, assignment; 213, expression_statement; 214, identifier:sma; 215, identifier:sma0; 216, binary_operator:2 * minit; 217, identifier:first_isophote; 218, identifier:minit; 219, attribute; 220, argument_list; 221, comparison_operator:isophote.stop_code < 0; 222, comparison_operator:isophote.stop_code == 1; 223, comparison_operator:len(isophote_list) == 1; 224, block; 225, call; 226, assignment; 227, comparison_operator:len(isophote_list) > 2; 228, block; 229, identifier:isophote_list; 230, unary_operator; 231, attribute; 232, argument_list; 233, identifier:sma; 234, identifier:maxsma; 235, attribute; 236, identifier:geometry; 237, attribute; 238, argument_list; 239, identifier:isophote; 240, identifier:stop_code; 241, call; 242, identifier:isophote_list; 243, unary_operator; 244, attribute; 245, argument_list; 246, identifier:max; 247, argument_list; 248, attribute; 249, argument_list; 250, identifier:sma; 251, attribute; 252, assignment; 253, integer:2; 254, identifier:minit; 255, identifier:self; 256, identifier:fit_isophote; 257, identifier:sma; 258, identifier:step; 259, identifier:conver; 260, identifier:minit_a; 261, identifier:maxit; 262, identifier:fflag; 263, identifier:maxgerr; 264, identifier:sclip; 265, identifier:nclip; 266, identifier:integrmode; 267, identifier:linear; 268, identifier:maxrit; 269, keyword_argument; 270, keyword_argument; 271, attribute; 272, integer:0; 273, attribute; 274, integer:1; 275, call; 276, integer:1; 277, expression_statement; 278, return_statement; 279, attribute; 280, argument_list; 281, identifier:isophote; 282, subscript; 283, call; 284, integer:2; 285, if_statement; 286, integer:1; 287, attribute; 288, identifier:update_sma; 289, identifier:step; 290, identifier:first_isophote; 291, identifier:sample; 292, identifier:self; 293, identifier:fit_isophote; 294, identifier:sma; 295, identifier:step; 296, identifier:conver; 297, identifier:minit; 298, identifier:maxit; 299, identifier:fflag; 300, identifier:maxgerr; 301, identifier:sclip; 302, identifier:nclip; 303, identifier:integrmode; 304, identifier:linear; 305, identifier:maxrit; 306, keyword_argument; 307, keyword_argument; 308, attribute; 309, argument_list; 310, integer:1; 311, attribute; 312, identifier:update_sma; 313, identifier:step; 314, identifier:minsma; 315, float:0.5; 316, identifier:self; 317, identifier:fit_isophote; 318, float:0.0; 319, keyword_argument; 320, attribute; 321, identifier:sma; 322, identifier:sma; 323, float:10.; 324, identifier:noniterate; 325, identifier:noiter; 326, identifier:isophote_list; 327, identifier:isophote_list; 328, identifier:isophote; 329, identifier:stop_code; 330, identifier:isophote; 331, identifier:stop_code; 332, identifier:len; 333, argument_list; 334, call; 335, call; 336, identifier:self; 337, identifier:_fix_last_isophote; 338, identifier:isophote_list; 339, unary_operator; 340, identifier:isophote_list; 341, unary_operator; 342, identifier:len; 343, argument_list; 344, parenthesized_expression; 345, block; 346, attribute; 347, identifier:geometry; 348, identifier:going_inwards; 349, True; 350, identifier:isophote_list; 351, identifier:isophote_list; 352, identifier:self; 353, identifier:_fix_last_isophote; 354, identifier:isophote_list; 355, integer:0; 356, attribute; 357, identifier:geometry; 358, identifier:isophote_list; 359, identifier:isophote_list; 360, identifier:self; 361, identifier:_geometry; 362, identifier:isophote_list; 363, attribute; 364, argument_list; 365, identifier:IsophoteList; 366, argument_list; 367, integer:1; 368, integer:1; 369, identifier:isophote_list; 370, boolean_operator; 371, if_statement; 372, identifier:isophote; 373, identifier:sample; 374, identifier:isophote; 375, identifier:sample; 376, identifier:warnings; 377, identifier:warn; 378, string; 379, identifier:AstropyUserWarning; 380, list; 381, parenthesized_expression; 382, comparison_operator:isophote.stop_code == 1; 383, boolean_operator; 384, comment:# if a maximum sma value was provided by; 385, comment:# user, and the current sma is smaller than; 386, comment:# maxsma, keep growing sma in non-iterative; 387, comment:# mode until reaching it.; 388, block; 389, else_clause; 390, string_content:No meaningful fit was possible.; 391, boolean_operator; 392, attribute; 393, integer:1; 394, identifier:maxsma; 395, comparison_operator:maxsma > isophote.sma; 396, expression_statement; 397, comment:# if no maximum sma, stop growing and change; 398, comment:# to go inwards.; 399, block; 400, comparison_operator:isophote.stop_code == 5; 401, comparison_operator:isophote_list[-2].stop_code == 5; 402, identifier:isophote; 403, identifier:stop_code; 404, identifier:maxsma; 405, attribute; 406, assignment; 407, break_statement; 408, attribute; 409, integer:5; 410, attribute; 411, integer:5; 412, identifier:isophote; 413, identifier:sma; 414, identifier:noiter; 415, True; 416, identifier:isophote; 417, identifier:stop_code; 418, subscript; 419, identifier:stop_code; 420, identifier:isophote_list; 421, unary_operator; 422, integer:2
code: def fit_image(self, sma0=None, minsma=0., maxsma=None, step=0.1,
                    conver=DEFAULT_CONVERGENCE, minit=DEFAULT_MINIT,
                    maxit=DEFAULT_MAXIT, fflag=DEFAULT_FFLAG,
                    maxgerr=DEFAULT_MAXGERR, sclip=3., nclip=0,
                    integrmode=BILINEAR, linear=False, maxrit=None):
          # This parameter list is quite large and should in principle be
          # simplified by re-distributing these controls to somewhere else.
          # We keep this design though because it better mimics the flat
          # architecture used in the original STSDAS task `ellipse`.
          """
          Fit multiple isophotes to the image array.
  
          This method loops over each value of the semimajor axis (sma)
          length (constructed from the input parameters), fitting a single
          isophote at each sma.  The entire set of isophotes is returned
          in an `~photutils.isophote.IsophoteList` instance.
  
          Parameters
          ----------
          sma0 : float, optional
              The starting value for the semimajor axis length (pixels).
              This value must not be the minimum or maximum semimajor axis
              length, but something in between. The algorithm can't start
              from the very center of the galaxy image because the
              modelling of elliptical isophotes on that region is poor and
              it will diverge very easily if not tied to other previously
              fit isophotes. It can't start from the maximum value either
              because the maximum is not known beforehand, depending on
              signal-to-noise. The ``sma0`` value should be selected such
              that the corresponding isophote has a good signal-to-noise
              ratio and a clearly defined geometry. If set to `None` (the
              default), one of two actions will be taken:  if a
              `~photutils.isophote.EllipseGeometry` instance was input to
              the `~photutils.isophote.Ellipse` constructor, its ``sma``
              value will be used.  Otherwise, a default value of 10. will
              be used.
          minsma : float, optional
              The minimum value for the semimajor axis length (pixels).
              The default is 0.
          maxsma : float or `None`, optional
              The maximum value for the semimajor axis length (pixels).
              When set to `None` (default), the algorithm will increase
              the semimajor axis until one of several conditions will
              cause it to stop and revert to fit ellipses with sma <
              ``sma0``.
          step : float, optional
              The step value used to grow/shrink the semimajor axis length
              (pixels if ``linear=True``, or a relative value if
              ``linear=False``). See the ``linear`` parameter.  The
              default is 0.1.
          conver : float, optional
              The main convergence criterion. Iterations stop when the
              largest harmonic amplitude becomes smaller (in absolute
              value) than ``conver`` times the harmonic fit rms.  The
              default is 0.05.
          minit : int, optional
              The minimum number of iterations to perform. A minimum of 10
              (the default) iterations guarantees that, on average, 2
              iterations will be available for fitting each independent
              parameter (the four harmonic amplitudes and the intensity
              level). For the first isophote, the minimum number of
              iterations is 2 * ``minit`` to ensure that, even departing
              from not-so-good initial values, the algorithm has a better
              chance to converge to a sensible solution.
          maxit : int, optional
              The maximum number of iterations to perform.  The default is
              50.
          fflag : float, optional
              The acceptable fraction of flagged data points in the
              sample.  If the actual fraction of valid data points is
              smaller than this, the iterations will stop and the current
              `~photutils.isophote.Isophote` will be returned.  Flagged
              data points are points that either lie outside the image
              frame, are masked, or were rejected by sigma-clipping.  The
              default is 0.7.
          maxgerr : float, optional
              The maximum acceptable relative error in the local radial
              intensity gradient. This is the main control for preventing
              ellipses to grow to regions of too low signal-to-noise
              ratio.  It specifies the maximum acceptable relative error
              in the local radial intensity gradient.  `Busko (1996; ASPC
              101, 139)
              <http://adsabs.harvard.edu/abs/1996ASPC..101..139B>`_ showed
              that the fitting precision relates to that relative error.
              The usual behavior of the gradient relative error is to
              increase with semimajor axis, being larger in outer, fainter
              regions of a galaxy image.  In the current implementation,
              the ``maxgerr`` criterion is triggered only when two
              consecutive isophotes exceed the value specified by the
              parameter. This prevents premature stopping caused by
              contamination such as stars and HII regions.
  
              A number of actions may happen when the gradient error
              exceeds ``maxgerr`` (or becomes non-significant and is set
              to `None`).  If the maximum semimajor axis specified by
              ``maxsma`` is set to `None`, semimajor axis growth is
              stopped and the algorithm proceeds inwards to the galaxy
              center. If ``maxsma`` is set to some finite value, and this
              value is larger than the current semimajor axis length, the
              algorithm enters non-iterative mode and proceeds outwards
              until reaching ``maxsma``.  The default is 0.5.
          sclip : float, optional
              The sigma-clip sigma value.  The default is 3.0.
          nclip : int, optional
              The number of sigma-clip interations.  The default is 0,
              which means sigma-clipping is skipped.
          integrmode : {'bilinear', 'nearest_neighbor', 'mean', 'median'}, optional
              The area integration mode.  The default is 'bilinear'.
          linear : bool, optional
              The semimajor axis growing/shrinking mode. If `False`
              (default), the geometric growing mode is chosen, thus the
              semimajor axis length is increased by a factor of (1. +
              ``step``), and the process is repeated until either the
              semimajor axis value reaches the value of parameter
              ``maxsma``, or the last fitted ellipse has more than a given
              fraction of its sampled points flagged out (see ``fflag``).
              The process then resumes from the first fitted ellipse (at
              ``sma0``) inwards, in steps of (1./(1. + ``step``)), until
              the semimajor axis length reaches the value ``minsma``. In
              case of linear growing, the increment or decrement value is
              given directly by ``step`` in pixels.  If ``maxsma`` is set
              to `None`, the semimajor axis will grow until a low
              signal-to-noise criterion is met. See ``maxgerr``.
          maxrit : float or `None`, optional
              The maximum value of semimajor axis to perform an actual
              fit.  Whenever the current semimajor axis length is larger
              than ``maxrit``, the isophotes will be extracted using the
              current geometry, without being fitted.  This non-iterative
              mode may be useful for sampling regions of very low surface
              brightness, where the algorithm may become unstable and
              unable to recover reliable geometry information.
              Non-iterative mode can also be entered automatically
              whenever the ellipticity exceeds 1.0 or the ellipse center
              crosses the image boundaries.  If `None` (default), then no
              maximum value is used.
  
          Returns
          -------
          result : `~photutils.isophote.IsophoteList` instance
              A list-like object of `~photutils.isophote.Isophote`
              instances, sorted by increasing semimajor axis length.
          """
  
          # multiple fitted isophotes will be stored here
          isophote_list = []
  
          # get starting sma from appropriate source: keyword parameter,
          # internal EllipseGeometry instance, or fixed default value.
          if not sma0:
              if self._geometry:
                  sma = self._geometry.sma
              else:
                  sma = 10.
          else:
              sma = sma0
  
          # first, go from initial sma outwards until
          # hitting one of several stopping criteria.
          noiter = False
          first_isophote = True
          while True:
              # first isophote runs longer
              minit_a = 2 * minit if first_isophote else minit
              first_isophote = False
  
              isophote = self.fit_isophote(sma, step, conver, minit_a, maxit,
                                           fflag, maxgerr, sclip, nclip,
                                           integrmode, linear, maxrit,
                                           noniterate=noiter,
                                           isophote_list=isophote_list)
  
              # check for failed fit.
              if (isophote.stop_code < 0 or isophote.stop_code == 1):
                  # in case the fit failed right at the outset, return an
                  # empty list. This is the usual case when the user
                  # provides initial guesses that are too way off to enable
                  # the fitting algorithm to find any meaningful solution.
  
                  if len(isophote_list) == 1:
                      warnings.warn('No meaningful fit was possible.',
                                    AstropyUserWarning)
                      return IsophoteList([])
  
                  self._fix_last_isophote(isophote_list, -1)
  
                  # get last isophote from the actual list, since the last
                  # `isophote` instance in this context may no longer be OK.
                  isophote = isophote_list[-1]
  
                  # if two consecutive isophotes failed to fit,
                  # shut off iterative mode. Or, bail out and
                  # change to go inwards.
                  if len(isophote_list) > 2:
                      if ((isophote.stop_code == 5 and
                           isophote_list[-2].stop_code == 5)
                              or isophote.stop_code == 1):
                          if maxsma and maxsma > isophote.sma:
                              # if a maximum sma value was provided by
                              # user, and the current sma is smaller than
                              # maxsma, keep growing sma in non-iterative
                              # mode until reaching it.
                              noiter = True
                          else:
                              # if no maximum sma, stop growing and change
                              # to go inwards.
                              break
  
              # reset variable from the actual list, since the last
              # `isophote` instance may no longer be OK.
              isophote = isophote_list[-1]
  
              # update sma. If exceeded user-defined
              # maximum, bail out from this loop.
              sma = isophote.sample.geometry.update_sma(step)
              if maxsma and sma >= maxsma:
                  break
  
          # reset sma so as to go inwards.
          first_isophote = isophote_list[0]
          sma, step = first_isophote.sample.geometry.reset_sma(step)
  
          # now, go from initial sma inwards towards center.
          while True:
              isophote = self.fit_isophote(sma, step, conver, minit, maxit,
                                           fflag, maxgerr, sclip, nclip,
                                           integrmode, linear, maxrit,
                                           going_inwards=True,
                                           isophote_list=isophote_list)
  
              # if abnormal condition, fix isophote but keep going.
              if isophote.stop_code < 0:
                  self._fix_last_isophote(isophote_list, 0)
  
              # reset variable from the actual list, since the last
              # `isophote` instance may no longer be OK.
              isophote = isophote_list[-1]
  
              # figure out next sma; if exceeded user-defined
              # minimum, or too small, bail out from this loop
              sma = isophote.sample.geometry.update_sma(step)
              if sma <= max(minsma, 0.5):
                  break
  
          # if user asked for minsma=0, extract special isophote there
          if minsma == 0.0:
              isophote = self.fit_isophote(0.0, isophote_list=isophote_list)
  
          # sort list of isophotes according to sma
          isophote_list.sort()
  
          return IsophoteList(isophote_list)