Skip to content

Commit

Permalink
Check for NaN and inf when calculating the goodness-of-fit statistic …
Browse files Browse the repository at this point in the history
…in CompareSpectra
  • Loading branch information
tomasstolker committed Jun 26, 2024
1 parent c680303 commit 16206ae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
1 change: 0 additions & 1 deletion species/data/companion_data/companion_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@
"Chauvin et al. 2004",
"Gaia Early Data Release 3",
"Mohanty et al. 2007",
"Mohanty et al. 200z",
"Patience et al. 2010",
"Song et al. 2006"
]
Expand Down
2 changes: 0 additions & 2 deletions species/data/model_data/model_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ def add_model_grid(
flush=True,
)

print(data_folder)
print(data_file)
extract_tarfile(str(data_file), str(data_folder), member_list=member_list)

print(" [DONE]")
Expand Down
9 changes: 6 additions & 3 deletions species/fit/compare_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,15 @@ def spectral_type(
g_k = 0.0
c_k_spec = []

c_k = np.sum(c_numer) / np.sum(c_denom)
idx_select = np.isfinite(c_numer) & np.isfinite(c_denom)

c_k = np.sum(c_numer[idx_select]) / np.sum(c_denom[idx_select])
c_k_spec.append(c_k)

chi_sq = (
spec_item[indices, 1] - c_k * flux_resample
) / spec_item[indices, 2]
spec_item[indices, 1][idx_select] - c_k * flux_resample[idx_select]
) / spec_item[indices, 2][idx_select]
print(chi_sq)

g_k += np.sum(w_i * chi_sq**2)

Expand Down
2 changes: 1 addition & 1 deletion species/util/fit_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def get_residuals(

n_param = dset.attrs["n_param"]

if "fixed_param" in hdf5_file[f"results/fit/{tag}/"]:
if "n_fixed" in dset.attrs:
n_fixed = dset.attrs["n_fixed"]

else:
Expand Down
20 changes: 14 additions & 6 deletions species/util/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,12 @@ def update_labels(param: List[str], object_type: str = "planet") -> List[str]:
index = param.index("fsed")
param[index] = r"$f_\mathrm{sed}$"

if "fsed_1" in param:
index = param.index("fsed_1")
if "fsed_0" in param:
index = param.index("fsed_0")
param[index] = r"$f_\mathrm{sed,1}$"

if "fsed_2" in param:
index = param.index("fsed_2")
if "fsed_1" in param:
index = param.index("fsed_1")
param[index] = r"$f_\mathrm{sed,2}$"

if "f_clouds" in param:
Expand Down Expand Up @@ -1078,14 +1078,19 @@ def quantity_unit(

elif item_split[0] == "logg":
quantity.append(f"logg_{param_index}")
unit.append("")
unit.append(None)
label.append(rf"$\log g_\mathrm{{{param_index+1}}}$")

elif item_split[0] == "feh":
quantity.append(f"feh_{param_index}")
unit.append("")
unit.append(None)
label.append(rf"[Fe/H]$_\mathrm{{{param_index+1}}}$")

elif item_split[0] == "fsed":
quantity.append(f"fsed_{param_index}")
unit.append(None)
label.append(rf"$f_\mathrm{{sed,{param_index+1}}}$")

elif item_split[0] == "radius":
quantity.append(f"radius_{param_index}")

Expand Down Expand Up @@ -1556,6 +1561,9 @@ def create_model_label(
elif param_item[:3] == "feh":
value = f"{model_param[param_item]:{param_fmt['feh']}}"

elif param_item[:4] == "fsed":
value = f"{model_param[param_item]:{param_fmt['fsed']}}"

elif param_item[:6] == "radius":
if object_type == "planet":
value = f"{model_param[param_item]:{param_fmt['radius']}}"
Expand Down

0 comments on commit 16206ae

Please sign in to comment.