From ad496945b46bbd703ae318fa3f413b129fd725b7 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:13:40 -0600 Subject: [PATCH 01/28] updated config file --- docs/_config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index 464c9af..7bd1364 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,9 +1,9 @@ # Book settings # Learn more at https://jupyterbook.org/customize/config.html -title: My sample book -author: The Jupyter Book Community -logo: logo.png +title: solpolpy +author: PUNCH SOC +#logo: logo.png # Force re-execution of notebooks on each build. # See https://jupyterbook.org/content/execute.html From da094ca8c0aec04e673743309db3fa059aa62f69 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:16:06 -0600 Subject: [PATCH 02/28] updated functions, alpha, conversions --- solpolpy/alpha.py | 4 ++-- solpolpy/constants.py | 3 ++- solpolpy/instruments.py | 12 ++++++------ solpolpy/polarizers.py | 7 ++++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/solpolpy/alpha.py b/solpolpy/alpha.py index 156381a..91e14b3 100644 --- a/solpolpy/alpha.py +++ b/solpolpy/alpha.py @@ -27,8 +27,8 @@ def radial_north(shape): x = np.arange(-x_size // 2, x_size // 2) y = np.arange(-y_size // 2, y_size // 2) xx, yy = np.meshgrid(x, y) - # return np.fliplr(np.arctan2(yy, xx))*u.radian - return np.flipud(np.rot90(np.fliplr(np.arctan2(yy, xx) + np.pi), k=1))* u.radian + return np.rot90(np.fliplr(np.arctan2(yy, xx)+np.pi), k=1)*u.radian + # return np.flipud(np.rot90(np.fliplr(np.arctan2(yy, xx) + np.pi), k=1))* u.radian def zeros(shape): diff --git a/solpolpy/constants.py b/solpolpy/constants.py index d869b9a..ec4a46b 100644 --- a/solpolpy/constants.py +++ b/solpolpy/constants.py @@ -5,4 +5,5 @@ "Stokes": [["Bi", "Bq", "Bu"]], "Bp3": [["B", "pB", "pBp", "alpha"], ["B", "pB", "pBp"]], "Bthp": [["B", "theta", "p"]], - "npol": [["angle_1", "angle_2", "angle_3"], ["angle_1", "angle_2", "angle_3", "angle_4"]]} + "npol": [["angle_1", "angle_2", "angle_3"]], + "fourpol": [["angle_1", "angle_2", "angle_3", "angle_4"]]} diff --git a/solpolpy/instruments.py b/solpolpy/instruments.py index c1b8726..2bfb156 100644 --- a/solpolpy/instruments.py +++ b/solpolpy/instruments.py @@ -28,12 +28,12 @@ def load_data(path_list: List[str]) -> NDCollection: list_len = len(path_list) assert list_len >= 2, 'requires at least 2 FITS files' - for xlist_item in path_list: - with fits.open(xlist_item) as hdul: - fits_type.append(hdul[0].header['DETECTOR']) - - if len(set(fits_type)) != 1: - raise Exception("Input FITS are of different types") + # for xlist_item in path_list: + # with fits.open(xlist_item) as hdul: + # fits_type.append(hdul[0].header['DETECTOR']) + # + # if len(set(fits_type)) != 1: + # raise Exception("Input FITS are of different types") data_out = [] i = 0 diff --git a/solpolpy/polarizers.py b/solpolpy/polarizers.py index 9e26864..001105e 100644 --- a/solpolpy/polarizers.py +++ b/solpolpy/polarizers.py @@ -19,6 +19,11 @@ def npol_to_mzp(input_cube): in_list = list(input_cube) conv_fact = (np.pi * u.radian) / (180 * u.degree) + if input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_B': + offset_angle = -18 * u.degree * conv_fact # STEREOB + if input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_A': + offset_angle = 45.8 * u.degree * conv_fact # STEREOA + for p_angle in in_list: if p_angle == "alpha": break @@ -28,7 +33,7 @@ def npol_to_mzp(input_cube): mzp_ang = [-60, 0, 60] Bmzp = {} for ang in mzp_ang: Bmzp[ang * u.degree] = (1 / 3) * np.sum( - [ith_polarizer_brightness * (1 + 2 * np.cos(2 * (ang * u.degree * conv_fact - ith_angle))) + [ith_polarizer_brightness * (1 + 2 * np.cos(2 * (ang * u.degree * conv_fact - (ith_angle-offset_angle)))) for ith_angle, ith_polarizer_brightness in input_dict.items()], axis=0) # todo: update header properly; time info? From 19eed8cb6d0f6ab233f8e2c0796884f0a13b2362 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:18:27 -0600 Subject: [PATCH 03/28] Update _config.yml --- docs/_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_config.yml b/docs/_config.yml index 7bd1364..a4bce11 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -3,7 +3,7 @@ title: solpolpy author: PUNCH SOC -#logo: logo.png +logo: "" # Force re-execution of notebooks on each build. # See https://jupyterbook.org/content/execute.html From e118d0f6e51f10ccbf529d7f53191d7530da3db9 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:19:30 -0600 Subject: [PATCH 04/28] Update _config.yml --- docs/_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_config.yml b/docs/_config.yml index a4bce11..6e4d3f1 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -3,7 +3,7 @@ title: solpolpy author: PUNCH SOC -logo: "" +# logo: "" # Force re-execution of notebooks on each build. # See https://jupyterbook.org/content/execute.html From 1d5aaa6d2df3a3c8f9689e5a20890a029a806f55 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Thu, 2 Nov 2023 07:36:18 -0600 Subject: [PATCH 05/28] Updated the functions --- solpolpy/polarizers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/solpolpy/polarizers.py b/solpolpy/polarizers.py index 001105e..b22191c 100644 --- a/solpolpy/polarizers.py +++ b/solpolpy/polarizers.py @@ -21,8 +21,10 @@ def npol_to_mzp(input_cube): if input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_B': offset_angle = -18 * u.degree * conv_fact # STEREOB - if input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_A': + elif input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_A': offset_angle = 45.8 * u.degree * conv_fact # STEREOA + else: + offset_angle = 0 for p_angle in in_list: if p_angle == "alpha": @@ -33,7 +35,7 @@ def npol_to_mzp(input_cube): mzp_ang = [-60, 0, 60] Bmzp = {} for ang in mzp_ang: Bmzp[ang * u.degree] = (1 / 3) * np.sum( - [ith_polarizer_brightness * (1 + 2 * np.cos(2 * (ang * u.degree * conv_fact - (ith_angle-offset_angle)))) + [ith_polarizer_brightness * (1 + 2 * np.cos(2 * (ang * u.degree * conv_fact - (ith_angle-offset_angle* u.degree * conv_fact)))) for ith_angle, ith_polarizer_brightness in input_dict.items()], axis=0) # todo: update header properly; time info? From 77b0640aa2d411de1b95284e668f7cb9fb941475 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Thu, 2 Nov 2023 07:37:39 -0600 Subject: [PATCH 06/28] Updated test for updated functions --- tests/test_polarizers.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_polarizers.py b/tests/test_polarizers.py index 294465e..93b4e38 100644 --- a/tests/test_polarizers.py +++ b/tests/test_polarizers.py @@ -18,9 +18,9 @@ @fixture def npol_mzp_zeros(): data_out = [] - data_out.append(("angle_1", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 60.0}))) - data_out.append(("angle_2", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 0.0}))) - data_out.append(("angle_3", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': -60.0}))) + data_out.append(("angle_1", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 60.0, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_2", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 0.0, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_3", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': -60.0, 'OBSRVTRY': 'LASCO'}))) data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") @@ -37,9 +37,9 @@ def test_npol_mzp_zeros(npol_mzp_zeros): @fixture def npol_mzp_ones(): data_out = [] - data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60}))) - data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0}))) - data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60}))) + data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60, 'OBSRVTRY': 'LASCO'}))) # data_out.append(("alpha", NDCube(np.array([0]))*u.radian, wcs=wcs)) return NDCollection(data_out, meta={}, aligned_axes="all") @@ -56,9 +56,9 @@ def test_npol_mzp_ones(npol_mzp_ones): @fixture def mzp_ones_alpha(): data_out = [] - data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60}))) - data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0}))) - data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60}))) + data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_3", 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") From e3736b9596d442d0f8bb5826acf99f583dd566e9 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Thu, 2 Nov 2023 07:46:10 -0600 Subject: [PATCH 07/28] Update test_core.py --- tests/test_core.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index ed2293b..d2dbf84 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -27,9 +27,9 @@ @fixture def npol_ones(): data_out = [] - data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60}))) - data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0}))) - data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60}))) + data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60, 'OBSRVTRY': 'LASCO'}))) # data_out.append(("alpha", NDCube(np.array([0])*u.radian, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") @@ -142,7 +142,7 @@ def test_determine_input_kind_npol(npol_ones): assert determine_input_kind(npol_ones), "npol" def test_determine_input_kind_fourpol(four_pol_ones): - assert determine_input_kind(four_pol_ones), "npol" + assert determine_input_kind(four_pol_ones), "fourpol" def test_determine_input_kind_mzp(mzp_ones): assert determine_input_kind(mzp_ones), "MZP" @@ -441,4 +441,4 @@ def test_bp3_to_bthp(bp3_ones): # """test pB from single angle fn in core""" # # output=pB_from_single_angle(B, B_theta, theta, alpha) -# np.testing.assert_allclose(output, expected, rtol=1e-05) \ No newline at end of file +# np.testing.assert_allclose(output, expected, rtol=1e-05) From f7072a71be0718b5f9ddff8b0d6bb67eae8401fa Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Thu, 2 Nov 2023 10:38:20 -0600 Subject: [PATCH 08/28] Update CI.yml --- .github/workflows/CI.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 118d3f2..360d480 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,6 +34,8 @@ jobs: pytest --cov=solpolpy tests/ --cov-report xml:/home/runner/coverage.xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: fail_ci_if_error: true verbose: true From f1cb41445bd62beec713bc8ae1d2b112970ea201 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Thu, 2 Nov 2023 10:51:37 -0600 Subject: [PATCH 09/28] Create weeklypr.yaml --- .github/workflows/weeklypr.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/weeklypr.yaml diff --git a/.github/workflows/weeklypr.yaml b/.github/workflows/weeklypr.yaml new file mode 100644 index 0000000..ed53654 --- /dev/null +++ b/.github/workflows/weeklypr.yaml @@ -0,0 +1,13 @@ +on: + schedule: + - cron: '0 0 * * THU' +name: weekly PR +jobs: + createPullRequest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: create pull request + run: gh pr create -B main -H develop --title 'Weekly merge to develop' --body 'Created by Github action' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 3c265c1c93db0cc4cf274ce6d957d01547047bbd Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Fri, 3 Nov 2023 03:23:10 -0600 Subject: [PATCH 10/28] Update alpha.py --- solpolpy/alpha.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/solpolpy/alpha.py b/solpolpy/alpha.py index 91e14b3..c6d3f8f 100644 --- a/solpolpy/alpha.py +++ b/solpolpy/alpha.py @@ -28,8 +28,7 @@ def radial_north(shape): y = np.arange(-y_size // 2, y_size // 2) xx, yy = np.meshgrid(x, y) return np.rot90(np.fliplr(np.arctan2(yy, xx)+np.pi), k=1)*u.radian - # return np.flipud(np.rot90(np.fliplr(np.arctan2(yy, xx) + np.pi), k=1))* u.radian - + def zeros(shape): return np.zeros(shape) From a9761e2aa874c98f8f08f8df6a90d4fd293232e5 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:07:50 -0600 Subject: [PATCH 11/28] Update polarizers.py --- solpolpy/polarizers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solpolpy/polarizers.py b/solpolpy/polarizers.py index b22191c..c0fd892 100644 --- a/solpolpy/polarizers.py +++ b/solpolpy/polarizers.py @@ -20,9 +20,9 @@ def npol_to_mzp(input_cube): conv_fact = (np.pi * u.radian) / (180 * u.degree) if input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_B': - offset_angle = -18 * u.degree * conv_fact # STEREOB + offset_angle = -18 # STEREOB elif input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_A': - offset_angle = 45.8 * u.degree * conv_fact # STEREOA + offset_angle = 45.8 # STEREOA else: offset_angle = 0 From b1c594938f733943d324ba73c5d93a0ac8706c48 Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:08:31 -0600 Subject: [PATCH 12/28] updated test_polarizers.py --- tests/test_polarizers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_polarizers.py b/tests/test_polarizers.py index 93b4e38..5314a83 100644 --- a/tests/test_polarizers.py +++ b/tests/test_polarizers.py @@ -18,9 +18,9 @@ @fixture def npol_mzp_zeros(): data_out = [] - data_out.append(("angle_1", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 60.0, 'OBSRVTRY': 'LASCO'}))) - data_out.append(("angle_2", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 0.0, 'OBSRVTRY': 'LASCO'}))) - data_out.append(("angle_3", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': -60.0, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_1", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 60.0, 'OBSRVTRY': 'STEREO_A'}))) + data_out.append(("angle_2", NDCube(np.array([0]), wcs=wcs, meta={'POLAR': 0.0, 'OBSRVTRY': 'STEREO_A'}))) + data_out.append(("angle_3", 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") @@ -37,9 +37,9 @@ def test_npol_mzp_zeros(npol_mzp_zeros): @fixture def npol_mzp_ones(): data_out = [] - data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60, 'OBSRVTRY': 'LASCO'}))) - data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0, 'OBSRVTRY': 'LASCO'}))) - data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60, 'OBSRVTRY': 'LASCO'}))) + data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60, 'OBSRVTRY': 'STEREO_B'}))) + data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0, 'OBSRVTRY': 'STEREO_B'}))) + data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60, 'OBSRVTRY': 'STEREO_B'}))) # data_out.append(("alpha", NDCube(np.array([0]))*u.radian, wcs=wcs)) return NDCollection(data_out, meta={}, aligned_axes="all") From 4b51c40d619ad41716c98ad090fb92385fdfbcde Mon Sep 17 00:00:00 2001 From: Ritesh Patel <84658086+s0larish@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:20:31 -0600 Subject: [PATCH 13/28] Update _config.yml --- docs/_config.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index 6e4d3f1..4c2003c 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -21,9 +21,25 @@ bibtex_bibfiles: # Information about where the book exists on the web repository: - url: https://github.com/executablebooks/jupyter-book # Online location of your book + url: https://github.com/punch-mission/solpolpy # Online location of your book path_to_book: docs # Optional path to your book, relative to the repository root - branch: master # Which branch of the repository should be used when creating links (optional) + branch: main # Which branch of the repository should be used when creating links (optional) + +parse: + # default extensions to enable in the myst parser. + # See https://myst-parser.readthedocs.io/en/latest/using/syntax-optional.html + myst_enable_extensions: + # - amsmath + - colon_fence + # - deflist + - dollarmath + - html_admonition + # - html_image + - linkify + # - replacements + # - smartquotes + - substitution + myst_url_schemes: [mailto, http, https] # URI schemes that will be recognised as external URLs in Markdown links # Add GitHub buttons to your book # See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository From 8a157560b6aceaceb69f794164ee6304e9b3c13d Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 09:55:09 -0700 Subject: [PATCH 14/28] Delete solpolpy/.DS_Store --- solpolpy/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 solpolpy/.DS_Store diff --git a/solpolpy/.DS_Store b/solpolpy/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 6 Nov 2023 09:55:37 -0700 Subject: [PATCH 15/28] Update .gitignore to ignore DS_Store --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 26bbea1..013b6f2 100644 --- a/.gitignore +++ b/.gitignore @@ -127,4 +127,4 @@ dmypy.json # Pyre type checker .pyre/ -tests/.DS_Store +*.DS_Store From 78263f5ba8c3e1993a3e95e50548c63ef2dd24b1 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 09:59:13 -0700 Subject: [PATCH 16/28] removed old code --- solpolpy/polarizers.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/solpolpy/polarizers.py b/solpolpy/polarizers.py index c0fd892..4392ec5 100644 --- a/solpolpy/polarizers.py +++ b/solpolpy/polarizers.py @@ -19,23 +19,23 @@ def npol_to_mzp(input_cube): in_list = list(input_cube) conv_fact = (np.pi * u.radian) / (180 * u.degree) + # constants come from https://www.sciencedirect.com/science/article/pii/S0019103515003620?via%3Dihub if input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_B': - offset_angle = -18 # STEREOB + offset_angle = -18 * u.degree # STEREOB elif input_cube['angle_1'].meta['OBSRVTRY'] == 'STEREO_A': - offset_angle = 45.8 # STEREOA + offset_angle = 45.8 * u.degree # STEREOA else: offset_angle = 0 for p_angle in in_list: if p_angle == "alpha": break - # input_dict[(conv_polar_from_head(input_cube[p_angle])) * u.degree * conv_fact] = input_cube[p_angle].data input_dict[(conv_polar_from_head(input_cube[p_angle])) * u.degree * conv_fact] = input_cube[p_angle].data mzp_ang = [-60, 0, 60] Bmzp = {} for ang in mzp_ang: Bmzp[ang * u.degree] = (1 / 3) * np.sum( - [ith_polarizer_brightness * (1 + 2 * np.cos(2 * (ang * u.degree * conv_fact - (ith_angle-offset_angle* u.degree * conv_fact)))) + [ith_polarizer_brightness * (1 + 2 * np.cos(2 * (ang * u.degree * conv_fact - (ith_angle-offset_angle)))) for ith_angle, ith_polarizer_brightness in input_dict.items()], axis=0) # todo: update header properly; time info? @@ -69,9 +69,6 @@ def mzp_to_bpb(input_cube): break input_dict[(input_cube[p_angle].meta['POLAR']) * u.degree * conv_fact] = input_cube[p_angle].data - # if "alpha" not in input_cube: - # raise ValueError("missing alpha") - alpha = input_cube['alpha'].data * u.radian B = (2 / 3) * (np.sum([ith_polarizer_brightness for ith_angle, ith_polarizer_brightness @@ -104,11 +101,6 @@ def bpb_to_mzp(input_cube): if "alpha" not in input_cube: raise ValueError("missing alpha") - # for p_angle in in_list: - # if p_angle == "alpha": - # break - # input_dict[(input_cube[p_angle].meta['POLAR'])] = input_cube[p_angle].data - alpha = input_cube['alpha'].data * u.radian B, pB = input_cube["B"].data, input_cube["pB"].data mzp_ang = [-60, 0, 60] @@ -217,8 +209,6 @@ def mzp_to_stokes(input_cube): BStokes_cube.append(("Bi", NDCube(Bi, wcs=input_cube["Bm"].wcs, meta=metaI))) BStokes_cube.append(("Bq", NDCube(Bq, wcs=input_cube["Bm"].wcs, meta=metaQ))) BStokes_cube.append(("Bu", NDCube(Bu, wcs=input_cube["Bm"].wcs, meta=metaU))) - # BStokes_cube["alpha"] = NDCube(alpha, wcs=input_cube["B"].wcs) - return NDCollection(BStokes_cube, meta={}, aligned_axes="all") @@ -265,12 +255,7 @@ def mzp_to_bp3(input_cube): if p_angle == "alpha": break input_dict[(input_cube[p_angle].meta['POLAR'] * u.degree * conv_fact)] = input_cube[p_angle].data - - # alpha = alpha1([input_cube['Bm'].meta['NAXIS1'], input_cube['Bm'].meta['NAXIS2']]) #input_dict['alpha'] - - # if "alpha" not in input_cube: - # raise ValueError("missing alpha") - + alpha = input_cube['alpha'].data * u.radian B = (2 / 3) * (np.sum([ith_polarizer_brightness for ith_angle, ith_polarizer_brightness in input_dict.items() if ith_angle != "alpha"], axis=0)) @@ -430,6 +415,5 @@ def fourpol_to_stokes(input_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") From c258d8340c5a3f4008db361b04ce5697ba13c48a Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:03:21 -0700 Subject: [PATCH 17/28] cleaned up formatting --- solpolpy/instruments.py | 60 +++++++++-------------------------------- 1 file changed, 13 insertions(+), 47 deletions(-) diff --git a/solpolpy/instruments.py b/solpolpy/instruments.py index 2bfb156..c2856bb 100644 --- a/solpolpy/instruments.py +++ b/solpolpy/instruments.py @@ -1,5 +1,5 @@ - from typing import List + from ndcube import NDCube, NDCollection from astropy.io import fits from astropy.wcs import WCS @@ -7,65 +7,31 @@ def load_data(path_list: List[str]) -> NDCollection: """ - path_list: String of path list where group of files to be loaded is present. - default_alpha: bool, optional - If default_alpha is true the alpha matrix will be referenced from Solar North. Default is True. - Make it False to provide alpha (in FITS format) with same size as of input data - or select the alpha matrix (from the list). + Parameters + ---------- + path_list: List[str] + list of paths to be loaded Returns ------- NDCollection The data are loaded as NDCollection object with WCS and header information available. - The keys are labelled as 'angle_1', 'angle_2, 'angle_3', ... - Alpha matrix is also added apart from the polarizing angles data and can be accessed through 'alpha' key. + The keys are labeled as 'angle_1', 'angle_2, 'angle_3', ... """ - # create list of FITS fits_type = [] # get length of list to determine how many files to process. list_len = len(path_list) assert list_len >= 2, 'requires at least 2 FITS files' - - # for xlist_item in path_list: - # with fits.open(xlist_item) as hdul: - # fits_type.append(hdul[0].header['DETECTOR']) - # - # if len(set(fits_type)) != 1: - # raise Exception("Input FITS are of different types") - + data_out = [] - i = 0 - - for data_path in path_list: + for i, data_path in enumerate(path_list): with fits.open(data_path) as hdul: - i = i+1 wcs = WCS(hdul[0].header) - data_out.append(("angle_" + str(i), NDCube(hdul[0].data, wcs=wcs, meta=hdul[0].header))) - # size = hdul[0].data.shape - # if default_alpha: - # alph = radial_north(size) - # data_out.append(("alpha", NDCube(alph, wcs=wcs))) - # else: - # inp = input("Do you wish to provide an alpha array?").lower() - # if inp.startswith('n'): - # print("Continuing with default options... Waiting for input...") - # inp_ref = input("Choose the reference along the Solar: \"North\" or \"West\":").lower() - # if inp_ref.startswith('n'): - # alpha = radial_north(size) - # else: - # alpha = radial_west(size) - # data_out.append(("alpha", NDCube(alpha, wcs=wcs, meta=hdul[0].header))) - # elif inp.startswith('y'): - # print("Provide the alpha matrix in FITS format") - # alpha_path = input("Provide the path of alpha FITS file:") - # hdu = fits.open(alpha_path) - # if np.max(hdu[0].data) > 2 * np.pi + 1: - # alph = hdu[0].data * deg2rad - # else: - # alph = hdu[0].data - # data_out.append(("alpha", NDCube(alph, wcs=wcs, meta=hdu[0].header))) - - print("Hurray!!! Data loaded successfully.") + data_out.append(("angle_" + str(i), + NDCube(hdul[0].data, + wcs=wcs, + meta=hdul[0].header))) + return NDCollection(data_out, meta={}, aligned_axes="all") From 86556cfb4347e95d1371eb7bff13c8f762057660 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:05:12 -0700 Subject: [PATCH 18/28] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 8983cee8b718bf217388e8f0d576f9ac547c7ef6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!AiqG5S^{9wusP!LXQEjg0=J_UP9F$Fro*Q+L)rjm@Q3eky6N6f5~1;tl}~?pyE01gK?VZ^xF1I z^^*8~3h=k9Qbd}rDEsvN>Xad$(8#q9;WQhCi4MVe4o69xbdT%GT*uxRO|+~q^LCo6YD zQReBG-!tW;e2dbG0;0f21(s~L$>;y!_xJygBf*V8L;{fP8EG!}elRpAR25CfrA64KLTv1-b From b2b907a7b65d341a6aafcba2f8d73df46738a278 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:05:22 -0700 Subject: [PATCH 19/28] Delete docs/.DS_Store --- docs/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 docs/.DS_Store diff --git a/docs/.DS_Store b/docs/.DS_Store deleted file mode 100644 index cbf579b9b41a59a34296108fa2bf86266d5b9020..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKI|>3Z5S>vG!N$@uSMUZw^aOhVMFbH^|vYm-cL}Uavl$#A*vwic9^)jMBIL WHL(qJI^s?T@@K$wp;3WfEARkPw-tr} From 07e919432d87ba4897fac9979c9ada5211a84959 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:05:43 -0700 Subject: [PATCH 20/28] Delete tests/.DS_Store --- tests/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/.DS_Store diff --git a/tests/.DS_Store b/tests/.DS_Store deleted file mode 100644 index ad1071e74dfb52573c471d0b5550ffcb34a6545d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr<=6ur@EQ$;MI;4B_o;=Qwq!$2KrR^^P6aj!^BFs%-_JL79r2!i;EqO$y#;8F8 zZHVzF2fS^ARlq9n+Z3R)I|C^+@Z_fO_WZU~{Tu=asn_cyu@_1Y{U5wI43e~5eqtk| zxv}v)=X{c%xRd7j?7y?NXop6h>^8()5H zz1MCl3T1SGYwU~sX3Mtt=M*qskx%})mD>ed1*`(!tpME*0u!NQFw>~64$M>tfSAK( zWmu+If;hsUV=&W*J!ni*5jB;W5QAwtwhQCu7|b+kIxrJ_Ff%hV5eieY Date: Mon, 6 Nov 2023 10:06:23 -0700 Subject: [PATCH 21/28] removes unused tests --- tests/test_core.py | 216 --------------------------------------------- 1 file changed, 216 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index d2dbf84..4edb6bd 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -226,219 +226,3 @@ def test_btbr_to_mzp(btbr_ones): def test_bp3_to_bthp(bp3_ones): result = resolve(bp3_ones, "Bthp") assert isinstance(result, NDCollection) - - -# def test_determine_input_kind(): -# d = {"B": np.array([0]), "pB": np.array([1])} -# determined_kind = determine_input_kind(d) -# assert determined_kind, "BpB" -# -# -# def test_determine_input_kind_fail(): -# d = {"B": np.array([0]), "M": np.array([1])} -# with pytest.raises(ValueError): -# determine_input_kind(d) -# @fixture -# def example_mzp(): -# d = {-60*u.degree: np.array([2]), 0*u.degree: np.array([1]), 60*u.degree: np.array([1.5]), -# "alpha": np.array([5])*u.degree} -# return d -# -# -# @fixture -# def mixed_mzp(): -# """MZP data that uses both degrees and radians""" -# d = {-60*u.degree: np.array([2]), 0*u.radian: np.array([1]), np.pi/3*u.radian: np.array([1.5]), -# "alpha": np.array([5])*u.degree} -# return d -# -# -# @fixture -# def unitless_mzp(): -# d = {-60: np.array([2]), 0: np.array([1]), 60: np.array([1.5]), -# "alpha": np.array([5])} -# return d -# -# -# @fixture -# def incorrect_units_mzp(): -# d = {-60 * u.meter: np.array([2]), 0: np.array([1]), 60: np.array([1.5]), -# "alpha": np.array([5])*u.degree} -# return d -# -# -# def test_sanitize_mzp_deg2deg(example_mzp): -# """ converts mzp from deg 2 deg""" -# sanitized, use_radians = sanitize_data_dict(example_mzp, u.degree) -# assert not use_radians -# assert example_mzp == sanitized -# -# -# def test_sanitize_mzp_deg2rad(example_mzp): -# """ converts mzp deg 2 rad""" -# sanitized, use_radians = sanitize_data_dict(example_mzp, u.radian) -# assert not use_radians -# assert set(sanitized.keys()) == {np.pi/3*u.radian, 0*u.radian, -np.pi/3*u.radian, 'alpha'} -# assert sanitized['alpha'][0] == np.pi/36 * u.radian -# -# -# def test_sanitize_mzp_mixed2rad(mixed_mzp): -# """ converts mzp with mixed units to radians""" -# sanitized, use_radians = sanitize_data_dict(mixed_mzp, u.radian) -# assert use_radians -# assert set(sanitized.keys()) == {np.pi / 3 * u.radian, 0 * u.radian, -np.pi / 3 * u.radian, 'alpha'} -# assert sanitized['alpha'][0] == np.pi / 36 * u.radian -# -# -# def test_sanitize_mzp_mixed2deg(mixed_mzp): -# """ converts mzp mixed units to degrees""" -# sanitized, use_radians = sanitize_data_dict(mixed_mzp, u.degree) -# assert use_radians -# assert -60 * u.degree in sanitized -# assert (0*u.rad) * ((180*u.degree) / (np.pi* u.radian)) in sanitized -# assert (np.pi/3*u.rad) * ((180*u.degree) / (np.pi* u.radian)) in sanitized -# assert sanitized['alpha'][0] == 5 * u.degree -# -# -# def test_sanitize_mzp_unitless2deg(unitless_mzp): -# """ converts unitless mzp to degrees""" -# sanitized, use_radians = sanitize_data_dict(unitless_mzp, u.degree) -# assert not use_radians -# assert -60 * u.degree in sanitized -# assert 0 * u.degree in sanitized -# assert 60 * u.degree in sanitized -# assert sanitized['alpha'][0] == 5 * u.degree -# -# -# def test_sanitize_mzp_unitless2rad(unitless_mzp): -# """ converts unitless mzp to radians""" -# sanitized, use_radians = sanitize_data_dict(unitless_mzp, u.radian) -# assert not use_radians -# assert -np.pi/3 * u.radian in sanitized -# assert 0 * u.radian in sanitized -# assert np.pi/3 * u.radian in sanitized -# assert sanitized['alpha'][0] == np.pi/36 * u.radian -# -# -# def test_sanitize_wrong_unit_request(example_mzp): -# """ tries to convert to a nonsensical unit""" -# with pytest.raises(RuntimeError): -# sanitize_data_dict(example_mzp, 'fizbop') -# -# -# def test_sanitize_wrong_unit_mzp(incorrect_units_mzp): -# """ key has the wrong unit (meters instead of an angle unit)""" -# with pytest.raises(RuntimeError): -# sanitize_data_dict(incorrect_units_mzp, u.degree) -# -# -# def test_sanitize_wrong_unit_alpha(): -# """ alpha has non-angle unit of meter""" -# d = {"alpha": np.array([5])*u.meter} -# with pytest.raises(RuntimeError): -# sanitize_data_dict(d, u.degree) -# -# -# def test_sanitize_nonnumeric_alpha(): -# """ alpha is nonnumeric so can't sanitize""" -# d = {"alpha": np.array(["fail"])} -# with pytest.raises(RuntimeError): -# sanitize_data_dict(d, u.degree) -# -# -# def test_sanitize_radian2degree_alpha(): -# """ alpha gets converted from radians to degrees""" -# d = {"alpha": np.array([0])*u.radian} -# sanitized, use_radians = sanitize_data_dict(d, u.degree) -# assert use_radians -# assert sanitized['alpha'][0] == 0 * u.degree -# -# -# def test_sanitize_radian2radian_alpha(): -# """ alpha gets converted from radians to radians""" -# d = {"alpha": np.array([0])*u.radian} -# sanitized, use_radians = sanitize_data_dict(d, u.radian) -# assert use_radians -# assert sanitized['alpha'][0] == 0 * u.radian -# -# -# def test_determine_input_kind_mzp(example_mzp): -# assert determine_input_kind(example_mzp), "MZP" -# -# -# def test_determine_input_kind(): -# d = {"B": np.array([0]), "pB": np.array([1])} -# determined_kind = determine_input_kind(d) -# assert determined_kind, "BpB" -# -# -# def test_determine_input_kind_fail(): -# d = {"B": np.array([0]), "M": np.array([1])} -# with pytest.raises(ValueError): -# determine_input_kind(d) -# -# -# def test_bpb_to_btbr(): -# d = {"B": np.array([2]), "pB": np.array([1])} -# result = resolve(d, "BtBr") -# assert isinstance(result, dict) -# -# -# def test_mzp_to_btbr(example_mzp): -# result = resolve(example_mzp, "BtBr") -# assert isinstance(result, dict) -# -# -# def test_STEREO_triplet(): -# """ingest STEREO data nd test does something""" -# TESTDATA_DIR = os.path.dirname(__file__) -# path_to_test_files=TESTDATA_DIR+'/test_support_files/' -# file_list=[path_to_test_files+"stereo_0.fts", -# path_to_test_files+"stereo_120.fts", -# path_to_test_files+"stereo_240.fts"] -# result = convert_image_list_to_dict(file_list) -# assert isinstance(result, dict) -# assert 0*u.degree in result -# assert 120*u.degree in result -# assert 240*u.degree in result -# -# -# def test_LASCO_triplet(): -# """ingest STEREO data nd test does something""" -# TESTDATA_DIR = os.path.dirname(__file__) -# path_to_test_files=TESTDATA_DIR+'/test_support_files/' -# file_list=[path_to_test_files+"lasco_-60.fts", -# path_to_test_files+"lasco_+60.fts", -# path_to_test_files+"lasco_0.fts"] -# result = convert_image_list_to_dict(file_list) -# assert isinstance(result, dict) -# assert 0*u.degree in result -# assert -60*u.degree in result -# assert 60*u.degree in result -# -# -# def test_LASCO_BpB(): -# """ingest STEREO data nd test does something""" -# TESTDATA_DIR = os.path.dirname(__file__) -# path_to_test_files=TESTDATA_DIR+'/test_support_files/' -# file_list=[path_to_test_files+"lasco_-60.fts", -# path_to_test_files+"lasco_clear.fts"] -# result = convert_image_list_to_dict(file_list) -# assert isinstance(result, dict) -# assert 'pB' in result -# assert 'B' in result -# assert 'alpha' in result -# -# -# @pytest.mark.parametrize("B, B_theta, theta, alpha, expected", -# [(0, 0.5, 0*u.degree, 0*u.degree, -1), -# (0, 0.5, 0*u.radian, 0*u.radian, -1), -# (0, 0.5, 0*u.radian, 0*u.degree, -1), -# (0, 0.5, 1*u.degree, 1*u.degree, -1), -# (0, 0.5, 1*u.degree, 2*u.degree, -1.00061)]) -# -# def test_pB_from_single_angle_function(B, B_theta, theta, alpha, expected): -# """test pB from single angle fn in core""" -# -# output=pB_from_single_angle(B, B_theta, theta, alpha) -# np.testing.assert_allclose(output, expected, rtol=1e-05) From 05bf0d6370d05aa7951f35f1843b7760530d890d Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:10:39 -0700 Subject: [PATCH 22/28] adds fourpol test --- tests/test_polarizers.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_polarizers.py b/tests/test_polarizers.py index 5314a83..d538650 100644 --- a/tests/test_polarizers.py +++ b/tests/test_polarizers.py @@ -40,7 +40,6 @@ def npol_mzp_ones(): data_out.append(("angle_1", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 60, 'OBSRVTRY': 'STEREO_B'}))) data_out.append(("angle_2", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0, 'OBSRVTRY': 'STEREO_B'}))) data_out.append(("angle_3", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': -60, 'OBSRVTRY': 'STEREO_B'}))) - # data_out.append(("alpha", NDCube(np.array([0]))*u.radian, wcs=wcs)) return NDCollection(data_out, meta={}, aligned_axes="all") def test_npol_mzp_ones(npol_mzp_ones): @@ -316,3 +315,22 @@ def test_btbr_npol_ones(btbr_ones): 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(): + data_out = [] + data_out.append(("B0", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B0'}))) + data_out.append(("B45", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B45'}))) + data_out.append(("B90", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B90'}))) + data_out.append(("B135", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B135'}))) + return NDCollection(data_out, meta={}, aligned_axes="all") + +def test_fourpol_to_stokes_ones(): + actual = pol.btbr_to_npol(btbr_ones,[0,120,240]) + expected_data = [] + expected_data.append(("Bi", NDCube(np.array([2]), wcs=wcs))) + expected_data.append(("Bq", NDCube(np.array([0]), wcs=wcs))) + expected_data.append(("Bu", 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) From 6fd1e71ff335877bd6cd831e1a894f70a621a6e1 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:14:46 -0700 Subject: [PATCH 23/28] fix #35 --- solpolpy/core.py | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/solpolpy/core.py b/solpolpy/core.py index 4d09d4b..7cd6d7f 100644 --- a/solpolpy/core.py +++ b/solpolpy/core.py @@ -121,10 +121,6 @@ def resolve(input_data: Union[List[str], NDCollection], out_polarize_state: str) input_data = sp.polarizers.npol_to_mzp(input_data) input_kind = "MZP" -# Convert a set of inputs given at different polarizing angles to a common base of MZP. -# input_data_mzp = sp.polarizers.npol_to_mzp(input_data) -# input_kind = "MZP" - input_key = list(input_data) transform_path = get_transform_path(input_kind, out_polarize_state) equation = get_transform_equation(transform_path) @@ -186,28 +182,11 @@ def add_alpha(input_data: NDCollection) -> NDCollection: metad = input_data[keys[0]].meta deg2rad = (np.pi * u.radian) / (180 * u.degree) - # TODO: don't use inputs inside if len(img_shape) == 2: # it's an image and not just an array - inp = input("Do you wish to provide an alpha array?").lower() - if inp.startswith('n'): - print("Continuing with default options... Waiting for input...") - inp_ref = input("Choose the reference along the Solar: \"North\" or \"West\":").lower() - if inp_ref.startswith('n'): - alpha = radial_north(img_shape) - else: - alpha = radial_west(img_shape) - input_data.update(NDCollection([("alpha", NDCube(alpha, wcs=wcs, meta=metad))], meta={}, aligned_axes='all')) - elif inp.startswith('y'): - print("Provide the alpha matrix in FITS format") - alpha_path = input("Provide the path of alpha FITS file:") - hdu = fits.open(alpha_path) - - # TODO: make the FITS file use a header keyword to specify the units of alpha - if np.max(hdu[0].data) > 2 * np.pi + 1: - alph = hdu[0].data * deg2rad - else: - alph = hdu[0].data - input_data.update(NDCollection([("alpha", NDCube(alph, wcs=wcs, meta=metad))], meta={}, aligned_axes='all')) + alpha = radial_north(img_shape) + else: + raise ValueError(f"Data must be an image with 2 dimensions, found {len(img_shape)}.") + input_data.update(NDCollection([("alpha", NDCube(alph, wcs=wcs, meta=metad))], meta={}, aligned_axes='all')) return input_data From 78c45d000ee895becfdad32fc8f47ea1eb007817 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:16:32 -0700 Subject: [PATCH 24/28] fix typo --- solpolpy/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solpolpy/core.py b/solpolpy/core.py index 7cd6d7f..57985c1 100644 --- a/solpolpy/core.py +++ b/solpolpy/core.py @@ -186,7 +186,7 @@ def add_alpha(input_data: NDCollection) -> NDCollection: alpha = radial_north(img_shape) else: raise ValueError(f"Data must be an image with 2 dimensions, found {len(img_shape)}.") - input_data.update(NDCollection([("alpha", NDCube(alph, wcs=wcs, meta=metad))], meta={}, aligned_axes='all')) + input_data.update(NDCollection([("alpha", NDCube(alpha, wcs=wcs, meta=metad))], meta={}, aligned_axes='all')) return input_data From 3ff5464025b318c66ad095f4aae76a4d73aaa818 Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:18:07 -0700 Subject: [PATCH 25/28] correct test to use proper function --- tests/test_polarizers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_polarizers.py b/tests/test_polarizers.py index d538650..8cd304e 100644 --- a/tests/test_polarizers.py +++ b/tests/test_polarizers.py @@ -326,7 +326,7 @@ def fourpol_ones(): return NDCollection(data_out, meta={}, aligned_axes="all") def test_fourpol_to_stokes_ones(): - actual = pol.btbr_to_npol(btbr_ones,[0,120,240]) + actual = pol.fourpol_to_stokes(btbr_ones,[0,120,240]) expected_data = [] expected_data.append(("Bi", NDCube(np.array([2]), wcs=wcs))) expected_data.append(("Bq", NDCube(np.array([0]), wcs=wcs))) From 01f97faf576505a06f00eb28f4b8bde555af5b5f Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:20:01 -0700 Subject: [PATCH 26/28] fix test --- tests/test_polarizers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_polarizers.py b/tests/test_polarizers.py index 8cd304e..53f5238 100644 --- a/tests/test_polarizers.py +++ b/tests/test_polarizers.py @@ -325,8 +325,8 @@ def fourpol_ones(): data_out.append(("B135", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B135'}))) return NDCollection(data_out, meta={}, aligned_axes="all") -def test_fourpol_to_stokes_ones(): - actual = pol.fourpol_to_stokes(btbr_ones,[0,120,240]) +def test_fourpol_to_stokes_ones(fourpol_ones): + actual = pol.fourpol_to_stokes(fourpol_ones) expected_data = [] expected_data.append(("Bi", NDCube(np.array([2]), wcs=wcs))) expected_data.append(("Bq", NDCube(np.array([0]), wcs=wcs))) From 81ac828d704ab002e5d180a71707151b4a6a07ea Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:25:43 -0700 Subject: [PATCH 27/28] fixes keys to float for fourpol --- tests/test_polarizers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_polarizers.py b/tests/test_polarizers.py index 53f5238..e23aab6 100644 --- a/tests/test_polarizers.py +++ b/tests/test_polarizers.py @@ -319,10 +319,10 @@ def test_btbr_npol_ones(btbr_ones): @fixture def fourpol_ones(): data_out = [] - data_out.append(("B0", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B0'}))) - data_out.append(("B45", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B45'}))) - data_out.append(("B90", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B90'}))) - data_out.append(("B135", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'B135'}))) + data_out.append((0, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0}))) + data_out.append((45, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 45}))) + data_out.append((90, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 90}))) + data_out.append((135, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 135}))) return NDCollection(data_out, meta={}, aligned_axes="all") def test_fourpol_to_stokes_ones(fourpol_ones): From 2cbf7e7302185c21763a5f480f04ad816132303b Mon Sep 17 00:00:00 2001 From: Marcus Hughes Date: Mon, 6 Nov 2023 10:43:03 -0700 Subject: [PATCH 28/28] fixed fourpol test --- solpolpy/polarizers.py | 23 +++++++----------- tests/test_polarizers.py | 52 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/solpolpy/polarizers.py b/solpolpy/polarizers.py index 4392ec5..c839936 100644 --- a/solpolpy/polarizers.py +++ b/solpolpy/polarizers.py @@ -391,6 +391,7 @@ def btbr_to_npol(input_cube, angles): return NDCollection(Bnpol_cube, meta={}, aligned_axes="all") + def fourpol_to_stokes(input_cube): """ Notes @@ -398,22 +399,14 @@ def fourpol_to_stokes(input_cube): Table 1 in DeForest et al. 2022. """"" - 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 + Bi = input_cube["B0"].data + input_cube["B90"].data + Bq = input_cube["B90"].data - input_cube["B0"].data + Bu = input_cube["B135"].data - input_cube["B45"].data - metaI, metaQ, metaU = copy.copy(input_cube[0].meta), copy.copy(input_cube[0].meta), copy.copy(input_cube[0].meta) + metaI, metaQ, metaU = copy.copy(input_cube["B0"].meta), copy.copy(input_cube["B0"].meta), copy.copy(input_cube["B0"].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.append(("Bi", NDCube(Bi, wcs=input_cube["B0"].wcs, meta=metaI))) + BStokes_cube.append(("Bq", NDCube(Bq, wcs=input_cube["B0"].wcs, meta=metaQ))) + BStokes_cube.append(("Bu", NDCube(Bu, wcs=input_cube["B0"].wcs, meta=metaU))) return NDCollection(BStokes_cube, meta={}, aligned_axes="all") diff --git a/tests/test_polarizers.py b/tests/test_polarizers.py index e23aab6..97995c9 100644 --- a/tests/test_polarizers.py +++ b/tests/test_polarizers.py @@ -15,6 +15,7 @@ wcs.crval = 10, 0.5, 1 wcs.cname = 'wavelength', 'HPC lat', 'HPC lon' + @fixture def npol_mzp_zeros(): data_out = [] @@ -24,6 +25,7 @@ def npol_mzp_zeros(): 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 = pol.npol_to_mzp(npol_mzp_zeros) expected_data = [] @@ -34,6 +36,7 @@ def test_npol_mzp_zeros(npol_mzp_zeros): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def npol_mzp_ones(): data_out = [] @@ -42,6 +45,7 @@ def npol_mzp_ones(): data_out.append(("angle_3", 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 = pol.npol_to_mzp(npol_mzp_ones) expected_data = [] @@ -52,6 +56,7 @@ def test_npol_mzp_ones(npol_mzp_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def mzp_ones_alpha(): data_out = [] @@ -61,6 +66,7 @@ def mzp_ones_alpha(): 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 = pol.npol_to_mzp(mzp_ones_alpha) expected_data = [] @@ -72,6 +78,7 @@ def test_npol_mzp_ones_alpha(mzp_ones_alpha): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def mzp_zeros(): data_out = [] @@ -81,6 +88,7 @@ def mzp_zeros(): 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 = pol.mzp_to_bpb(mzp_zeros) expected_data = [] @@ -91,6 +99,7 @@ def test_mzp_bpb_zeros(mzp_zeros): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def mzp_ones(): data_out = [] @@ -100,6 +109,7 @@ def mzp_ones(): 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 = pol.mzp_to_bpb(mzp_ones) expected_data = [] @@ -110,6 +120,7 @@ def test_mzp_bpb_ones(mzp_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def bpb_zeros(): data_out = [] @@ -118,6 +129,7 @@ def bpb_zeros(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_bpb_mzp_zeros(bpb_zeros): actual = pol.bpb_to_mzp(bpb_zeros) expected_data = [] @@ -129,6 +141,7 @@ def test_bpb_mzp_zeros(bpb_zeros): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def bpb_ones(): data_out = [] @@ -137,6 +150,7 @@ def bpb_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_bpb_mzp_ones(bpb_ones): actual = pol.bpb_to_mzp(bpb_ones) expected_data = [] @@ -148,6 +162,7 @@ def test_bpb_mzp_ones(bpb_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def btbr_bpb_ones(): data_out = [] @@ -156,6 +171,7 @@ def btbr_bpb_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_bpb_btbr_ones(btbr_bpb_ones): actual = pol.bpb_to_btbr(btbr_bpb_ones) expected_data = [] @@ -166,6 +182,7 @@ def test_bpb_btbr_ones(btbr_bpb_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def btbr_ones(): data_out = [] @@ -174,6 +191,7 @@ def btbr_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_btbr_bpb_ones(btbr_ones): actual = pol.btbr_to_bpb(btbr_ones) expected_data = [] @@ -184,6 +202,7 @@ def test_btbr_bpb_ones(btbr_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def mzp_ones(): data_out = [] @@ -193,6 +212,7 @@ def mzp_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_mzp_stokes_ones(mzp_ones): actual = pol.mzp_to_stokes(mzp_ones) expected_data = [] @@ -203,6 +223,7 @@ def test_mzp_stokes_ones(mzp_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def stokes_ones(): data_out = [] @@ -211,6 +232,7 @@ def stokes_ones(): data_out.append(("Bu", NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 'Bu'}))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_stokes_mzp_ones(stokes_ones): actual = pol.stokes_to_mzp(stokes_ones) expected_data = [] @@ -221,6 +243,7 @@ def test_stokes_mzp_ones(stokes_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def mzp_ones(): data_out = [] @@ -230,6 +253,7 @@ def mzp_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_mzp_bp3_ones(mzp_ones): actual = pol.mzp_to_bp3(mzp_ones) expected_data = [] @@ -241,6 +265,7 @@ def test_mzp_bp3_ones(mzp_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def bp3_ones(): data_out = [] @@ -250,6 +275,7 @@ def bp3_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_bp3_mzp_ones(bp3_ones): actual = pol.bp3_to_mzp(bp3_ones) expected_data = [] @@ -260,6 +286,7 @@ def test_bp3_mzp_ones(bp3_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def btbr_ones_mzp(): data_out = [] @@ -268,6 +295,7 @@ def btbr_ones_mzp(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_btbr_mzp_ones(btbr_ones_mzp): actual = pol.btbr_to_mzp(btbr_ones_mzp) expected_data = [] @@ -278,6 +306,7 @@ def test_btbr_mzp_ones(btbr_ones_mzp): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def bp3_ones(): data_out = [] @@ -287,6 +316,7 @@ def bp3_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_bp3_bthp_ones(bp3_ones): actual = pol.bp3_to_bthp(bp3_ones) expected_data = [] @@ -297,6 +327,7 @@ def test_bp3_bthp_ones(bp3_ones): for k in list(expected): assert np.allclose(actual[str(k)].data, expected[str(k)].data) + @fixture def btbr_ones(): data_out = [] @@ -305,6 +336,7 @@ def btbr_ones(): data_out.append(("alpha", NDCube(np.array([0])*u.degree, wcs=wcs))) return NDCollection(data_out, meta={}, aligned_axes="all") + def test_btbr_npol_ones(btbr_ones): actual = pol.btbr_to_npol(btbr_ones,[0,120,240]) expected_data = [] @@ -316,14 +348,24 @@ def test_btbr_npol_ones(btbr_ones): 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) + wcs.ctype = 'ONE' + wcs.cunit = 'deg' + wcs.cdelt = 0.1 + wcs.crpix = 0 + wcs.crval = 0 + wcs.cname = 'ONE' + data_out = [] - data_out.append((0, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 0}))) - data_out.append((45, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 45}))) - data_out.append((90, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 90}))) - data_out.append((135, NDCube(np.array([1]), wcs=wcs, meta={'POLAR': 135}))) - return NDCollection(data_out, meta={}, aligned_axes="all") + data_out.append(("B0", NDCube(data=np.array([1]), wcs=wcs, meta={'POLAR': 0}))) + data_out.append(("B45", NDCube(data=np.array([1]), wcs=wcs, meta={'POLAR': 45}))) + data_out.append(("B90", NDCube(data=np.array([1]), wcs=wcs, meta={'POLAR': 90}))) + data_out.append(("B135", NDCube(data=np.array([1]), wcs=wcs, meta={'POLAR': 135}))) + return NDCollection(key_data_pairs=data_out, meta={}, aligned_axes='all') + def test_fourpol_to_stokes_ones(fourpol_ones): actual = pol.fourpol_to_stokes(fourpol_ones)