Skip to content

Commit

Permalink
Add ASAD method for polarization
Browse files Browse the repository at this point in the history
  • Loading branch information
eneights committed Sep 3, 2024
1 parent 99fdff7 commit 440ebff
Show file tree
Hide file tree
Showing 3 changed files with 1,067 additions and 0 deletions.
1 change: 1 addition & 0 deletions cosipy/polarization/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .polarization_asad import PolarizationASAD, calculate_uncertainties

Check warning on line 1 in cosipy/polarization/__init__.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/__init__.py#L1

Added line #L1 was not covered by tests
384 changes: 384 additions & 0 deletions cosipy/polarization/polarization_asad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,384 @@
import numpy as np
from astropy.coordinates import Angle
import astropy.units as u
from astropy.stats import poisson_conf_interval
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from cosipy.polarization import PolarizationAngle
from cosipy.polarization.conventions import MEGAlibRelativeX, IAUPolarizationConvention
from scoords import SpacecraftFrame

Check warning on line 9 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L1-L9

Added lines #L1 - L9 were not covered by tests

def calculate_uncertainties(counts):

Check warning on line 11 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L11

Added line #L11 was not covered by tests
"""
Calculate the Poisson/Gaussian uncertainties for a list of binned counts.
Parameters
----------
counts : list
List of counts in each bin
Returns
-------
uncertainties : np.ndarray
Lower & upper uncertainties for each bin
"""

uncertainties_low = []
uncertainties_high = []
for i in range(len(counts)):
if counts[i] <= 5:
poisson_uncertainty = poisson_conf_interval(counts[i], interval="frequentist-confidence", sigma=1)
uncertainties_low.append(counts[i] - poisson_uncertainty[0])
uncertainties_high.append(poisson_uncertainty[1] - counts[i])

Check warning on line 32 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L26-L32

Added lines #L26 - L32 were not covered by tests
else:
gaussian_uncertainty = np.sqrt(counts[i])
uncertainties_low.append(gaussian_uncertainty)
uncertainties_high.append(gaussian_uncertainty)

Check warning on line 36 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L34-L36

Added lines #L34 - L36 were not covered by tests

uncertainties = np.array([uncertainties_low, uncertainties_high])

Check warning on line 38 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L38

Added line #L38 was not covered by tests

return uncertainties

Check warning on line 40 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L40

Added line #L40 was not covered by tests

class PolarizationASAD():

Check warning on line 42 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L42

Added line #L42 was not covered by tests
"""
Azimuthal scattering angle distribution (ASAD) method to fit polarization.
Parameters
----------
source_vector : astropy.coordinates.sky_coordinate.SkyCoord
Source direction
fit_convention : cosipy.polarization.conventions.PolarizationConvention, optional
Polarization reference convention to use for fit. Default is RelativeX
"""

def __init__(self, source_vector, fit_convention=None):

Check warning on line 54 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L54

Added line #L54 was not covered by tests

if fit_convention == None:
self._convention = MEGAlibRelativeX(attitude=source_vector.attitude)

Check warning on line 57 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L56-L57

Added lines #L56 - L57 were not covered by tests
else:
self._convention = fit_convention

Check warning on line 59 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L59

Added line #L59 was not covered by tests

reference_vector = self._convention.get_basis(source_vector)[0] #px

Check warning on line 61 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L61

Added line #L61 was not covered by tests

if isinstance(source_vector.frame, SpacecraftFrame):
self._source_vector = source_vector

Check warning on line 64 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L63-L64

Added lines #L63 - L64 were not covered by tests
else:
self._source_vector = source_vector.transform_to(SpacecraftFrame(attitude=source_vector.attitude))

Check warning on line 66 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L66

Added line #L66 was not covered by tests

if isinstance(reference_vector.frame, SpacecraftFrame):
self._reference_vector = reference_vector

Check warning on line 69 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L68-L69

Added lines #L68 - L69 were not covered by tests
else:
self._reference_vector = reference_vector.transform_to(SpacecraftFrame(attitude=source_vector.attitude))

Check warning on line 71 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L71

Added line #L71 was not covered by tests

self._source_vector_cartesian = [self._source_vector.cartesian.x.value,

Check warning on line 73 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L73

Added line #L73 was not covered by tests
self._source_vector.cartesian.y.value,
self._source_vector.cartesian.z.value]
self._reference_vector_cartesian = [self._reference_vector.cartesian.x.value,

Check warning on line 76 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L76

Added line #L76 was not covered by tests
self._reference_vector.cartesian.y.value,
self._reference_vector.cartesian.z.value]

def calculate_azimuthal_scattering_angle(self, psi, chi):

Check warning on line 80 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L80

Added line #L80 was not covered by tests
"""
Calculate the azimuthal scattering angle of a scattered photon.
Parameters
----------
psi : float
Polar angle (radians) of scattered photon in local coordinates
chi : float
Azimuthal angle (radians) of scattered photon in local coordinates
Returns
-------
azimuthal_angle : astropy.coordinates.Angle
Azimuthal scattering angle defined with respect to given reference vector
"""

# Convert scattered photon vector from spherical to Cartesian coordinates
scattered_photon_vector = [np.sin(psi) * np.cos(chi), np.sin(psi) * np.sin(chi), np.cos(psi)]

Check warning on line 98 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L98

Added line #L98 was not covered by tests

# Project scattered photon vector onto plane perpendicular to source direction
d = np.dot(scattered_photon_vector, self._source_vector_cartesian) / np.dot(self._source_vector_cartesian, self._source_vector_cartesian)
projection = [scattered_photon_vector[0] - (d * self._source_vector_cartesian[0]),

Check warning on line 102 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L101-L102

Added lines #L101 - L102 were not covered by tests
scattered_photon_vector[1] - (d * self._source_vector_cartesian[1]),
scattered_photon_vector[2] - (d * self._source_vector_cartesian[2])]

# Calculate angle between scattered photon vector & reference vector on plane perpendicular to source direction
cross_product = np.cross(projection, self._reference_vector_cartesian)
if np.dot(self._source_vector_cartesian, cross_product) < 0:
sign = -1

Check warning on line 109 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L107-L109

Added lines #L107 - L109 were not covered by tests
else:
sign = 1
normalization = np.sqrt(np.dot(projection, projection)) * np.sqrt(np.dot(self._reference_vector_cartesian, self._reference_vector_cartesian))

Check warning on line 112 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L111-L112

Added lines #L111 - L112 were not covered by tests

azimuthal_angle = Angle(sign * np.arccos(np.dot(projection, self._reference_vector_cartesian) / normalization), unit=u.rad)

Check warning on line 114 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L114

Added line #L114 was not covered by tests

return azimuthal_angle

Check warning on line 116 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L116

Added line #L116 was not covered by tests

def calculate_azimuthal_scattering_angles(self, unbinned_data):

Check warning on line 118 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L118

Added line #L118 was not covered by tests
"""
Calculate the azimuthal scattering angles for all events in a dataset.
Parameters
----------
unbinned_data : dict
Unbinned data including polar and azimuthal angles (radians) of scattered photon in local coordinates
Returns
-------
azimuthal_angles : list
Azimuthal scattering angles. Each angle must be an astropy.coordinates.Angle object
"""

azimuthal_angles = []

Check warning on line 133 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L133

Added line #L133 was not covered by tests

for i in range(len(unbinned_data['Psi local'])):
azimuthal_angle = self.calculate_azimuthal_scattering_angle(unbinned_data['Psi local'][i], unbinned_data['Chi local'][i])
azimuthal_angles.append(azimuthal_angle)

Check warning on line 137 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L135-L137

Added lines #L135 - L137 were not covered by tests

return azimuthal_angles

Check warning on line 139 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L139

Added line #L139 was not covered by tests

def create_asad(self, azimuthal_angles, bins=20):

Check warning on line 141 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L141

Added line #L141 was not covered by tests
"""
Create ASAD and calculate uncertainties.
Parameters
----------
azimuthal_angles : list
Azimuthal scattering angles (radians)
bin_edges : np.array
Edges of azimuthal scattering angle bins (radians)
Returns
-------
asad : dict
Counts and Gaussian/Poisson errors in each bin
"""

if isinstance(bins, int):
bin_edges = Angle(np.linspace(-np.pi, np.pi, bins), unit=u.rad)

Check warning on line 159 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L158-L159

Added lines #L158 - L159 were not covered by tests
else:
bin_edges = bins

Check warning on line 161 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L161

Added line #L161 was not covered by tests

counts, edges = np.histogram(azimuthal_angles, bins=bin_edges)
self._bin_edges = edges
self._bins = []
for i in range(len(self._bin_edges) - 1):
self._bins.append((self._bin_edges[i] + self._bin_edges[i+1]) / 2)
errors = calculate_uncertainties(counts)

Check warning on line 168 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L163-L168

Added lines #L163 - L168 were not covered by tests

asad = {'counts': counts, 'uncertainties': errors}

Check warning on line 170 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L170

Added line #L170 was not covered by tests

return asad

Check warning on line 172 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L172

Added line #L172 was not covered by tests

def asad_sinusoid(self, x, a, b, c):

Check warning on line 174 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L174

Added line #L174 was not covered by tests
"""
Sinusoid to fit to ASAD.
Parameters
----------
x : float
Azimuthal scattering angle (radians)
a : float
First parameter
b : float
Second parameter
c : float
Third parameter
Returns
-------
asad_function : float
Y-value of ASAD
"""

asad_function = a - (b * np.cos(2 * (x - c)))

Check warning on line 195 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L195

Added line #L195 was not covered by tests

return asad_function

Check warning on line 197 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L197

Added line #L197 was not covered by tests

def fit_asad(self, counts, p0, bounds, sigma):

Check warning on line 199 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L199

Added line #L199 was not covered by tests
"""
Fit the ASAD with a sinusoid.
Parameters
----------
counts : list
Counts in each azimuthal scattering angle bin
p0 : list or np.array
Initial guess for parameter values
bounds : 2-tuple of float, list, or np.array
Lower & upper bounds on parameters
sigma : float, list, or np.array
Uncertainties in y data
Returns
-------
popt : np.ndarray
Fitted parameter values
uncertainties : list
Uncertainty on each parameter value
"""

popt, pcov = curve_fit(self.asad_sinusoid, Angle(self._bins).rad, counts, p0=p0, bounds=bounds, sigma=sigma)
uncertainties = []
for i in range(len(pcov)):
uncertainties.append(np.sqrt(pcov[i][i]))

Check warning on line 225 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L222-L225

Added lines #L222 - L225 were not covered by tests

return popt, uncertainties

Check warning on line 227 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L227

Added line #L227 was not covered by tests

def plot_asad(self, counts, error, title, coefficients=[]):

Check warning on line 229 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L229

Added line #L229 was not covered by tests
"""
Plot the ASAD.
Parameters
----------
counts : list
Counts in each azimuthal scattering angle bin
error : np.ndarray
Lower & upper uncertainties for each bin
title : str
Title of plot
coefficients : list, optional
Coefficients to plot fitted sinusoidal function
"""

plt.scatter(Angle(self._bins).degree, counts)
plt.errorbar(Angle(self._bins).degree, counts, yerr=error, linewidth=0, elinewidth=1)
plt.title(title)
plt.xlabel('Azimuthal Scattering Angle (degrees)')

Check warning on line 248 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L245-L248

Added lines #L245 - L248 were not covered by tests

if len(coefficients) == 3:
x = np.linspace(-np.pi, np.pi, 1000)
y = []
for item in x:
y.append(self.asad_sinusoid(item, coefficients[0], coefficients[1], coefficients[2]))
plt.plot(list(np.rad2deg(x)), y, color='green')

Check warning on line 255 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L250-L255

Added lines #L250 - L255 were not covered by tests

plt.show()

Check warning on line 257 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L257

Added line #L257 was not covered by tests

def correct_asad(self, data_asad, unpolarized_asad):

Check warning on line 259 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L259

Added line #L259 was not covered by tests
"""
Correct the ASAD using the ASAD of an unpolarized source.
Parameters
----------
data_asad : dict
Counts and uncertainties in each azimuthal scattering angle bin of data
unpolarized_asad : dict
Counts and uncertainties in each azimuthal scattering angle bin of unpolarized source
Returns
-------
asad : dict
Normalized counts and uncertainties in each azimuthal scattering angle bin
"""

corrected = []
for i in range(len(self._bins)):
corrected.append(data_asad['counts'][i] / np.sum(data_asad['counts']) / unpolarized_asad['counts'][i] * np.sum(unpolarized_asad['counts']))

Check warning on line 278 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L276-L278

Added lines #L276 - L278 were not covered by tests

errors_low = []
errors_high = []
for i in range(len(self._bins)):
sigma_corrected_low = corrected[i] * np.sqrt(((data_asad['uncertainties'][0][i])/data_asad['counts'][i])**2 + ((unpolarized_asad['uncertainties'][0][i])/unpolarized_asad['counts'][i])**2)
sigma_corrected_high = corrected[i] * np.sqrt(((data_asad['uncertainties'][1][i])/data_asad['counts'][i])**2 + ((unpolarized_asad['uncertainties'][1][i])/unpolarized_asad['counts'][i])**2)
errors_low.append(sigma_corrected_low)
errors_high.append(sigma_corrected_high)

Check warning on line 286 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L280-L286

Added lines #L280 - L286 were not covered by tests

asad = {'counts': corrected, 'uncertainties': np.array([errors_low, errors_high])}

Check warning on line 288 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L288

Added line #L288 was not covered by tests

return asad

Check warning on line 290 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L290

Added line #L290 was not covered by tests

def calculate_mu(self, counts_corrected, p0=None, bounds=(-np.inf, np.inf), sigma=None):

Check warning on line 292 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L292

Added line #L292 was not covered by tests
"""
Calculate the modulation (mu).
Parameters
----------
counts_corrected : list
Counts in each azimuthal scattering angle bin
p0 : list or np.array
Initial guess for parameter values
bounds : 2-tuple of float, list, or np.array
Lower & upper bounds on parameters
sigma : float, list, or np.array
Uncertainties for each azimuthal scattering angle bin
Returns
-------
modulation : dict
Modulation and uncertainty of fitted sinusoid
"""

if isinstance(sigma, np.ndarray) and len(sigma.shape) == 2:
for i in range(len(sigma[0])):
if sigma[0][i] != sigma[1][i]:
print('Warning: Uncertainty in at least one bin of ASAD is not Gaussian. Making error bars symmetric. Fit may not be accurate.')
break
symmetric_sigma = []
for i in range(len(sigma[0])):
symmetric_sigma.append((sigma[0][i] + sigma[1][i]) / 2)
sigma = symmetric_sigma

Check warning on line 321 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L313-L321

Added lines #L313 - L321 were not covered by tests

parameter_values, uncertainties = self.fit_asad(counts_corrected, p0, bounds, sigma)

Check warning on line 323 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L323

Added line #L323 was not covered by tests

mu = parameter_values[1] / parameter_values[0]
mu_uncertainty = mu * np.sqrt((uncertainties[0]/parameter_values[0])**2 + (uncertainties[1]/parameter_values[1])**2)

Check warning on line 326 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L325-L326

Added lines #L325 - L326 were not covered by tests

modulation = {'mu': mu, 'uncertainty': mu_uncertainty}

Check warning on line 328 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L328

Added line #L328 was not covered by tests

print('Modulation:', round(mu, 3), '+/-', round(mu_uncertainty, 3))

Check warning on line 330 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L330

Added line #L330 was not covered by tests

return modulation

Check warning on line 332 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L332

Added line #L332 was not covered by tests

def fit(self, mu_100, counts_corrected, p0=None, bounds=(-np.inf, np.inf), sigma=None):

Check warning on line 334 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L334

Added line #L334 was not covered by tests
"""
Fit the polarization fraction and angle.
Parameters
----------
mu_100 : dict
Modulation and uncertainty of a 100% polarized source
counts_corrected : list
Counts in each azimuthal scattering angle bin
p0 : list or np.array
Initial guess for parameter values
bounds : 2-tuple of float, list, or np.array
Lower & upper bounds on parameters
sigma : float, list, or np.array
Uncertainties for each azimuthal scattering angle bin
Returns
-------
polarization : dict
Polarization fraction, polarization angle, and best fit parameter values for fitted sinusoid, and associated uncertainties
"""

if isinstance(sigma, np.ndarray) and len(sigma.shape) == 2:
for i in range(len(sigma[0])):
if sigma[0][i] != sigma[1][i]:
print('Warning: Uncertainty in at least one bin of ASAD is not Gaussian. Making error bars symmetric. Fit may not be accurate.')
break
symmetric_sigma = []
for i in range(len(sigma[0])):
symmetric_sigma.append((sigma[0][i] + sigma[1][i]) / 2)
sigma = symmetric_sigma

Check warning on line 365 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L357-L365

Added lines #L357 - L365 were not covered by tests

parameter_values, uncertainties = self.fit_asad(counts_corrected, p0, bounds, sigma)

Check warning on line 367 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L367

Added line #L367 was not covered by tests

polarization_fraction = parameter_values[1] / (parameter_values[0] * mu_100['mu'])
polarization_fraction_uncertainty = polarization_fraction * np.sqrt((uncertainties[0]/parameter_values[0])**2 + (uncertainties[1]/parameter_values[1])**2 + (mu_100['uncertainty']/mu_100['mu'])**2)

Check warning on line 370 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L369-L370

Added lines #L369 - L370 were not covered by tests

polarization_angle = Angle(parameter_values[2], unit=u.rad)
polarization_angle.wrap_at(180 * u.deg, inplace=True)
if polarization_angle.degree < 0:
polarization_angle += Angle(180, unit=u.deg)
polarization_angle = PolarizationAngle(polarization_angle, self._source_vector, convention=self._convention).transform_to(IAUPolarizationConvention())
polarization_angle_uncertainty = Angle(uncertainties[2], unit=u.rad)

Check warning on line 377 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L372-L377

Added lines #L372 - L377 were not covered by tests

polarization = {'fraction': polarization_fraction, 'angle': polarization_angle, 'fraction uncertainty': polarization_fraction_uncertainty, 'angle uncertainty': polarization_angle_uncertainty, 'best fit parameter values': parameter_values, 'best fit parameter uncertainties': uncertainties}

Check warning on line 379 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L379

Added line #L379 was not covered by tests

print('Best fit polarization fraction:', round(polarization_fraction, 3), '+/-', round(polarization_fraction_uncertainty, 3))
print('Best fit polarization angle:', round(polarization_angle.angle.degree, 3), '+/-', round(polarization_angle_uncertainty.degree, 3))

Check warning on line 382 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L381-L382

Added lines #L381 - L382 were not covered by tests

return polarization

Check warning on line 384 in cosipy/polarization/polarization_asad.py

View check run for this annotation

Codecov / codecov/patch

cosipy/polarization/polarization_asad.py#L384

Added line #L384 was not covered by tests
Loading

0 comments on commit 440ebff

Please sign in to comment.