3
���h&= � @ s� d dl Z d dlZddlmZ ddlmZmZmZm Z ddl
mZmZm
Z
dd d
�Zdd� Zd
d� Zdd� Zdd� Zddd�Zddd�ZdS )� N� )�utils)� iteritems�reduce�OrderedDict�
basestring)�Variable�as_variable�
Coordinate�all� different�equalsc
C s� ddl m} ddlm}
ytj| �\}} W n tk
rF td��Y nX |dkrdtj dt
dd� d }|dk r�tj d
t
dd� |}|dk r�td��|dk r�td��t||
�r�t}nt|| �r�t
}ntd
��|| |||||�S )a� Concatenate xarray objects along a new or existing dimension.
Parameters
----------
objs : sequence of Dataset and DataArray objects
xarray objects to concatenate together. Each object is expected to
consist of variables and coordinates with matching shapes except for
along the concatenated dimension.
dim : str or DataArray or pandas.Index
Name of the dimension to concatenate along. This can either be a new
dimension name, in which case it is added along axis=0, or an existing
dimension name, in which case the location of the dimension is
unchanged. If dimension is provided as a DataArray or Index, its name
is used as the dimension to concatenate along and the values are added
as a coordinate.
data_vars : {'minimal', 'different', 'all' or list of str}, optional
These data variables will be concatenated together:
* 'minimal': Only data variables in which the dimension already
appears are included.
* 'different': Data variables which are not equal (ignoring
attributes) across all datasets are also concatenated (as well as
all for which dimension already appears). Beware: this option may
load the data payload of data variables into memory if they are not
already loaded.
* 'all': All data variables will be concatenated.
* list of str: The listed data variables will be concatenated, in
addition to the 'minimal' data variables.
If objects are DataArrays, data_vars must be 'all'.
coords : {'minimal', 'different', 'all' o list of str}, optional
These coordinate variables will be concatenated together:
* 'minimal': Only coordinates in which the dimension already appears
are included.
* 'different': Coordinates which are not equal (ignoring attributes)
across all datasets are also concatenated (as well as all for which
dimension already appears). Beware: this option may load the data
payload of coordinate variables into memory if they are not already
loaded.
* 'all': All coordinate variables will be concatenated, except
those corresponding to other dimensions.
* list of str: The listed coordinate variables will be concatenated,
in addition the 'minimal' coordinates.
compat : {'equals', 'identical'}, optional
String indicating how to compare non-concatenated variables and
dataset global attributes for potential conflicts. 'equals' means
that all variable values and dimensions must be the same;
'identical' means that variable attributes and global attributes
must also be equal.
positions : None or list of integer arrays, optional
List of integer arrays which specifies the integer positions to which
to assign each dataset along the concatenated dimension. If not
supplied, objects are concatenated in the provided order.
indexers, mode, concat_over : deprecated
Returns
-------
concatenated : type of objs
See also
--------
auto_combine
r )�Dataset)� DataArrayz.must supply at least one object to concatenateNz�the `dim` argument to `concat` will be required in a future version of xarray; for now, setting it to the old default of 'concat_dim'� )�
stacklevel�concat_dimsz_indexers has been renamed to positions; the alias will be removed in a future version of xarrayzt`mode` is no longer a valid argument to xarray.concat; it has been split into the `data_vars` and `coords` argumentsz{`concat_over` is no longer a valid argument to xarray.concat; it has been split into the `data_vars` and `coords` argumentsz9can only concatenate xarray Dataset and DataArray objects)�datasetr Z dataarrayr r Zpeek_at�
StopIteration�
ValueError�warnings�warn�
FutureWarning�
isinstance�_dataarray_concat�_dataset_concat� TypeError)
�objs�dim� data_vars�coords�compat� positionsZindexers�mode�concat_overr r Z first_obj�f� r& |