diff --git a/pyproject.toml b/pyproject.toml index 749d77a..e8eb32f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "solpolpy" -version = "0.3.0" +version = "0.3.1" authors = [ { name="J. Marcus Hughes", email="mhughes@boulder.swri.edu"}, { name="Matthew J. West", email="mwest@boulder.swri.edu"}, diff --git a/solpolpy/core.py b/solpolpy/core.py index 3640ddd..dd12900 100644 --- a/solpolpy/core.py +++ b/solpolpy/core.py @@ -15,7 +15,7 @@ @u.quantity_input def resolve(input_data: list[str] | NDCollection, - out_system: System | str, + out_system: str, imax_effect: bool = False, out_angles: u.degree = None) -> NDCollection: """Apply a polarization transformation to a set of input dataframes. @@ -26,7 +26,7 @@ def resolve(input_data: list[str] | NDCollection, Either: 1) a collection where each member NDCube has an expected name or 2) a list of paths to FITS files. We recommend option 2. - out_system : System | string + out_system : string The polarization state you want to convert your input dataframes to. Must be one of the following strings: diff --git a/solpolpy/decorators.py b/solpolpy/decorators.py deleted file mode 100644 index e69de29..0000000 diff --git a/solpolpy/transforms.py b/solpolpy/transforms.py index 6c457e6..d800802 100644 --- a/solpolpy/transforms.py +++ b/solpolpy/transforms.py @@ -448,22 +448,23 @@ def mzp_to_npol(input_collection, out_angles: u.degree, offset_angle=0*u.degree, break input_dict[input_collection[p_angle].meta["POLAR"]] = input_collection[p_angle].data - npol_ang = out_angles - Bnpol = {} - Bnpol_cube = [] + output_cubes = [] mask = combine_all_collection_masks(input_collection) - for ang in npol_ang: - Bnpol[ang] = (1/3) * np.sum([v.data * (4 * np.power(np.cos(ang - k - offset_angle), 2)) - 1 - for k, v in input_dict.items()], axis=0) - meta_tmp = copy.copy(input_collection[in_list[0]].meta) - meta_tmp.update(Polar=ang) - Bnpol_cube.append((str(ang), NDCube(Bnpol[ang], wcs=input_collection[in_list[0]].wcs, mask=mask, meta=meta_tmp))) + first_meta = input_collection[in_list[0]].meta + first_wcs = input_collection[in_list[0]].wcs + for out_angle in out_angles: + value = (1/3) * np.sum([input_cube.data * (4 * np.square(np.cos(out_angle - input_angle - offset_angle)) - 1) + for input_angle, input_cube in input_dict.items()], axis=0) + out_meta = copy.copy(first_meta) + out_meta.update(POLAR=out_angle) + output_cubes.append((str(out_angle), + NDCube(value, wcs=first_wcs, mask=mask, meta=out_meta))) if "alpha" in input_collection: alpha = input_collection["alpha"].data * u.radian - Bnpol_cube.append(("alpha", NDCube(alpha, wcs=input_collection[in_list[0]].wcs, mask=mask))) + output_cubes.append(("alpha", NDCube(alpha, wcs=input_collection[in_list[0]].wcs, mask=mask))) - return NDCollection(Bnpol_cube, meta={}, aligned_axes="all") + return NDCollection(output_cubes, meta={}, aligned_axes="all") @transform(System.fourpol, System.stokes, use_alpha=False) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index f8ad5ea..b09150b 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -17,114 +17,6 @@ wcs.crval = 10, 0.5, 1 wcs.cname = "wavelength", "HPC lat", "HPC lon" -# -# @fixture() -# def npol_mzp_zeros(): -# data_out = [] -# data_out.append(("Bp", NDCube(np.array([0]), wcs=wcs, meta={"POLAR": 60.0, "OBSRVTRY": "STEREO_A"}))) -# data_out.append(("Bz", NDCube(np.array([0]), wcs=wcs, meta={"POLAR": 0.0, "OBSRVTRY": "STEREO_A"}))) -# data_out.append(("Bm", NDCube(np.array([0]), wcs=wcs, meta={"POLAR": -60.0, "OBSRVTRY": "STEREO_A"}))) -# data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) -# return NDCollection(data_out, meta={}, aligned_axes="all") -# -# -# def test_npol_mzp_zeros(npol_mzp_zeros): -# actual = transforms.npol_to_mzp(npol_mzp_zeros) -# expected_data = [] -# expected_data.append(("Bm", NDCube(np.array([0]), wcs=wcs))) -# expected_data.append(("Bz", NDCube(np.array([0]), wcs=wcs))) -# expected_data.append(("Bp", NDCube(np.array([0]), wcs=wcs))) -# expected = NDCollection(expected_data, meta={}, aligned_axes="all") -# for k in list(expected): -# assert np.allclose(actual[str(k)].data, expected[str(k)].data) -# -# -# @fixture() -# def npol_mzp_ones(): -# data_out = [] -# data_out.append(("Bm", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": 60, "OBSRVTRY": "STEREO_B"}))) -# data_out.append(("Bz", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": 0, "OBSRVTRY": "STEREO_B"}))) -# data_out.append(("Bp", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": -60, "OBSRVTRY": "STEREO_B"}))) -# return NDCollection(data_out, meta={}, aligned_axes="all") -# -# -# def test_npol_mzp_ones(npol_mzp_ones): -# actual = transforms.npol_to_mzp(npol_mzp_ones) -# expected_data = [] -# expected_data.append(("Bm", NDCube(np.array([1]), wcs=wcs))) -# expected_data.append(("Bz", NDCube(np.array([1]), wcs=wcs))) -# expected_data.append(("Bp", NDCube(np.array([1]), wcs=wcs))) -# expected = NDCollection(expected_data, meta={}, aligned_axes="all") -# for k in list(expected): -# assert np.allclose(actual[str(k)].data, expected[str(k)].data) -# -# -# @fixture() -# def mzp_ones_alpha(): -# data_out = [] -# data_out.append(("Bp", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": 60, "OBSRVTRY": "LASCO"}))) -# data_out.append(("Bz", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": 0, "OBSRVTRY": "LASCO"}))) -# data_out.append(("Bm", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": -60, "OBSRVTRY": "LASCO"}))) -# data_out.append(("alpha", NDCube(np.array([0]), wcs=wcs))) -# return NDCollection(data_out, meta={}, aligned_axes="all") -# -# -# def test_npol_mzp_ones_alpha(mzp_ones_alpha): -# actual = transforms.npol_to_mzp(mzp_ones_alpha) -# expected_data = [] -# expected_data.append(("Bm", NDCube(np.array([1]), wcs=wcs))) -# expected_data.append(("Bz", NDCube(np.array([1]), wcs=wcs))) -# expected_data.append(("Bp", NDCube(np.array([1]), wcs=wcs))) -# expected_data.append(("alpha", NDCube(np.array([0]), wcs=wcs))) -# expected = NDCollection(expected_data, meta={}, aligned_axes="all") -# for k in list(expected): -# assert np.allclose(actual[str(k)].data, expected[str(k)].data) -# -# -# @fixture() -# def mzp_zeros(): -# data_out = [] -# data_out.append(("Bm", NDCube(np.array([0]), wcs=wcs, meta={"POLAR": 60}))) -# data_out.append(("Bz", NDCube(np.array([0]), wcs=wcs, meta={"POLAR": 0}))) -# data_out.append(("Bp", NDCube(np.array([0]), wcs=wcs, meta={"POLAR": -60}))) -# data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) -# return NDCollection(data_out, meta={}, aligned_axes="all") -# -# -# def test_mzp_bpb_zeros(mzp_zeros): -# actual = transforms.mzp_to_bpb(mzp_zeros) -# expected_data = [] -# expected_data.append(("B", NDCube(np.array([0]), wcs=wcs))) -# expected_data.append(("pB", NDCube(np.array([0]), wcs=wcs))) -# expected_data.append(("alpha", NDCube(np.array([0])*u.radian, wcs=wcs))) -# expected = NDCollection(expected_data, meta={}, aligned_axes="all") -# for k in list(expected): -# assert np.allclose(actual[str(k)].data, expected[str(k)].data) -# -# -# @fixture() -# def mzp_ones(): -# data_out = [] -# data_out.append(("Bm", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": 60}))) -# data_out.append(("Bz", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": 0}))) -# data_out.append(("Bp", NDCube(np.array([1]), wcs=wcs, meta={"POLAR": -60}))) -# data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) -# return NDCollection(data_out, meta={}, aligned_axes="all") -# -# -# def test_mzp_bpb_ones(mzp_ones): -# actual = transforms.mzp_to_bpb(mzp_ones) -# expected_data = [] -# expected_data.append(("B", NDCube(np.array([2]), wcs=wcs))) -# expected_data.append(("pB", NDCube(np.zeros(1), wcs=wcs))) -# expected_data.append(("alpha", NDCube(np.array([0])*u.radian, wcs=wcs))) -# expected = NDCollection(expected_data, meta={}, aligned_axes="all") -# for k in list(expected): -# assert np.allclose(actual[str(k)].data, expected[str(k)].data) -# -# - -# def test_bpb_mzp_zeros(bpb_zeros): actual = transforms.bpb_to_mzp(bpb_zeros) @@ -305,13 +197,22 @@ def test_btbr_npol_ones(btbr_ones): assert np.allclose(actual[str(k)].data, expected[str(k)].data) -def test_mzp_t_npol_ones(mzp_ones): - actual = transforms.mzp_to_npol(mzp_ones, out_angles=[0]*u.degree) - expected_data = [(str(0 * u.degree), NDCube(np.array([1]), wcs=wcs))] +def test_mzp_to_npol_custom(): + """M, Z, P = 0, 1, 0 conversion""" + input_data = NDCollection( + [("P", NDCube(np.array([[0]]), wcs=wcs, meta={"POLAR": 60 * u.degree})), + ("Z", NDCube(np.array([[1]]), wcs=wcs, meta={"POLAR": 0 * u.degree})), + ("M", NDCube(np.array([[0]]), wcs=wcs, meta={"POLAR": -60 * u.degree}))], + meta={}, aligned_axes="all") + actual = transforms.mzp_to_npol(input_data, out_angles=[0, 45, 90]*u.degree) + expected_data = [(str(0 * u.degree), NDCube(np.array([1]), wcs=wcs, meta={"POLAR": 0*u.degree})), + (str(45 * u.degree), NDCube(np.array([1/3]), wcs=wcs, meta={"POLAR": 45*u.degree})), + (str(90 * u.degree), NDCube(np.array([-1/3]), wcs=wcs, meta={"POLAR": 90*u.degree}))] expected = NDCollection(expected_data, meta={}, aligned_axes="all") for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture() def fourpol_ones(): wcs = astropy.wcs.WCS(naxis=1)