[misc] May last round of bug corrections
This commit is contained in:
+15
-16
@@ -109,15 +109,15 @@ def quiver(ax, map_h, map_v, extent, key_v=None, label="", **kwargs):
|
||||
# add vector key
|
||||
if key_v is None:
|
||||
key_v = (max_v + min_v) / 2.0
|
||||
ax.quiverkey(
|
||||
vec_field,
|
||||
0.6,
|
||||
0.98,
|
||||
key_v,
|
||||
f"${key_v:g}$ {label}",
|
||||
labelpos="E",
|
||||
coordinates="figure",
|
||||
)
|
||||
ax.quiverkey(
|
||||
vec_field,
|
||||
0.6,
|
||||
0.98,
|
||||
key_v,
|
||||
f"${key_v:g}$ {label}",
|
||||
labelpos="E",
|
||||
coordinates="figure",
|
||||
)
|
||||
|
||||
|
||||
def line_integral_convolution(ax, map_h, map_v, extent, **kwargs):
|
||||
@@ -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,14 +824,13 @@ 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)
|
||||
|
||||
plt.xlim(xlim)
|
||||
plt.ylim(ylim)
|
||||
|
||||
return PlotInfo(
|
||||
plot_type=PlotType.IMAGE,
|
||||
|
||||
+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)
|
||||
|
||||
+80
-63
@@ -56,39 +56,38 @@ 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
|
||||
1. Define the set of runs and outputs considered
|
||||
|
||||
path_in : str, path to the folder of the runs
|
||||
path_in : str, path to the folder of the runs
|
||||
|
||||
2. Filter runs and outputs
|
||||
2. Filter runs and outputs
|
||||
|
||||
in_runs : str or list of str. The name runs to consider. Default: all.
|
||||
in_nums : int or list of int or str.
|
||||
The output numbers to consider.
|
||||
"last" select only the last output.
|
||||
"all" preselect all outputs (default)
|
||||
in_runs : str or list of str. The name runs to consider. Default: all.
|
||||
in_nums : int or list of int or str.
|
||||
The output numbers to consider.
|
||||
"last" select only the last output.
|
||||
"all" preselect all outputs (default)
|
||||
|
||||
nml_filename : str name of the namelist (should be the same for all outputs)
|
||||
nml_filename : str name of the namelist (should be the same for all outputs)
|
||||
|
||||
filter_name : str, filter runs by name. Default "*"
|
||||
filter_nml : tuple or list of tupple.
|
||||
Filter runs by namelist.
|
||||
tuples are in the following form:
|
||||
(nml_key, operator, nml_value)
|
||||
with nml_key a key from the namelist (eg. "cloud_params/dens0")
|
||||
operator within ("=", "!=", "<", ">", "in")
|
||||
and nml_value a string, float or int
|
||||
time_min : float, select output where time >= time_min (in code units)
|
||||
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.
|
||||
filter_name : str, filter runs by name. Default "*"
|
||||
filter_nml : tuple or list of tupple.
|
||||
Filter runs by namelist.
|
||||
tuples are in the following form:
|
||||
(nml_key, operator, nml_value)
|
||||
with nml_key a key from the namelist (eg. "cloud_params/dens0")
|
||||
operator within ("=", "!=", "<", ">", "in")
|
||||
and nml_value a string, float or int
|
||||
time_min : float, select output where time >= time_min (in code units)
|
||||
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.
|
||||
|
||||
3. Sort the runs
|
||||
3. Sort the runs
|
||||
|
||||
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)
|
||||
|
||||
"""
|
||||
|
||||
@@ -146,37 +145,35 @@ class RunSelector:
|
||||
"""
|
||||
Sub-select runs and outputs from already selected runs and outputs
|
||||
|
||||
Parameters
|
||||
---------
|
||||
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.
|
||||
"last" select only the last output.
|
||||
"all" preselect all outputs (default)
|
||||
Args:
|
||||
|
||||
filter_name : str.
|
||||
glob pattern used to filter run names.
|
||||
default is "*" (all runs)
|
||||
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.
|
||||
"last" select only the last output.
|
||||
"all" preselect all outputs (default)
|
||||
|
||||
filter_nml : tuple or list of tupple.
|
||||
Filter runs by namelist.
|
||||
tuples are in the following form:
|
||||
(nml_key, operator, nml_value)
|
||||
with nml_key a key from the namelist (eg. "cloud_params/dens0")
|
||||
operator within ("=", "!=", "<", ">", "in")
|
||||
and nml_value a string, float or int
|
||||
time_min : float, select output where time >= time_min (in code units)
|
||||
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.
|
||||
filter_name : str.
|
||||
glob pattern used to filter run names.
|
||||
default is "*" (all runs)
|
||||
|
||||
filter_nml : tuple or list of tupple.
|
||||
Filter runs by namelist.
|
||||
tuples are in the following form:
|
||||
(nml_key, operator, nml_value)
|
||||
with nml_key a key from the namelist (eg. "cloud_params/dens0")
|
||||
operator within ("=", "!=", "<", ">", "in")
|
||||
and nml_value a string, float or int
|
||||
time_min : float, select output where time >= time_min (in code units)
|
||||
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.
|
||||
|
||||
|
||||
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
|
||||
-------
|
||||
|
||||
(selected_runs, selected_nums)
|
||||
Returns:
|
||||
(selected_runs, selected_nums)
|
||||
"""
|
||||
|
||||
if runs is None:
|
||||
@@ -301,20 +298,19 @@ class RunSelector:
|
||||
"""
|
||||
Select snapshots from the disk
|
||||
|
||||
Parameters
|
||||
---------
|
||||
Args:
|
||||
|
||||
in_nums : int or list of int or str.
|
||||
The output numbers to consider.
|
||||
"last" select only the last output.
|
||||
"all" preselect all outputs (default)
|
||||
in_nums : int or list of int or str.
|
||||
The output numbers to consider.
|
||||
"last" select only the last output.
|
||||
"all" preselect all outputs (default)
|
||||
|
||||
time_min : float, select output where time >= time_min (in code units)
|
||||
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.
|
||||
time_min : float, select output where time >= time_min (in code units)
|
||||
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.
|
||||
|
||||
do_tests : test if the snapshots are actually on disk. Not needed when subselecting snapshots.
|
||||
do_tests : test if the snapshots are actually on disk. Not needed when subselecting snapshots.
|
||||
"""
|
||||
|
||||
# -- Initialize info loader --
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
+22
-21
@@ -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(
|
||||
in_dir,
|
||||
filter_name=names,
|
||||
nums="first",
|
||||
tag="select",
|
||||
).study
|
||||
if __name__ == '__main__':
|
||||
path_from_home = "simus/ismfeed/allmode"
|
||||
names = "n6_st_2e5_seed3_T5Myr_nsink1e3_comp*"
|
||||
|
||||
|
||||
nums = find_nums(study, prep_mcons, time_mcons)
|
||||
write_paths(nums, ".")
|
||||
|
||||
pl = Plotter(in_dir, runs=nums.keys(), nums=nums)
|
||||
|
||||
pl.rho_pdf()
|
||||
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, ".")
|
||||
@@ -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)
|
||||
|
||||
+8
-3
@@ -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
|
||||
z0 = self.get_nml("galbox_params/height0", run) * U.pc
|
||||
n0 = self.get_nml("galbox_params/dens0", run) * U.cm**(-3)
|
||||
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