Skip to content

Commit

Permalink
Move properties to ParticleFileHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Dec 6, 2023
1 parent 502ce2a commit 51ce380
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions yt/frontends/ramses/particle_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,43 @@ def read_header(self):
It is in charge of setting `self.field_offsets` and `self.field_types`.
* `field_offsets`: dictionary: tuple -> integer
* `_field_offsets`: dictionary: tuple -> integer
A dictionary that maps `(type, field_name)` to their
location in the file (integer)
* `field_types`: dictionary: tuple -> character
* `_field_types`: dictionary: tuple -> character
A dictionary that maps `(type, field_name)` to their type
(character), following Python's struct convention.
"""
pass

@property
def field_offsets(self) -> dict[tuple[str, str], int]:
if hasattr(self, "_field_offsets"):
return self._field_offsets
self.read_header()
return self._field_offsets

@property
def field_types(self) -> dict[tuple[str, str], str]:
if hasattr(self, "_field_types"):
return self._field_types
self.read_header()
return self._field_types

@property
def local_particle_count(self) -> int:
if hasattr(self, "_local_particle_count"):
return self._local_particle_count
self.read_header()
return self._local_particle_count

@property
def header(self) -> dict[str, Any]:
if hasattr(self, "_header"):
return self._header
self.read_header()
return self._header


_default_dtypes: dict[int, str] = {
1: "c", # char
Expand Down Expand Up @@ -261,34 +289,6 @@ def build_iterator():
self._field_offsets = field_offsets
self._field_types = _pfields

@property
def field_offsets(self) -> dict[tuple[str, str], int]:
if hasattr(self, "_field_offsets"):
return self._field_offsets
self.read_header()
return self._field_offsets

@property
def field_types(self) -> dict[tuple[str, str], str]:
if hasattr(self, "_field_types"):
return self._field_types
self.read_header()
return self._field_types

@property
def local_particle_count(self) -> int:
if hasattr(self, "_local_particle_count"):
return self._local_particle_count
self.read_header()
return self._local_particle_count

@property
def header(self) -> dict[str, Any]:
if hasattr(self, "_header"):
return self._header
self.read_header()
return self._header


class SinkParticleFileHandler(ParticleFileHandler):
"""Handle sink files"""
Expand Down

0 comments on commit 51ce380

Please sign in to comment.