Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def chisq_total(data, im, D):
if const_fpol:
fpol_model = D[-1]
fpol_data_1 = 2.0 * data['rlvis']/(data['rrvis'] + data['llvis'])
fpol_data_2 = 2.0 * np.conj(data['lrvis']/(data['rrvis'] + data['llvis']))
fpol_sigma_1 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['rlsigma']
fpol_sigma_2 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['lrsigma']
return 0.5*np.mean(np.abs((fpol_model - fpol_data_1)/fpol_sigma_1)**2
+ np.abs((fpol_model - fpol_data_2)/fpol_sigma_2)**2)
else:
chisq_RR = chisq_LL = chisq_RL = chisq_LR = 0.0
if 'RR' in pol_fit: chisq_RR = iu.chisq(im.rrvec, ARR, obs_test.unpack_dat(data,['rr' + dtype])['rr' + dtype], data['rrsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LL' in pol_fit: chisq_LL = iu.chisq(im.llvec, ALL, obs_test.unpack_dat(data,['ll' + dtype])['ll' + dtype], data['llsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'RL' in pol_fit: chisq_RL = iu.chisq(im.rlvec, ARL, obs_test.unpack_dat(data,['rl' + dtype])['rl' + dtype], data['rlsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LR' in pol_fit: chisq_LR = iu.chisq(im.lrvec, ALR, obs_test.unpack_dat(data,['lr' + dtype])['lr' + dtype], data['lrsigma'], dtype=dtype, ttype=ttype, mask=mask)
return (chisq_RR + chisq_LL + chisq_RL + chisq_LR)/len(pol_fit)
def chisq_total(data, im, D):
if const_fpol:
fpol_model = D[-1]
fpol_data_1 = 2.0 * data['rlvis']/(data['rrvis'] + data['llvis'])
fpol_data_2 = 2.0 * np.conj(data['lrvis']/(data['rrvis'] + data['llvis']))
fpol_sigma_1 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['rlsigma']
fpol_sigma_2 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['lrsigma']
return 0.5*np.mean(np.abs((fpol_model - fpol_data_1)/fpol_sigma_1)**2
+ np.abs((fpol_model - fpol_data_2)/fpol_sigma_2)**2)
else:
chisq_RR = chisq_LL = chisq_RL = chisq_LR = 0.0
if 'RR' in pol_fit: chisq_RR = iu.chisq(im.rrvec, ARR, obs_test.unpack_dat(data,['rr' + dtype])['rr' + dtype], data['rrsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LL' in pol_fit: chisq_LL = iu.chisq(im.llvec, ALL, obs_test.unpack_dat(data,['ll' + dtype])['ll' + dtype], data['llsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'RL' in pol_fit: chisq_RL = iu.chisq(im.rlvec, ARL, obs_test.unpack_dat(data,['rl' + dtype])['rl' + dtype], data['rlsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LR' in pol_fit: chisq_LR = iu.chisq(im.lrvec, ALR, obs_test.unpack_dat(data,['lr' + dtype])['lr' + dtype], data['lrsigma'], dtype=dtype, ttype=ttype, mask=mask)
return (chisq_RR + chisq_LL + chisq_RL + chisq_LR)/len(pol_fit)
def chisq_total(data, im, D):
if const_fpol:
fpol_model = D[-1]
fpol_data_1 = 2.0 * data['rlvis']/(data['rrvis'] + data['llvis'])
fpol_data_2 = 2.0 * np.conj(data['lrvis']/(data['rrvis'] + data['llvis']))
fpol_sigma_1 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['rlsigma']
fpol_sigma_2 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['lrsigma']
return 0.5*np.mean(np.abs((fpol_model - fpol_data_1)/fpol_sigma_1)**2
+ np.abs((fpol_model - fpol_data_2)/fpol_sigma_2)**2)
else:
chisq_RR = chisq_LL = chisq_RL = chisq_LR = 0.0
if 'RR' in pol_fit: chisq_RR = iu.chisq(im.rrvec, ARR, obs_test.unpack_dat(data,['rr' + dtype])['rr' + dtype], data['rrsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LL' in pol_fit: chisq_LL = iu.chisq(im.llvec, ALL, obs_test.unpack_dat(data,['ll' + dtype])['ll' + dtype], data['llsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'RL' in pol_fit: chisq_RL = iu.chisq(im.rlvec, ARL, obs_test.unpack_dat(data,['rl' + dtype])['rl' + dtype], data['rlsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LR' in pol_fit: chisq_LR = iu.chisq(im.lrvec, ALR, obs_test.unpack_dat(data,['lr' + dtype])['lr' + dtype], data['lrsigma'], dtype=dtype, ttype=ttype, mask=mask)
return (chisq_RR + chisq_LL + chisq_RL + chisq_LR)/len(pol_fit)
def chisq_total(data, im, D):
if const_fpol:
fpol_model = D[-1]
fpol_data_1 = 2.0 * data['rlvis']/(data['rrvis'] + data['llvis'])
fpol_data_2 = 2.0 * np.conj(data['lrvis']/(data['rrvis'] + data['llvis']))
fpol_sigma_1 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['rlsigma']
fpol_sigma_2 = 2.0/np.abs(data['rrvis'] + data['llvis']) * data['lrsigma']
return 0.5*np.mean(np.abs((fpol_model - fpol_data_1)/fpol_sigma_1)**2
+ np.abs((fpol_model - fpol_data_2)/fpol_sigma_2)**2)
else:
chisq_RR = chisq_LL = chisq_RL = chisq_LR = 0.0
if 'RR' in pol_fit: chisq_RR = iu.chisq(im.rrvec, ARR, obs_test.unpack_dat(data,['rr' + dtype])['rr' + dtype], data['rrsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LL' in pol_fit: chisq_LL = iu.chisq(im.llvec, ALL, obs_test.unpack_dat(data,['ll' + dtype])['ll' + dtype], data['llsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'RL' in pol_fit: chisq_RL = iu.chisq(im.rlvec, ARL, obs_test.unpack_dat(data,['rl' + dtype])['rl' + dtype], data['rlsigma'], dtype=dtype, ttype=ttype, mask=mask)
if 'LR' in pol_fit: chisq_LR = iu.chisq(im.lrvec, ALR, obs_test.unpack_dat(data,['lr' + dtype])['lr' + dtype], data['lrsigma'], dtype=dtype, ttype=ttype, mask=mask)
return (chisq_RR + chisq_LL + chisq_RL + chisq_LR)/len(pol_fit)
fft_pad_factor (float): zero pad the image to fft_pad_factor * image size in FFT
systematic_noise (float): a fractional systematic noise tolerance to add to thermal sigmas
systematic_noise_cphase (float): a value in degrees to add to the closure phase sigmas
maxset (bool): set to True to use a maximal set instead of minimal set
Returns:
(float): image chi^2
"""
# TODO -- import this at top, but circular dependencies create a mess...
import ehtim.imaging.imager_utils as iu
(data, sigma, A) = iu.chisqdata(self, im, mask, dtype, ttype=ttype,
fft_pad_factor=fft_pad_factor, maxset=maxset,
systematic_cphase_noise=systematic_cphase_noise,
systematic_noise=systematic_noise)
chisq = iu.chisq(im.imvec, A, data, sigma, dtype, ttype=ttype, mask=mask)
return chisq