
    !\i                     j   S r SSKJrJr  SSKJ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  SSKJr  SS	KJr  SS
KJr  SSKJrJr  SS jrSS jrS r " S S\\5      r\	R:                  " SS9\	R<                  " S5      \R>                  \R@                  \RB                  \	RD                  " SSSS9\RF                  \RH                  \RJ                  \	RD                  " S\&SSS9\RN                  \	RP                  S 5       5       5       5       5       5       5       5       5       5       5       5       r)g)z
$ rio calc    )OrderedDictUserDict)	ExitStackN)Mapping)snuggs)sieve)
fillnodata)options)resolve_inout)Window	subdividec                     U[        U 5      ;   a  UO[        U5      S-
  nX   nU(       a  [        R                  " XS5      $ UR                   Vs/ s H  n[        R                  " XV5      PM     sn$ s  snf )z.Get a rasterio.Band object from calc's inputs.   )dictintrasteriobandindexes)inputssourcesdiidxsrcjs          T/var/www/html/kml_chatgpt/mouzaenv/lib/python3.13/site-packages/rasterio/rio/calc.py
_get_bandsr      sX    DL !c!fqjC
,C$%8== W3;;+W;aHMM#,A;+WW+Ws    A2c                 t    [         R                  R                  X5      nU(       a  UR                  U5      nU$ )z Change the type of a read array.)r   _ctxlookupastype)ixsubixdtypearrs       r   _read_arrayr&      s,    
++

R
'CjjJ    c                      [        U 5      S:X  a6  [        U S   S5      (       a"  [        R                  " [	        U S   5      5      $ [        R                  " [	        U 5      5      $ )Nr   r   __iter__)lenhasattrnumpy
asanyarraylist)argss    r   asarrayr0   #   sK    
4yA~'$q':66T!W..T
++r'   c                       \ rS rSrSrS rSrg)
FuncMapper*   z6Resolves functions from names in pipeline expressions.c                    ^ TU R                   ;   a  U R                   T   $ T[        ;   a  TR                  S5      (       d	  [        T   $ U4S j$ )zGet a function by its name.__c                 t   > [        [        U T5      5      (       a  [        U T5      " U0 UD6$ [        U T5      $ N)callablegetattr)gr/   kwargskeys      r   <lambda>(FuncMapper.__getitem__.<locals>.<lambda>5   s<    GAsO,, ,31c?D+KF+K ,%Q_,%r'   )data__builtins__
startswith)selfr<   s    `r   __getitem__FuncMapper.__getitem__-   sH    $))99S>!L )=)=$$%r'    N)__name__
__module____qualname____firstlineno____doc__rC   __static_attributes__rE   r'   r   r2   r2   *   s
    @r'   r2   zRaster data calculator.)
short_helpcommandz--nameTzrSpecify an input file with a unique short (alphas only) name for use in commands like "a=tests/data/RGB.byte.tif".)multiplehelpz--mem-limit@   z4Limit on memory used to perform calculations, in MB.)typedefaultrO   c                   ^^ Sn/ mU R                   S      [        5        n[        X#US9u  p2U Vs/ s H  n[        UR	                  S5      5      PM     snU Vs/ s H  nSU4PM	     sn-   mT VVs/ s H*  u  p^UR                  [        R                  " U5      5      PM,     snnm[        [        S [        UU4S jUU4S j[        [        S9[        l        TS	   nUR                  nUR                   " S0 U
D6  U=(       d    UR"                  S
   nUUS
'   UR%                  SS5        U(       a  UUS'   ['        S	S	SS5      /nU GH5  n[)        5       n[+        [-        TT5      5       H-  u  nu  u  p^nUR/                  UUS9UU=(       d    SUS-   -  '   M/      [        R0                  " U40 UD6nUR3                  U5      n[C        U[D        RF                  RH                  RJ                  5      (       aW  URM                  [O        US   5      5      n[Q        URR                  5      S:X  a   [D        RF                  RU                  U/5      nO0[Q        URR                  5      S:X  a  [D        RT                  " U/5      nUc  URR                  S	   US'   UR                  [        R                  " US40 UD65      nU	S-  [D        RV                  " URX                  S	   5      RZ                  UR\                  -  -  n[_        [`        Rb                  " [`        Rd                  " U5      5      5      nURg                  [i        ['        S	S	URj                  URl                  5      UU5      5        GM%  URo                  UUS9  GM8     SSS5        SSS5        gs  snf s  snf s  snnf ! [        R4                   a  n[6        R8                  " S5        [6        R8                  " SUR:                   35        [6        R8                  " SR=                  SUR>                  -  5      5        [6        R8                  " U5        [6        R@                  " 5       eSnAff = f! , (       d  f       N= f! , (       d  f       g= f)af  A raster data calculator

Evaluates an expression using input datasets and writes the result
to a new dataset.

Command syntax is lisp-like. An expression consists of an operator
or function name and one or more strings, numbers, or expressions
enclosed in parentheses. Functions include ``read`` (gets a raster
array) and ``asarray`` (makes a 3-D array from 2-D arrays).


    * (read i) evaluates to the i-th input dataset (a 3-D array).
    * (read i j) evaluates to the j-th band of the i-th dataset (a
      2-D array).
    * (read i j 'float64') casts the array to, e.g. float64. This
      is critical if calculations will produces values that exceed
      the limits of the dataset's natural data type.
    * (take foo j) evaluates to the j-th band of a dataset named foo
      (see help on the --name option above).
    * Standard numpy array operators (+, -, *, /) are available.
    * When the final result is a list of arrays, a multiple band
      output file is written.
    * When the final result is a single array, a single band output
      file is written.

Example:


     $ rio calc "(+ 2 (* 0.95 (read 1)))" tests/data/RGB.byte.tif \
     > /tmp/out.tif

The command above produces a 3-band GeoTIFF with all values scaled
by 0.95 and incremented by 2.


    $ rio calc "(asarray (+ 125 (read 1)) (read 1) (read 1))" \
    > tests/data/shade.tif /tmp/out.tif

The command above produces a 3-band RGB GeoTIFF, with red levels
incremented by 125, from the single-band input.

The maximum amount of memory used to perform calculations defaults to
64 MB. This number can be increased to improve speed of calculation.

Nenv)filesoutput	overwrite=c                 2    [         R                  " XS-
  SS9$ )Nr   r   )axis)r,   take)ar   s     r   r=   calc.<locals>.<lambda>   s    

1AgA >r'   c                    > [        TTX5      $ r7   r   )r   r   r   r   s     r   r=   r]      s    j!?r'   c                    > [        TTU 5      $ r7   r_   )r   r   r   s    r   r=   r]      s    Jvw:r'   )r0   r[   readr   bandsr	   r   r   r$   driver   )maskedwindowz_i%dr   zExpression Error:z  z {}^ nodata   countwg    .A)rf   rE   )8objr   r   tuplesplitenter_contextr   openr2   r0   r&   r	   r   r   func_mapprofileupdatemetapopr   r   	enumeratezipra   evalr!   ExpressionErrorclickechotextformatoffsetAbort
isinstancer,   macoreMaskedArrayfilledfloatr*   shaper-   r$   dtypesitemsizerj   r   mathfloorsqrtextendr   widthheightwrite)ctxrM   rU   rV   rc   namer$   re   rW   	mem_limitcreation_optionsdststacknpathfirstr;   work_windowsrf   ctxkwdsr   r   resresultserr
max_pixels
chunk_sizer   r   s                              @@r   calcr   ;   s   z CG	%EIV/34t!%%t457Q5aq	57QQNTUf
5&&x}}T':;fU$>?:!
 
)(),G,w

8T"%F8
 q!R,-"F!mG*3C4H*I&&LT#47HH!& 5= 50!a% 01 +J
	,kk'5W5 **U+'588==#<#<==!..vh/?)@Aw}}%*#hh117)<GW]]#q(**G95 {")--"2w))(--*Nv*NO&/5;;szz!}3M3V3VY\YbYb3bc
 DIIj,A!BC
##q!SYY

;"" 		'&	1W #; %47QUH )) $

./

Rz?+

6==szz)9:;

3kkm#$O %sr   Q)Q$NQN
*
Q41N 
%C:Q N&7GQQ)Q&Q	:BQ	Q	Q
Q&	"Q))
Q7r7   )NN)*rJ   collectionsr   r   
contextlibr   r   collections.abcr   rz   r,   r   rasterio._vendorr   rasterio.featuresr   rasterio.fillr	   rasterio.rior
   rasterio.rio.helpersr   rasterio.windowsr   r   r   r&   r0   r2   rM   argumentfiles_inout_arg
output_opt
format_optoption	dtype_opt
masked_optoverwrite_optr   r   pass_contextr   rE   r'   r   <module>r      s#    -    #    # # $   . .X,7 " 34	h23 	m#r8noy2   p   	3     5y2r'   