Remove log in Brho, clean and comment
This commit is contained in:
+39
-51
@@ -8,7 +8,7 @@ vol_func = lambda dset: dset["dx"] ** 3 # Volume function
|
||||
getter_T = lambda dset: dset["P"] / dset["rho"] # Temperature
|
||||
|
||||
|
||||
def _getter_abs_cos_vB(dset):
|
||||
def getter_abs_cos_vB(dset):
|
||||
B_norm = np.sqrt(np.sum(dset["Br"] ** 2, axis=1))
|
||||
v_norm = np.sqrt(np.sum(dset["vel"] ** 2, axis=1))
|
||||
# Compute the dot product in each cell
|
||||
@@ -16,12 +16,12 @@ def _getter_abs_cos_vB(dset):
|
||||
return np.abs(dot_prod) / (v_norm * B_norm)
|
||||
|
||||
|
||||
def _getter_B_int(dset):
|
||||
def getter_B_int(dset):
|
||||
B_norm = np.sqrt(np.sum(dset["Br"] ** 2, axis=1))
|
||||
return B_norm
|
||||
|
||||
|
||||
def _getter_rho(dset):
|
||||
def getter_rho(dset):
|
||||
return dset["rho"]
|
||||
|
||||
|
||||
@@ -302,27 +302,44 @@ class PostProcessor(HDF5Container):
|
||||
centers = 0.5 * (edges[1:] + edges[:-1])
|
||||
return (np.stack([values, centers]), {"logbins": logbins})
|
||||
|
||||
def _Brho(self, bins=100):
|
||||
def _Brho(self, bins=100, logbins=True):
|
||||
"""
|
||||
Mean of B in rho bins
|
||||
"""
|
||||
self.load_cells()
|
||||
B = _getter_B_int(self.cells)
|
||||
rho = _getter_rho(self.cells)
|
||||
B = np.log10(B)
|
||||
rho = np.log10(rho)
|
||||
abscisse = np.linspace(np.min(rho), np.max(rho), bins)
|
||||
B = getter_B_int(self.cells)
|
||||
rho = getter_rho(self.cells)
|
||||
|
||||
if logbins:
|
||||
rho_bins = np.logspace(
|
||||
np.log10(np.min(rho)), np.log10(np.max(rho)), bins, base=10
|
||||
)
|
||||
else:
|
||||
rho_bins = np.linspace(np.min(rho), np.max(rho), bins)
|
||||
|
||||
weights = mass_func(self.cells)
|
||||
|
||||
# For each cell, bin_number contains the number of the bins it belongs to
|
||||
bin_number = np.zeros(len(B))
|
||||
for rho_min in abscisse[:-1]:
|
||||
|
||||
# Go through the min value of rho of each bin
|
||||
for rho_min in rho_bins[:-1]:
|
||||
bin_number = bin_number + (rho > rho_min).astype(int)
|
||||
|
||||
B_mean = np.zeros(len(abscisse) - 1)
|
||||
# Compute the mean in each bin
|
||||
B_mean = np.zeros(len(rho_bins) - 1)
|
||||
for i in range(len(B_mean)):
|
||||
B_mean[i] = np.mean(B[bin_number == i])
|
||||
values, edges = np.histogram(B, abscisse, weights=weights)
|
||||
centers = 0.5 * (edges[1:] + edges[:-1])
|
||||
print("centers")
|
||||
|
||||
# Get the center of each bin
|
||||
if logbins:
|
||||
centers = 10 ** (0.5 * (np.log10(rho_bins[1:]) + np.log10(rho_bins[:-1])))
|
||||
else:
|
||||
centers = 0.5 * (rho_bins[1:] + rho_bins[:-1])
|
||||
|
||||
if self.pp_params.process.unload_cells:
|
||||
self.unload_cells()
|
||||
return {"rho": centers, "B": B_mean}
|
||||
return ({"rho": centers, "B": B_mean}, {"logbins": logbins})
|
||||
|
||||
def _mwa_sigma(self, axes=["x", "y", "z"]):
|
||||
mw_speed = self.save.get_node("/globals/mwa_speed").read()
|
||||
@@ -381,6 +398,9 @@ class PostProcessor(HDF5Container):
|
||||
return self._vector_v("Br", "unit_mag", ax_los, z)
|
||||
|
||||
def _B_int(self, ax_los, z=0.0):
|
||||
"""
|
||||
Slice ont the intensity of the magnétic field
|
||||
"""
|
||||
B_op = ScalarOperator(
|
||||
lambda dset: np.sqrt(np.sum(dset["Br"] ** 2, axis=1)),
|
||||
self._ro.info["unit_mag"],
|
||||
@@ -606,38 +626,6 @@ class PostProcessor(HDF5Container):
|
||||
pdf.attrs.var = np.var
|
||||
return True
|
||||
|
||||
# def kappa(self, mask):
|
||||
# mask_flat = mask.flatten()
|
||||
# fmap = self.get_value("/maps/fluct_coldens_z")
|
||||
# nb_cells = np.sum(self.mask_flat)
|
||||
# values, edges = np.histogram(np.log10(fmap.flatten()[mask_flat]),
|
||||
# self.pp_params.pdf.nb_bin,
|
||||
# weights = np.ones(nb_cells) / nb_cells)
|
||||
|
||||
# centers = 0.5 * (edges[1:] + edges[:-1])
|
||||
# mask_fit = ((centers > self.pp.pp_params.pdf.xmin_fit) &
|
||||
# (centers < self.pp.pp_params.pdf.xmax_fit) &
|
||||
# (values > 0))
|
||||
# (a, b, r, p, err) = linregress(centers[mask_fit], np.log10(values[mask_fit]))
|
||||
# return a, err
|
||||
|
||||
# def gamma(self, mask):
|
||||
# rho3d = np.log10(self.cells["rho"])
|
||||
# P3d = np.log10(np.sqrt(self.cells["P"]))
|
||||
# xy3d = self.pp.cells["pos"][:, :2] - 0.5
|
||||
# self.rr3d = np.sqrt(np.sum((self.xy3d)**2, axis=1))
|
||||
# nb_cells = np.sum(self.mask_flat)
|
||||
# values, edges = np.histogram(np.log10(fmap.flatten()[mask_flat]),
|
||||
# self.pp_params.pdf.nb_bin,
|
||||
# weights = np.ones(nb_cells) / nb_cells)
|
||||
|
||||
# centers = 0.5 * (edges[1:] + edges[:-1])
|
||||
# mask_fit = ((centers > self.pp.pp_params.pdf.xmin_fit) &
|
||||
# (centers < self.pp.pp_params.pdf.xmax_fit) &
|
||||
# (values > 0))
|
||||
# (a, b, r, p, err) = linregress(centers[mask_fit], np.log10(values[mask_fit]))
|
||||
# return a, err
|
||||
|
||||
def _sinks(self):
|
||||
csv_name = (
|
||||
self.path
|
||||
@@ -829,17 +817,17 @@ class PostProcessor(HDF5Container):
|
||||
),
|
||||
"cos_pdf": Rule(
|
||||
self,
|
||||
partial(self._vol_pdf, _getter_abs_cos_vB, logbins=False),
|
||||
partial(self._vol_pdf, getter_abs_cos_vB, logbins=False),
|
||||
"Global cos-PDF",
|
||||
"/hist",
|
||||
unit=cst.none,
|
||||
),
|
||||
"Brho": Rule(
|
||||
self,
|
||||
partial(self._Brho),
|
||||
"Brho average",
|
||||
self._Brho,
|
||||
"Average of B as a function of rho",
|
||||
"/datasets",
|
||||
unit=self.info["unit_mag"],
|
||||
unit={"rho": self.info["unit_density"], "B": self.info["unit_mag"]},
|
||||
),
|
||||
# Profiles
|
||||
"axis": Rule(
|
||||
|
||||
Reference in New Issue
Block a user