Ë
    ÷Q(h¿$  ã                   ó‚  — d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlZddlZddlmZ dd	lmZmZ d
dlmZ d
dlmZmZmZ  eddd¬«      Z eddd¬«      ZdZ ej<                  e«      Z dejB                  fd„Z"d„ Z#d„ Z$ ee%edgdg eed
dd¬«      g eeddd¬«      gdœd¬ «      ddd!d"dœd#„«       Z&y)$aõ  
=============================
Species distribution dataset
=============================

This dataset represents the geographic distribution of species.
The dataset is provided by Phillips et. al. (2006).

The two species are:

 - `"Bradypus variegatus"
   <http://www.iucnredlist.org/details/3038/0>`_ ,
   the Brown-throated Sloth.

 - `"Microryzomys minutus"
   <http://www.iucnredlist.org/details/13408/0>`_ ,
   also known as the Forest Small Rice Rat, a rodent that lives in Peru,
   Colombia, Ecuador, Peru, and Venezuela.

References
----------

`"Maximum entropy modeling of species geographic distributions"
<http://rob.schapire.net/papers/ecolmod.pdf>`_ S. J. Phillips,
R. P. Anderson, R. E. Schapire - Ecological Modelling, 190:231-259, 2006.
é    N)ÚBytesIO)ÚIntegralÚReal)ÚPathLikeÚmakedirsÚremove)Úexistsé   )ÚBunch)ÚIntervalÚvalidate_paramsé   )Úget_data_home)ÚRemoteFileMetadataÚ_fetch_remoteÚ_pkl_filepathzsamples.zipz.https://ndownloader.figshare.com/files/5976075Ú@abb07ad284ac50d9e6d20f1c4211e0fd3c098f7f85955e89d321ee8efe37ac28)ÚfilenameÚurlÚchecksumzcoverages.zipz.https://ndownloader.figshare.com/files/5976078Ú@4d862674d72e79d6cee77e63b98651ec7926043ba7d39dcb31329cf3f6073807zspecies_coverage.pkzé   c                 ó  — t        |«      D �cg c]  }| j                  «       ‘Œ }}d„ }t        |D �cg c]
  } ||«      ‘Œ c}«      }t        j                  | |¬«      }t        |d   «      }|dk7  rd||<   |S c c}w c c}w )zjLoad a coverage file from an open file object.

    This will return a numpy array of the given dtype
    c                 ó`   — | j                  «       d   t        | j                  «       d   «      fS )Nr   r   )ÚsplitÚfloat)Úts    úe/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/datasets/_species_distributions.pyú<lambda>z _load_coverage.<locals>.<lambda>I   s$   € ˜AŸG™G›I a™L¬%°·±³	¸!±Ó*=Ð>€ ó    ©Údtypes   NODATA_valueiñØÿÿ)ÚrangeÚreadlineÚdictÚnpÚloadtxtÚint)	ÚFÚheader_lengthr"   Ú_ÚheaderÚ
make_tupleÚlineÚMÚnodatas	            r   Ú_load_coverager1   C   s}   € ô
 %*¨-Ó$8Ö9˜qˆa�j‰j�lÐ9€FÐ9Ù>€JÜ°Ö7¨‘:˜dÕ#Ò7Ó8€Fä
�
‰
�1˜EÔ"€AÜ�˜Ñ(Ó)€FØ�‚Øˆˆ&‰	Ø€Hùò :ùâ7s
   ŽA:³A?c                 óÒ   — | j                  «       j                  d«      j                  «       j                  d«      }t	        j
                  | ddd¬«      }||j                  _        |S )zÃLoad csv file.

    Parameters
    ----------
    F : file object
        CSV file open in byte mode.

    Returns
    -------
    rec : np.ndarray
        record array representing the data
    Úasciiú,r   z	S22,f4,f4)ÚskiprowsÚ	delimiterr"   )r$   ÚdecodeÚstripr   r&   r'   r"   Únames)r)   r9   Úrecs      r   Ú	_load_csvr;   S   sR   € ð �J‰J‹L×Ñ Ó(×.Ñ.Ó0×6Ñ6°sÓ;€Eä
�*‰*�Q ¨c¸Ô
E€CØ€C‡I�I„OØ€Jr    c                 ób  — | j                   | j                  z   }|| j                  | j                  z  z   }| j                  | j                  z   }|| j                  | j                  z  z   }t        j                  ||| j                  «      }t        j                  ||| j                  «      }||fS )a%  Construct the map grid from the batch object

    Parameters
    ----------
    batch : Batch object
        The object returned by :func:`fetch_species_distributions`

    Returns
    -------
    (xgrid, ygrid) : 1-D arrays
        The grid corresponding to the values in batch.coverages
    )Úx_left_lower_cornerÚ	grid_sizeÚNxÚy_left_lower_cornerÚNyr&   Úarange)ÚbatchÚxminÚxmaxÚyminÚymaxÚxgridÚygrids          r   Úconstruct_gridsrJ   g   s’   € ð ×$Ñ$ u§¡Ñ6€DØ�5—8‘8˜eŸo™oÑ-Ñ.€DØ×$Ñ$ u§¡Ñ6€DØ�5—8‘8˜eŸo™oÑ-Ñ.€Dô �I‰I�d˜D %§/¡/Ó2€Eä�I‰I�d˜D %§/¡/Ó2€Eà�5ˆ>Ðr    ÚbooleanÚleft)Úclosedg        Úneither)Ú	data_homeÚdownload_if_missingÚ	n_retriesÚdelayT)Úprefer_skip_nested_validationé   g      ð?c                 ó†  — t        | «      } t        | «      st        | «       t        ddddd¬«      }t        j
                  }t        | t        «      }t        |«      �sµ|st        d«      ‚t        j                  dt        j                  ›d	| ›�«       t        t        | ||¬
«      }t	        j                  |«      5 }|j                  D ]/  }	t!        ||	   «      }
d|	v rt#        |
«      }d|	v sŒ%t#        |
«      }Œ1 	 ddd«       t%        |«       t        j                  dt&        j                  ›d	| ›�«       t        t&        | ||¬
«      }t	        j                  |«      5 }g }|j                  D ]N  }	t!        ||	   «      }
t        j)                  dj+                  |	«      «       |j-                  t/        |
«      «       ŒP t	        j0                  ||¬«      }ddd«       t%        |«       t3        ddœ|¤Ž}t5        j6                  ||d¬«       |S t5        j                  |«      }|S # 1 sw Y   �Œ0xY w# 1 sw Y   ŒaxY w)a  Loader for species distribution dataset from Phillips et. al. (2006).

    Read more in the :ref:`User Guide <species_distribution_dataset>`.

    Parameters
    ----------
    data_home : str or path-like, default=None
        Specify another download and cache folder for the datasets. By default
        all scikit-learn data is stored in '~/scikit_learn_data' subfolders.

    download_if_missing : bool, default=True
        If False, raise an OSError if the data is not locally available
        instead of trying to download the data from the source site.

    n_retries : int, default=3
        Number of retries when HTTP errors are encountered.

        .. versionadded:: 1.5

    delay : float, default=1.0
        Number of seconds between retries.

        .. versionadded:: 1.5

    Returns
    -------
    data : :class:`~sklearn.utils.Bunch`
        Dictionary-like object, with the following attributes.

        coverages : array, shape = [14, 1592, 1212]
            These represent the 14 features measured
            at each point of the map grid.
            The latitude/longitude values for the grid are discussed below.
            Missing data is represented by the value -9999.
        train : record array, shape = (1624,)
            The training points for the data.  Each point has three fields:

            - train['species'] is the species name
            - train['dd long'] is the longitude, in degrees
            - train['dd lat'] is the latitude, in degrees
        test : record array, shape = (620,)
            The test points for the data.  Same format as the training data.
        Nx, Ny : integers
            The number of longitudes (x) and latitudes (y) in the grid
        x_left_lower_corner, y_left_lower_corner : floats
            The (x,y) position of the lower-left corner, in degrees
        grid_size : float
            The spacing between points of the grid, in degrees

    Notes
    -----

    This dataset represents the geographic distribution of species.
    The dataset is provided by Phillips et. al. (2006).

    The two species are:

    - `"Bradypus variegatus"
      <http://www.iucnredlist.org/details/3038/0>`_ ,
      the Brown-throated Sloth.

    - `"Microryzomys minutus"
      <http://www.iucnredlist.org/details/13408/0>`_ ,
      also known as the Forest Small Rice Rat, a rodent that lives in Peru,
      Colombia, Ecuador, Peru, and Venezuela.

    References
    ----------

    * `"Maximum entropy modeling of species geographic distributions"
      <http://rob.schapire.net/papers/ecolmod.pdf>`_
      S. J. Phillips, R. P. Anderson, R. E. Schapire - Ecological Modelling,
      190:231-259, 2006.

    Examples
    --------
    >>> from sklearn.datasets import fetch_species_distributions
    >>> species = fetch_species_distributions()
    >>> species.train[:5]
    array([(b'microryzomys_minutus', -64.7   , -17.85  ),
           (b'microryzomys_minutus', -67.8333, -16.3333),
           (b'microryzomys_minutus', -67.8833, -16.3   ),
           (b'microryzomys_minutus', -67.8   , -16.2667),
           (b'microryzomys_minutus', -67.9833, -15.9   )],
          dtype=[('species', 'S22'), ('dd long', '<f4'), ('dd lat', '<f4')])

    For a more extended example,
    see :ref:`sphx_glr_auto_examples_applications_plot_species_distribution_modeling.py`
    g33333³WÀi¼  gfffffLÀi8  gš™™™™™©?)r=   r?   r@   rA   r>   z1Data not found and `download_if_missing` is FalsezDownloading species data from z to )ÚdirnamerQ   rR   ÚtrainÚtestNzDownloading coverage data from z - converting {}r!   )Ú	coveragesrX   rW   é	   )Úcompress© )r   r	   r   r%   r&   Úint16r   ÚDATA_ARCHIVE_NAMEÚOSErrorÚloggerÚinfoÚSAMPLESr   r   ÚloadÚfilesr   r;   r   Ú	COVERAGESÚdebugÚformatÚappendr1   Úasarrayr   ÚjoblibÚdump)rO   rP   rQ   rR   Úextra_paramsr"   Úarchive_pathÚsamples_pathÚXÚfÚfhandlerW   rX   Úcoverages_pathrY   Úbunchs                   r   Úfetch_species_distributionsrt   ‚   s  € ôR ˜iÓ(€IÜ�)ÔÜ�Ôô
 Ø!ØØ"ØØô€Lô �H‰H€Eä  Ô,=Ó>€Lä�,ÕÙ"ÜÐMÓNÐNÜ�ŠÄÇÃÉYÐWÔXÜ$Ü˜Y°)À5ô
ˆô �W‰W�\Ó"ð 	. aØ—W‘Wò .�Ü! ! A¡$›-�Ø˜a‘<Ü% gÓ.�EØ˜Q’;Ü$ WÓ-‘Dñ.÷	.ô 	ˆ|Ôä�ŠÜ9B¿»É	ÐRô	
ô 'Ü˜y°IÀUô
ˆô �W‰W�^Ó$ð 	;¨ØˆIØ—W‘Wò :�Ü! ! A¡$›-�Ü—‘Ð/×6Ñ6°qÓ9Ô:Ø× Ñ ¤°Ó!8Õ9ð:ô Ÿ
™
 9°EÔ:ˆI÷	;ô 	ˆ~ÔäÐR 	°¸EÑRÀ\ÑRˆÜ�‰�E˜<°!Õ4ð €Lô —‘˜LÓ)ˆà€L÷;	.ñ 	.ú÷	;ð 	;ús   Â<1H*Ã.H*Å A7H7È*H4È7I )'Ú__doc__ÚloggingÚior   Únumbersr   r   Úosr   r   r   Úos.pathr	   rj   Únumpyr&   Úutilsr   Úutils._param_validationr   r   Ú r   Ú_baser   r   r   rb   re   r^   Ú	getLoggerÚ__name__r`   r]   r1   r;   rJ   Ústrrt   r\   r    r   ú<module>rƒ      s÷   ðñó< Ý ß "ß )Ñ )Ý ã Û å ß ?Ý ß CÑ Cñ ØØ8ØOô€ñ ØØ8ØOô€	ð +Ð ð 
ˆ×	Ñ	˜8Ó	$€ð %&¨R¯X©Xó ò ò(ñ6 à˜8 TÐ*Ø )˜{Ù˜x¨¨D¸Ô@ÐAÙ˜4  d°9Ô=Ð>ñ	ð #'ôð ØØØ
óVóñVr    