Skip to content

Commit b017bc5

Browse files
authored
Merge pull request #24 from SWIFTSIM/spherical_overdensity
Register Spherical Over-density Quantities
2 parents bde3463 + 4cceb7c commit b017bc5

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

velociraptor/catalogue/registration.py

+40
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,45 @@ def registration_species_fractions(
970970

971971
return unit, full_name, snake_case
972972

973+
def registration_spherical_overdensities(
974+
field_path: str, unit_system: VelociraptorUnits
975+
) -> (unyt.Unit, str, str):
976+
"""
977+
Registers SO aperture values by searching them with regex.
978+
"""
979+
980+
# Capture group 1: quantity
981+
# Capture group 2: particle type
982+
# Capture group 3: sf / nsf
983+
# Capture group 4: size of aperture
984+
985+
match_string = "SO_([^_]*)_([a-zA-Z]*)?_?([a-zA-Z]*)?_?([0-9]*)_rhocrit"
986+
regex = cached_regex(match_string)
987+
988+
match = regex.match(field_path)
989+
990+
if match:
991+
quantity = match.group(1)
992+
ptype = match.group(2)
993+
star_forming = match.group(3)
994+
aperture_size = int(match.group(4))
995+
996+
unit = get_aperture_unit(quantity, unit_system)
997+
name = get_particle_property_name_conversion(quantity, ptype)
998+
999+
if star_forming:
1000+
sf_in_name = f"{star_forming.upper()} "
1001+
else:
1002+
sf_in_name = ""
1003+
1004+
full_name = f"{sf_in_name}{name} ({aperture_size} \\rho_{{\\rm crit}})"
1005+
snake_case = field_path.lower().replace("so_", "")
1006+
1007+
return unit, full_name, snake_case
1008+
else:
1009+
raise RegistrationDoesNotMatchError
1010+
1011+
9731012

9741013
# TODO
9751014
# lambda_B
@@ -997,6 +1036,7 @@ def registration_species_fractions(
9971036
"ids",
9981037
"energies",
9991038
"stellar_age",
1039+
"spherical_overdensities",
10001040
"rotational_support",
10011041
"star_formation_rate",
10021042
"masses",

velociraptor/catalogue/translator.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ def get_aperture_unit(unit_name: str, unit_system: VelociraptorUnits):
2828
"""
2929

3030
# Correct any typos
31-
corrected_name = typo_correct(unit_name)
31+
corrected_name = typo_correct(unit_name).lower()
3232

3333
key = {
34-
"SFR": unit_system.star_formation_rate,
35-
"Zmet": unit_system.metallicity,
34+
"sfr": unit_system.star_formation_rate,
35+
"zmet": unit_system.metallicity,
3636
"mass": unit_system.mass,
3737
"npart": unyt.dimensionless,
3838
"rhalfmass": unit_system.length,
3939
"veldisp": unit_system.velocity,
40+
"r": unit_system.length,
41+
"lx": unit_system.length * unit_system.velocity,
42+
"ly": unit_system.length * unit_system.velocity,
43+
"lz": unit_system.length * unit_system.velocity,
4044
}
4145

4246
return key.get(corrected_name, None)
@@ -51,15 +55,15 @@ def get_particle_property_name_conversion(name: str, ptype: str):
5155

5256
corrected_name = typo_correct(name)
5357

54-
combined_name = f"{corrected_name}_{ptype}"
58+
combined_name = f"{corrected_name}_{ptype}".lower()
5559

5660
key = {
57-
"SFR_": "SFR $\dot{\\rho}_*$",
58-
"SFR_gas": "Gas SFR $\dot{\\rho}_*$",
59-
"Zmet_": "Metallicity $Z$",
60-
"Zmet_gas": "Gas Metallicity $Z_{\\rm g}$",
61-
"Zmet_star": "Star Metallicity $Z_*$",
62-
"Zmet_bh": "Black Hole Metallicity $Z_{\\rm BH}$",
61+
"sfr_": "SFR $\dot{\\rho}_*$",
62+
"sfr_gas": "Gas SFR $\dot{\\rho}_*$",
63+
"zmet_": "Metallicity $Z$",
64+
"zmet_gas": "Gas Metallicity $Z_{\\rm g}$",
65+
"zmet_star": "Star Metallicity $Z_*$",
66+
"zmet_bh": "Black Hole Metallicity $Z_{\\rm BH}$",
6367
"mass_": "Mass $M$",
6468
"mass_gas": "Gas Mass $M_{\\rm g}$",
6569
"mass_star": "Stellar Mass $M_*$",
@@ -74,11 +78,12 @@ def get_particle_property_name_conversion(name: str, ptype: str):
7478
"rhalfmass_gas": "Gas Half-mass Radius $R_{50, {\\rm g}}$",
7579
"rhalfmass_star": "Stellar Half-mass Radius $R_{50, *}$",
7680
"rhalfmass_bh": "Black Hole Half-mass Radius $R_{50, {\\rm BH}}$",
81+
"r_": "Radius $R_{\\rm SO}$",
7782
"veldisp_": "Velocity Dispersion $\sigma$",
7883
"veldisp_gas": "Gas Velocity Dispersion $\sigma_{\\rm g}}$",
7984
"veldisp_star": "Stellar Velocity Dispersion $\sigma_{*}$",
8085
"veldisp_bh": "Black Hole Velocity Dispersion $\sigma_{\\rm BH}$",
81-
"SubgridMasses_aperture_total_solar_mass_bh": "Subgrid Black Hole Mass $M_{\\rm BH}$",
86+
"subgridmasses_aperture_total_solar_mass_bh": "Subgrid Black Hole Mass $M_{\\rm BH}$",
8287
}
8388

8489
return key.get(combined_name, corrected_name)

0 commit comments

Comments
 (0)