Skip to content

Commit

Permalink
polarimetry: fixed l/4 tests. q<0&k>1 and q>0&k<1
Browse files Browse the repository at this point in the history
  • Loading branch information
juliotux committed Sep 12, 2023
1 parent 609f46f commit 8e8f56b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 7 additions & 3 deletions astropop/polarimetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,13 @@ def _estimate_normalize_half(self, psi, f_ord, f_ext):
def _estimate_normalize_quarter(self, psi, f_ord, f_ext, q):
"""Estimate the normalization factor for quarterwave retarder."""
ratio = self._estimate_normalize_half(psi, f_ord, f_ext)
q_norm = (1+0.5*q)/(1-0.5*q)
if (ratio < 1 and q < 0) or (ratio > 1 and q > 0):
q_norm = 1/q_norm
# PCCDPACK uses the following if to calculate the normalization. But
# it seems that the models are not fitting correctly for combinations
# outside this case. So, bypass it
# q_norm = (1+0.5*q)/(1-0.5*q)
# if (ratio < 1 and q < 0) or (ratio > 1 and q > 0):
# q_norm = 1/q_norm
q_norm = (1-0.5*q)/(1+0.5*q)
return ratio*q_norm

def _half_compute(self, psi, f_ord, f_ext):
Expand Down
9 changes: 4 additions & 5 deletions tests/test_polarimetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ def test_estimate_normalize_half_error(self):
pol._estimate_normalize_half(psi, flux_o, flux_e)

@pytest.mark.parametrize('k', [1.2, 1.05, 1.0, 0.95, 0.8])
def test_estimate_normalize_quarter_ok(self, k):
def test_estimate_normalize_quarter_ok_no_q(self, k):
params = dict(
q = 0.02,
q = 0.0, # to avoid problems in simple computations, use q=0
u = -0.03,
v = 0.02,
k = k,
Expand Down Expand Up @@ -634,7 +634,6 @@ def test_fit_half_no_k(self, q, u):
assert_almost_equal(p.k, 1.0)
assert_is_none(p.zero)


@pytest.mark.parametrize('q, u', [(0.05, 0.02), (-0.02, 0.04),
(0.1, 0.0), (0.0, -0.2)])
@pytest.mark.parametrize('zero', [0, 30, 60])
Expand Down Expand Up @@ -726,7 +725,7 @@ def test_fit_quarter_no_errors_k1(self, q, u, v, zero):
@pytest.mark.parametrize('k', [1.2, 1.05, 1.0, 0.95, 0.8])
@pytest.mark.parametrize('q, u, v', [(0.05, 0.02, 0.1),
(-0.02, 0.04, -0.1),
(0.1, 0.0, 0.1),
(0.0, 0.0, 0.1),
(0.0, -0.2, -0.2)])
def test_fit_quarter_estimate_k(self, k, q, u, v):
zero = 15
Expand Down Expand Up @@ -782,7 +781,7 @@ def test_fit_quarter_estimate_zero(self, q, u, v, zero):
psi = np.arange(0, 360, 22.5)
flux_o, flux_e = get_flux_oe(1e5, psi, k=1.0, q=q, u=u, v=v, zero=zero)
pol = SLSDualBeamPolarimetry(retarder='quarterwave', compute_k=False,
k=1.0)
k=1.0, zero_range=[0, 45])
p = pol.compute(psi, flux_o, flux_e)

assert_almost_equal(p.q.nominal, q, decimal=3)
Expand Down

0 comments on commit 8e8f56b

Please sign in to comment.