
    NcgD\                         d dl mZ d dlmZ ddlmZmZmZ ddl	m
Z
mZmZ d dlZd dlZd dlZd dlmZ 	 d dlZdZg Zdd	Zd
 Zdddi dddddddddddddddddddddfdej4                  fdZy# e$ r dZY =w xY w)    N)ColorscaleValidator   )apply_default_cascadeinit_figureconfigure_animation_controls)rescale_intensity_integer_ranges_integer_types)image_array_to_data_uriTFc                 "   |dk(  rdnd}| | S t        j                  |       r
| gdz  |gz   S t        |       dk(  rt        |       dz  |gz   S t        |       dk(  rt        |       |gz   S t        |       dk(  r| S t	        dt        |       z        )Nmax   r      r      z\zmax can be a scalar, or an iterable of length 1, 3 or 4. A value of %s was passed for zmax.)npisscalarlenlist
ValueErrorstr)zmodealphas      Q/var/www/html/bid-api/venv/lib/python3.12/site-packages/plotly/express/_imshow.py_vectorize_zvaluer      s    5=CaEy	QsQw%  	Q1Aw{eW$$	Q1Aw%  	Q1136q6:
 	
    c                     | j                   j                  }d}|t        v rt        |   d   S | t	        j
                  |          j                         }|d|z  k  ry|d|z  k  ry|d|z  k  ryy)Ng?r   r   i  l        )dtypetyper
   r	   r   isfiniter   )imgdtrtolim_maxs       r   _infer_zmax_from_typer%   '   sx    	BD	^r"1%%R[[%&**,QXsTz!ut|#r   autor   pngreturnc                    t               }t        |       |j                         }d}|gt        |t              r| j
                  j                  |      }| j                  |   }t        |      }|	t        |	      n|}||z  r||z  dz   n||z  }nd}d}|Et        |t              r| j
                  j                  |      }| j                  |   }t        |      } |du|duz   }!d}"d}#d}$t        rTt        | t        j                        r9t        | j
                        }%d}$g }&|F| j                  | j
                  |      j                  }|&j!                  |       | j
                  |   }"|F| j                  | j
                  |      j                  } |&j!                  |       | j
                  |   }#t#        |&d      D ]  }'|%j%                  |'      }( |%d   |%d   }*})|*|)fD ]m  }+t'        j(                  | j                  |+   j*                  t&        j,                        s?| j                  |+   j/                  t              | j                  |+<   o || j                  |*   j                  }|| j                  |)   j                  }|d}|j1                  dd      |*|d<   |j1                  d	d      |)|d	<   |j1                  d
d      |#|d
<   |j1                  dd      |"|d<   |j1                  dd      yt        j2                  j4                  j7                  |       |d<   |d   j9                  dd      |d<   n3t;        | d      rit;        | j<                  d      rS|| j<                  }|j1                  dd      3t;        | j<                  d      r| j<                  j>                  xs d|d<   t;        | d      rit;        | j                  d      rS|| j                  }|j1                  d	d      3t;        | j                  d      r| j                  j>                  xs d|d	<   |j1                  dd      d|d<   |j1                  d	d      d|d	<   |j1                  dd      d|d<   |d}t        | t@        jB                        r|rtE        d      d},nd},t'        jF                  |       } |%t'        jH                  | |d      } |
||k  r|dz  }d}|4t'        jH                  | |d      } d}|j1                  d
      d
n|d
   |d
<   d}-||-t              fz  }-||-t        |      fz  }-|| jJ                  d|!z   k\  xr |, }| j*                  tL        k(  r"d| j/                  t&        jN                        z  } |
|d   }|d   }|| jJ                  d|!z   k(  rdnd}|dk(  r-||r|| jQ                         }||rC|A| jS                         }n0|(| j*                  t&        jN                  k7  rtU        |       }||d}| jJ                  d|!z   k(  rJ|sG|!}.|&| j                  |.   tW        |      k7  rtE        d      |!dz   }/|&| j                  |/   tW        |      k7  rtE        d      d}0|du rd}0n|durd|z   d z   }0tY        t[        j\                  |-       D 12cg c],  \  }1}2t_        j`                  ||| |2   d!t	        |1      |0"      . }3}1}2|d#k(  rdnd$}4tc        tc        |4%      &      }5|dk(  rtc        d	d'(      |5d)<   d'|5d*   d+<   te        d,d-      }6tc        |6jg                  |d.         |||/      |5d!<   |d   rtc        |d   0      |5d!   d1<   n| jJ                  dk\  r| j                  d2   d3v s|!r|s| jJ                  dk(  r|rd}7||ti        |d45      ti        |d65      }}d7\  }8}9}:};d8}<|et'        jF                  |      }t'        j(                  |j*                  t&        jj                        r|d   }8|d   |d   z
  }:n|$r|<nd9}=tE        |=      |et'        jF                  |      }t'        j(                  |j*                  t&        jj                        r|d   }9|d   |d   z
  };n|$r|<nd:}=tE        |=      |r||| }>d}7n| jJ                  d|!z   k(  r%tm        | |d   |d   ft&        jN                  ;      }>nbt'        jn                  t        | j                  d2         D ?cg c]+  }?tm        | d<|?f   ||?   ||?   ft&        jN                  ;      - c}?d2=      }>t[        j\                  |- D 2cg c]  }2tq        |>|2   |||>       }@}2tY        |@      D 1Acg c])  \  }1}At_        jr                  |At	        |1      |8|9|:|;?      + }3}1}AnS| j                  d2   dk(  rd@ndA}Bt[        j\                  |- D 2cg c]"  }2t_        jr                  | |2   ||B|8|9|:|;B      $ }3}2i }5|d#k(  s|;|;dk  rtc        d%      |5d*<   |:6|:dk  r1tc        d$%      |5d)<   n!tE        dCt	        | j                        z        g }C|,|j1                  d      dn|d   }DD 1cg c]	  }1D dD|1  }C}1tu        |dEg ||Cg       }EdFD ]  }F||F   s	|F   |5|F<    |dG   r	|dG   |5dH<   n*|dI   jv                  jx                  jz                  dJdKi|5dL<   g }GtY        |3      D ]5  \  }'}H|r|'||z  k  s|'dk(  sEj}                  H||'|z  z
  |'|z  dz   M       7 |Ot        t                     D ]7  \  }1}'Gj!                  tc        |3||1z  ||1dz   z   |5t	        |'      N             9 |rGE_@        Ej                  |5       |r17r/t'        j                  | >k(        s|d   xs ddO|d	   xs d	dP}InfHdQ   dRk(  rd}Jn8| jJ                  dk(  rdS}Jn&| jJ                  dk(  r| j                  d2   dk(  rdT}Jnd}J|d   xs ddO|d	   xs d	dU|d   xs ddVJdW}IEj                  IX       |d   rEj                  |d   dY       |d	   rEj                  |d	   dZ       t        |t^        jr                  E       |Ej                  |dI   d[       |ES c c}2}1w c c}?w c c}2w c c}A}1w c c}2w c c}1w )\al  
    Display an image, i.e. data on a 2D regular raster.

    Parameters
    ----------

    img: array-like image, or xarray
        The image data. Supported array shapes are

        - (M, N): an image with scalar data. The data is visualized
          using a colormap.
        - (M, N, 3): an image with RGB values.
        - (M, N, 4): an image with RGBA values, i.e. including transparency.

    zmin, zmax : scalar or iterable, optional
        zmin and zmax define the scalar range that the colormap covers. By default,
        zmin and zmax correspond to the min and max values of the datatype for integer
        datatypes (ie [0-255] for uint8 images, [0, 65535] for uint16 images, etc.). For
        a multichannel image of floats, the max of the image is computed and zmax is the
        smallest power of 256 (1, 255, 65535) greater than this max value,
        with a 5% tolerance. For a single-channel image, the max of the image is used.
        Overridden by range_color.

    origin : str, 'upper' or 'lower' (default 'upper')
        position of the [0, 0] pixel of the image array, in the upper left or lower left
        corner. The convention 'upper' is typically used for matrices and images.

    labels : dict with str keys and str values (default `{}`)
        Sets names used in the figure for axis titles (keys ``x`` and ``y``),
        colorbar title and hoverlabel (key ``color``). The values should correspond
        to the desired label to be displayed. If ``img`` is an xarray, dimension
        names are used for axis titles, and long name for the colorbar title
        (unless overridden in ``labels``). Possible keys are: x, y, and color.

    x, y: list-like, optional
        x and y are used to label the axes of single-channel heatmap visualizations and
        their lengths must match the lengths of the second and first dimensions of the
        img argument. They are auto-populated if the input is an xarray.

    animation_frame: int or str, optional (default None)
        axis number along which the image array is sliced to create an animation plot.
        If `img` is an xarray, `animation_frame` can be the name of one the dimensions.

    facet_col: int or str, optional (default None)
        axis number along which the image array is sliced to create a facetted plot.
        If `img` is an xarray, `facet_col` can be the name of one the dimensions.

    facet_col_wrap: int
        Maximum number of facet columns. Wraps the column variable at this width,
        so that the column facets span multiple rows.
        Ignored if `facet_col` is None.

    facet_col_spacing: float between 0 and 1
        Spacing between facet columns, in paper units. Default is 0.02.

    facet_row_spacing: float between 0 and 1
        Spacing between facet rows created when ``facet_col_wrap`` is used, in
        paper units. Default is 0.0.7.

    color_continuous_scale : str or list of str
        colormap used to map scalar data to colors (for a 2D image). This parameter is
        not used for RGB or RGBA images. If a string is provided, it should be the name
        of a known color scale, and if a list is provided, it should be a list of CSS-
        compatible colors.

    color_continuous_midpoint : number
        If set, computes the bounds of the continuous color scale to have the desired
        midpoint. Overridden by range_color or zmin and zmax.

    range_color : list of two numbers
        If provided, overrides auto-scaling on the continuous color scale, including
        overriding `color_continuous_midpoint`. Also overrides zmin and zmax. Used only
        for single-channel images.

    title : str
        The figure title.

    template : str or dict or plotly.graph_objects.layout.Template instance
        The figure template name or definition.

    width : number
        The figure width in pixels.

    height: number
        The figure height in pixels.

    aspect: 'equal', 'auto', or None
      - 'equal': Ensures an aspect ratio of 1 or pixels (square pixels)
      - 'auto': The axes is kept fixed and the aspect ratio of pixels is
        adjusted so that the data fit in the axes. In general, this will
        result in non-square pixels.
      - if None, 'equal' is used for numpy arrays and 'auto' for xarrays
        (which have typically heterogeneous coordinates)

    contrast_rescaling: 'minmax', 'infer', or None
        how to determine data values corresponding to the bounds of the color
        range, when zmin or zmax are not passed. If `minmax`, the min and max
        values of the image are used. If `infer`, a heuristic based on the image
        data type is used.

    binary_string: bool, default None
        if True, the image data are first rescaled and encoded as uint8 and
        then passed to plotly.js as a b64 PNG string. If False, data are passed
        unchanged as a numerical array. Setting to True may lead to performance
        gains, at the cost of a loss of precision depending on the original data
        type. If None, use_binary_string is set to True for multichannel (eg) RGB
        arrays, and to False for single-channel (2D) arrays. 2D arrays are
        represented as grayscale and with no colorbar if use_binary_string is
        True.

    binary_backend: str, 'auto' (default), 'pil' or 'pypng'
        Third-party package for the transformation of numpy arrays to
        png b64 strings. If 'auto', Pillow is used if installed,  otherwise
        pypng.

    binary_compression_level: int, between 0 and 9 (default 4)
        png compression level to be passed to the backend when transforming an
        array to a png b64 string. Increasing `binary_compression` decreases the
        size of the png string, but the compression step takes more time. For most
        images it is not worth using levels greater than 5, but it's possible to
        test `len(fig.data[0].source)` and to time the execution of `imshow` to
        tune the level of compression. 0 means no compression (not recommended).

    binary_format: str, 'png' (default) or 'jpg'
        compression format used to generate b64 string. 'png' is recommended
        since it uses lossless compression, but 'jpg' (lossy) compression can
        result if smaller binary strings for natural images.

    text_auto: bool or str (default `False`)
        If `True` or a string, single-channel `img` values will be displayed as text.
        A string like `'.2f'` will be interpreted as a `texttemplate` numeric formatting directive.

    Returns
    -------
    fig : graph_objects.Figure containing the displayed image

    See also
    --------

    plotly.graph_objects.Image : image trace
    plotly.graph_objects.Heatmap : heatmap trace

    Notes
    -----

    In order to update and customize the returned figure, use
    `go.Figure.update_traces` or `go.Figure.update_layout`.

    If an xarray is passed, dimensions names and coordinates are used for
    axes labels and ticks.
    r   NFT)reverser   r&   xyanimation_frame	facet_colcolor
z<br>columns__len__name indexequalz0Binary strings cannot be used with pandas arrays r   r      minmaxinferzZThe length of the y vector must match the length of the first dimension of the img matrix.z[The length of the x vector must match the length of the second dimension of the img matrix.z%{z}z%{z:}
coloraxis1)r+   r,   r   	coloraxisr3   texttemplatelowerreversed)	autorange)yaxisdomain)scaleanchor	constrainxaxisrB   rE   
colorscaleimshowcolor_continuous_scale)rG   cmidcmincmax)
title_textcolorbar)r   r   min)r   r   )NNNNzNon-numerical coordinates were passed with xarray `img`, but the Image trace cannot handle it. Please use `binary_string=False` for 2D data or pass instead the numpy array `img.values` to `px.imshow`.zUOnly numerical values are accepted for the `x` parameter when an Image trace is used.zUOnly numerical values are accepted for the `y` parameter when an Image trace is used.)in_range	out_range.)axis)backendcompressionext)sourcer3   x0y0dxdyrgbrgba256)r   zminzmax
colormodelrX   rY   rZ   r[   zpx.imshow only accepts 2D single-channel, RGB or RGBA images. An image of shape %s was provided. Alternatively, 3- or 4-D single or multichannel datasets can be visualized using the `facet_col` or/and `animation_frame` arguments.=xy)heightwidthtitlerM   templatet<   margin)rowcol)datalayoutr3   z
: %{x}<br>z: %{y}<extra></extra>r   heatmapz%{z[0]}z[%{z[0]}, %{z[1]}, %{z[2]}]z
: %{y}<br>z: z<extra></extra>)hovertemplate)rM   rj   )rM   rk   )rf   	overwrite)Glocalsr   copy
isinstancer   dimsr5   shaperangeintxarray_importedxarray	DataArrayr   coordsvaluesappendsortedpopr   
issubdtyper   
datetime64astypegetplotutilslabel_from_attrsreplacehasattrr1   r3   pd	DataFramer   
asanyarraymoveaxisndimbooluint8r   rP   r%   r   	enumerate	itertoolsproductgoHeatmapdictr   validate_coercer   numberr   stackr   Imager   rm   ri   rg   	add_tracezipframesupdate_layoutallupdate_tracesupdate_xaxesupdate_yaxesr   )Kr!   r^   r_   originlabelsr+   r,   r-   r.   facet_col_wrapfacet_col_spacingfacet_row_spacingrI   color_continuous_midpointrange_colorre   rf   rd   rc   aspectcontrast_rescalingbinary_stringbinary_backendbinary_compression_levelbinary_format	text_autoargsnslices_facetfacet_slicesncolsnrowsnslices_animationanimation_slicesslice_dimensionsfacet_labelanimation_labelimg_is_xarrayrt   pop_indexesr5   _y_labelx_labelaxis_dataframe	iterablesy_indexx_indexr>   i	index_tuptracesrA   rm   colorscale_validatorrescale_imagerX   rY   rZ   r[   error_msg_xarray	error_msgimg_rescaledchimg_strimg_str_slicer`   
col_labelsslice_labelfig	attr_name
frame_listtracero   
hover_namesK                                                                              r   rH   rH   8   s   f 8D$[[]FMi%y1I		),]+'5'AN#} u$ U"Q&%' 	 "os+!hhnn_=OIIo6 !23!-t# KOM:c6+;+;<CHH~ ::chhy&9:AALy)((9-K&"zz#((?*CDKK/!hh7OK6EA 77DGG$B}}SZZ^112==A!$B!6!6s!;

2 % 9

7#**A9

7#**A>F::c4 (!F3K::c4 (!F3K::'.6(7F$%::k4(0"-F;::gt$,$kk//@@EF7O$Wo55dFCF7O3	"ws{{I'FyKKzz#t$,f1M!kk..4"s3 WSYY	%ByIIzz#t$,F1K!iinn2s::c4 (F3K::c4 (F3K::gt$, F7O>F #r||$OPP --
Ckk#y!,&?Y+Fq O	"kk#2 zz+,4 )* 	
 I"e-.00	eM*,,	 Q)9%9:O<?O yyDCJJrxx((1~1~ !),a:J6J)KXQX X%4<779D4<779D <CII1(-D<D,D xx1'''"=SYYw/3q691  #Q&=SYYw/3q691 
 !Le#!I-3L !*)*;*;Y*G H

 !I9 JJi.&V) !I 	 

 #g-D:	D956W"shGF7O+3F7OK(2<J#+;;-. + 
| '?/3vg/OF< , 	AYYr]f$(8]
((a-M 0!$U3!$U3 D %BBW 	
 =a A}}QWWbii0qTqTAaD[ % %7	  !++=a A}}QWWbii0qTqTAaD[ % %7	  !++|" %Q!111047DG"4   "xx #(		""6 #7B *RL&*2hR%9&(hh
 #7 
 $ "+!2!2I!> "?I ( +* 8%	 "?   )2'(:(:$A} CFrbRTVW(:  
 #&))B-1"4)J "+!2!2I!> "?I )n)	 "?   WBF"T2F7O>b1f"Z8F7OS #))n	
 	
 J!::k2:K{@S 	 5AALqQqc*L
A
dD"eUJ
CC(		? $YF9 ) G}#G}|	j		 	 	'	'	)	)	19xJ!&)u%%%-/EQJMM%UUe^%;QRARMS * "E"346FGHAu 1MQU4KL!U H 
frvvc\6I/J 3K33K3

 =I%JXX]"JXX]syy}16JJ3K33K37O&w&	
 M2c{F3KQ7c{F3KQ7 rxx5tJ/4@JQ

jB Bs$   /1r(0r.r3<.r8'r>6s)r   )plotly.graph_objs
graph_objsr   _plotly_utils.basevalidatorsr   _corer   r   r   imshow_utilsr   r	   r
   pandasr   numpyr   r   plotly.utilsr   ry   rx   ImportError_float_typesr   r%   FigurerH   r7   r   r   <module>r      s     < S S L L    0O 
&& 
	

"

5d6 YY7dU  Os   A. .A87A8