[misc] May last round of bug corrections
This commit is contained in:
+4
-5
@@ -793,7 +793,7 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
except AttributeError:
|
||||
cbar = plt.colorbar()
|
||||
if label is not None:
|
||||
if text_embeded:
|
||||
if colorbar_embeded:
|
||||
cbar.set_label(" " + label, color=overtext_color, loc="bottom")
|
||||
else:
|
||||
cbar.set_label(label)
|
||||
@@ -824,12 +824,11 @@ class Plotter(Aggregator, BaseProcessor):
|
||||
plot_overlay = self.overlays[plot_overlay]
|
||||
xlim = plt.xlim()
|
||||
ylim = plt.ylim()
|
||||
try:
|
||||
if len(overlays_kwargs) > i:
|
||||
plot_overlay(ax_los, im_extent, **overlays_kwargs[i])
|
||||
except IndexError:
|
||||
else:
|
||||
plot_overlay(ax_los, im_extent)
|
||||
finally:
|
||||
# Restore previous limits in case overlays changed it
|
||||
|
||||
plt.xlim(xlim)
|
||||
plt.ylim(ylim)
|
||||
|
||||
|
||||
+3
-3
@@ -434,7 +434,7 @@ parser.add_argument(
|
||||
"repo", help="RAMSES output repository", type=str, default=".", nargs="?"
|
||||
)
|
||||
parser.add_argument(
|
||||
"iouts", help="output numbers", type=args.selection, default=":", nargs="?"
|
||||
"iouts", help="output numbers", type=int, default=[1], nargs="+"
|
||||
)
|
||||
parser.add_argument(
|
||||
"outfile",
|
||||
@@ -520,7 +520,7 @@ def main(arg):
|
||||
iouts = arg.iouts # tools.select_outputs(arg.repo, arg.iouts)
|
||||
|
||||
for iout in iouts:
|
||||
print("Output %d" % iout)
|
||||
print(f"Output {iout}")
|
||||
print("Load data")
|
||||
read_lvl = None
|
||||
if True:
|
||||
@@ -933,7 +933,7 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
def pspec(**kwargs):
|
||||
arg = parser.parse_args("")
|
||||
arg = parser.parse_args("1")
|
||||
for kwarg in kwargs:
|
||||
setattr(arg, kwarg, kwargs[kwarg])
|
||||
main(arg)
|
||||
|
||||
+27
-10
@@ -56,8 +56,7 @@ class RunSelector:
|
||||
Select runs and outputs with several filter options.
|
||||
By default, all runs and outputs within path_in are considered
|
||||
|
||||
Parameters
|
||||
---------
|
||||
Args:
|
||||
|
||||
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
|
||||
|
||||
Parameters
|
||||
---------
|
||||
Args:
|
||||
|
||||
runs : str or list of str. The name runs to consider. Default: all.
|
||||
nums : int or list of int or str.
|
||||
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)
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
||||
Returns:
|
||||
(selected_runs, selected_nums)
|
||||
"""
|
||||
|
||||
@@ -301,8 +298,7 @@ class RunSelector:
|
||||
"""
|
||||
Select snapshots from the disk
|
||||
|
||||
Parameters
|
||||
---------
|
||||
Args:
|
||||
|
||||
in_nums : int or list of int or str.
|
||||
The output numbers to consider.
|
||||
@@ -382,7 +378,7 @@ class RunSelector:
|
||||
if position == "left":
|
||||
return ileft
|
||||
elif position == "right":
|
||||
return nums[iright]
|
||||
return iright
|
||||
else:
|
||||
dleft = np.abs(get_time(nums[ileft]) - time)
|
||||
dright = np.abs(get_time(nums[iright]) - time)
|
||||
@@ -457,3 +453,24 @@ class RunSelector:
|
||||
nums = list(filter(try_load_info, 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()
|
||||
|
||||
|
||||
|
||||
|
||||
+19
-18
@@ -2,10 +2,6 @@ from run_selector import RunSelector
|
||||
from plotter import Plotter, U
|
||||
import os
|
||||
|
||||
path_from_home = "simus/ismfeed/allmode"
|
||||
names = "n6_st_2e5_seed3_T5Myr_nsink1e3_comp*"
|
||||
|
||||
|
||||
def prep_mcons(study):
|
||||
study.coarse_step_from_log()
|
||||
|
||||
@@ -18,12 +14,19 @@ def time_mcons(study, run, target=0.2):
|
||||
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 = {}
|
||||
prep_function(study)
|
||||
for run in study.runs:
|
||||
time_target = time_function(study, run)
|
||||
rs = RunSelector(path_in=in_dir, in_runs=run, time=time_target, unit_time=U.Myr)
|
||||
time_target = max(time_min, time_function(study, run))
|
||||
rs = RunSelector(path_in=study.path, in_runs=run, time_min=time_min, time=time_target, unit_time=U.Myr)
|
||||
nums.update(rs.nums)
|
||||
return nums
|
||||
|
||||
@@ -38,18 +41,16 @@ def write_paths(nums, path_from_home, filename="~/list_file"):
|
||||
f.close()
|
||||
|
||||
|
||||
in_dir = os.path.expanduser(f"~/{path_from_home}")
|
||||
study = Plotter(
|
||||
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}")
|
||||
study = Plotter(
|
||||
in_dir,
|
||||
filter_name=names,
|
||||
nums="first",
|
||||
tag="select",
|
||||
).study
|
||||
|
||||
|
||||
nums = find_nums(study, prep_mcons, time_mcons)
|
||||
write_paths(nums, ".")
|
||||
|
||||
pl = Plotter(in_dir, runs=nums.keys(), nums=nums)
|
||||
|
||||
pl.rho_pdf()
|
||||
).study
|
||||
nums = find_nums(study, prep_mcons, time_mcons)
|
||||
write_paths(nums, ".")
|
||||
@@ -1340,7 +1340,7 @@ class SnapshotProcessor(HDF5Container):
|
||||
second_line = f.readline()
|
||||
f.close()
|
||||
|
||||
if first_line[1] == "#":
|
||||
if len(first_line) > 0 and first_line[1] == "#":
|
||||
header = first_line[3:-2].split(",")
|
||||
units = second_line[3:-2].split(",")
|
||||
df = pd.read_csv(csv_name, header=None, names=header, skiprows=2)
|
||||
|
||||
+6
-1
@@ -269,7 +269,7 @@ class StudyProcessor(Aggregator, HDF5Container):
|
||||
return series
|
||||
|
||||
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()
|
||||
nb_stellar = list(map(lambda s: int(s.split()[1]), 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):
|
||||
mp = 1.4 * 1.66 * 10**(-24) * U.g
|
||||
try:
|
||||
z0 = self.get_nml("galbox_params/height0", run) * U.pc
|
||||
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)
|
||||
|
||||
def total_mass(self):
|
||||
|
||||
Reference in New Issue
Block a user