Skip to content

Commit

Permalink
update HI match
Browse files Browse the repository at this point in the history
  • Loading branch information
yymao committed Dec 13, 2023
1 parent 6e79720 commit 07e4d85
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
4 changes: 4 additions & 0 deletions SAGA/database/saga_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ def __init__(self, shared_dir=None, local_dir=None):
),
use_local_first=True,
),
"spectra_fashi": DataObject(
FastCsvTable(os.path.join(self._shared_dir, "Spectra", "Final", "FASHI", "FASHI_oc_included.csv")),
),
"spectra_halpha": DataObject(
FileObject(
os.path.join(self._shared_dir, "Spectra", "saga_halpha.dat"),
Expand Down Expand Up @@ -448,6 +451,7 @@ def __init__(self, shared_dir=None, local_dir=None):
"slackers": self._tables["spectra_slackers"],
"palomar": self._tables["spectra_palomar"],
"alfalfa": self._tables["spectra_alfalfa"],
"fashi": self._tables["spectra_fashi"],
"hecs": self._tables["spectra_hecs"],
"hectomap": self._tables["spectra_hectomap"],
"vipers": (self._tables["spectra_vipers_w1"], self._tables["spectra_vipers_w4"]),
Expand Down
16 changes: 9 additions & 7 deletions SAGA/objects/build2.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def match_spectra_to_base_and_merge_duplicates(specs, base, debug=None, matching

def get_tel_rank(
tel,
ranks=("MMT", "AAT", "PAL", "BINO", "NSA", "_OTHERS", "SDSS", "ALFALF", "WIYN"),
ranks=("MMT", "AAT", "PAL", "BINO", "NSA", "_OTHERS", "SDSS", "WIYN", "FASHI", "ALFALF"),
):
try:
return ranks.index(tel)
Expand All @@ -696,12 +696,14 @@ def get_tel_rank(
# now it's the real thing, we have more than one specs
# we design a rank for each spec, using ZQUALITY, TELNAME, and SPEC_Z_ERR
specs_to_merge = specs[group_slice]
rank = np.fromiter(map(get_tel_rank, specs_to_merge["TELNAME"]), np.int32, len(specs_to_merge))
rank += (10 - specs_to_merge["ZQUALITY"]) * (rank.max() + 1)
rank = rank.astype(np.float32) + np.where(
Query((np.isfinite, "SPEC_Z_ERR"), "SPEC_Z_ERR > 0", "SPEC_Z_ERR < 1").mask(specs_to_merge),
specs_to_merge["SPEC_Z_ERR"],
0.99999,
rank = ((10 - specs_to_merge["ZQUALITY"])).astype(np.uint64)
rank *= np.uint64(100)
rank += np.fromiter(map(get_tel_rank, specs_to_merge["TELNAME"]), np.uint64, len(specs_to_merge))
rank *= np.uint64(10000)
rank += np.where(
Query("SPEC_Z_ERR >= 1e-10", "SPEC_Z_ERR < 1").mask(specs_to_merge),
np.floor((np.log10(np.maximum(specs_to_merge["SPEC_Z_ERR"], 1e-10)) + 10) * 1000).astype(np.uint64),
9999,
)
specs_to_merge = specs_to_merge[rank.argsort()]
best_spec = specs_to_merge[0]
Expand Down
1 change: 1 addition & 0 deletions SAGA/objects/cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"LCRS",
"slack",
"ALFALF",
"FASHI",
"SGA",
"HECS",
"HECMAP",
Expand Down
4 changes: 3 additions & 1 deletion SAGA/spectra/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
("MASKNAME", "<U48"),
("TELNAME", "<U6"),
("HELIO_CORR", "|b1"),
("LOG_MHI", "<f4"),
)

SPECS_COLUMNS = dict(_SPECS_COLUMNS)
Expand All @@ -38,7 +39,8 @@ def ensure_specs_dtype(spectra, cols_definition=_SPECS_COLUMNS, skip_missing_col
spectra[c] = False
else:
raise ValueError("unknown spec type!")
cols.append(c)
else:
cols.append(c)
if spectra[c].dtype.str != t:
spectra.replace_column(c, spectra[c].astype(t))
if spectra[c].description:
Expand Down
38 changes: 30 additions & 8 deletions SAGA/spectra/read_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"read_lcrs",
"read_slackers",
"read_alfalfa",
"read_fashi",
"read_hecs",
"read_hectomap",
"read_vipers",
Expand Down Expand Up @@ -302,23 +303,19 @@ def read_alfalfa(file_path):
"DECdeg_OC",
"Vhelio",
"W50",
"HIcode",
"logMH",
]

specs.rename_column("AGCNr", "SPECOBJID")
specs.rename_column("logMH", "LOG_MHI")

valid_oc_coord = Query(
"abs(RAdeg_OC) + abs(DECdeg_OC) > 0",
Query(np.isfinite, "RAdeg_OC"),
Query(np.isfinite, "DECdeg_OC"),
)

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["ZQUALITY"] = np.where(specs["HIcode"] == 1, 4, 3)
specs["ZQUALITY"] = np.where(valid_oc_coord, 3, 2)

specs["TELNAME"] = "ALFALF"
specs["MASKNAME"] = "ALFALFA"
Expand All @@ -327,6 +324,31 @@ def read_alfalfa(file_path):
return ensure_specs_dtype(specs, remove_extra_cols=True)


def read_fashi(file_path):

if not hasattr(file_path, "read"):
file_path = FastCsvTable(file_path)

specs = file_path.read()

# ID_FASHI,RA,DEC,z,z_err,log10Mass,RA_oc,DEC_oc
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")

valid_oc_coord = Query("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["TELNAME"] = "FASHI"
specs["MASKNAME"] = "FASHI"
specs["HELIO_CORR"] = True

return ensure_specs_dtype(specs, remove_extra_cols=True)


def read_hecs(file_path):
if not hasattr(file_path, "read"):
file_path = FitsTable(file_path)
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.67.1"
__version__ = "0.68.0"

0 comments on commit 07e4d85

Please sign in to comment.