From 2c32713cf7d2722f5df1b99cf5c005c00b1d1916 Mon Sep 17 00:00:00 2001 From: Corentin Cadiou Date: Mon, 6 Nov 2023 15:41:48 +0000 Subject: [PATCH] oct_handler should be a read-only property --- yt/data_objects/index_subobjects/octree_subset.py | 9 +++++---- yt/frontends/art/data_structures.py | 6 +++++- yt/frontends/artio/data_structures.py | 6 +++++- yt/frontends/ramses/data_structures.py | 5 ++++- yt/frontends/stream/data_structures.py | 6 +----- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/yt/data_objects/index_subobjects/octree_subset.py b/yt/data_objects/index_subobjects/octree_subset.py index a74f5dc24f8..eb08750b9d7 100644 --- a/yt/data_objects/index_subobjects/octree_subset.py +++ b/yt/data_objects/index_subobjects/octree_subset.py @@ -1,3 +1,4 @@ +import abc from contextlib import contextmanager from functools import cached_property from itertools import product, repeat @@ -33,7 +34,7 @@ def cc_cache_func(self, dobj): return cc_cache_func -class OctreeSubset(YTSelectionContainer): +class OctreeSubset(YTSelectionContainer, abc.ABC): _spatial = True _num_ghost_zones = 0 _type_name = "octree_subset" @@ -57,10 +58,10 @@ def __init__(self, base_region, domain, ds, num_zones=2, num_ghost_zones=0): self.base_selector = base_region.selector @property + @abc.abstractmethod def oct_handler(self): - # Use an indirection so that oct_handler - # doesn't have to exist when we create the subset - return self.domain.oct_handler + # In charge of returning the oct_handler + pass def __getitem__(self, key): tr = super().__getitem__(key) diff --git a/yt/frontends/art/data_structures.py b/yt/frontends/art/data_structures.py index 5c5281cc1b1..a901f780e3b 100644 --- a/yt/frontends/art/data_structures.py +++ b/yt/frontends/art/data_structures.py @@ -798,7 +798,11 @@ def __init__(self, ds, nvar, oct_handler, domain_id): self._level_count = None self._level_oct_offsets = None self._level_child_offsets = None - self.oct_handler = oct_handler + self._oct_handler = oct_handler + + @property + def oct_handler(self): + return self._oct_handler @property def level_count(self): diff --git a/yt/frontends/artio/data_structures.py b/yt/frontends/artio/data_structures.py index 45052f01552..c220c5f82be 100644 --- a/yt/frontends/artio/data_structures.py +++ b/yt/frontends/artio/data_structures.py @@ -34,7 +34,7 @@ def __init__(self, base_region, sfc_start, sfc_end, oct_handler, ds): self.field_parameters = {} self.sfc_start = sfc_start self.sfc_end = sfc_end - self.oct_handler = oct_handler + self._oct_handler = oct_handler self.ds = ds self._last_mask = None self._last_selector_id = None @@ -43,6 +43,10 @@ def __init__(self, base_region, sfc_start, sfc_end, oct_handler, ds): self.base_region = base_region self.base_selector = base_region.selector + @property + def oct_handler(self): + return self._oct_handler + @property def min_ind(self): return self.sfc_start diff --git a/yt/frontends/ramses/data_structures.py b/yt/frontends/ramses/data_structures.py index abed7c157c2..96b7b389aa1 100644 --- a/yt/frontends/ramses/data_structures.py +++ b/yt/frontends/ramses/data_structures.py @@ -223,7 +223,6 @@ def __init__(self, ds, domain_id): "Detected particle type %s in domain_id=%s", ph.ptype, domain_id ) ph.read_header() - # self._add_ptype(ph.ptype) def __repr__(self): return "RAMSESDomainFile: %i" % self.domain_id @@ -385,6 +384,10 @@ def __init__( "of ghost zones, was called with num_ghost_zones=%s" % num_ghost_zones ) + @property + def oct_handler(self): + return self.domain.oct_handler + def _fill_no_ghostzones(self, fd, fields, selector, file_handler): ndim = self.ds.dimensionality # Here we get a copy of the file, which we skip through and read the diff --git a/yt/frontends/stream/data_structures.py b/yt/frontends/stream/data_structures.py index 4cc8b58354c..e6302649375 100644 --- a/yt/frontends/stream/data_structures.py +++ b/yt/frontends/stream/data_structures.py @@ -766,7 +766,7 @@ def __init__(self, base_region, ds, oct_handler, num_zones=2, num_ghost_zones=0) self.field_data = YTFieldData() self.field_parameters = {} self.ds = ds - self.oct_handler = oct_handler + self._oct_handler = oct_handler self._last_mask = None self._last_selector_id = None self._current_particle_type = "io" @@ -788,10 +788,6 @@ def __init__(self, base_region, ds, oct_handler, num_zones=2, num_ghost_zones=0) def oct_handler(self): return self._oct_handler - @oct_handler.setter - def oct_handler(self, oh): - self._oct_handler = oh - def retrieve_ghost_zones(self, ngz, fields, smoothed=False): try: new_subset = self._subset_with_gz