Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccd_tempreture taking astropy unit #150

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
eda4374
ccd_tempreture taking astropy unit
Abinash-bit Nov 29, 2024
7b4f3f3
Update sunkit_instruments/suvi/suvi.py
Abinash-bit Nov 30, 2024
9625f71
Update sunkit_instruments/suvi/suvi.py
Abinash-bit Nov 30, 2024
33d13fa
Update sunkit_instruments/suvi/suvi.py
Abinash-bit Nov 30, 2024
85f3ff6
Adding unit tests for get_response
Abinash-bit Nov 30, 2024
5ddc1b0
updates
Abinash-bit Nov 30, 2024
752a01d
Fixing precommit
Abinash-bit Nov 30, 2024
fc20b49
Adding the changelog
Abinash-bit Nov 30, 2024
fcbd964
again fixing the precommit
Abinash-bit Nov 30, 2024
55acee0
Adding the quantity decorators and removing the manual checks
Abinash-bit Dec 1, 2024
7e74533
Correcting changelog
Abinash-bit Dec 1, 2024
832b89c
Coming back to the code base where test cases did not fail so that i …
Abinash-bit Dec 4, 2024
2277451
Just Changes
Abinash-bit Dec 4, 2024
119f05b
updates
Abinash-bit Dec 4, 2024
7b0e0e8
May be proceeding towards final script
Abinash-bit Dec 4, 2024
e5c8160
Fixing pre-commit
Abinash-bit Dec 4, 2024
5da93f3
Update changelog/150.feature.3.rst
Abinash-bit Dec 4, 2024
c47016c
Passing all the test cases
Abinash-bit Dec 5, 2024
dc30d6f
Changes in changelog too
Abinash-bit Dec 5, 2024
d8b1cae
Checking precommit
Abinash-bit Dec 5, 2024
4f2a35b
Merge branch 'main' into ccd-temp
Abinash-bit Dec 6, 2024
cca132c
Addressing the comments
Abinash-bit Dec 7, 2024
37c05d6
Resolving conflicts
Abinash-bit Dec 7, 2024
d7f11bb
Update sunkit_instruments/suvi/suvi.py
Abinash-bit Dec 7, 2024
0340232
addressing comments
Abinash-bit Dec 7, 2024
89c08d7
Resolving conflicts
Abinash-bit Dec 7, 2024
4e5fd72
Addressing comments
Abinash-bit Dec 7, 2024
22c8f7c
Addressing comments
Abinash-bit Dec 7, 2024
427ada4
precommit-fix
Abinash-bit Dec 7, 2024
49d11b6
Resolving final comments
Abinash-bit Dec 7, 2024
0b1de6a
back to the changes
Abinash-bit Dec 7, 2024
e1b7abf
fixing codestyle and resolving commits
Abinash-bit Dec 7, 2024
c2d1899
precommit-fix
Abinash-bit Dec 7, 2024
c98c627
Update sunkit_instruments/suvi/suvi.py
Abinash-bit Dec 7, 2024
6084b6c
Adding line space in test_suvi.py
Abinash-bit Dec 7, 2024
eb45e53
resolving conflicts
Abinash-bit Dec 7, 2024
64148c9
Update sunkit_instruments/suvi/tests/test_suvi.py
Abinash-bit Dec 7, 2024
f2bf28a
Update sunkit_instruments/suvi/tests/test_suvi.py
Abinash-bit Dec 7, 2024
9436955
Update sunkit_instruments/suvi/tests/test_suvi.py
Abinash-bit Dec 7, 2024
c203be7
Update sunkit_instruments/suvi/tests/test_suvi.py
Abinash-bit Dec 7, 2024
26a0548
precommit-fix
Abinash-bit Dec 7, 2024
4337ea4
resolving conflicts
Abinash-bit Dec 7, 2024
89e9221
addressing old comments
Abinash-bit Dec 7, 2024
35e03e0
Update sunkit_instruments/suvi/suvi.py
Abinash-bit Dec 7, 2024
91063ca
addressing old comments
Abinash-bit Dec 7, 2024
85689ee
Resolving conflicts
Abinash-bit Dec 7, 2024
f0d5c8d
Update sunkit_instruments/suvi/suvi.py
Abinash-bit Dec 7, 2024
8fd73da
just precommit
Abinash-bit Dec 7, 2024
70d6339
resolving conflicts
Abinash-bit Dec 7, 2024
c99b66f
Changing the name of the changelog
Abinash-bit Dec 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/150.feature.3.rst
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this file.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated `~.get_response` to enforce ``ccd_temperature`` as an `astropy.units.Quantity`
1 change: 1 addition & 0 deletions changelog/150.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated `~.get_response` to enforce ``ccd_temperature`` as an `astropy.units.Quantity`
17 changes: 9 additions & 8 deletions sunkit_instruments/suvi/suvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
"""
return _despike(data, dqf, filter_width)


def get_response(request, spacecraft=16, ccd_temperature=-60.0, exposure_type="long"):
@u.quantity_input(ccd_temperature=u.deg_C)
def get_response(request, spacecraft=16, ccd_temperature=-60.0 * u.deg_C, exposure_type="long"):
"""
Get the SUVI instrument response for a specific wavelength channel,
spacecraft, CCD temperature, and exposure type.
Expand All @@ -113,13 +113,13 @@

Parameters
----------
request: `str` or {94 | 131 | 171 | 195 | 284 | 304}.
request: `str` or {94, 131, 171, 195, 284, 304}
Either an L1b filename (FITS or netCDF), or an integer
specifying the wavelength channel.
spacecraft: `int`, optional.
Which GOES spacecraft, default is 16.
ccd_temperature: `float`, optional.
The CCD temperature, in degrees Celsius, default is -60.
ccd_temperature: `astropy.units.Quantity`
The CCD temperature, in degrees Celsius, default is ``-60.0 * u.deg_C``.
Needed for getting the correct gain number.
exposure_type: {"long" | "short" | "short_flare"}, optional.
The exposure type of the SUVI image.
Expand Down Expand Up @@ -156,7 +156,8 @@
header, _, _ = read_suvi(request)
wavelength_channel = int(header["WAVELNTH"])
spacecraft = int(header["TELESCOP"].replace(" ", "").replace("G", ""))
ccd_temperature = (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0
ccd_temp_avg = (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0
ccd_temperature = ccd_temp_avg * u.deg_C

Check warning on line 160 in sunkit_instruments/suvi/suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/suvi.py#L159-L160

Added lines #L159 - L160 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we redefine ccd_temperature here?

exposure_type = "_".join(
header["SCI_OBJ"].replace(" ", "").split(sep="_")[3:]
).replace("_exposure", "")
Expand Down Expand Up @@ -195,7 +196,7 @@
temp_x = gain_table[:, 0]
gain_y = gain_table[:, 1]
gain_vs_temp = interpolate.interp1d(temp_x, gain_y)
gain = gain_vs_temp(ccd_temperature)
gain = gain_vs_temp(ccd_temperature.to(u.deg_C).value)

Check warning on line 199 in sunkit_instruments/suvi/suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/suvi.py#L199

Added line #L199 was not covered by tests

geometric_area = 19.362316 * u.cm * u.cm
solid_angle = ((2.5 / 3600.0 * (np.pi / 180.0)) ** 2.0) * u.sr
Expand All @@ -210,7 +211,7 @@
"response": response,
"wavelength_channel": wavelength_channel,
"spacecraft": "GOES-" + str(spacecraft),
"ccd_temperature": ccd_temperature * u.deg_C,
"ccd_temperature": ccd_temperature,
"exposure_type": exposure_type,
"flight_model": FLIGHT_MODEL[spacecraft],
"gain": float(gain),
Expand Down
19 changes: 18 additions & 1 deletion sunkit_instruments/suvi/tests/test_suvi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np
import pytest

import astropy.units as u

from sunkit_instruments import suvi

# Test files are all remote data.
pytestmark = pytest.mark.remote_data


Expand All @@ -24,15 +25,31 @@


def test_get_response_nc(L1B_NC):
header, _, _ = suvi.read_suvi(L1B_NC)

Check warning on line 28 in sunkit_instruments/suvi/tests/test_suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/tests/test_suvi.py#L28

Added line #L28 was not covered by tests
l1b_nc_response = suvi.get_response(L1B_NC)
assert l1b_nc_response["wavelength_channel"] == 171
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
assert l1b_nc_response["ccd_temperature"] == (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C

Check warning on line 31 in sunkit_instruments/suvi/tests/test_suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/tests/test_suvi.py#L31

Added line #L31 was not covered by tests


def test_get_response_fits(L1B_FITS):
header, _, _ = suvi.read_suvi(L1B_FITS)

Check warning on line 35 in sunkit_instruments/suvi/tests/test_suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/tests/test_suvi.py#L35

Added line #L35 was not covered by tests
l1b_fits_response = suvi.get_response(L1B_FITS)
assert l1b_fits_response["wavelength_channel"] == 171
assert l1b_fits_response["ccd_temperature"] == (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C

Check warning on line 38 in sunkit_instruments/suvi/tests/test_suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/tests/test_suvi.py#L38

Added line #L38 was not covered by tests


def test_get_response_wavelength():
response_195 = suvi.get_response(195)
assert response_195["wavelength_channel"] == 195


def test_get_response_explicit_temperature():
temp = -70.0 * u.deg_C
response = suvi.get_response(195, ccd_temperature=temp)
assert response["ccd_temperature"] == temp

Check warning on line 49 in sunkit_instruments/suvi/tests/test_suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/tests/test_suvi.py#L47-L49

Added lines #L47 - L49 were not covered by tests


def test_get_response_invalid_temperature():
temp = -70.0 # Without units
with pytest.raises(TypeError):
suvi.get_response(195, ccd_temperature=temp)

Check warning on line 55 in sunkit_instruments/suvi/tests/test_suvi.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/suvi/tests/test_suvi.py#L53-L55

Added lines #L53 - L55 were not covered by tests
Loading