def _slice_datasets(self, dataset_ids, slice_key, new_area, area_only=True):
        """Slice scene in-place for the datasets specified."""
        new_datasets = {}
        datasets = (self[ds_id] for ds_id in dataset_ids)
        for ds, parent_ds in dataset_walker(datasets):
            ds_id = DatasetID.from_dict(ds.attrs)
            # handle ancillary variables
            pres = None
            if parent_ds is not None:
                pres = new_datasets[DatasetID.from_dict(parent_ds.attrs)]
            if ds_id in new_datasets:
                replace_anc(ds, pres)
                continue
            if area_only and ds.attrs.get('area') is None:
                new_datasets[ds_id] = ds
                replace_anc(ds, pres)
                continue

            if not isinstance(slice_key, dict):
                # match dimension name to slice object
                key = dict(zip(ds.dims, slice_key))
            else:
                key = slice_key
            new_ds = ds.isel(**key)
            if new_area is not None:
                new_ds.attrs['area'] = new_area

            new_datasets[ds_id] = new_ds
            if parent_ds is None:
                # don't use `__setitem__` because we don't want this to
                # affect the existing wishlist/dep tree
                self.datasets[ds_id] = new_ds
            else:
                replace_anc(new_ds, pres)
def _slice_datasets ( self , dataset_ids , slice_key , new_area , area_only = True ) : new_datasets = { } datasets = ( self [ ds_id ] for ds_id in dataset_ids ) for ds , parent_ds in dataset_walker ( datasets ) : ds_id = DatasetID . from_dict ( ds . attrs ) pres = None if parent_ds is not None : pres = new_datasets [ DatasetID . from_dict ( parent_ds . attrs ) ] if ds_id in new_datasets : replace_anc ( ds , pres ) continue if area_only and ds . attrs . get ( 'area' ) is None : new_datasets [ ds_id ] = ds replace_anc ( ds , pres ) continue if not isinstance ( slice_key , dict ) : key = dict ( zip ( ds . dims , slice_key ) ) else : key = slice_key new_ds = ds . isel ( ** key ) if new_area is not None : new_ds . attrs [ 'area' ] = new_area new_datasets [ ds_id ] = new_ds if parent_ds is None : self . datasets [ ds_id ] = new_ds else : replace_anc ( new_ds , pres )
Slice scene in-place for the datasets specified.