diff --git a/run_selector.py b/run_selector.py index 80c1877..a1e7e6f 100644 --- a/run_selector.py +++ b/run_selector.py @@ -51,6 +51,7 @@ class RunSelector: time_max=None, time=None, unit_time=None, + allow_nodata=False, ): """ Select runs and outputs with several filter options. @@ -84,6 +85,7 @@ class RunSelector: time_max : float, select output where time <= time_min (in code units) time : float or list of float. For each value, select the output closer to it. unit_time : astrophysix.Unit, unit for the time above. None is code unit. + allow_nodata : allow runs whith only postprocessed datas 3. Sort the runs @@ -97,6 +99,8 @@ class RunSelector: self.namelist = {} self.runs = self.get_runs(in_runs, filter_name, filter_nml, sort_run_by) + self.allow_nodata = allow_nodata + self.info = {} for run in self.runs: self.info[run] = {} @@ -281,8 +285,10 @@ class RunSelector: info_filename_folder = f"{self.path_in}/{run}/info/info_{num:05}.txt" if os.path.exists(info_filename_output): info = read_ramses_info_file(info_filename_output) - else: + elif self.allow_nodata: info = read_ramses_info_file(info_filename_folder) + else: + raise IOError return info def get_nums( @@ -336,10 +342,16 @@ class RunSelector: def get_time(num): return self.info[run][num]["time"] - else: - + elif isinstance(unit_time, str): + + factor = self.get_nml_value(unit_time, run) def get_time(num): - time_code = self.info[run][num]["time"] + time_code = self.info[run][num]["time"] + return time_code / factor + + else: + def get_time(num): + time_code = self.info[run][num]["time"] return time_code * self.info[run][num]["unit_time"].express(unit_time) # -- A function to search a given time using dichotomy @@ -466,7 +478,7 @@ class RunSelector: prefix = self.path_in paths = [] for run in self.nums: - for num in nums[run]: + for num in self.nums[run]: paths.append(f"{prefix}/{run}/output_{num:05}\n") f = open(os.path.expanduser(filename), "w") f.writelines(paths)