If obj is a DataArray or Dataset, return a new object of the same type and with the same variables and dtypes, but where all variables have size 0 and numpy backend. If obj is neither a DataArray nor Dataset, return it unaltered.
(obj)
| 89 | |
| 90 | |
| 91 | def make_meta(obj): |
| 92 | """If obj is a DataArray or Dataset, return a new object of the same type and with |
| 93 | the same variables and dtypes, but where all variables have size 0 and numpy |
| 94 | backend. |
| 95 | If obj is neither a DataArray nor Dataset, return it unaltered. |
| 96 | """ |
| 97 | if isinstance(obj, DataArray): |
| 98 | obj_array = obj |
| 99 | obj = dataarray_to_dataset(obj) |
| 100 | elif isinstance(obj, Dataset): |
| 101 | obj_array = None |
| 102 | else: |
| 103 | return obj |
| 104 | |
| 105 | from dask.array.utils import meta_from_array |
| 106 | |
| 107 | meta = Dataset() |
| 108 | for name, variable in obj.variables.items(): |
| 109 | meta_obj = meta_from_array(variable.data, ndim=variable.ndim) |
| 110 | meta[name] = (variable.dims, meta_obj, variable.attrs) |
| 111 | meta.attrs = obj.attrs |
| 112 | meta = meta.set_coords(obj.coords) |
| 113 | |
| 114 | if obj_array is not None: |
| 115 | return dataset_to_dataarray(meta) |
| 116 | return meta |
| 117 | |
| 118 | |
| 119 | def infer_template( |
searching dependent graphs…