[misc] May last round of bug corrections

This commit is contained in:
Noe Brucy
2022-05-31 16:15:33 +02:00
parent 6c912a5294
commit 124f24f92c
6 changed files with 129 additions and 107 deletions
+4 -5
View File
@@ -793,7 +793,7 @@ class Plotter(Aggregator, BaseProcessor):
except AttributeError: except AttributeError:
cbar = plt.colorbar() cbar = plt.colorbar()
if label is not None: if label is not None:
if text_embeded: if colorbar_embeded:
cbar.set_label(" " + label, color=overtext_color, loc="bottom") cbar.set_label(" " + label, color=overtext_color, loc="bottom")
else: else:
cbar.set_label(label) cbar.set_label(label)
@@ -824,12 +824,11 @@ class Plotter(Aggregator, BaseProcessor):
plot_overlay = self.overlays[plot_overlay] plot_overlay = self.overlays[plot_overlay]
xlim = plt.xlim() xlim = plt.xlim()
ylim = plt.ylim() ylim = plt.ylim()
try: if len(overlays_kwargs) > i:
plot_overlay(ax_los, im_extent, **overlays_kwargs[i]) plot_overlay(ax_los, im_extent, **overlays_kwargs[i])
except IndexError: else:
plot_overlay(ax_los, im_extent) plot_overlay(ax_los, im_extent)
finally:
# Restore previous limits in case overlays changed it
plt.xlim(xlim) plt.xlim(xlim)
plt.ylim(ylim) plt.ylim(ylim)
+3 -3
View File
@@ -434,7 +434,7 @@ parser.add_argument(
"repo", help="RAMSES output repository", type=str, default=".", nargs="?" "repo", help="RAMSES output repository", type=str, default=".", nargs="?"
) )
parser.add_argument( parser.add_argument(
"iouts", help="output numbers", type=args.selection, default=":", nargs="?" "iouts", help="output numbers", type=int, default=[1], nargs="+"
) )
parser.add_argument( parser.add_argument(
"outfile", "outfile",
@@ -520,7 +520,7 @@ def main(arg):
iouts = arg.iouts # tools.select_outputs(arg.repo, arg.iouts) iouts = arg.iouts # tools.select_outputs(arg.repo, arg.iouts)
for iout in iouts: for iout in iouts:
print("Output %d" % iout) print(f"Output {iout}")
print("Load data") print("Load data")
read_lvl = None read_lvl = None
if True: if True:
@@ -933,7 +933,7 @@ if __name__ == "__main__":
def pspec(**kwargs): def pspec(**kwargs):
arg = parser.parse_args("") arg = parser.parse_args("1")
for kwarg in kwargs: for kwarg in kwargs:
setattr(arg, kwarg, kwargs[kwarg]) setattr(arg, kwarg, kwargs[kwarg])
main(arg) main(arg)
+27 -10
View File
@@ -56,8 +56,7 @@ class RunSelector:
Select runs and outputs with several filter options. Select runs and outputs with several filter options.
By default, all runs and outputs within path_in are considered By default, all runs and outputs within path_in are considered
Parameters Args:
---------
1. Define the set of runs and outputs considered 1. Define the set of runs and outputs considered
@@ -146,8 +145,8 @@ class RunSelector:
""" """
Sub-select runs and outputs from already selected runs and outputs Sub-select runs and outputs from already selected runs and outputs
Parameters Args:
---------
runs : str or list of str. The name runs to consider. Default: all. runs : str or list of str. The name runs to consider. Default: all.
nums : int or list of int or str. nums : int or list of int or str.
The output numbers to consider. The output numbers to consider.
@@ -173,9 +172,7 @@ class RunSelector:
sort_run_by : str, a key from the namelist used to sort the runs (by ascending order) sort_run_by : str, a key from the namelist used to sort the runs (by ascending order)
Returns Returns:
-------
(selected_runs, selected_nums) (selected_runs, selected_nums)
""" """
@@ -301,8 +298,7 @@ class RunSelector:
""" """
Select snapshots from the disk Select snapshots from the disk
Parameters Args:
---------
in_nums : int or list of int or str. in_nums : int or list of int or str.
The output numbers to consider. The output numbers to consider.
@@ -382,7 +378,7 @@ class RunSelector:
if position == "left": if position == "left":
return ileft return ileft
elif position == "right": elif position == "right":
return nums[iright] return iright
else: else:
dleft = np.abs(get_time(nums[ileft]) - time) dleft = np.abs(get_time(nums[ileft]) - time)
dright = np.abs(get_time(nums[iright]) - time) dright = np.abs(get_time(nums[iright]) - time)
@@ -457,3 +453,24 @@ class RunSelector:
nums = list(filter(try_load_info, nums)) nums = list(filter(try_load_info, nums))
return nums return nums
def write_paths(self, prefix=None, filename="~/list_file"):
"""
Write the paths of the selected runs on a file
Args:
prefix (str, optional): Prefix for the pathscd si. Defaults to path_in.
filename (str, optional): F. Defaults to "~/list_file".
"""
if prefix is None:
prefix = self.path_in
paths = []
for run in self.nums:
for num in nums[run]:
paths.append(f"{prefix}/{run}/output_{num:05}\n")
f = open(os.path.expanduser(filename), "w")
f.writelines(paths)
f.close()
+14 -13
View File
@@ -2,10 +2,6 @@ from run_selector import RunSelector
from plotter import Plotter, U from plotter import Plotter, U
import os import os
path_from_home = "simus/ismfeed/allmode"
names = "n6_st_2e5_seed3_T5Myr_nsink1e3_comp*"
def prep_mcons(study): def prep_mcons(study):
study.coarse_step_from_log() study.coarse_step_from_log()
@@ -18,12 +14,19 @@ def time_mcons(study, run, target=0.2):
return time_target return time_target
def find_nums(study, prep_function, time_function): def find_nums(study, prep_function, time_function, time_min=0):
"""
Once other filter are applied, select one output based on the time given by time function
Args:
prep_function (study:studyProcessor -> None): prepare a study object
time_function (study:studyProcessor, run:str -> time:float): compute selected time from the object
"""
nums = {} nums = {}
prep_function(study) prep_function(study)
for run in study.runs: for run in study.runs:
time_target = time_function(study, run) time_target = max(time_min, time_function(study, run))
rs = RunSelector(path_in=in_dir, in_runs=run, time=time_target, unit_time=U.Myr) rs = RunSelector(path_in=study.path, in_runs=run, time_min=time_min, time=time_target, unit_time=U.Myr)
nums.update(rs.nums) nums.update(rs.nums)
return nums return nums
@@ -38,6 +41,10 @@ def write_paths(nums, path_from_home, filename="~/list_file"):
f.close() f.close()
if __name__ == '__main__':
path_from_home = "simus/ismfeed/allmode"
names = "n6_st_2e5_seed3_T5Myr_nsink1e3_comp*"
in_dir = os.path.expanduser(f"~/{path_from_home}") in_dir = os.path.expanduser(f"~/{path_from_home}")
study = Plotter( study = Plotter(
in_dir, in_dir,
@@ -45,11 +52,5 @@ study = Plotter(
nums="first", nums="first",
tag="select", tag="select",
).study ).study
nums = find_nums(study, prep_mcons, time_mcons) nums = find_nums(study, prep_mcons, time_mcons)
write_paths(nums, ".") write_paths(nums, ".")
pl = Plotter(in_dir, runs=nums.keys(), nums=nums)
pl.rho_pdf()
+1 -1
View File
@@ -1340,7 +1340,7 @@ class SnapshotProcessor(HDF5Container):
second_line = f.readline() second_line = f.readline()
f.close() f.close()
if first_line[1] == "#": if len(first_line) > 0 and first_line[1] == "#":
header = first_line[3:-2].split(",") header = first_line[3:-2].split(",")
units = second_line[3:-2].split(",") units = second_line[3:-2].split(",")
df = pd.read_csv(csv_name, header=None, names=header, skiprows=2) df = pd.read_csv(csv_name, header=None, names=header, skiprows=2)
+6 -1
View File
@@ -269,7 +269,7 @@ class StudyProcessor(Aggregator, HDF5Container):
return series return series
def _extract_stellar_from_log(self, stellar_objects, log_filename, run): def _extract_stellar_from_log(self, stellar_objects, log_filename, run):
cmd_grep = f"grep stellar {log_filename} -n" cmd_grep = f"grep 'stellar objects:' {log_filename} -n"
content = os.popen(cmd_grep).readlines() content = os.popen(cmd_grep).readlines()
nb_stellar = list(map(lambda s: int(s.split()[1]), content)) nb_stellar = list(map(lambda s: int(s.split()[1]), content))
line_numbers = list(map(lambda s: int(s.split(":")[0]), content)) line_numbers = list(map(lambda s: int(s.split(":")[0]), content))
@@ -440,8 +440,13 @@ class StudyProcessor(Aggregator, HDF5Container):
def get_coldens0(self, run): def get_coldens0(self, run):
mp = 1.4 * 1.66 * 10**(-24) * U.g mp = 1.4 * 1.66 * 10**(-24) * U.g
try:
z0 = self.get_nml("galbox_params/height0", run) * U.pc z0 = self.get_nml("galbox_params/height0", run) * U.pc
n0 = self.get_nml("galbox_params/dens0", run) * U.cm**(-3) n0 = self.get_nml("galbox_params/dens0", run) * U.cm**(-3)
except KeyError:
z0 = self.get_nml("cloud_params/height0", run) * U.pc
n0 = self.get_nml("cloud_params/dens0", run) * U.cm**(-3)
return (np.sqrt(2 * np.pi) * mp * z0 * n0).express(U.coldens) return (np.sqrt(2 * np.pi) * mp * z0 * n0).express(U.coldens)
def total_mass(self): def total_mass(self):