
    ]e$7                        d Z ddlZddlZddlZddlmZmZ ddl	m
Z
mZmZmZmZmZ  G d de          Z G d de          Zd	 Zej                            d
dg          d             Zd Zd Zej                            d
g dd           d             Zej                            d
g dd           d             Zd Zd Zd Zd Zd Zd Zd Z dS )z2
Tests  utilities to convert data and projections
    N)TestCaseSkipTest)	check_crsis_list_likeprocess_crsprocess_xarray_convert_col_names_to_strinstantiate_crs_strc                   V    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )TestProcessXarrayc                     	 dd l }dd l}n#  t          d          xY wdd dddd d d d g d
| _        |j                            d          | _        d S )Nr   zxarray or pandas not availablevalueF)
value_labellabelgriddedpersistuse_daskgroupbyyxby
other_dimsair_temperature)xarraypandasr   default_kwargstutorialopen_datasetds)selfxrpds      5lib/python3.11/site-packages/hvplot/tests/testutil.pysetUpzTestProcessXarray.setUp   s    	=	=;<<<"
 
 +**+<==s    c                     dd l }dd l}|                    g d          }t          dd|i| j        \  }}}}}t          ||j                  sJ |dk    sJ |dgk    sJ |rJ |rJ d S )Nr            )datar*   indexr    r   r   	DataArrayr   r   
isinstance	DataFrame	r    r!   r"   dar*   r   r   r   r   s	            r#   /test_process_1d_xarray_dataarray_with_no_coordszATestProcessXarray.test_process_1d_xarray_dataarray_with_no_coords&   s    \\    #1"P"Pb"PD<O"P"PaB$-----G||||WI~~~~    c                     dd l }dd l}|                    g ddg didg          }t          dd|i| j        \  }}}}}t          ||j                  sJ |dk    sJ |dgk    sJ |rJ |rJ d S )	Nr   r&   day         r*   coordsdimsr*   r   r,   r-   r1   s	            r#   ,test_process_1d_xarray_dataarray_with_coordsz>TestProcessXarray.test_process_1d_xarray_dataarray_with_coords4   s    \\999%   
 #1"P"Pb"PD<O"P"PaB$-----EzzzzWI~~~~r4   c                     dd l }dd l}|                    g ddg didgd          }t          dd|i| j        \  }}}}}t          ||j                  sJ |dk    sJ |dgk    sJ |rJ |rJ d S )	Nr   r&   r6   r7   temp)r*   r<   r=   namer*   r,   r-   r1   s	            r#   5test_process_1d_xarray_dataarray_with_coords_and_namezGTestProcessXarray.test_process_1d_xarray_dataarray_with_coords_and_nameD   s    \\999%	    #1"P"Pb"PD<O"P"PaB$-----EzzzzVH}}}}r4   c                    dd l }dd l}|                    t          j                            dd                    }t          dd|i| j        \  }}}}}t          ||j	                  sJ |dk    sJ |dgk    sJ |rJ |rJ d S )Nr      r8   r*   r+   r   r,   )
r   r   r.   nprandomrandnr   r   r/   r0   r1   s	            r#   /test_process_2d_xarray_dataarray_with_no_coordszATestProcessXarray.test_process_2d_xarray_dataarray_with_no_coordsU   s    \\")//!A..//"0"P"Pb"PD<O"P"PaB$-----G||||WI~~~~r4   c                    dd l }|                    t          j                            dd                    }| j        }|                    d           t          d
d|i|\  }}}}}t          ||j	                  sJ t          |j                                                  dgk    sJ |dk    sJ |d	k    sJ |rJ |rJ d S )Nr   rD   r8   Tr   r*   r   dim_1dim_0r,   r   r.   rE   rF   rG   r   updater   r/   Datasetlist	data_varskeys	r    r!   r2   kwargsr*   r   r   r   r   s	            r#   :test_process_2d_xarray_dataarray_with_no_coords_as_griddedzLTestProcessXarray.test_process_2d_xarray_dataarray_with_no_coords_as_griddedb   s    \\")//!A..//$d###"0"C"Cb"CF"C"CaB$
+++++DN''))**wi7777G||||G||||r4   c                    dd l }|                    t          j                            dd          dg diddg          }| j        }|                    d	           t          dd
|i|\  }}}}}t          ||j	                  sJ t          |j                                                  dgk    sJ |dk    sJ |dk    sJ |rJ |rJ d S )Nr   rD   r8   r   )r)   rD   r8   r9   r:   r   r;   TrJ   r*   r   r,   rM   rS   s	            r#   7test_process_2d_xarray_dataarray_with_coords_as_griddedzITestProcessXarray.test_process_2d_xarray_dataarray_with_coords_as_griddedr   s   \\1%%)s   
 $d###"0"C"Cb"CF"C"CaB$
+++++DN''))**wi7777CxxxxCxxxxr4   c                     dd l }t          dd| j        i| j        \  }}}}}t	          ||j                  sJ |dk    sJ |dgk    sJ |rJ |ddgk    sJ d S )Nr   r*   timeairlonlatr,   )r   r   r   r   r/   r0   )r    r"   r*   r   r   r   r   s          r#   *test_process_3d_xarray_dataset_with_coordsz<TestProcessXarray.test_process_3d_xarray_dataset_with_coords   s    "0"U"Udg"UAT"U"UaB$-----F{{{{UG||||5%.((((((r4   c                 @   dd l }| j        }|                    ddd           t          d	d| j        i|\  }}}}}t          ||j                  sJ t          |j        	                                          dgk    sJ |dk    sJ |dk    sJ |J |dgk    sJ d S )
Nr   Tr[   r\   )r   r   r   r*   rZ   rY   r,   
r   r   rN   r   r   r/   rO   rP   rQ   rR   r    r!   rT   r*   r   r   r   r   s           r#   5test_process_3d_xarray_dataset_with_coords_as_griddedzGTestProcessXarray.test_process_3d_xarray_dataset_with_coords_as_gridded   s    $deu555"0"H"Hdg"H"H"HaB$
+++++DN''))**ug5555EzzzzEzzzzzzz6(""""""r4   c                 <   dd l }| j        }|                    d           t          d	d| j        i|\  }}}}}t          ||j                  sJ t          |j        	                                          dgk    sJ |dk    sJ |dk    sJ |rJ |dgk    sJ d S )
Nr   TrJ   r*   rZ   r[   r\   rY   r,   r_   r`   s           r#   Otest_process_3d_xarray_dataset_with_coords_as_gridded_uses_axis_to_get_defaultszaTestProcessXarray.test_process_3d_xarray_dataset_with_coords_as_gridded_uses_axis_to_get_defaults   s    $d###"0"H"Hdg"H"H"HaB$
+++++DN''))**ug5555EzzzzEzzzz6(""""""r4   c                    dd l }| j                            ddg          }| j        }|                    dddg           t          dd	|i|\  }}}}}t          ||j                  sJ |d
k    sJ |dk    sJ |dgk    sJ |rJ d S )Nr   r\   r[   dimFrZ   z	time.hour)r   r   r   r*   rY   r,   r   r   meanr   rN   r   r/   r0   r    r"   r*   rT   r   r   r   r   s           r#   7test_process_xarray_dataset_with_by_as_derived_datetimezITestProcessXarray.test_process_xarray_dataset_with_by_as_derived_datetime   s    w|||//$eu+???"0"E"Ed"Ef"E"EaB$-----F{{{{Ezzzzk]""""r4   c                    dd l }| j                            ddg          }| j        }|                    ddd           t          d
d	|i|\  }}}}}t          ||j                  sJ |dk    sJ |dk    sJ |rJ |rJ d S )Nr   r\   r[   re   FrZ   ztime.dayofyear)r   r   r   r*   r,   rg   ri   s           r#   6test_process_xarray_dataset_with_x_as_derived_datetimezHTestProcessXarray.test_process_xarray_dataset_with_x_as_derived_datetime   s    w|||//$eu0@AAA"0"E"Ed"Ef"E"EaB$-----$$$$$Ezzzzr4   N)__name__
__module____qualname__r$   r3   r>   rB   rH   rU   rW   r]   ra   rc   rj   rl   r,   r4   r#   r   r      s        > > >(       "       &) ) )# # ## # #      r4   r   c                   &    e Zd Zd Zd Zd Zd ZdS )TestDynamicArgsc                 8    	 dd l }d S #  t          d          xY w)Nr   zpanel not available)panelr   )r    pns     r#   r$   zTestDynamicArgs.setUp   s1    	2	20111s    c                     dd l }ddlm} d}|j                            ddddg          }|j                            d	d
dd
g          } ||||          \  }}}d|vsJ d|v sJ |g k    sJ d S )Nr   r(   process_dynamic_argssepal_widthr   sepal_lengthpetal_length)rA   r   optionskindscatter	bivariater   )rs   utilrw   widgetsSelect)	r    rt   rw   r   r   r|   dynamicarg_deps	arg_namess	            r#   test_dynamic_and_staticz'TestDynamicArgs.test_dynamic_and_static   s    //////J3n~WeFfggz  fIU^G_ ``';';Aq$'G'G$9'!!!!g~~~~2~~~~~~r4   c                     dd l }ddlm} d}d}d}|j                            d          } |||||	          \  }}}	d
|vsJ d|v sJ |g k    sJ d S )Nr   r(   rv   ry   rx   r}   #ff0000r   cr   r   )rs   r   rw   r   ColorPicker)
r    rt   rw   r   r   r|   colorr   r   r   s
             r#   test_dynamic_kwdsz!TestDynamicArgs.test_dynamic_kwds   s    //////
&&Y&77';';Aq$%'P'P'P$9'!!!!g~~~~2~~~~~~r4   c                 l   dd l }ddlm} d}d}d}|j                            d          }|j                            d	
          }|                    |j        j        |j        j                  d             } |||||          \  }	}
}|	i k    sJ |ddgk    sJ t          |
          dk    sJ d S )Nr   r(   rv   ry   rx   r}   z
By species)rA   r   r   c                     | rdn|S )Nspeciesr,   )
by_speciesr   s     r#   by_species_fnz3TestDynamicArgs.test_fn_kwds.<locals>.by_species_fn   s     *5995r4   r   r   )
rs   r   rw   r   Checkboxr   dependsparamr   len)r    rt   rw   r   r   r|   r   r   r   r   r   r   s               r#   test_fn_kwdszTestDynamicArgs.test_fn_kwds   s    //////Z((l(;;

&&Y&77	J$*EK,=	>	>	6 	6 
?	>	6 (<';Aq$-'X'X'X$9"}}}}S#J&&&&8}}!!!!!!r4   N)rm   rn   ro   r$   r   r   r   r,   r4   r#   rq   rq      sP        2 2 2    " " " " "r4   rq   c                      t          j        d           t          d          } | j        dk    sJ t          d          } | J d S )Npyprojzepsg:26915 +units=mz1+proj=utm +zone=15 +datum=NAD83 +units=m +no_defswrong)pytestimportorskipr   srs)ps    r#   test_check_crsr      sO    
!!!'((A5GGGGG'A99999r4   inputz+init=epsg:26911c                     t          j        d           t          j        d          }t          |           }t          ||j                  sJ d S Nr   cartopy.crs)r   r   r   r/   CRSr   ccrscrss      r#   test_process_crsr     sP     !!!}--D
e

Cc48$$$$$$$r4   c                      t          j        d          } t          j        d          }t          | j                            d                    }t          ||j                  sJ d S )Nr   r     )r   r   r   r   	from_epsgr/   PlateCarreer   r   r   s      r#   test_process_crs_pyproj_crsr     s^     **F}--D
fj**400
1
1Cc4+,,,,,,,r4   c                      t          j        d          } t          j        d          }t          |                     d                    }t	          ||j                  sJ d S )Nr   r   	epsg:4326)init)r   r   r   Projr/   r   r   s      r#   test_process_crs_pyproj_projr     s\     **F}--D
fkk{k33
4
4Cc4+,,,,,,,r4   )4326r   r   z
EPSG: 4326z+init=epsg:4326a5  GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],MEMBER["World Geodetic System 1984 (G2139)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]]c                 0    t          |           d d         S N   strr   s    r#   <lambda>r   '      Q r4   )idsc                     t          j        d           t          j        d          }t          |           }t          ||j                  sJ d S r   )r   r   r   r/   r   r   s      r#   test_process_crs_platecarreer     sQ     !!!}--D
e

Cc4+,,,,,,,r4   )3857i  z	epsg:3857z
EPSG: 3857z+init=epsg:3857a  PROJCS["WGS 84 / Pseudo-Mercator",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Mercator_1SP"],PARAMETER["central_meridian",0],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"],AUTHORITY["EPSG","3857"]]u  PROJCRS["WGS 84 / Pseudo-Mercator",BASEGEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],MEMBER["World Geodetic System 1984 (G2139)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4326]],CONVERSION["Popular Visualisation Pseudo-Mercator",METHOD["Popular Visualisation Pseudo Mercator",ID["EPSG",1024]],PARAMETER["Latitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8801]],PARAMETER["Longitude of natural origin",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8802]],PARAMETER["False easting",0,LENGTHUNIT["metre",1],ID["EPSG",8806]],PARAMETER["False northing",0,LENGTHUNIT["metre",1],ID["EPSG",8807]]],CS[Cartesian,2],AXIS["easting (X)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["northing (Y)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Web mapping and visualisation."],AREA["World between 85.06°S and 85.06°N."],BBOX[-85.06,-180,85.06,180]],ID["EPSG",3857]]c                 0    t          |           d d         S r   r   r   s    r#   r   r   8  r   r4   c                     t          j        d           t          j        d          }t          |           }t          ||j                  sJ d S r   )r   r   r   r/   Mercatorr   s      r#   test_process_crs_mercatorr   /  sP     !!!}--D
e

Cc4=)))))))r4   c                  "   t          j        d           t          j        d          } t          j        d          }| j                            d                                          }t          |          }t          ||j                  sJ d S )Nr   zrasterio.crsr   r   )r   r   r   r   to_wktr   r/   )rcrsr   r   r   s       r#   test_process_crs_rasterior   @  s    
!!!~..D}--DHt$$++--E
e

Cc48$$$$$$$r4   c                      t          j        d           t          j        d           t          j        t          d          5  t	          d           d d d            d S # 1 swxY w Y   d S )Nr   r   z,must be defined as a EPSG code, proj4 string)matchi/  )r   r   raises
ValueErrorr   r,   r4   r#   test_process_crs_raises_errorr   H  s    
!!!
&&&	z)W	X	X	X  E                 s   A!!A%(A%c                     t          d          rJ t          d          rJ t          t          j        d                    rJ t          ddg          sJ t          d          sJ t          ddh          sJ t          t          j        ddg                    sJ t          t          j        ddg                    sJ t          t          j        ddg                    sJ d S )Nr   stringab)r   r   )r   rE   arrayr"   SeriesIndexr,   r4   r#   test_is_list_liker   O  s    AH%%%%%BHSMM*****c
#####
#####c
#####	3*--.....#s,,-----#s,,-------r4   c                     t          j        t          j                            d                    } t	          d | j        D                       sJ t          |           } t	          d | j        D                       sJ d S )N)
   r(   c              3   B   K   | ]}t          |t                     V  d S Nr/   r   .0cols     r#   	<genexpr>z0test_convert_col_names_to_str.<locals>.<genexpr>]  s/      >>C:c3'''>>>>>>r4   c              3   @   K   | ]}t          |t                    V  d S r   r   r   s     r#   r   z0test_convert_col_names_to_str.<locals>.<genexpr>_  s,      ::z#s##::::::r4   )r"   r0   rE   rF   allcolumnsr	   )dfs    r#   test_convert_col_names_to_strr   [  s~    	bi&&w//	0	0B>>2:>>>>>>>>	"2	&	&B::rz::::::::::r4   c                  v    t          j        d          } t          t          d          | j                  sJ d S )Nr   r   )r   r   r/   r
   r   r   s    r#   test_instantiate_crs_strr   b  s:    }--D)-88$:JKKKKKKKr4   c                      t          j        d          } t          d          | j        k    sJ t          d          | j        k    sJ d S )Nr   GOOGLE_MERCATORgoogle_mercator)r   r   r
   r   r   s    r#   $test_instantiate_crs_google_mercatorr   g  sR    }--D011T5IIIII011T5IIIIIIIr4   c                     t          j        d          } t          d|                     d                    }t	          || j                  sJ t	          |j        | j                  sJ |j        j        dk    sJ d S )Nr   r   WGS84)datum)globe)r   r   r
   Glober/   r   r   r   )r   r   s     r#   test_instantiate_crs_str_kwargsr   m  s    }--D
m4::G:3L3L
M
M
MCc4+,,,,,ci,,,,,9?g%%%%%%r4   )!__doc__numpyrE   r   r"   r   unittestr   r   hvplot.utilr   r   r   r   r	   r
   r   rq   r   markparametrizer   r   r   r   r   r   r   r   r   r   r   r   r,   r4   r#   <module>r      st             ' ' ' ' ' ' ' '               u u u u u u u up4" 4" 4" 4" 4"h 4" 4" 4"n   #  % % %- - -- - -  # # #    - - -  	# 	# 	#   	 	* *	 	*% % %  	. 	. 	.; ; ;L L L
J J J& & & & &r4   