black without mortimer

This commit is contained in:
Noe Brucy
2022-11-28 18:01:18 +01:00
parent 7548ef7e0a
commit fa396178c6
14 changed files with 371 additions and 304 deletions
+16 -11
View File
@@ -1,6 +1,5 @@
from snapshotprocessor import SnapshotProcessor, U
import pandas as pd
import os
def get_velocity_cubes(pp, unit=None):
velcubes = [None, None, None]
@@ -10,8 +9,9 @@ def get_velocity_cubes(pp, unit=None):
velcubes[i] *= pp.info["unit_velocity"].express(unit)
return velcubes
def get_density_cube(pp, unit=None):
dens_cube = pp.datacube(getter=lambda dset: dset["rho"])
dens_cube = pp.datacube(getter=lambda dset: dset["rho"])
if unit is not None:
dens_cube *= pp.info["unit_density"].express(unit)
return dens_cube
@@ -19,27 +19,32 @@ def get_density_cube(pp, unit=None):
def write_data(filename, vel, dens):
# write fields to ramses frig readable ascii file
f = open(filename, 'w')
f = open(filename, "w")
dummy = 1
size = vel[0].shape[0]
f.write('{:8}{:13.5f}{:13.5f}{:13.5f}{:13.5f}\n'.format(size, dummy, dummy, dummy, dummy))
f.write(
"{:8}{:13.5f}{:13.5f}{:13.5f}{:13.5f}\n".format(
size, dummy, dummy, dummy, dummy
)
)
vx, vy, vz = vel
# This strange order matches the one in the galbox condinit
for z in range(size):
for y in range(size):
for x in range(size):
f.write('{:13.5f}{:13.5f}{:13.5f}{:13.5f}\n'.format(vx[x,y,z], vy[x,y,z], vz[x,y,z], dens[x, y, z]))
f.write(
"{:13.5f}{:13.5f}{:13.5f}{:13.5f}\n".format(
vx[x, y, z], vy[x, y, z], vz[x, y, z], dens[x, y, z]
)
)
def extract_from_pp(pp):
vel = get_velocity_cubes(pp, unit=U.km_s)
dens = get_density_cube(pp, unit=U.H_cc)
write_data(f"{pp.path_out}/{pp.run}_{pp.num}_velrho.data", vel, dens)
def extract(path, snap_number):
pp = SnapshotProcessor(path, snap_number, params="../turbox_params.yml")
extract_from_pp(pp)
+10 -9
View File
@@ -283,7 +283,9 @@ class RunSelector:
def load_info(self, run, num):
info_filename_output = f"{self.path_in}/{run}/output_{num:05}/info_{num:05}.txt"
# Path of the filename if ratarmount was used
info_filename_tarmount_output = f"{self.path_in}/{run}/output_{num:05}/output_{num:05}/info_{num:05}.txt"
info_filename_tarmount_output = (
f"{self.path_in}/{run}/output_{num:05}/output_{num:05}/info_{num:05}.txt"
)
info_filename_folder = f"{self.path_in}/{run}/info/info_{num:05}.txt"
if os.path.exists(info_filename_output):
@@ -348,15 +350,17 @@ class RunSelector:
return self.info[run][num]["time"]
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"]
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
@@ -477,7 +481,7 @@ class RunSelector:
return nums
def write_paths(self, prefix=None, filename="~/list_file"):
"""
"""
Write the paths of the selected runs on a file
Args:
@@ -485,7 +489,7 @@ class RunSelector:
filename (str, optional): F. Defaults to "~/list_file".
"""
if prefix is None:
prefix = self.path_in
prefix = self.path_in
paths = []
for run in self.nums:
for num in self.nums[run]:
@@ -496,6 +500,3 @@ class RunSelector:
f = open(os.path.expanduser(filename), "w")
f.writelines(paths)
f.close()
+22 -11
View File
@@ -9,6 +9,7 @@ from utils.runselector import RunSelector
from plotter import Plotter, U
import os
def prep_mcons(study):
study.coarse_step_from_log()
@@ -22,36 +23,46 @@ def time_mcons(study, run, target=0.2):
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
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 = 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)
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
def write_paths(nums, path_from_home, filename="~/list_file"):
paths = []
for key in nums:
for num in self.nums[run]:
if os.path.exists("{prefix}/{run}/output_{num:05}/output_{num:05}\n"):
paths.append(f"{prefix}/{run}/output_{num:05}/output_{num:05}\n")
else:
paths.append(f"{prefix}/{run}/output_{num:05}\n")
for run in nums:
for num in nums[run]:
if os.path.exists(
"{path_from_home}/{run}/output_{num:05}/output_{num:05}\n"
):
paths.append(
f"{path_from_home}/{run}/output_{num:05}/output_{num:05}\n"
)
else:
paths.append(f"{path_from_home}/{run}/output_{num:05}\n")
f = open(os.path.expanduser(filename), "w")
f.writelines(paths)
f.close()
if __name__ == '__main__':
if __name__ == "__main__":
path_from_home = "simus/ismfeed/allmode"
names = "n6_st_2e5_seed3_T5Myr_nsink1e3_comp*"
@@ -63,4 +74,4 @@ if __name__ == '__main__':
tag="select",
).study
nums = find_nums(study, prep_mcons, time_mcons)
write_paths(nums, ".")
write_paths(nums, ".")
+1 -1
View File
@@ -43,7 +43,7 @@ def unit_str(unit, base=None, prefix="", format=" [{unit}]"):
return ""
elif base is not None:
coeff = unit.express(base)
return unit_str(base, prefix=convert_exp(coeff)+" ")
return unit_str(base, prefix=convert_exp(coeff) + " ")
elif len(unit.latex) > 0:
if "." in unit.latex or "^" in unit.latex:
base_str = ".".join(map(parse_exp_unit, unit.name.split(".")))