Concatenate variables along a new or existing dimension. Parameters ---------- variables : iterable of Variable Arrays to stack together. Each variable is expected to have matching dimensions and shape except for along the stacked dimension. dim : str or Data
(
variables,
dim="concat_dim",
positions=None,
shortcut=False,
combine_attrs="override",
)
| 3080 | |
| 3081 | |
| 3082 | def concat( |
| 3083 | variables, |
| 3084 | dim="concat_dim", |
| 3085 | positions=None, |
| 3086 | shortcut=False, |
| 3087 | combine_attrs="override", |
| 3088 | ): |
| 3089 | """Concatenate variables along a new or existing dimension. |
| 3090 | |
| 3091 | Parameters |
| 3092 | ---------- |
| 3093 | variables : iterable of Variable |
| 3094 | Arrays to stack together. Each variable is expected to have |
| 3095 | matching dimensions and shape except for along the stacked |
| 3096 | dimension. |
| 3097 | dim : str or DataArray, optional |
| 3098 | Name of the dimension to stack along. This can either be a new |
| 3099 | dimension name, in which case it is added along axis=0, or an |
| 3100 | existing dimension name, in which case the location of the |
| 3101 | dimension is unchanged. Where to insert the new dimension is |
| 3102 | determined by the first variable. |
| 3103 | positions : None or list of array-like, optional |
| 3104 | List of integer arrays which specifies the integer positions to which |
| 3105 | to assign each dataset along the concatenated dimension. If not |
| 3106 | supplied, objects are concatenated in the provided order. |
| 3107 | shortcut : bool, optional |
| 3108 | This option is used internally to speed-up groupby operations. |
| 3109 | If `shortcut` is True, some checks of internal consistency between |
| 3110 | arrays to concatenate are skipped. |
| 3111 | combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ |
| 3112 | "override"}, default: "override" |
| 3113 | String indicating how to combine attrs of the objects being merged: |
| 3114 | |
| 3115 | - "drop": empty attrs on returned Dataset. |
| 3116 | - "identical": all attrs must be the same on every object. |
| 3117 | - "no_conflicts": attrs from all objects are combined, any that have |
| 3118 | the same name must also have the same value. |
| 3119 | - "drop_conflicts": attrs from all objects are combined, any that have |
| 3120 | the same name but different values are dropped. |
| 3121 | - "override": skip comparing and copy attrs from the first dataset to |
| 3122 | the result. |
| 3123 | |
| 3124 | Returns |
| 3125 | ------- |
| 3126 | stacked : Variable |
| 3127 | Concatenated Variable formed by stacking all the supplied variables |
| 3128 | along the given dimension. |
| 3129 | """ |
| 3130 | variables = list(variables) |
| 3131 | if all(isinstance(v, IndexVariable) for v in variables): |
| 3132 | return IndexVariable.concat(variables, dim, positions, shortcut, combine_attrs) |
| 3133 | else: |
| 3134 | return Variable.concat(variables, dim, positions, shortcut, combine_attrs) |
| 3135 | |
| 3136 | |
| 3137 | def calculate_dimensions(variables: Mapping[Any, Variable]) -> dict[Hashable, int]: |
searching dependent graphs…