@@ -293,7 +293,7 @@ def compute_relative_polarimetry(cls, polarimetry_group):
293293 # 1. Compute all aperture photometries
294294
295295 aperpix , r_in , r_out , fit_res_dict = cls .estimate_common_apertures (polarimetry_group , reductionmethod = REDUCTIONMETHODS .RELPHOT )
296- target_fwhm = fit_res_dict [' mean_fwhm' ]
296+ mean_fwhm = fit_res_dict [" mean_fwhm" ]
297297
298298 logger .debug (f"Computing aperture photometries for the { len (polarimetry_group )} reducedfits in the group with target { aperpix :.1f} ." )
299299
@@ -307,18 +307,20 @@ def compute_relative_polarimetry(cls, polarimetry_group):
307307 photopolresult_L = list ()
308308
309309 for astrosource in group_sources :
310+
311+ qs = AperPhotResult .objects .filter (reducedfit__in = polarimetry_group , astrosource = astrosource , aperpix = aperpix , pairs = "O" )
310312
311- flux_0 = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , aperpix = aperpix , pairs = "O" , reducedfit__rotangle = 0.0 ).flux_counts
312- flux_0_err = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , pairs = "O" , aperpix = aperpix , reducedfit__rotangle = 0.0 ).flux_counts_err
313+ flux_0 = qs . get (reducedfit__rotangle = 0.0 ).flux_counts
314+ flux_0_err = qs . get (reducedfit__rotangle = 0.0 ).flux_counts_err
313315
314- flux_45 = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , pairs = "O" , aperpix = aperpix , reducedfit__rotangle = 45.0 ).flux_counts
315- flux_45_err = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , pairs = "O" , aperpix = aperpix , reducedfit__rotangle = 45.0 ).flux_counts_err
316+ flux_45 = qs . get (reducedfit__rotangle = 45.0 ).flux_counts
317+ flux_45_err = qs . get (reducedfit__rotangle = 45.0 ).flux_counts_err
316318
317- flux_90 = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , pairs = "O" , aperpix = aperpix , reducedfit__rotangle = 90.0 ).flux_counts
318- flux_90_err = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , pairs = "O" , aperpix = aperpix , reducedfit__rotangle = 90.0 ).flux_counts_err
319+ flux_90 = qs . get (reducedfit__rotangle = 90.0 ).flux_counts
320+ flux_90_err = qs . get (reducedfit__rotangle = 90.0 ).flux_counts_err
319321
320- flux_n45 = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , pairs = "O" , aperpix = aperpix , reducedfit__rotangle = - 45.0 ).flux_counts
321- flux_n45_err = AperPhotResult . objects . get (reducedfit__in = polarimetry_group , astrosource = astrosource , pairs = "O" , aperpix = aperpix , reducedfit__rotangle = - 45.0 ).flux_counts_err
322+ flux_n45 = qs . get (reducedfit__rotangle = - 45.0 ).flux_counts
323+ flux_n45_err = qs . get (reducedfit__rotangle = - 45.0 ).flux_counts_err
322324
323325 # from IOP3 polarimetry_osn() :
324326
@@ -340,34 +342,28 @@ def compute_relative_polarimetry(cls, polarimetry_group):
340342 dqc = math .sqrt (dqraw ** 2 + dqoff ** 2 )
341343 duc = math .sqrt (duraw ** 2 + duoff ** 2 )
342344
343- q = qc * math .cos (2 * Phi ) - uc * math .sin (2 * Phi )
344- u = qc * math .sin (2 * Phi ) + uc * math .cos (2 * Phi )
345+ qr = qc * math .cos (2 * Phi ) - uc * math .sin (2 * Phi )
346+ ur = qc * math .sin (2 * Phi ) + uc * math .cos (2 * Phi )
345347
346348 dqa = qc * math .cos (2 * Phi ) * math .sqrt ((dqc / qc )** 2 + ((2 * dPhi * math .sin (2 * Phi ))/ (math .cos (2 * Phi )))** 2 )
347349 dqb = uc * math .sin (2 * Phi ) * math .sqrt ((duc / uc )** 2 + ((2 * dPhi * math .cos (2 * Phi ))/ (math .sin (2 * Phi )))** 2 )
348350 dua = qc * math .sin (2 * Phi ) * math .sqrt ((dqc / qc )** 2 + ((2 * dPhi * math .cos (2 * Phi ))/ (math .sin (2 * Phi )))** 2 )
349351 dub = uc * math .cos (2 * Phi ) * math .sqrt ((duc / uc )** 2 + ((2 * dPhi * math .sin (2 * Phi ))/ (math .cos (2 * Phi )))** 2 )
350352
351- dq = np .sqrt (dqa ** 2 + dqb ** 2 )
352- du = np .sqrt (dua ** 2 + dub ** 2 )
353+ dqr = np .sqrt (dqa ** 2 + dqb ** 2 )
354+ dur = np .sqrt (dua ** 2 + dub ** 2 )
353355
354- P = math .sqrt (q ** 2 + u ** 2 )
355- dP = P * (1 / (q ** 2 + u ** 2 )) * math .sqrt ((q * dq )** 2 + (u * du )** 2 )
356+ P = math .sqrt (qr ** 2 + ur ** 2 )
357+ dP = P * (1 / (qr ** 2 + ur ** 2 )) * math .sqrt ((qr * dqr )** 2 + (ur * dur )** 2 )
356358
357359 Theta_0 = 0
358- Theta = (1 / 2 ) * math .degrees (math .atan2 (u , q ) + Theta_0 )
360+ Theta = (1 / 2 ) * math .degrees (math .atan2 (ur , qr ) + Theta_0 )
359361 dTheta = (0.5 * 180.0 / math .pi ) * dP / P
360362
361363 # compute also non-corrected values for computation of instrumental polarization
362364
363- _Phi_nocorr = 0 # no rotation correction?
364- _qc_nocorr = qraw # no offset correction
365- _uc_nocorr = uraw # no offset correction
366- _q_nocorr = _qc_nocorr * math .cos (2 * _Phi_nocorr ) - _uc_nocorr * math .sin (2 * _Phi_nocorr )
367- _u_nocorr = _qc_nocorr * math .sin (2 * _Phi_nocorr ) + _uc_nocorr * math .cos (2 * _Phi_nocorr )
368- _p_nocorr = math .sqrt (_q_nocorr ** 2 + _u_nocorr ** 2 )
369- _Theta_0_nocorr = 0
370- _Theta_nocorr = (1 / 2 ) * math .degrees (math .atan2 (_u_nocorr ,_q_nocorr ) + _Theta_0_nocorr )
365+ _p_nocorr = math .sqrt (qraw ** 2 + uraw ** 2 )
366+ _Theta_nocorr = (1 / 2 ) * math .degrees (math .atan2 (uraw ,qraw ))
371367 _x_px , _y_px = astrosource .coord .to_pixel (polarimetry_group [0 ].wcs )
372368
373369 # compute instrumental magnitude (same as for CAHA)
@@ -397,14 +393,25 @@ def compute_relative_polarimetry(cls, polarimetry_group):
397393
398394 # save the results
399395
400- result = PhotoPolResult .create (reducedfits = polarimetry_group ,
401- astrosource = astrosource ,
402- reduction = REDUCTIONMETHODS .RELPOL ,
403- mag_inst = mag_inst , mag_inst_err = mag_inst_err , mag_zp = mag_zp , mag_zp_err = mag_zp_err ,
404- flux_counts = flux_mean , p = P , p_err = dP , chi = Theta , chi_err = dTheta ,
405- _x_px = _x_px , _y_px = _y_px , _q_nocorr = _q_nocorr , _u_nocorr = _u_nocorr , _p_nocorr = _p_nocorr , _chi_nocorr = _Theta_nocorr ,
406- aperpix = aperpix )
396+ result = PhotoPolResult .create (
397+ reducedfits = polarimetry_group ,
398+ astrosource = astrosource ,
399+ reduction = REDUCTIONMETHODS .RELPOL ,
400+ mag_inst = mag_inst , mag_inst_err = mag_inst_err ,
401+ mag_zp = mag_zp , mag_zp_err = mag_zp_err ,
402+ flux_counts = flux_mean ,
403+ p = P , p_err = dP ,
404+ chi = Theta , chi_err = dTheta ,
405+ aperpix = aperpix ,
406+ aperas = aperpix * polarimetry_group [0 ].pixscale .to (u .arcsec / u .pix ).value ,
407+ fwhm = mean_fwhm * polarimetry_group [0 ].pixscale .to (u .arcsec / u .pix ).value ,
408+ _x_px = _x_px , _y_px = _y_px ,
409+ _q_nocorr = qraw , _u_nocorr = uraw ,
410+ _p_nocorr = _p_nocorr , _chi_nocorr = _Theta_nocorr ,
411+ )
407412
413+ result .aperphotresults .set (qs , clear = True )
414+
408415 photopolresult_L .append (result )
409416
410417
0 commit comments