
    !\i+                         S r SSKrSSKJr  SSKrSSKrSSKrSSKJ	r	  SSK
Jr  \R                  " \5      rS r  SS jrSS jrS	 rS
 r      SS jrSS jrg)zImplementations of various common operations.

Including `show()` for displaying an array or with matplotlib.
Most can handle a numpy array or `rasterio.Band()`.
Primarily supports `$ rio insp`.
    N)OrderedDict)DatasetReader)guard_transformc                  `     SSK Jn   U $ ! [        [        4 a    SnUS-  n[        U5      ef = f)zKimport matplotlib.pyplot
raise import error if matplotlib is not installed
r   NzCould not import matplotlib
z*matplotlib required for plotting functions)matplotlib.pyplotpyplotImportErrorRuntimeError)pltmsgs     P/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/rasterio/plot.pyget_pltr      s>    '
& -;;#s   
 #-c                 R   [        5       n	[        U [        5      (       aU  U S   R                  U S   5      n
[	        U
R
                  5      S:  a  [        U
5      n
U(       a  [        U S   5      US'   GOI[        U [        5      (       a  U(       a  [        U 5      US'   U R                  S:X  a  U R                  SSS9n
O [        [        U R                  U R                  5      5      n[        R                  R                   nUR"                  UR$                  UR&                  4 Vs/ s H  nX   PM	     nnU R                  USS9n
[        U
5      n
OiU R*                  S:  a  [,        R.                  R1                  U 5      n U R*                  S:  a  [        U 5      n
OU n
U(       a  U(       a  [        X5      US'   U(       aW  U
R*                  S:  aG  [3        U
5      R5                  S5      n
[7        U
5       H  u  nn[9        U5      X'   M     [        U
5      n
SnU(       d  SnU	R;                  5       nU(       a  S	U;  a  UR=                  S
S5      US
'   UR=                  SS5      US'   UR=                  SS5      US'   UR>                  " U
4SS0UD6nUc
  [A        SSS9nU(       a  URB                  " U40 UD6  OURD                  " U
40 UD6  U(       a  URG                  USS9  U(       a  U	RI                  5         U$ s  snf ! [(         a    U R                  SSS9n
 GNgf = f)a  Display a raster or raster band using matplotlib.

Parameters
----------
source : array or dataset object opened in 'r' mode or Band or tuple(dataset, bidx)
    If Band or tuple (dataset, bidx), display the selected band.
    If raster dataset display the rgb image
    as defined in the colorinterp metadata, or default to first band.
with_bounds : bool (opt)
    Whether to change the image extent to the spatial bounds of the image,
    rather than pixel coordinates. Only works when source is
    (raster dataset, bidx) or raster dataset.
contour : bool (opt)
    Whether to plot the raster data as contours
contour_label_kws : dictionary (opt)
    Keyword arguments for labeling the contours,
    empty dictionary for no labels.
ax : matplotlib.axes.Axes, optional
    Axes to plot on, otherwise uses current axes.
title : str, optional
    Title for the figure.
transform : Affine, optional
    Defines the affine transform if source is an array
adjust : bool
    If the plotted data is an RGB image, adjust the values of
    each band so that they fall between 0 and 1 before plotting. If
    True, values will be adjusted by the min / max of each band. If
    False, no adjustment will be applied.
**kwargs : key, value pairings optional
    These will be passed to the :func:`matplotlib.pyplot.imshow` or
    :func:`matplotlib.pyplot.contour` contour method depending on contour argument.

Returns
-------
ax : matplotlib.axes.Axes
    Axes with plot.

r         extentTmaskedfloat64Fcmapcolorsred
linewidthsg      ?alphag?originupper   )fontsizeinlinebold
fontweight)%r   
isinstancetuplereadlenshapereshape_as_imageplotting_extentr   countr   zipcolorinterpindexesrasterioenumsColorInterpr   greenblueKeyErrorndimnpmasqueezereshape_as_rasterastype	enumerateadjust_bandgcagetcontourdictclabelimshow	set_titleshow)sourcewith_boundsr>   contour_label_kwsaxtitle	transformadjustkwargsr   arrsource_colorinterpr,   cirgb_indexesiibandrC   Cs                      r   rC   rC   "   s   P )C&%  QinnVAY'syy>Q"3'C.vay9F8	FM	*	*.v6F8<<1++a+-C2 &1V5G5G1X%Y"&nn88
  +0A0A;CSCSTT '*T   kk+dk;&s+ ;;!UU]]6*F;;!"6*CC.s>F8#((a-$++I6!#HB!$'CG ' s#DWWY%zz(E:F8%zz,<| **Wc2wJJs575f5$ $a =IIa-,-
		#  
Uv.
IC  2kk!Dk12s%   A(L )L7L L L&%L&c                 Z   [        U S5      (       aX  U R                  R                  U R                  R                  U R                  R                  U R                  R
                  4nU$ U(       d  [        S5      e[        U5      nU R                  SS u  p4US-  u  pVXU4-  u  pxXWX4nU$ )a!  Returns an extent in the format needed
 for :func:`matplotlib.pyplot.imshow` (left, right, bottom, top)
 instead of rasterio's bounds (left, bottom, right, top)

Parameters
----------
source : numpy.ndarray or dataset object opened in 'r' mode
    If array, data in the order rows, columns and optionally bands. If array
    is band order (bands in the first dimension), use arr[0]
transform: Affine, required if source is array
    Defines the affine transform if source is an array

Returns
-------
tuple of float
    left, right, bottom, top
boundsz+transform is required if source is an arrayr      )r   r   )	hasattrrT   leftrightbottomtop
ValueErrorr   r'   )	rD   rI   r   rowscolsrW   rZ   rX   rY   s	            r   r)   r)      s    $ vx  --$$fmm&9&9--&&(9(9; M 9; 	; $I.	\\!A&
&	!4L0v+M    c                 J    [         R                  R                  U / SQ5      nU$ )a7  Returns the source array reshaped into the order
expected by image processing and visualization software
(matplotlib, scikit-image, etc)
by swapping the axes order from (bands, rows, columns)
to (rows, columns, bands)

Parameters
----------
arr : array-like of shape (bands, rows, columns)
    image to reshape
)r   rU   r   )r5   r6   	transposerL   ims     r   r(   r(      s     
i	(BIr^   c                 8    [         R                  " U / SQ5      nU$ )zReturns the array in a raster order
by swapping the axes order from (rows, columns, bands)
to (bands, rows, columns)

Parameters
----------
arr : array-like in the image form of (rows, columns, bands)
    image to reshape
)rU   r   r   )r5   r`   ra   s     r   r8   r8      s     
c9	%BIr^   c                    [        5       n[        U [        5      (       a  U R                  US9n	O>[        U [        [
        R                  45      (       a  U S   R                  U S   US9n	OU n	Uc,  [        R                  " U	5      [        R                  " U	5      4n[        U	R                  5      S:X  a3  [        R                  " U	R                  5       S5      R                  n	S/n
O-U	R                  U	R                  S   S5      R                  n	/ SQn
U	R                  S   [        U
5      :  au  U	R                  S   [        U
5      -
  nU
R!                  [        R"                  R%                  UR'                  S	5      " [        R(                  " SSU5      5      5      5        OU
SU	R                  S    n
U(       a  UnOp[        U [        [
        R                  45      (       a  [+        U S   5      /nO;[,        R.                  " [        U	5      5       Vs/ s H  n[+        US-   5      PM     nnU(       a  S
nOSnUR1                  5       nUR3                  5       nUR4                  " U	4XXS.UD6  UR7                  SS9  UR9                  USS9  UR;                  S5        UR=                  S5        UR?                  S5        U(       a  URA                  5         ggs  snf )a  Easily display a histogram with matplotlib.

Parameters
----------
source : array or dataset object opened in 'r' mode or Band or tuple(dataset, bidx)
    Input data to display.
    The first three arrays in multi-dimensional
    arrays are plotted as red, green, and blue.
bins : int, optional
    Compute histogram across N bins.
masked : bool, optional
    When working with a `rasterio.Band()` object, specifies if the data
    should be masked on read.
title : str, optional
    Title for the figure.
ax : matplotlib.axes.Axes, optional
    The raster will be added to this axes if passed.
label : str, optional
    String, or list of strings. If passed, matplotlib will use this label list.
    Otherwise, a default label list will be automatically created
range : list, optional
    List of `[min, max]` values. If passed, matplotlib will use this range.
    Otherwise, a default range will be automatically created
**kwargs : optional keyword arguments
    These will be passed to the :meth:`matplotlib.axes.Axes.hist` method.
r   r   r   NrU   gold)r   r1   r2   violetre   saddlebrownAccentFT)binscolorlabelrangezupper right)locr    r!   DN	Frequency)!r   r#   r   r%   r$   r.   Bandr5   nanminnanmaxr&   r'   expand_dimsflattenTreshapeextendndarraytolistget_cmaplinspacestrbuiltinsrm   r<   
get_figurehistlegendrB   grid
set_xlabel
set_ylabelrC   )rD   rj   r   rH   rG   rl   rm   rK   r   rL   r   nlabelsirC   figs                   r   	show_histr      s<   H )C&-((kkk(	FUHMM2	3	3QinnVAYvn6} 		#		#.
399~nnS[[]A.00kk#))A,+--J
 yy}s6{"IIbMCK'bjj''X(>r{{1aQR?S(TUV2' 
 fuhmm455&)n%F*2..S*BC*BQc!a%j*BFC	WWY
--/CGGCNdNvNII-I LL6L*GGDMMM$MM+
 # Ds   K c                     [         R                  " [         R                  " U 5      5      n[         R                  " [         R                  " U 5      5      nX-
  X2-
  -  $ )a6  Adjust a band to be between 0 and 1.

Parameters
----------
band : array, shape (height, width)
    A band of a raster object.
kind : str
    An unused option. For now, there is only one option ('linear').

Returns
-------
band_normed : array, shape (height, width)
    An adjusted version of the input band.

)r5   r   rr   rs   )rQ   kindiminimaxs       r   r;   r;   J  s?      ::biio&D::biio&DKDK((r^   )TFNNNNF)N)
   T	HistogramNNN)__doc__r~   collectionsr   loggingnumpyr5   r.   rasterio.ior   rasterio.transformr   	getLogger__name__loggerr   rC   r)   r(   r8   r   r;    r^   r   <module>r      sw     #    % .			8	$
 EI5:BJD"" 



^B)r^   