add loader for osyris

This commit is contained in:
Noe Brucy
2025-03-21 14:13:06 +01:00
parent 55d09c691c
commit a7284a6f99

View File

@@ -0,0 +1,55 @@
# coding: utf-8
import numpy as np
import osyris
def load_fields_osyris(path="", snap_id=0, data=None):
"""
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
"""
if data is None:
data = osyris.RamsesDataset(snap_id, path=path).load(select=["mesh", "part"])
time = data.meta["time"].to("Myr").magnitude
boxlen = data.meta["boxlen"] * data.units["x"].to("kpc")
gas = data["mesh"]
center = osyris.Vector(x=500, y=500, z=500, unit="pc")
# Create dataset
data = {
"header": {"time": time,
"fluids": ["gas"],
"box_size": boxlen },
"gas": {
"position": (gas["position"] - center).to("kpc").values,
"volume": (gas["dx"]**3).to("pc^3").values,
"velocity": gas["velocity"].to("km/s").values,
"mass": (gas["density"] * gas["dx"]**3).to("M_sun").values
},
}
return data