[refactoring] removed star imports, renamed cst in U
and applied flake8 guidelines
This commit is contained in:
+71
-51
@@ -1,15 +1,39 @@
|
||||
# coding: utf-8
|
||||
import pickle
|
||||
|
||||
import numpy as np
|
||||
import tables
|
||||
import pickle
|
||||
import astropy.units as u
|
||||
import pandas as pd
|
||||
import pymses.utils.regions as reg
|
||||
from fil_finder import FilFinder2D
|
||||
from pymses.filters import RegionFilter
|
||||
|
||||
from skimage.morphology import medial_axis
|
||||
|
||||
import os
|
||||
from functools import partial
|
||||
from scipy.stats import linregress
|
||||
|
||||
from astrophysix.simdm.results import Snapshot
|
||||
|
||||
import pymses
|
||||
import pymses.utils.regions as reg
|
||||
from pymses.analysis import (
|
||||
Camera,
|
||||
FractionOperator,
|
||||
MaxLevelOperator,
|
||||
ScalarOperator,
|
||||
raytracing,
|
||||
slicing,
|
||||
splatting,
|
||||
)
|
||||
from pymses.filters import CellsToPoints, RegionFilter
|
||||
|
||||
from fil_finder import FilFinder2D
|
||||
import pspec_new
|
||||
from baseprocessor import *
|
||||
|
||||
|
||||
from units import U
|
||||
from baseprocessor import HDF5Container, Rule, norm_getter, simple_getter, vect_getter
|
||||
|
||||
|
||||
# Getters
|
||||
|
||||
@@ -167,7 +191,7 @@ class PostProcessor(HDF5Container):
|
||||
path_out=None,
|
||||
pp_params=None,
|
||||
tag=None,
|
||||
unit_time=cst.year,
|
||||
unit_time=U.year,
|
||||
):
|
||||
"""
|
||||
Creates the basic structures needed for the outputs
|
||||
@@ -246,21 +270,25 @@ class PostProcessor(HDF5Container):
|
||||
|
||||
if self.pp_params.pymses.filter:
|
||||
center = (self.max_coords + self.min_coords) / 2.0
|
||||
im_extent = [
|
||||
self.min_coords[0],
|
||||
self.max_coords[0],
|
||||
self.min_coords[1],
|
||||
self.max_coords[1],
|
||||
]
|
||||
im_extent = np.array(
|
||||
[
|
||||
self.min_coords[0],
|
||||
self.max_coords[0],
|
||||
self.min_coords[1],
|
||||
self.max_coords[1],
|
||||
]
|
||||
)
|
||||
distance = (self.max_coords[2] - self.min_coords[2]) / 2.0
|
||||
else:
|
||||
center = self.pp_params.pymses.center
|
||||
im_extent = [
|
||||
(-self._radius + center[0]),
|
||||
(self._radius + center[0]),
|
||||
(-self._radius + center[1]),
|
||||
(self._radius + center[1]),
|
||||
]
|
||||
im_extent = np.array(
|
||||
[
|
||||
(-self._radius + center[0]),
|
||||
(self._radius + center[0]),
|
||||
(-self._radius + center[1]),
|
||||
(self._radius + center[1]),
|
||||
]
|
||||
)
|
||||
distance = self._radius
|
||||
|
||||
# Get time
|
||||
@@ -274,7 +302,7 @@ class PostProcessor(HDF5Container):
|
||||
self.save.root._v_attrs.unit_length = self.info["unit_length"]
|
||||
self.save.root._v_attrs.time = time
|
||||
|
||||
if not "/maps" in self.save:
|
||||
if "/maps" not in self.save:
|
||||
self.save.create_group("/", "maps", "2D maps")
|
||||
self.save.root.maps._v_attrs.center = center
|
||||
self.save.root.maps._v_attrs.radius = self._radius
|
||||
@@ -283,7 +311,6 @@ class PostProcessor(HDF5Container):
|
||||
# Initialize cameras
|
||||
self._cam = {}
|
||||
for ax_los in self._ax_nb: # los = line of sight
|
||||
ax_h = self._axes_h[ax_los]
|
||||
ax_v = self._axes_v[ax_los]
|
||||
|
||||
self._cam[ax_los] = Camera(
|
||||
@@ -306,13 +333,13 @@ class PostProcessor(HDF5Container):
|
||||
else:
|
||||
self.fil = None
|
||||
|
||||
time_in_right_unit = self.info["time"] * self.info["unit_time"].express(
|
||||
unit_time
|
||||
)
|
||||
self.snapshot = Snapshot(
|
||||
name=str(self.num),
|
||||
description="",
|
||||
time=(
|
||||
self.info["time"] * self.info["unit_time"].express(unit_time),
|
||||
unit_time,
|
||||
),
|
||||
time=(time_in_right_unit, unit_time),
|
||||
directory_path=self.path,
|
||||
data_reference="OUTPUT_{}".format(self.num),
|
||||
)
|
||||
@@ -323,7 +350,7 @@ class PostProcessor(HDF5Container):
|
||||
"""
|
||||
Load all cells from the source file in the memory.
|
||||
Cells will be accessible trough self.cells
|
||||
(/!\ Long and memory heavy)
|
||||
(Long and memory heavy)
|
||||
"""
|
||||
if not self.cells_loaded:
|
||||
if os.path.exists(self.cells_filename):
|
||||
@@ -424,7 +451,7 @@ class PostProcessor(HDF5Container):
|
||||
""" Azimuthal velocity """
|
||||
return self.oct_getter_vect_phi(dset, "vel")
|
||||
|
||||
def _slice(self, getter, ax_los="z", z=0.0, unit=cst.none):
|
||||
def _slice(self, getter, ax_los="z", z=0.0, unit=U.none):
|
||||
"""
|
||||
Slice process function.
|
||||
Return a slice of the source box.
|
||||
@@ -440,7 +467,7 @@ class PostProcessor(HDF5Container):
|
||||
z : float
|
||||
Coordinate of the slice on the ax_los axis
|
||||
|
||||
unit : cst.Unit
|
||||
unit : U.Unit
|
||||
Unit of the resulting dataset
|
||||
|
||||
Returns
|
||||
@@ -452,9 +479,7 @@ class PostProcessor(HDF5Container):
|
||||
datamap = slicing.SliceMap(self._amr, self._cam[ax_los], op, z=z)
|
||||
return datamap.map.T
|
||||
|
||||
def _ax_avg(
|
||||
self, getter, ax_los, unit=cst.none, mass_weighted=True, surf_qty=False
|
||||
):
|
||||
def _ax_avg(self, getter, ax_los, unit=U.none, mass_weighted=True, surf_qty=False):
|
||||
"""
|
||||
Map of the average of a quantity (given by getter) along an axis (ax_los)
|
||||
Returns 2D array if getter returns a scalar quantity
|
||||
@@ -505,7 +530,7 @@ class PostProcessor(HDF5Container):
|
||||
self.load_cells()
|
||||
return np.sort(np.unique(self.cells["pos"][:, axis]))
|
||||
|
||||
def _plane_avg_uniform(self, getter, axis, unit=cst.none, mass_weighted=False):
|
||||
def _plane_avg_uniform(self, getter, axis, unit=U.none, mass_weighted=False):
|
||||
"""
|
||||
Profile of the average of a quantity (given by getter) perpendicular to an axis
|
||||
WARNING : This version only works on an uniform grid, need of a box version for AMR
|
||||
@@ -622,17 +647,17 @@ class PostProcessor(HDF5Container):
|
||||
"""
|
||||
self.load_cells()
|
||||
mean_speed = self.save.get_node("/globals/mwa_speed").read()
|
||||
mean_speed = mean_speed * self.info["unit_velocity"].express(cst.km_s)
|
||||
mean_speed = mean_speed * self.info["unit_velocity"].express(U.km_s)
|
||||
vel_fluct = (self.cells)["vel"] * self.info["unit_velocity"].express(
|
||||
cst.km_s
|
||||
U.km_s
|
||||
) - mean_speed
|
||||
B_norm = getter_B_int(self.cells)
|
||||
B_norm = B_norm * self.info["unit_mag"].express(cst.T)
|
||||
B_norm = B_norm * self.info["unit_mag"].express(U.T)
|
||||
v_norm = np.sqrt(
|
||||
np.sum((vel_fluct * 10 ** (3)) ** 2, axis=1)
|
||||
) # v_norm [m/s] et vel_fluct [km/s]
|
||||
rho = getter_rho(self.cells)
|
||||
rho_kg_m3 = rho * self.info["unit_density"].express(cst.kg_m3)
|
||||
rho_kg_m3 = rho * self.info["unit_density"].express(U.kg_m3)
|
||||
eb = 0.5 * (B_norm) ** 2 / (4 * np.pi * 10 ** (-7)) # mettre le bon mu
|
||||
ek = 0.5 * v_norm ** 2 * rho_kg_m3
|
||||
rapport = ek / eb
|
||||
@@ -1024,8 +1049,7 @@ class PostProcessor(HDF5Container):
|
||||
return alpha
|
||||
|
||||
alpha_f = (
|
||||
self._ax_avg(getter_alpha_num, "z", unit=cst.none, mass_weighted=True)
|
||||
/ T_avg
|
||||
self._ax_avg(getter_alpha_num, "z", unit=U.none, mass_weighted=True) / T_avg
|
||||
)
|
||||
|
||||
# alpha
|
||||
@@ -1047,7 +1071,7 @@ class PostProcessor(HDF5Container):
|
||||
gphi = self.oct_getter_vect_phi(dset, "g")
|
||||
return gr * gphi / (4 * np.pi * self.G)
|
||||
|
||||
alpha_g = self._ax_avg(getter_alpha_grav, "z", unit=cst.none, surf_qty=True) / (
|
||||
alpha_g = self._ax_avg(getter_alpha_grav, "z", unit=U.none, surf_qty=True) / (
|
||||
coldens * T_avg
|
||||
)
|
||||
|
||||
@@ -1166,10 +1190,6 @@ class PostProcessor(HDF5Container):
|
||||
|
||||
GM = self.G * self.pp_params.disk.mass_star # Mass parameter
|
||||
|
||||
# Get mask for filaments
|
||||
fil = self.fil
|
||||
mask_fil = np.asarray(fil.mask.copy(), dtype=bool)
|
||||
|
||||
# Find center of filaments
|
||||
i_center, j_center = self._filaments_center()
|
||||
|
||||
@@ -1283,7 +1303,7 @@ class PostProcessor(HDF5Container):
|
||||
self._alpha_disk,
|
||||
"Map of the Shakura&Sunaev alpha parameter for disks",
|
||||
"/maps",
|
||||
unit=cst.none,
|
||||
unit=U.none,
|
||||
dependencies=[
|
||||
"avg_map_rho_avg",
|
||||
"avg_map_T_mwavg",
|
||||
@@ -1297,7 +1317,7 @@ class PostProcessor(HDF5Container):
|
||||
"Map of the graviational contrib to\
|
||||
Shakura&Sunaev alpha parameter for disks",
|
||||
"/maps",
|
||||
unit=cst.none,
|
||||
unit=U.none,
|
||||
dependencies=["avg_map_coldens", "avg_map_T_mwavg"],
|
||||
),
|
||||
"rho": Rule(
|
||||
@@ -1373,9 +1393,9 @@ class PostProcessor(HDF5Container):
|
||||
self._sinks,
|
||||
group="/datasets",
|
||||
unit={
|
||||
"Id": cst.none,
|
||||
"M": cst.Msun,
|
||||
"dmf": cst.Msun,
|
||||
"Id": U.none,
|
||||
"M": U.Msun,
|
||||
"dmf": U.Msun,
|
||||
"x": "",
|
||||
"y": "",
|
||||
"z": "",
|
||||
@@ -1388,9 +1408,9 @@ class PostProcessor(HDF5Container):
|
||||
"lz": "|l|",
|
||||
"acc_rate": "[Msol/y]",
|
||||
"acc_lum": "[Lsol]",
|
||||
"age": cst.year,
|
||||
"age": U.year,
|
||||
"int_lum": "[Lsol]",
|
||||
"Teff": cst.K,
|
||||
"Teff": U.K,
|
||||
},
|
||||
),
|
||||
"pspec": Rule(self, self._pspec, "Power spectrum", "/hdf5"),
|
||||
@@ -1473,7 +1493,7 @@ class PostProcessor(HDF5Container):
|
||||
"Global cos fluctuation-PDF",
|
||||
"/hist",
|
||||
dependencies=["mwa_speed"],
|
||||
unit=cst.none,
|
||||
unit=U.none,
|
||||
),
|
||||
"Brho": Rule(
|
||||
self,
|
||||
@@ -1488,7 +1508,7 @@ class PostProcessor(HDF5Container):
|
||||
"Average of Ek/Eb as a function of rho",
|
||||
"/datasets",
|
||||
dependencies=["mwa_speed"],
|
||||
unit={"rho": self.info["unit_density"], "Ek_Eb_rho": cst.none},
|
||||
unit={"rho": self.info["unit_density"], "Ek_Eb_rho": U.none},
|
||||
),
|
||||
# Profiles
|
||||
"axis": Rule(
|
||||
|
||||
Reference in New Issue
Block a user