Skip to content

Commit

Permalink
fix HI masses
Browse files Browse the repository at this point in the history
  • Loading branch information
yymao committed Dec 13, 2023
1 parent 44c0d62 commit 3e60e12
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
19 changes: 14 additions & 5 deletions SAGA/objects/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,24 +894,33 @@ def add_stellar_mass(base):
if "z_cosmo" not in base.colnames:
base = add_z_cosmo(base)

# HOST_ZCOSMO is calculated using host's distance, not measured redshift
z = np.where(np.isfinite(base["z_cosmo"]), base["z_cosmo"], base["HOST_ZCOSMO"])
z = np.clip(z, np.finfo(np.float32).eps, None)
gr = base["g_mag"] - base["r_mag"]

with np.errstate(invalid="ignore"):
base["Mr_phony"] = (base["r_mag"] - z2m(z) - calc_kcor("r", z, "g - r", gr)).astype(np.float32)
base["log_sm_phony"] = (1.254 + 1.0976 * gr - 0.4 * base["Mr_phony"]).astype(np.float32)
base["Mr_phony"] = (base["r_mag"] - z2m(z) - calc_kcor("r", z, "g - r", gr))
base["log_sm_phony"] = (1.254 + 1.0976 * gr - 0.4 * base["Mr_phony"])
base["log_MHI_phony"] = np.log10(2.356e5 / (z + 1.0) * (z2d(z) ** 2) * base["HI_FLUX"])

ok_to_calculate = Query(
QueryMaker.isfinite("Mr_phony"),
QueryMaker.isfinite("z_cosmo"),
"z_cosmo >= 0.001",
"z_cosmo < 0.5",
"abs(g_mag - r_mag) < 10",
).mask(base)

base["Mr"] = np.where(ok_to_calculate, base["Mr_phony"], np.float32(np.nan))
base["log_sm"] = np.where(ok_to_calculate, base["log_sm_phony"], np.float32(np.nan))
base["Mr"] = np.where(ok_to_calculate, base["Mr_phony"], np.nan).astype(np.float32)
base["log_sm"] = np.where(ok_to_calculate, base["log_sm_phony"], np.nan).astype(np.float32)

ok_to_calculate = Query(
"HI_FLUX > 0",
"z_cosmo >= 0.001",
"z_cosmo < 0.5",
).mask(base)

base["log_MHI"] = np.where(ok_to_calculate, base["log_MHI_phony"], np.nan).astype(np.float32)

return base

Expand Down
8 changes: 5 additions & 3 deletions SAGA/objects/build2.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,11 @@ def get_tel_rank(
set(specs_to_merge["TELNAME"][mask_within_dz & mask_same_zq_class])
)
specs["SPEC_REPEAT_ALL"][best_spec_index] = "+".join(set(specs_to_merge["TELNAME"]))
log_MHI = specs_to_merge["LOG_MHI"][mask_within_dz & np.isfinite(specs_to_merge["LOG_MHI"])]
if len(log_MHI):
specs["LOG_MHI"][best_spec_index] = log_MHI[0]
has_HI = mask_within_dz & (specs_to_merge["HI_FLUX"] > 0)
if has_HI.any():
has_HI = np.argmax(has_HI)
for c in ["HI_FLUX", "HI_FLUX_ERR"]:
specs[c][best_spec_index] = specs_to_merge[c][has_HI]

nsa_specs = specs_to_merge[specs_to_merge["TELNAME"] == "NSA"]
specs["OBJ_NSAID"][best_spec_index] = int(nsa_specs["SPECOBJID"][0]) if len(nsa_specs) else -1
Expand Down
3 changes: 2 additions & 1 deletion SAGA/spectra/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
("MASKNAME", "<U48"),
("TELNAME", "<U6"),
("HELIO_CORR", "|b1"),
("LOG_MHI", "<f4"),
("HI_FLUX", "<f4"),
("HI_FLUX_ERR", "<f4"),
)

SPECS_COLUMNS = dict(_SPECS_COLUMNS)
Expand Down
15 changes: 10 additions & 5 deletions SAGA/spectra/read_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,21 @@ def read_alfalfa(file_path):
"RAdeg_OC",
"DECdeg_OC",
"Vhelio",
"W50",
"logMH",
"sigW",
"HIflux",
"sigflux",
]

specs.rename_column("AGCNr", "SPECOBJID")
specs.rename_column("logMH", "LOG_MHI")
specs.rename_column("HIflux", "HI_FLUX")
specs.rename_column("sigflux", "HI_FLUX_ERR")

valid_oc_coord = Query("abs(RAdeg_OC) + abs(DECdeg_OC) > 0").mask(specs)
specs["RA"] = np.where(valid_oc_coord, specs["RAdeg_OC"], specs["RAdeg_HI"])
specs["DEC"] = np.where(valid_oc_coord, specs["DECdeg_OC"], specs["DECdeg_HI"])

specs["SPEC_Z"] = specs["Vhelio"].astype(np.float64) / SPEED_OF_LIGHT
specs["SPEC_Z_ERR"] = specs["W50"].astype(np.float64) / SPEED_OF_LIGHT / np.sqrt(2 * np.log(2))
specs["SPEC_Z_ERR"] = specs["sigW"].astype(np.float64) * 0.5 / SPEED_OF_LIGHT
specs["ZQUALITY"] = np.where(valid_oc_coord, 3, 2)

specs["TELNAME"] = "ALFALF"
Expand All @@ -335,12 +337,15 @@ def read_fashi(file_path):
specs.rename_column("ID_FASHI", "SPECOBJID")
specs.rename_column("z", "SPEC_Z")
specs.rename_column("z_err", "SPEC_Z_ERR")
specs.rename_column("log10Mass", "LOG_MHI")
specs.rename_column("S_bf", "HI_FLUX")
specs.rename_column("S_bf_err", "HI_FLUX_ERR")

valid_oc_coord = Query("oc_flag > 0.9995", "abs(RA_oc) + abs(DEC_oc) > 0").mask(specs)
specs["RA"] = np.where(valid_oc_coord, specs["RA_oc"], specs["RA"])
specs["DEC"] = np.where(valid_oc_coord, specs["DEC_oc"], specs["DEC"])
specs["ZQUALITY"] = np.where(valid_oc_coord, 3, 2)
specs["HI_FLUX"] *= 1.0e-3 # convret from mJy to Jy
specs["HI_FLUX_ERR"] *= 1.0e-3 # convret from mJy to Jy

specs["TELNAME"] = "FASHI"
specs["MASKNAME"] = "FASHI"
Expand Down
2 changes: 1 addition & 1 deletion SAGA/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""
SAGA package version
"""
__version__ = "0.68.0"
__version__ = "0.68.1"

0 comments on commit 3e60e12

Please sign in to comment.