[refactoring] removed star imports, renamed cst in U
and applied flake8 guidelines
This commit is contained in:
+38
-28
@@ -1,6 +1,17 @@
|
||||
# coding: utf-8
|
||||
|
||||
from aggregator import *
|
||||
import os
|
||||
import glob
|
||||
import numpy as np
|
||||
from functools import partial
|
||||
from scipy.stats import linregress
|
||||
|
||||
from baseprocessor import Rule, HDF5Container
|
||||
from aggregator import Aggregator
|
||||
from postprocessor import PostProcessor
|
||||
from run_selector import RunSelector
|
||||
from pp_params import default_params
|
||||
from units import U
|
||||
|
||||
|
||||
class Comparator(Aggregator, HDF5Container):
|
||||
@@ -17,7 +28,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
pp_params=default_params(),
|
||||
selector=None,
|
||||
tag=None,
|
||||
unit_time=cst.year,
|
||||
unit_time=U.year,
|
||||
**kwargs
|
||||
):
|
||||
"""
|
||||
@@ -78,14 +89,14 @@ class Comparator(Aggregator, HDF5Container):
|
||||
"""
|
||||
if overwrite or not (name_full in self.save):
|
||||
return True
|
||||
elif not "nums" in self.save.get_node(name_full)._v_attrs:
|
||||
elif "nums" not in self.save.get_node(name_full)._v_attrs:
|
||||
return True
|
||||
else:
|
||||
saved_nums = self.save.get_node(name_full)._v_attrs.nums
|
||||
missing_runs = len([run for run in self.nums if not run in saved_nums]) > 0
|
||||
missing_runs = len([run for run in self.nums if run not in saved_nums]) > 0
|
||||
missing_nums = missing_runs or all(
|
||||
[
|
||||
len([num for num in self.nums[run] if not num in saved_nums[run]])
|
||||
len([num for num in self.nums[run] if num not in saved_nums[run]])
|
||||
> 0
|
||||
for run in self.nums
|
||||
if run in saved_nums
|
||||
@@ -182,18 +193,18 @@ class Comparator(Aggregator, HDF5Container):
|
||||
|
||||
def get_attr(self, attr_name, run, num, node_name="/", arg=None):
|
||||
pp = self.pp[run][num]
|
||||
if not arg is None:
|
||||
if arg is not None:
|
||||
node_name = node_name + "_" + str(arg)
|
||||
return pp.get_attribute(node_name, attr_name)
|
||||
|
||||
def get_pp_value(self, name, run, num, arg=None):
|
||||
pp = self.pp[run][num]
|
||||
if not arg is None:
|
||||
if arg is not None:
|
||||
name = name + "_" + str(arg)
|
||||
return pp.get_value(name)
|
||||
|
||||
def get_global(self, node_name, run, num, arg=None, unload_cells=False):
|
||||
if not arg is None:
|
||||
if arg is not None:
|
||||
node_name = node_name + "_" + str(arg)
|
||||
pp = self.pp[run][num]
|
||||
if unload_cells:
|
||||
@@ -276,7 +287,6 @@ class Comparator(Aggregator, HDF5Container):
|
||||
return series
|
||||
|
||||
def _from_log(self, keys, extractor):
|
||||
nums = self.nums
|
||||
|
||||
# Initialize series
|
||||
series = {}
|
||||
@@ -318,15 +328,15 @@ class Comparator(Aggregator, HDF5Container):
|
||||
for run in self.runs:
|
||||
# Surface of the box in pc^2
|
||||
info = self.pp[run][self.nums[run][0]].info
|
||||
surface = (info["unit_length"].express(cst.pc)) ** 2
|
||||
surface = (info["unit_length"].express(U.pc)) ** 2
|
||||
# WARNING : We do not multiply by boxlen since already done in 'unit_length' (pymses)
|
||||
|
||||
time = self.save.get_node("/series/sinks_from_log/time/" + run).read()
|
||||
time = time * time_unit.express(cst.year)
|
||||
time = time * time_unit.express(U.year)
|
||||
mass_sink = self.save.get_node(
|
||||
"/series/sinks_from_log/mass_sink/" + run
|
||||
).read()
|
||||
mass_sink = mass_sink * mass_unit.express(cst.Msun)
|
||||
mass_sink = mass_sink * mass_unit.express(U.Msun)
|
||||
|
||||
if avg_window is None:
|
||||
shift = 1
|
||||
@@ -350,11 +360,11 @@ class Comparator(Aggregator, HDF5Container):
|
||||
for run in self.runs:
|
||||
# Surface of the box in pc^2
|
||||
info = self.pp[run][self.nums[run][0]].info
|
||||
surface = (info["unit_length"].express(cst.pc)) ** 2
|
||||
surface = (info["unit_length"].express(U.pc)) ** 2
|
||||
mass_sink = self.save.get_node(
|
||||
"/series/sinks_from_log/mass_sink/" + run
|
||||
).read()
|
||||
mass_sink = mass_sink * mass_unit.express(cst.Msun)
|
||||
mass_sink = mass_sink * mass_unit.express(U.Msun)
|
||||
|
||||
ssm[run] = mass_sink / surface
|
||||
|
||||
@@ -402,7 +412,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
glob_group="/globals",
|
||||
subarray_name=None,
|
||||
unload_cells=True,
|
||||
unit=cst.none,
|
||||
unit=U.none,
|
||||
description="",
|
||||
):
|
||||
|
||||
@@ -472,7 +482,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
)
|
||||
|
||||
def def_rules(self):
|
||||
averageables = ["coldens", "rho", "T", "Q"]
|
||||
|
||||
self.rules = {
|
||||
# Read from log
|
||||
"sinks_from_log": Rule(
|
||||
@@ -483,7 +493,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
self._extract_sinks_from_log,
|
||||
),
|
||||
group="/series",
|
||||
unit={"time": "unit_time", "mass_sink": cst.Msun, "nb_sink": cst.none},
|
||||
unit={"time": "unit_time", "mass_sink": U.Msun, "nb_sink": U.none},
|
||||
description={
|
||||
"time": "Time",
|
||||
"mass_sink": "Total mass of stars",
|
||||
@@ -494,7 +504,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
self,
|
||||
self._ssfr_from_mass_sink,
|
||||
group="/series/sinks_from_log",
|
||||
unit=cst.ssfr,
|
||||
unit=U.ssfr,
|
||||
description="Instantaneous surfacic star formation rate",
|
||||
dependencies=["sinks_from_log"],
|
||||
),
|
||||
@@ -502,7 +512,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
self,
|
||||
self._surfacic_sink_mass,
|
||||
group="/series/sinks_from_log",
|
||||
unit=cst.Msun / cst.pc ** 2,
|
||||
unit=U.Msun / U.pc ** 2,
|
||||
description="Surfacic sink mass",
|
||||
dependencies=["sinks_from_log"],
|
||||
),
|
||||
@@ -510,7 +520,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
self,
|
||||
partial(self._from_log, ["time", "sfr"], self._extract_sfr_from_log),
|
||||
group="/series",
|
||||
unit={"time": cst.year, "sfr": cst.ssfr},
|
||||
unit={"time": U.year, "sfr": U.ssfr},
|
||||
description={
|
||||
"time": "Time",
|
||||
"sfr": "Averaged surfacic star formation rate",
|
||||
@@ -527,7 +537,7 @@ class Comparator(Aggregator, HDF5Container):
|
||||
unit={
|
||||
"time": "unit_time",
|
||||
"dt": "unit_time",
|
||||
"turb_rms": cst.none,
|
||||
"turb_rms": U.none,
|
||||
"turb_energy": {
|
||||
"unit_length": 3,
|
||||
"unit_velocity": 2,
|
||||
@@ -551,13 +561,13 @@ class Comparator(Aggregator, HDF5Container):
|
||||
group="/series",
|
||||
unit={
|
||||
"time": "unit_time",
|
||||
"step": cst.none,
|
||||
"mcons": cst.none,
|
||||
"econs": cst.none,
|
||||
"epot": cst.none, # TODO find unit
|
||||
"ekin": cst.none,
|
||||
"eint": cst.none,
|
||||
"emag": cst.none,
|
||||
"step": U.none,
|
||||
"mcons": U.none,
|
||||
"econs": U.none,
|
||||
"epot": U.none, # TODO find unit
|
||||
"ekin": U.none,
|
||||
"eint": U.none,
|
||||
"emag": U.none,
|
||||
},
|
||||
),
|
||||
"turb_power": Rule(
|
||||
|
||||
Reference in New Issue
Block a user