
    IR-e5                     0   d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZmZmZmZmZmZmZ 	 ddlZddlmZ ddlmZ n# e$ r  G d	 d
          ZY nw xY wg dZddgiZ G d de          Z	 	 	 	 	 	 	 	 	 	 	 	 ddZ ej        e          ZddZdS )zK
Normalization class for Matplotlib that can be used to produce
colorbars.
    N)ma   )AsymmetricPercentileIntervalBaseIntervalManualIntervalMinMaxIntervalPercentileInterval)AsinhStretchBaseStretchLinearStretch
LogStretchPowerStretchSinhStretchSqrtStretch)pyplot)	Normalizec                       e Zd Zd ZdS )r   c                      t          d          )Nz2matplotlib is required in order to use this class.)ImportError)selfargskwargss      Clib/python3.11/site-packages/astropy/visualization/mpl_normalize.py__init__zNormalize.__init__#   s    RSSS    N)__name__
__module____qualname__r    r   r   r   r   "   s(        	T 	T 	T 	T 	Tr   r   )ImageNormalizesimple_normimshow_norm*
matplotlibc                   X     e Zd ZdZdddd e            ddf fd	Zd Zd	dZd
dZ xZ	S )r    a  
    Normalization class to be used with Matplotlib.

    Parameters
    ----------
    data : ndarray, optional
        The image array.  This input is used only if ``interval`` is
        also input.  ``data`` and ``interval`` are used to compute the
        vmin and/or vmax values only if ``vmin`` or ``vmax`` are not
        input.
    interval : `~astropy.visualization.BaseInterval` subclass instance, optional
        The interval object to apply to the input ``data`` to determine
        the ``vmin`` and ``vmax`` values.  This input is used only if
        ``data`` is also input.  ``data`` and ``interval`` are used to
        compute the vmin and/or vmax values only if ``vmin`` or ``vmax``
        are not input.
    vmin, vmax : float, optional
        The minimum and maximum levels to show for the data.  The
        ``vmin`` and ``vmax`` inputs override any calculated values from
        the ``interval`` and ``data`` inputs.
    stretch : `~astropy.visualization.BaseStretch` subclass instance
        The stretch object to apply to the data.  The default is
        `~astropy.visualization.LinearStretch`.
    clip : bool, optional
        If `True`, data values outside the [0:1] range are clipped to
        the [0:1] range.
    invalid : None or float, optional
        Value to assign NaN values generated by this class.  NaNs in the
        input ``data`` array are not changed.  For matplotlib
        normalization, the ``invalid`` value should map to the
        matplotlib colormap "under" value (i.e., any finite value < 0).
        If `None`, then NaN values are not replaced.  This keyword has
        no effect if ``clip=True``.
    NF      c                    t                                          |||           || _        || _        |t	          d          t          |t                    st          d          || _        |$t          |t                    st          d          || _
        |j        | _        || _        || _        ||                     |           d S d S )N)vminvmaxclipzstretch must be inputz5stretch must be an instance of a BaseStretch subclassz7interval must be an instance of a BaseInterval subclass)superr   r(   r)   
ValueError
isinstancer   	TypeErrorstretchr   intervalinverseinverse_stretchr*   invalid_set_limits)	r   datar0   r(   r)   r/   r*   r3   	__class__s	           r   r   zImageNormalize.__init__P   s     	dD999		?4555';// 	USTTT
8\(J(JUVVV &	 T""""" r   c                    | j         	| j        d S | j        t| j         1t          j        |t          j        |                             | _         | j        3t          j        |t          j        |                             | _        d S d S | j                            |          \  }}| j         || _         | j        	|| _        d S d S N)r(   r)   r0   npminisfinitemax
get_limits)r   r5   _vmin_vmaxs       r   r4   zImageNormalize._set_limitsr   s    9 TY%:F = y F4D(9(9#:;;	y F4D(9(9#:;;			 !   =33D99LE5y !	y !			 ! r   c                    || j         }|| j        }t          |t          j                  r'|rd}n|j        }|                    | j                  }nd}t          j	        |          rt          j
        |gt                    }nt          j
        |dt                    }|                     |           t          j        || j        |           t          j        || j        | j        z
  |           |rt          j         |dd|          }| j        j        r|                     ||d|	          }n|                     ||d
          }t          j
        ||          S )ar  
        Transform values using this normalization.

        Parameters
        ----------
        values : array-like
            The input values.
        clip : bool, optional
            If `True`, values outside the [0:1] range are clipped to the
            [0:1] range.  If `None` then the ``clip`` value from the
            `ImageNormalize` instance is used (the default of which is
            `False`).
        invalid : None or float, optional
            Value to assign NaN values generated by this class.  NaNs in
            the input ``data`` array are not changed.  For matplotlib
            normalization, the ``invalid`` value should map to the
            matplotlib colormap "under" value (i.e., any finite value <
            0).  If `None`, then the `ImageNormalize` instance value is
            used.  This keyword has no effect if ``clip=True``.
        NF)dtypeT)copyrA   )out              ?)rC   r*   r3   )rC   r*   )mask)r*   r3   r-   r   MaskedArrayrF   filledr)   r9   isscalararrayfloatr4   subtractr(   true_divider/   _supports_invalid_kw)r   valuesr*   r3   rF   s        r   __call__zImageNormalize.__call__   sp   * <9D?lGfbn-- 	 #{]]49--FFD ;v 	>Xvhe444FF Xf4u===F 	    	FDI62222
vty494&AAAA  	;WVS#6:::F <, 	B\\&f5'\RRFF\\&f5\AAF xT****r   c                     | j         j        r|                      |d|          }n|                      |d          }|| j        | j        z
  z  | j        z   S )NF)r*   r3   )r*   )r2   rN   r)   r(   )r   rO   r3   values_norms       r   r1   zImageNormalize.inverse   sb    4 	C..vE7.SSKK..vE.BBK di$)34ty@@r   )NNr8   )
r   r   r   __doc__r   r   r4   rP   r1   __classcell__)r6   s   @r   r    r    ,   s        ! !J  #  #  #  #  #  #D" " ""=+ =+ =+ =+~A A A A A A A Ar   r    linearrE   皙?F  r&   333333?c                     |t          |          }n<||t          |pd|pd          }n#||t          ||          }nt                      }|dk    rt	                      }n|dk    rt                      }nk|dk    rt          |          }nU|dk    rt          |
          }n?|dk    rt          |          }n)|d	k    rt          |          }nt          d
| d          |                    |           \  }}t          ||||	|          S )a  
    Return a Normalization class that can be used for displaying images
    with Matplotlib.

    This function enables only a subset of image stretching functions
    available in `~astropy.visualization.mpl_normalize.ImageNormalize`.

    This function is used by the
    ``astropy.visualization.scripts.fits2bitmap`` script.

    Parameters
    ----------
    data : ndarray
        The image array.

    stretch : {'linear', 'sqrt', 'power', log', 'asinh', 'sinh'}, optional
        The stretch function to apply to the image.  The default is
        'linear'.

    power : float, optional
        The power index for ``stretch='power'``.  The default is 1.0.

    asinh_a : float, optional
        For ``stretch='asinh'``, the value where the asinh curve
        transitions from linear to logarithmic behavior, expressed as a
        fraction of the normalized image.  Must be in the range between
        0 and 1.  The default is 0.1.

    min_cut : float, optional
        The pixel value of the minimum cut level.  Data values less than
        ``min_cut`` will set to ``min_cut`` before stretching the image.
        The default is the image minimum.  ``min_cut`` overrides
        ``min_percent``.

    max_cut : float, optional
        The pixel value of the maximum cut level.  Data values greater
        than ``min_cut`` will set to ``min_cut`` before stretching the
        image.  The default is the image maximum.  ``max_cut`` overrides
        ``max_percent``.

    min_percent : float, optional
        The percentile value used to determine the pixel value of
        minimum cut level.  The default is 0.0.  ``min_percent``
        overrides ``percent``.

    max_percent : float, optional
        The percentile value used to determine the pixel value of
        maximum cut level.  The default is 100.0.  ``max_percent``
        overrides ``percent``.

    percent : float, optional
        The percentage of the image values used to determine the pixel
        values of the minimum and maximum cut levels.  The lower cut
        level will set at the ``(100 - percent) / 2`` percentile, while
        the upper cut level will be set at the ``(100 + percent) / 2``
        percentile.  The default is 100.0.  ``percent`` is ignored if
        either ``min_percent`` or ``max_percent`` is input.

    clip : bool, optional
        If `True`, data values outside the [0:1] range are clipped to
        the [0:1] range.

    log_a : float, optional
        The log index for ``stretch='log'``. The default is 1000.

    invalid : None or float, optional
        Value to assign NaN values generated by the normalization.  NaNs
        in the input ``data`` array are not changed.  For matplotlib
        normalization, the ``invalid`` value should map to the
        matplotlib colormap "under" value (i.e., any finite value < 0).
        If `None`, then NaN values are not replaced.  This keyword has
        no effect if ``clip=True``.

    sinh_a : float, optional
        The scaling parameter for ``stretch='sinh'``. The default is
        0.3.

    Returns
    -------
    result : `ImageNormalize` instance
        An `ImageNormalize` instance that can be used for displaying
        images with Matplotlib.
    NrD   g      Y@rU   sqrtpowerlogasinhsinhzUnknown stretch: .)r(   r)   r/   r*   r3   )r	   r   r   r   r   r   r   r   r
   r   r,   r=   r    )r5   r/   r[   asinh_amin_cutmax_cutmin_percentmax_percentpercentr*   log_ar3   sinh_ar0   r(   r)   s                   r   r!   r!      sU   D %g..		 K$;/3 4u
 
 
	 3!'733!##(//	F		--	G		u%%	E		U##	G		w''	F		f%%7W777888$$T**JD$gD'   r   c                 B   d|v rt          d          d|v rt          d          t          |          }d| i}t          j        D ]}||v r|                    |          ||<   t          di ||d<   |t          j        | fi |}n |j        | fi |}||d         fS )a*  A convenience function to call matplotlib's `matplotlib.pyplot.imshow`
    function, using an `ImageNormalize` object as the normalization.

    Parameters
    ----------
    data : 2D or 3D array-like
        The data to show. Can be whatever `~matplotlib.pyplot.imshow` and
        `ImageNormalize` both accept. See `~matplotlib.pyplot.imshow`.
    ax : None or `~matplotlib.axes.Axes`, optional
        If None, use pyplot's imshow.  Otherwise, calls ``imshow`` method of
        the supplied axes.
    **kwargs : dict, optional
        All other keyword arguments are parsed first by the
        `ImageNormalize` initializer, then to
        `~matplotlib.pyplot.imshow`.

    Returns
    -------
    result : tuple
        A tuple containing the `~matplotlib.image.AxesImage` generated
        by `~matplotlib.pyplot.imshow` as well as the `ImageNormalize`
        instance.

    Notes
    -----
    The ``norm`` matplotlib keyword is not supported.

    Examples
    --------
    .. plot::
        :include-source:

        import numpy as np
        import matplotlib.pyplot as plt
        from astropy.visualization import (imshow_norm, MinMaxInterval,
                                           SqrtStretch)

        # Generate and display a test image
        image = np.arange(65536).reshape((256, 256))
        fig = plt.figure()
        ax = fig.add_subplot(1, 1, 1)
        im, norm = imshow_norm(image, ax, origin='lower',
                               interval=MinMaxInterval(),
                               stretch=SqrtStretch())
        fig.colorbar(im)
    Xz#Cannot give both ``X`` and ``data``normzoThere is no point in using imshow_norm if you give the ``norm`` keyword - use imshow directly if you want that.r5   Nr   )r,   dict	_norm_sig
parameterspopr    pltimshow)r5   axr   imshow_kwargsnorm_kwargspnameimshow_results          r   r"   r"   T  s    ^ f}}>???
 
 	
 LLM4.K% : :F??!.!2!25!9!9K*99[99M&	z
499=99!	$88-88-///r   )rU   rE   rV   NNNNNFrW   r&   rX   r8   ) rS   inspectnumpyr9   r   r0   r   r   r   r   r	   r/   r
   r   r   r   r   r   r   r$   r   ro   matplotlib.colorsr   r   __all____doctest_requires__r    r!   	signaturerl   r"   r   r   r   <module>r|      s8   
                                         T((((((+++++++ T T TT T T T T T T T T TT ;
:
:l^, ^A ^A ^A ^A ^AY ^A ^A ^AF 
	
@ @ @ @H Gn--	G0 G0 G0 G0 G0 G0s   A AA