Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip missing sources in CAFOS polarimetry groups #153

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions iop4lib/instruments/cafos.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ def compute_relative_polarimetry(cls, polarimetry_group):

qs = AperPhotResult.objects.filter(reducedfit__in=polarimetry_group, astrosource=astrosource, aperpix=aperpix, flux_counts__isnull=False)

if not qs.exists():
logger.error(f"No aperture photometry results found for {astrosource}, skipping.")
continue

equivs = ((('O',0.0), ('E',44.98)),
(('O',22.48), ('E',67.48)),
(('O',44.98), ('E',0.0)),
Expand All @@ -299,16 +303,20 @@ def compute_relative_polarimetry(cls, polarimetry_group):
(('E',67.48), ('O',22.48)))

flux_D = dict()
_skip = False
for equiv in equivs:
if qs.filter(pairs=equiv[0][0], reducedfit__rotangle=equiv[0][1]).exists():
flux_D[(equiv[0][0], equiv[0][1])] = qs.filter(pairs=equiv[0][0], reducedfit__rotangle=equiv[0][1]).values_list("flux_counts", "flux_counts_err").last()
elif qs.filter(pairs=equiv[1][0], reducedfit__rotangle=equiv[1][1]).exists():
logger.warning(f"Missing flux for {astrosource} {equiv[0][0]} {equiv[0][1]}, using {equiv[1][0]} {equiv[1][1]}")
flux_D[(equiv[0][0], equiv[0][1])] = qs.filter(pairs=equiv[1][0], reducedfit__rotangle=equiv[1][1]).values_list("flux_counts", "flux_counts_err").last()
else:
logger.error(f"Missing flux for {astrosource} {equiv[0][0]} {equiv[0][1]} and {equiv[1][0]} {equiv[1][1]}")
return

logger.error(f"Missing flux for {astrosource} {equiv[0][0]} {equiv[0][1]} and {equiv[1][0]} {equiv[1][1]}, skipping this source.")
_skip = True
break
if _skip:
continue

flux_O_0, flux_O_0_err = flux_D[('O',0.0)]
flux_O_22, flux_O_22_err = flux_D[('O',22.48)]
flux_O_45, flux_O_45_err = flux_D[('O',44.98)]
Expand Down Expand Up @@ -396,7 +404,10 @@ def compute_relative_polarimetry(cls, polarimetry_group):

photopolresult_L.append(result)


if not photopolresult_L:
logger.error("No results could be computed for this group.")
return

# 3. Get average zero point from zp of all calibrators in the group

calib_mag_zp_array = np.array([result.mag_zp or np.nan for result in photopolresult_L if result.astrosource.is_calibrator]) # else it fills with None also and the dtype becomes object
Expand Down
Loading