Skip to content

Commit

Permalink
Added support to 4-polarizers
Browse files Browse the repository at this point in the history
  • Loading branch information
s0larish committed Jul 31, 2023
1 parent aa0d313 commit 0538723
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 59 deletions.
9 changes: 5 additions & 4 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
`solpolpy` supports the conversion among the polarization systems listed below
(Use the keyword inside the parenthesis in string format for out_polarize_state in the calling sequence).

Npol (npol): Set of images taken at more than three polarizing angles
(e.g. 0°, 45°, 90° and 135°).

MZP (MZP): Triplet of images taken at -60°, 0°, and +60° polarizing angles.

B<sub>T</sub>, B<sub>R</sub> (BtBr): Pair of images with polarization along the
Expand All @@ -23,6 +20,10 @@ Sun unlike the later with fixed frame of reference of the instrument.

B, θ, p (Bthp): System with total (unpolarized) brightness, angle and degree of polarization.

4 polarizer system (fourpol): For observations taken at sequence of four polarizer angles, i.e. 0°, 45°, 90° and 135°.

Npol (npol): Set of images taken at more than three polarizing angles

The equations required for the transformations from one system to another can be found in [Deforest et al. 2022](https://doi.org/10.3847/1538-4357/ac43b6).

## Calling Sequence
Expand All @@ -31,7 +32,7 @@ import solpolpy as sp
output = sp.resolve(input_data, out_polarize_state)
```

input_data: Input NDCollection of the type listed above
input_data: Input NDCollection of the type listed above or string of path to FITS files

out_polarize_state: String of required output polarization state

Expand Down
6 changes: 5 additions & 1 deletion solpolpy/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from solpolpy.polarizers import npol_to_mzp, bpb_to_mzp, mzp_to_bpb, \
bpb_to_btbr, btbr_to_bpb, mzp_to_stokes, stokes_to_mzp, \
mzp_to_bp3, bp3_to_mzp, btbr_to_mzp, bp3_to_bthp, btbr_to_npol
mzp_to_bp3, bp3_to_mzp, btbr_to_mzp, bp3_to_bthp, btbr_to_npol, \
fourpol_to_stokes


transform_graph = nx.DiGraph()
Expand Down Expand Up @@ -42,3 +43,6 @@
transform_graph.add_edge("BtBr", "npol",
func=btbr_to_npol,
requires_alpha=True)
transform_graph.add_edge("fourpol", "Stokes",
func=fourpol_to_stokes,
requires_alpha=False)
92 changes: 38 additions & 54 deletions solpolpy/polarizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def npol_to_mzp(input_cube):
"""
Notes
------
Equation 44 in Deforest et al. 2022.
Equation 44 in DeForest et al. 2022.
"""""
input_dict = {}
Expand Down Expand Up @@ -48,7 +48,7 @@ def mzp_to_bpb(input_cube):
"""
Notes
------
Equation 7 and 9 in Deforest et al. 2022.
Equation 7 and 9 in DeForest et al. 2022.
"""""
# TODO: need to check if 3 angles are input.
Expand Down Expand Up @@ -91,7 +91,7 @@ def bpb_to_mzp(input_cube):
"""
Notes
------
Equation 4 in Deforest et al. 2022.
Equation 4 in DeForest et al. 2022.
"""

if "alpha" not in input_cube:
Expand Down Expand Up @@ -125,7 +125,7 @@ def bpb_to_btbr(input_cube):
"""
Notes
------
Equation 1 and 2 in Deforest et al. 2022.
Equation 1 and 2 in DeForest et al. 2022.
"""
input_dict = {}
in_list = list(input_cube)
Expand Down Expand Up @@ -159,7 +159,7 @@ def btbr_to_bpb(input_cube):
"""
Notes
------
Equation in Table 1 in Deforest et al. 2022.
Equation in Table 1 in DeForest et al. 2022.
"""
input_dict = {}
in_list = list(input_cube)
Expand Down Expand Up @@ -193,7 +193,7 @@ def mzp_to_stokes(input_cube):
"""
Notes
------
Equation 9, 12 and 13 in Deforest et al. 2022.
Equation 9, 12 and 13 in DeForest et al. 2022.
"""
Bm, Bz, Bp = input_cube["Bm"].data, input_cube["Bz"].data, input_cube["Bp"].data

Expand All @@ -219,7 +219,7 @@ def stokes_to_mzp(input_cube):
"""
Notes
------
Equation 11 in Deforest et al. 2022. with alpha = np.pi/2
Equation 11 in DeForest et al. 2022. with alpha = np.pi/2
"""

alpha = np.pi / 2
Expand Down Expand Up @@ -248,7 +248,7 @@ def mzp_to_bp3(input_cube):
"""
Notes
------
Equation 7, 9 and 10 in Deforest et al. 2022.
Equation 7, 9 and 10 in DeForest et al. 2022.
"""""
input_dict = {}
in_list = list(input_cube)
Expand Down Expand Up @@ -295,7 +295,7 @@ def bp3_to_mzp(input_cube):
"""
Notes
------
Equation 11 in Deforest et al. 2022.
Equation 11 in DeForest et al. 2022.
"""""
conv_fact = (np.pi * u.radian) / (180 * u.degree)

Expand Down Expand Up @@ -325,7 +325,7 @@ def btbr_to_mzp(input_cube):
"""
Notes
------
Equation 3 in Deforest et al. 2022.
Equation 3 in DeForest et al. 2022.
"""
if "alpha" not in input_cube:
raise ValueError("missing alpha")
Expand All @@ -352,7 +352,7 @@ def bp3_to_bthp(input_cube):
"""
Notes
------
Equations 9, 15, 16 in Deforest et al. 2022.
Equations 9, 15, 16 in DeForest et al. 2022.
"""""
if "alpha" not in input_cube:
raise ValueError("missing alpha")
Expand All @@ -378,7 +378,7 @@ def btbr_to_npol(input_cube, angles):
"""
Notes
------
Equation 3 in Deforest et al. 2022.
Equation 3 in DeForest et al. 2022.
angles: list of input angles in degree
"""
if "alpha" not in input_cube:
Expand All @@ -399,46 +399,30 @@ def btbr_to_npol(input_cube, angles):

return NDCollection(Bnpol_cube, meta={}, aligned_axes="all")

def fourpol_to_stokes(input_cube):
"""
Notes
------
Table 1 in DeForest et al. 2022.
# TODO: decide if we keep
# def pB_from_single_angle(B, B_theta, theta, alpha, tol=1e-6):
# """
# Converts unpolarized brightness,`B`, Radiance through a polarizer at angle theta,`B_theta`,
# Polarizer angle,`theta`, and Solar position angle of an image point, `alpha` into Coronal
# polarized brightness, `pB`.
#
# This function takes in four vars of `B`, `B_theta`, `theta`,and `alpha`.
#
# Parameters
# ----------
# B : np.ndarray
# 'Clear' or total brightness data frame
# B_theta : np.ndarray
# polarized data at angle theta
# theta : Quantity (astropy)
# angle of polarized data frame
# alpha : Quantity (astropy)
# alpha array to accompany STEREO or LASCO dataframes
# tol : float
# tolerence at which the denominator is converted to a nan (see Notes)
#
# Returns
# -------
# polarized brightness in terms of the radiance through a single arbitrary polarizer
#
# Notes
# ------
# see Equation 5 in Deforest et al. 2022.
# if this equation is used for single values, alpha will need to be a Quantity
#
# Equation (5) is problematic, because the denominator is small when theta-alpha
# is near pm pi/4. Therefore, a nan is inserted when < tol
#
# Due to the cosine in the denominator, with an alpha varying from 0 to 360 degrees pB should vary from positive to
# negative twice crossing zero four times (pB will go to infinity at this point).
# """
#
# pB_denominator = np.cos(2 * (theta - alpha))
# pB_denominator[np.abs(pB_denominator) < tol] = np.nan
#
# return (B - (2 * B_theta)) / pB_denominator
"""""
input_dict = {}
in_list = list(input_cube)

for p_angle in in_list:
if p_angle == "alpha":
break
input_dict[(input_cube[p_angle].meta['POLAR'])] = input_cube[p_angle].data

Bi = input_cube[0].data + input_cube[90].data
Bq = input_cube[90].data - input_cube[0].data
Bu = input_cube[135].data - input_cube[45].data

metaI, metaQ, metaU = copy.copy(input_cube[0].meta), copy.copy(input_cube[0].meta), copy.copy(input_cube[0].meta)
BStokes_cube = []
BStokes_cube.append(("Bi", NDCube(Bi, wcs=input_cube[0].wcs, meta=metaI)))
BStokes_cube.append(("Bq", NDCube(Bq, wcs=input_cube[0].wcs, meta=metaQ)))
BStokes_cube.append(("Bu", NDCube(Bu, wcs=input_cube[0].wcs, meta=metaU)))
# BStokes_cube["alpha"] = NDCube(alpha, wcs=input_cube["B"].wcs)

return NDCollection(BStokes_cube, meta={}, aligned_axes="all")

0 comments on commit 0538723

Please sign in to comment.