repo organisation
This commit is contained in:
80
loaders/load_data_arepo.py
Normal file
80
loaders/load_data_arepo.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# coding: utf-8
|
||||
|
||||
import numpy as np
|
||||
import h5py
|
||||
from astropy import units as u
|
||||
|
||||
|
||||
def load_fields_arepo(path):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
path : _type_
|
||||
_description_
|
||||
output : _type_
|
||||
_description_
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict
|
||||
A dataset of cells in the following format:
|
||||
gas:
|
||||
position (Ngas, 3) [kpc], centered
|
||||
volume (Ngas) [pc^3]
|
||||
velocity (Ngas, 3) [km/s]
|
||||
mass (Ngas) [Msun]
|
||||
stars:
|
||||
position (Nstar, 3) [kpc], centered
|
||||
velocity (Nstar, 3) [km/s]
|
||||
mass (Nstar) [Msun]
|
||||
birth_time (Nstar) [Myr]
|
||||
dm:
|
||||
position (Ngas, 3) [kpc], centered
|
||||
velocity (Ngas, 3) [km/s]
|
||||
mass (Ngas) [Msun]
|
||||
maps:
|
||||
extent (xmin, xmax, ymin, ymax) Coordinates of the edges of the map, centered
|
||||
gas_coldens (Nx, Ny) [Msun/pc^2], map of column density
|
||||
"""
|
||||
|
||||
snap = h5py.File(path)
|
||||
info = snap["Header"].attrs
|
||||
gas = snap["PartType0"]
|
||||
stars = snap["PartType4"]
|
||||
time = info["Time"]
|
||||
box_size = info["BoxSize"]
|
||||
UnitLength_in_kpc = info["UnitLength_in_cm"] * u.cm.to(u.kpc)
|
||||
UnitVelocity_in_km_per_s = info["UnitVelocity_in_cm_per_s"] * u.cm.to(u.km)
|
||||
UnitTime_in_Myr = (
|
||||
info["UnitLength_in_cm"] / info["UnitVelocity_in_cm_per_s"]
|
||||
) * u.s.to(u.Myr)
|
||||
UnitMass_in_Msun = info["UnitMass_in_g"] * u.g.to(u.Msun)
|
||||
|
||||
# Create dataset
|
||||
data = {
|
||||
"header": {"time": time * UnitTime_in_Myr,
|
||||
"fluids": ["gas", "stars"],
|
||||
"box_size": box_size * UnitLength_in_kpc },
|
||||
"gas": {
|
||||
"position": (
|
||||
np.asarray(gas["CenterOfMass"]) - np.array([0.5, 0.5, 0.5]) * box_size
|
||||
)
|
||||
* UnitLength_in_kpc,
|
||||
"volume": (np.asarray(gas["Masses"]) / np.asarray(gas["Density"]))
|
||||
* UnitLength_in_kpc**3,
|
||||
"velocity": np.asarray(gas["Velocities"]) * UnitVelocity_in_km_per_s,
|
||||
"mass": np.asarray(gas["Masses"]) * UnitMass_in_Msun,
|
||||
},
|
||||
"stars": {
|
||||
"position": (
|
||||
np.asarray(stars["Coordinates"]) - np.array([0.5, 0.5, 0.5]) * box_size
|
||||
)
|
||||
* UnitLength_in_kpc,
|
||||
"velocity": np.asarray(stars["Velocities"]) * UnitVelocity_in_km_per_s,
|
||||
"mass": np.asarray(stars["Masses"]) * UnitMass_in_Msun,
|
||||
"birth_time": np.asarray(stars["StellarFormationTime"]) * UnitTime_in_Myr,
|
||||
},
|
||||
}
|
||||
snap.close()
|
||||
return data
|
||||
|
||||
110
loaders/load_data_suez.py
Normal file
110
loaders/load_data_suez.py
Normal file
@@ -0,0 +1,110 @@
|
||||
# coding: utf-8
|
||||
|
||||
import numpy as np
|
||||
from snapshotprocessor import U
|
||||
from tables import NoSuchNodeError
|
||||
|
||||
|
||||
def load_fields(pp):
|
||||
"""
|
||||
Parameters
|
||||
----------
|
||||
path : _type_
|
||||
_description_
|
||||
output : _type_
|
||||
_description_
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict
|
||||
A dataset of cells in the following format:
|
||||
gas:
|
||||
position (Ngas, 3) [kpc], centered
|
||||
volume (Ngas) [pc^3]
|
||||
velocity (Ngas, 3) [km/s]
|
||||
mass (Ngas) [Msun]
|
||||
stars:
|
||||
position (Nstar, 3) [kpc], centered
|
||||
velocity (Nstar, 3) [km/s]
|
||||
mass (Nstar) [Msun]
|
||||
birth_time (Nstar) [Myr]
|
||||
dm:
|
||||
position (Ngas, 3) [kpc], centered
|
||||
velocity (Ngas, 3) [km/s]
|
||||
mass (Ngas) [Msun]
|
||||
maps:
|
||||
extent (xmin, xmax, ymin, ymax) Coordinates of the edges of the map, centered
|
||||
gas_coldens (Nx, Ny) [Msun/pc^2], map of column density
|
||||
"""
|
||||
|
||||
# Load arrays
|
||||
pp.load_cells(keys=["pos", "vel", "dx", "rho"])
|
||||
|
||||
try:
|
||||
pp.load_parts(keys=["pos", "vel", "mass", "epoch"])
|
||||
except (KeyError, NoSuchNodeError):
|
||||
pp.load_parts(keys=["pos", "vel", "mass"])
|
||||
|
||||
cells = pp.cells
|
||||
parts = pp.parts
|
||||
|
||||
if "epoch" not in parts:
|
||||
parts["epoch"] = np.zeros(len(pp.parts["mass"]))
|
||||
|
||||
# Compute extra fields and convert units
|
||||
for dset in (cells, parts):
|
||||
dset["position"] = dset["pos"] - np.array([0.5, 0.5, 0.5])
|
||||
|
||||
cells["mass"] = (
|
||||
cells["rho"]
|
||||
* cells["dx"] ** 3
|
||||
* (pp.info["unit_density"] * pp.info["unit_length"] ** 3).express(U.Msun)
|
||||
)
|
||||
|
||||
cells["volume"] = cells["dx"] ** 3 * (pp.info["unit_length"] ** 3).express(
|
||||
U.kpc**3
|
||||
)
|
||||
|
||||
# Separate DM from stars
|
||||
mass_dm = np.max(parts["mass"])
|
||||
mask_dm = parts["mass"] == mass_dm
|
||||
mask_star = parts["mass"] < mass_dm
|
||||
|
||||
# Create dataset
|
||||
data = {
|
||||
"header": {"time": pp.time * pp.info["unit_time"].express(U.Myr),
|
||||
"fluids": ["gas", "stars", "dm"],
|
||||
"box_size": pp.info["unit_length"].express(U.kpc)},
|
||||
"gas": {
|
||||
"position": cells["position"] * pp.info["unit_length"].express(U.kpc),
|
||||
"volume": cells["volume"],
|
||||
"velocity": cells["vel"] * pp.info["unit_velocity"].express(U.km_s),
|
||||
"mass": cells["mass"],
|
||||
},
|
||||
"stars": {
|
||||
"position": parts["position"][mask_star]
|
||||
* pp.info["unit_length"].express(U.kpc),
|
||||
"velocity": parts["vel"][mask_star]
|
||||
* pp.info["unit_velocity"].express(U.km_s),
|
||||
"mass": parts["mass"][mask_star] * pp.info["unit_mass"].express(U.Msun),
|
||||
"birth_time": parts["epoch"][mask_star]
|
||||
* pp.info["unit_time"].express(U.Myr),
|
||||
},
|
||||
"dm": {
|
||||
"position": parts["position"][mask_dm]
|
||||
* pp.info["unit_length"].express(U.kpc),
|
||||
"velocity": parts["vel"][mask_dm]
|
||||
* pp.info["unit_velocity"].express(U.km_s),
|
||||
"mass": parts["mass"][mask_dm] * pp.info["unit_mass"].express(U.Msun),
|
||||
},
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
if __name__ == "__main__" and False:
|
||||
from snapshotprocessor import SnapshotProcessor
|
||||
|
||||
pp = SnapshotProcessor(
|
||||
"/home/nbrucy/ecogal/galturb/F20H_15_4pc_frig_from_relax", num=50, params="params_gal.yml"
|
||||
)
|
||||
data = load_fields(pp)
|
||||
96
loaders/params_gal.yml
Normal file
96
loaders/params_gal.yml
Normal file
@@ -0,0 +1,96 @@
|
||||
plot : # Plot parameters
|
||||
put_title : False # Add a title to plot
|
||||
|
||||
# Maps
|
||||
ntick : 6 # Number of ticks for maps
|
||||
|
||||
# Overlays
|
||||
vel_red : 40 # Take point each vel_red for velocities
|
||||
|
||||
time_fmt : "time = {:.3g} {}" # Time format string, 1st field is time and 2nd is unit
|
||||
|
||||
disk: # Disk specific parameters
|
||||
enable : True # Enable specific disk analysis
|
||||
center : [0.5, 0.5, 0.5] # Position of the center
|
||||
binning : "log" # Kind of binning (lin : linear, log : logarithmic)
|
||||
mass_star : 1. # Mass of the central star
|
||||
nb_bin : 256 # Number of bins for averaged quantities
|
||||
bin_in : 1e-3 # Outer radius of the inner bin
|
||||
bin_out : 18 # Inner radius of the outer bin
|
||||
rmin_pdf : 1 # Inner radius for PDF computation
|
||||
rmax_pdf : 18 # Outer radius for PDF computation
|
||||
|
||||
|
||||
pdf: # parameters for probability density functions
|
||||
nb_bin : 100 # Number of bins for the PDF
|
||||
range : [-1.5, 2.5] # Range of the PDF (log of fluctuation)
|
||||
xmin_fit : 0.3 # Lower boundary of the fit (log of fluctuation)
|
||||
xmax_fit : 1.5 # Upper boundary of the fit (log of fluctuation)
|
||||
fit_cut : 1e-4 # Exclude value that are < fit_cut * maximum
|
||||
|
||||
|
||||
pymses: # Parameters for Pymses reader
|
||||
|
||||
# Source settings
|
||||
variables : ["rho", "vel", "P"] # Read these variables
|
||||
part_variables : ["vel","mass","id","level","epoch"] # Read these variables
|
||||
order : '<' # Bit order
|
||||
|
||||
|
||||
# Processing options
|
||||
levelmax : 20 # Maximal AMR level visited when looking levels
|
||||
fft : False # Quick and dirty rendering using FFT
|
||||
verbose : True # Let pymses write on standart output
|
||||
multiprocessing : True # Whether to use multiprocessing
|
||||
|
||||
# Camera settings
|
||||
center : [0.5, 0.5, 0.5] # Center of the image
|
||||
zoom : 4. # Zoom of the image
|
||||
map_size : 2048 # Size of the computed maps in pixel
|
||||
|
||||
# Filter parameters
|
||||
filter : False # Enable filtering
|
||||
min_coords : [0.35, 0.35, 0.45]
|
||||
max_coords : [0.65, 0.65, 0.55]
|
||||
|
||||
input: # Parameters on how to look for input files (= output from Ramses)
|
||||
|
||||
log_prefix : "run.log" # Prefix of the log file
|
||||
label_filename : "label.txt" # Name of the label file
|
||||
nml_filename : "galaxy.nml" # name of the namelist file
|
||||
ramses_ism : False # If ramses-ism is used
|
||||
|
||||
out: # Parameters for post processing
|
||||
tag : "" # Tag for the image
|
||||
interactive : True # Interactive mode (keep figures open)
|
||||
save : True # Save the plots on the disk
|
||||
ext : '.jpeg' # extension for plots
|
||||
fmt : "" # Format of the output filename for plots
|
||||
# The following keys are accepted
|
||||
# {out} : The output directory (where hdf5 files are also stored)
|
||||
# {run} : Name of the relevant run
|
||||
# {num} : Name of the input file (from Ramses)
|
||||
# {ext} : Extension defined above
|
||||
# {name} : Name of the rule
|
||||
# {tag} : Tag defined above
|
||||
# {nml[nml_key]} : The value of nml_key in the namelist (ex: {nml[amr_params/levelmin]})
|
||||
|
||||
|
||||
process: # General setting of the post-processor module
|
||||
verbose : True # Give more infos on what is going on
|
||||
num_process : 1 # Number of forks
|
||||
save_cells : True # Save cells structure on disk
|
||||
save_parts : True # Save particles on disk
|
||||
unload_cells : True # Save memory usage
|
||||
|
||||
rules: # Specific rules parameters
|
||||
turb_energy_threshold : -1 # Remove invalid data (<0 = no threshold)
|
||||
|
||||
|
||||
astrophysix: # Parameters for astrophysix and galactica
|
||||
simu_fmt : "{tag}_{run}" # Format of the name of simulation
|
||||
descr_fmt : "{tag}_{run}" # Format of the default description
|
||||
# The following keys are accepted
|
||||
# {run} : Name of the relevant run
|
||||
# {tag} : Tag defined above
|
||||
# {nml[nml_key]} : The value of nml_key in the namelist (ex: {nml[amr_params/levelmin]})
|
||||
Reference in New Issue
Block a user