
    dV              
          d Z ddlmZ ddlZddlZddlmZ ddlZddl	m
Z ddlmZ ddlmZ erddl	mZ d	Zd
ZdZd Zi Zdddddddddd	Zd Z	 	 d#ddd$dZ
d%dZddd&d"ZdS )'zR
Useful for:

* users learning xarray
* building tutorials in the documentation.

    )annotationsN)TYPE_CHECKING)open_dataset)	DataArray)Dataset)T_Enginexarray_tutorial_dataz%https://github.com/pydata/xarray-datamasterc                    dd l }t          | t          j                  rt          j        |           } n| |                    t                    } | S )Nr   )pooch
isinstanceosPathLikefspathos_cache_default_cache_dir_name)pathr   s     /lib/python3.11/site-packages/xarray/tutorial.py_construct_cache_dirr      sJ    LLL$$$ 7y	~~566K          )	air_temperatureair_temperature_gradientASE_ice_velocity
basin_maskersstv5rasmROMS_exampletiny
eraint_uvzc                H   t                               |           }|dk    r=	 dd l}n7# t          $ r* 	 dd l}n!# t          $ r t          d|  d          w xY wY nw xY w|dk    r>	 dd l}d S # t          $ r* 	 dd l}Y d S # t          $ r t          d|  d          w xY ww xY wd S )Nr   r   zopening tutorial dataset z2 requires either scipy or netCDF4 to be installed.r   z5 requires either h5netcdf or netCDF4 to be installed.)file_formatsgetscipyImportErrornetCDF4h5netcdf)nameversionr%   r'   r(   s        r   _check_netcdf_engine_installedr+   6   s9   t$$G!||		LLLL 	 	 	   !/ / / /   	 !||		OOOOO 	 	 	   !2 2 2 2  	 |sA   ' 
A7AAAA%A+ +
B6A==BBT)enginer)   strcachebool	cache_dirNone | str | os.PathLiker,   r   returnr   c                  	 ddl }n"# t          $ r}t          d          |d}~ww xY w|                                }|                    d           t	          |          }| t
          v rt
          |          }nt          j        |           }	|	j        s)d}
|t          |            |	
                    |
          }	n7|	j        dk    r,|*d}	 ddl}n"# t          $ r}t          d          |d}~ww xY wt           d	t           d
|	j         }|                    |d|          }t!          |fd|i|}|s:|                                }t          j        |                                           |S )a  
    Open a dataset from the online repository (requires internet).

    If a local copy is found then always use that to avoid network traffic.

    Available datasets:

    * ``"air_temperature"``: NCEP reanalysis subset
    * ``"air_temperature_gradient"``: NCEP reanalysis subset with approximate x,y gradients
    * ``"basin_mask"``: Dataset with ocean basins marked using integers
    * ``"ASE_ice_velocity"``: MEaSUREs InSAR-Based Ice Velocity of the Amundsen Sea Embayment, Antarctica, Version 1
    * ``"rasm"``: Output of the Regional Arctic System Model (RASM)
    * ``"ROMS_example"``: Regional Ocean Model System (ROMS) output
    * ``"tiny"``: small synthetic dataset with a 1D data variable
    * ``"era5-2mt-2019-03-uk.grib"``: ERA5 temperature data over the UK
    * ``"eraint_uvz"``: data from ERA-Interim reanalysis, monthly averages of upper level data
    * ``"ersstv5"``: NOAA's Extended Reconstructed Sea Surface Temperature monthly averages

    Parameters
    ----------
    name : str
        Name of the file containing the dataset.
        e.g. 'air_temperature'
    cache_dir : path-like, optional
        The directory in which to search for and write cached data.
    cache : bool, optional
        If True, then cache data locally for use on subsequent calls
    **kws : dict, optional
        Passed to xarray.open_dataset

    See Also
    --------
    tutorial.load_dataset
    open_dataset
    load_dataset
    r   Nzhtutorial.open_dataset depends on pooch to download and manage datasets. To proceed please install pooch.WARNINGz.ncz.gribcfgribz:Reading this tutorial dataset requires the cfgrib package.z/raw//)url
known_hashr   r,   )r   r&   
get_loggersetLevelr   external_urlspathlibPathsuffixr+   with_suffixr5   base_urlr*   r)   retrieve_open_datasetloadunlink)r)   r.   r0   r,   kwsr   eloggerr7   r   default_extensionr5   filepathdss                 r   r   r   Q   s   X   0
 
 	 F
OOI$Y//I}D!|D!!{ 	 %~.t444##$566DD[G##~!!MMMM"   %T 
 5555$)55 ~~#$Y~GGH	x	6	6	6#	6	6B (WWYYX%%'''Is(    
&!&C 
C0C++C0c                 v    t          | i |5 }|                                cddd           S # 1 swxY w Y   dS )aS  
    Open, load into memory, and close a dataset from the online repository
    (requires internet).

    If a local copy is found then always use that to avoid network traffic.

    Available datasets:

    * ``"air_temperature"``: NCEP reanalysis subset
    * ``"air_temperature_gradient"``: NCEP reanalysis subset with approximate x,y gradients
    * ``"basin_mask"``: Dataset with ocean basins marked using integers
    * ``"rasm"``: Output of the Regional Arctic System Model (RASM)
    * ``"ROMS_example"``: Regional Ocean Model System (ROMS) output
    * ``"tiny"``: small synthetic dataset with a 1D data variable
    * ``"era5-2mt-2019-03-uk.grib"``: ERA5 temperature data over the UK
    * ``"eraint_uvz"``: data from ERA-Interim reanalysis, monthly averages of upper level data
    * ``"ersstv5"``: NOAA's Extended Reconstructed Sea Surface Temperature monthly averages

    Parameters
    ----------
    name : str
        Name of the file containing the dataset.
        e.g. 'air_temperature'
    cache_dir : path-like, optional
        The directory in which to search for and write cached data.
    cache : bool, optional
        If True, then cache data locally for use on subsequent calls
    **kws : dict, optional
        Passed to xarray.open_dataset

    See Also
    --------
    tutorial.open_dataset
    open_dataset
    load_dataset
    N)r   rC   )argskwargsrJ   s      r   load_datasetrN      s    J 
t	&v	&	& "wwyy                 s   .22)seedrO   
None | intc                   t           j                            |           }t          t          j        g d          g dt          j        d          t          j        ddd          t          j        d          d|                    d          z  d	          }d|j        d
z  z  |j	        dz  z   d|j
        z  |j        z  z   }d|j        z  |j	        d|j
        z   z  z   |j        z   }t          ||d          }g d|d<   d|j        j        d<   d|j	        j        d<   d|j
        j        d<   d|j        j        d<   d|j        j        d<   d|j        j        d<   |S )z
    Create an example dataset.

    Parameters
    ----------
    seed : int, optional
        Seed for the random number generation.
    )r      r   r   )xyzwr   r      rR   r   g?)dimscoords   g      @g   )AB)onetwothreefiverV   xunitsunitsyunitszunitswunitsAunitsBunits)nprandomdefault_rngr   zerosarangelinspacestandard_normalrS   rT   rU   rV   r   attrsr\   r]   )rO   rngr\   r]   rJ   s        r   scatter_example_datasetrr      s[    )


%
%C
!!!1Q2&&1s**1---	
 
		 		 		A 	ac1fqsCx#)ac/1Aqs
QSAG_$qs*A	qq!!	"	"B---BsG"BDJw"BDJw"BDJw"BDJw"BDJw"BDJwIr   )TN)
r)   r-   r.   r/   r0   r1   r,   r   r2   r   )r2   r   )rO   rP   r2   r   )__doc__
__future__r   r   r<   typingr   numpyri   xarray.backends.apir   rB   xarray.core.dataarrayr   xarray.core.datasetr   r   r   r@   r*   r   r;   r#   r+   rN   rr    r   r   <module>r{      s{    # " " " " " 				                  = = = = = = + + + + + + ' ' ' ' ' ' -,,,,,, 1 2
    !
 
  : *.U
 U U U U U Up& & & &R 37 ! ! ! ! ! ! ! !r   