U
    Cvf*+                     @  s  U d dl mZ d dlZd dlmZmZmZ d dlmZ er|zd dl	m
Z
 W n ek
rb   eZ
Y nX ed ZG dd deZd	d
ddddddddddddddddddZded< ed	ddddgZeddgZdddddZejeeejedd  d!d  d"d  d#d  d$d  d%d  d&d  ed'd  d(d  d)d  d*d  d+Zd,d-d.d/Zd0d1 Zeed2Zd3ddd4d5d6Zddd7d8d9ZG d:d; d;Zd<d= ZdS )>    )annotationsN)TYPE_CHECKINGLiteral	TypedDict)
FrozenDict)Colormap)arithmetic_joincmap_divergentcmap_sequentialdisplay_max_rowsdisplay_values_thresholddisplay_styledisplay_widthdisplay_expand_attrsdisplay_expand_coordsdisplay_expand_data_varsdisplay_expand_datadisplay_expand_indexesdisplay_default_indexesenable_cftimeindexfile_cache_maxsize
keep_attrswarn_for_unclosed_filesuse_bottleneckuse_floxc                   @  s   e Zd ZU ded< ded< ded< ded< ded< d	ed
< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< ded< dS )	T_Optionsz5Literal[('inner', 'outer', 'left', 'right', 'exact')]r   zstr | Colormapr	   r
   intr   r   zLiteral[('text', 'html')]r   r   z!Literal[('default', True, False)]r   r   r   r   r   r   boolr   r   r   r   r   r   N)__name__
__module____qualname____annotations__ r"   r"   7/tmp/pip-unpacked-wheel-h316xyqg/xarray/core/options.pyr   #   s&   
r   innerZRdBu_rZviridis      htmlP   defaultFT   OPTIONSouterleftrightexacttextr   r   )valuereturnc                 C  s   t | to| dkS )Nr   )
isinstancer   r1   r"   r"   r#   _positive_integerS   s    r5   c                 C  s   | dkS N)TFr)   r"   choicer"   r"   r#   <lambda>]       r9   c                 C  s   | dkS r6   r"   r7   r"   r"   r#   r9   ^   r:   c                 C  s   | dkS r6   r"   r7   r"   r"   r#   r9   _   r:   c                 C  s   | dkS r6   r"   r7   r"   r"   r#   r9   `   r:   c                 C  s   | dkS r6   r"   r7   r"   r"   r#   r9   a   r:   c                 C  s   | dkS r6   r"   r7   r"   r"   r#   r9   b   r:   c                 C  s
   t | tS Nr3   r   r4   r"   r"   r#   r9   c   r:   c                 C  s   | dkS r6   r"   r7   r"   r"   r#   r9   e   r:   c                 C  s
   t | tS r;   r<   r4   r"   r"   r#   r9   f   r:   c                 C  s
   t | tS r;   r<   r4   r"   r"   r#   r9   g   r:   c                 C  s
   t | tS r;   r<   r4   r"   r"   r#   r9   h   r:   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   None)r2   c                 C  s   ddl m} | |_d S )Nr   )
FILE_CACHE)Zxarray.backends.file_managerr>   maxsize)r1   r>   r"   r"   r#   _set_file_cache_maxsizel   s    r@   c                 C  s   t dt d S )Nz_The enable_cftimeindex option is now a no-op and will be removed in a future version of xarray.)warningswarnFutureWarning)r   r"   r"   r#   #_warn_on_setting_enable_cftimeindexr   s    rD   )r   r   Options)optionr)   r2   c                 C  s6   t |  }|dkr|S t|tr"|S td|  dd S )Nr)   zThe global option z) must be one of True, False or 'default'.)r+   r3   r   
ValueError)rF   r)   Zglobal_choicer"   r"   r#   _get_boolean_with_default   s    

rH   )r)   r2   c                 C  s
   t d| S )Nr   )rH   )r)   r"   r"   r#   _get_keep_attrs   s    rI   c                   @  s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )set_optionsa  
    Set options for xarray in a controlled context.

    Parameters
    ----------
    arithmetic_join : {"inner", "outer", "left", "right", "exact"}, default: "inner"
        DataArray/Dataset alignment in binary operations:

        - "outer": use the union of object indexes
        - "inner": use the intersection of object indexes
        - "left": use indexes from the first object with each dimension
        - "right": use indexes from the last object with each dimension
        - "exact": instead of aligning, raise `ValueError` when indexes to be
          aligned are not equal
        - "override": if indexes are of same size, rewrite indexes to be
          those of the first object with that dimension. Indexes for the same
          dimension must have the same size in all objects.

    cmap_divergent : str or matplotlib.colors.Colormap, default: "RdBu_r"
        Colormap to use for divergent data plots. If string, must be
        matplotlib built-in colormap. Can also be a Colormap object
        (e.g. mpl.cm.magma)
    cmap_sequential : str or matplotlib.colors.Colormap, default: "viridis"
        Colormap to use for nondivergent data plots. If string, must be
        matplotlib built-in colormap. Can also be a Colormap object
        (e.g. mpl.cm.magma)
    display_expand_attrs : {"default", True, False}
        Whether to expand the attributes section for display of
        ``DataArray`` or ``Dataset`` objects. Can be

        * ``True`` : to always expand attrs
        * ``False`` : to always collapse attrs
        * ``default`` : to expand unless over a pre-defined limit
    display_expand_coords : {"default", True, False}
        Whether to expand the coordinates section for display of
        ``DataArray`` or ``Dataset`` objects. Can be

        * ``True`` : to always expand coordinates
        * ``False`` : to always collapse coordinates
        * ``default`` : to expand unless over a pre-defined limit
    display_expand_data : {"default", True, False}
        Whether to expand the data section for display of ``DataArray``
        objects. Can be

        * ``True`` : to always expand data
        * ``False`` : to always collapse data
        * ``default`` : to expand unless over a pre-defined limit
    display_expand_data_vars : {"default", True, False}
        Whether to expand the data variables section for display of
        ``Dataset`` objects. Can be

        * ``True`` : to always expand data variables
        * ``False`` : to always collapse data variables
        * ``default`` : to expand unless over a pre-defined limit
    display_expand_indexes : {"default", True, False}
        Whether to expand the indexes section for display of
        ``DataArray`` or ``Dataset``. Can be

        * ``True`` : to always expand indexes
        * ``False`` : to always collapse indexes
        * ``default`` : to expand unless over a pre-defined limit (always collapse for html style)
    display_max_rows : int, default: 12
        Maximum display rows.
    display_values_threshold : int, default: 200
        Total number of array elements which trigger summarization rather
        than full repr for variable data views (numpy arrays).
    display_style : {"text", "html"}, default: "html"
        Display style to use in jupyter for xarray objects.
    display_width : int, default: 80
        Maximum display width for ``repr`` on xarray objects.
    file_cache_maxsize : int, default: 128
        Maximum number of open files to hold in xarray's
        global least-recently-usage cached. This should be smaller than
        your system's per-process file descriptor limit, e.g.,
        ``ulimit -n`` on Linux.
    keep_attrs : {"default", True, False}
        Whether to keep attributes on xarray Datasets/dataarrays after
        operations. Can be

        * ``True`` : to always keep attrs
        * ``False`` : to always discard attrs
        * ``default`` : to use original logic that attrs should only
          be kept in unambiguous circumstances
    use_bottleneck : bool, default: True
        Whether to use ``bottleneck`` to accelerate 1D reductions and
        1D rolling reduction operations.
    use_flox : bool, default: True
        Whether to use ``numpy_groupies`` and `flox`` to
        accelerate groupby and resampling reductions.
    warn_for_unclosed_files : bool, default: False
        Whether or not to issue a warning when unclosed files are
        deallocated. This is mostly useful for debugging.

    Examples
    --------
    It is possible to use ``set_options`` either as a context manager:

    >>> ds = xr.Dataset({"x": np.arange(1000)})
    >>> with xr.set_options(display_width=40):
    ...     print(ds)
    ...
    <xarray.Dataset>
    Dimensions:  (x: 1000)
    Coordinates:
      * x        (x) int64 0 1 2 ... 998 999
    Data variables:
        *empty*

    Or to set global options:

    >>> xr.set_options(display_width=80)  # doctest: +ELLIPSIS
    <xarray.core.options.set_options object at 0x...>
    c                 K  s   i | _ | D ]\}}|tkr6td|dtt|tkrt| |s|dkr^dt}n|dkrrdt}nd}td|d|d	| t| | j |< q| | d S )
Nzargument name z$ is not in the set of valid options r   zExpected one of r    zoption z given an invalid value: z. )	olditemsr+   rG   set_VALIDATORS_JOIN_OPTIONS_DISPLAY_OPTIONS_apply_update)selfkwargskvexpectedr"   r"   r#   __init__  s"    zset_options.__init__c                 C  s4   |  D ]\}}|tkrt| | qt| d S r;   )rM   _SETTERSr+   update)rS   Zoptions_dictrU   rV   r"   r"   r#   rR     s    zset_options._apply_updatec                 C  s   d S r;   r"   )rS   r"   r"   r#   	__enter__  s    zset_options.__enter__c                 C  s   |  | j d S r;   )rR   rL   )rS   typer1   	tracebackr"   r"   r#   __exit__!  s    zset_options.__exit__N)r   r   r    __doc__rX   rR   r[   r^   r"   r"   r"   r#   rJ      s
   rrJ   c                   C  s   t tS )zO
    Get options for xarray.

    See Also
    ----------
    set_options

    )r   r+   r"   r"   r"   r#   get_options%  s    	r`   )
__future__r   rA   typingr   r   r   Zxarray.core.utilsr   Zmatplotlib.colorsr   ImportErrorstrrE   r   r+   r!   	frozensetrP   rQ   r5   __contains__rO   r@   rD   rY   rH   rI   rJ   r`   r"   r"   r"   r#   <module>   s    
	 