Skip to content

Commit

Permalink
check for indetifier directly in path and support damping id in fargocpt
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rometsch committed Oct 20, 2023
1 parent e737bcd commit 0b96753
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/disgrid/loaders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from copy import deepcopy
import os

class UnknownCodeError(Exception):
pass
Expand Down Expand Up @@ -27,9 +28,20 @@ class MultipleCodeError(Exception):
available[PLUTO42.code_info] = PLUTO42
available[PLUTO43.code_info] = PLUTO43

smoking_guns = dict()
for key, mod in available.items():
try:
smoking_guns[key] = mod.smoking_gun
except AttributeError:
pass


def identify_code(path, choices=available):
code_list = []
# first check if a smoking gun file is present
for key, sg in smoking_guns.items():
if os.path.exists(os.path.join(path, sg)):
return deepcopy(key)
for key, mod in choices.items():
if mod.identify(path):
code_list.append(key)
Expand Down
8 changes: 8 additions & 0 deletions src/disgrid/loaders/fargocpt_1_2/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
identifier = "fargocpt_output_v1_2"
code_info = ("fargocpt", "1.2", "output v1.2")

smoking_gun = identifier

def identify(path):

Expand Down Expand Up @@ -249,6 +250,7 @@ def load_times(self):
# self.datadir_path("snapshots/timeSnapshot.dat"), "time step")
self._output_times_dict = {
n: t for n, t in zip(self._snapshot_numbers, self._output_times)}
self._output_times_dict["damping"] = self._output_times[0]
self._fine_output_times = loadscalar.load_text_data_file(
self.datadir_path("monitor/Quantities.dat"), "physical time")
self.spec["output_times"] = (
Expand Down Expand Up @@ -297,6 +299,12 @@ def get_particles(self):
p = re.compile(r"([\d]+)")
timesteps = []
datafile_pattern = "snapshots/{}/particles.dat"

# exit if there is no particles file in the last snapshot
last_particle_file = datafile_pattern.format(self._snapshot_numbers[-1])
if not os.path.exists(os.path.join(self.data_dir, last_particle_file)):
return

for s in os.listdir(os.path.join(self.data_dir, "snapshots")):
m = re.match(p, s)
if m:
Expand Down

0 comments on commit 0b96753

Please sign in to comment.