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

Conversation

Abinash-bit
Copy link
Contributor

PR Description

Function Signature Update:

Changed ccd_temperature=-60.0 to ccd_temperature=-60.0 * u.deg_C.

Temperature Handling:

Added a check to ensure ccd_temperature is an Astropy Quantity.

Converted non-Quantity inputs to u.deg_C.

Ensured temperature is in degrees Celsius for consistency.

Gain Interpolation:

Used temp_x values directly (assumed in degrees Celsius).

Used .value to get numerical values for interpolation.

Docstring Update:

Described ccd_temperature as an Astropy Quantity with units.

Testing:

The function now accepts both Quantity and float inputs for temperature.

Temperatures provided in different units are converted to degrees Celsius.

Screenshot 2024-11-29 103728

This fixes #77

Copy link
Contributor

@nabobalis nabobalis left a comment

Choose a reason for hiding this comment

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

This will need to make sure there is a unit test for this and a changelog entry.

"""
Get the SUVI instrument response for a specific wavelength channel,
spacecraft, CCD temperature, and exposure type.
Get the SUVI instrument response for a specific wavelength channel, spacecraft, CCD temperature, and exposure type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Get the SUVI instrument response for a specific wavelength channel, spacecraft, CCD temperature, and exposure type.
Get the SUVI instrument response for a specific wavelength channel, spacecraft,
CCD temperature, and exposure type.

parameters are read automatically from the metadata, or the parameters
can be passed manually, with ``request`` specifying the desired wavelength
channel.
``request`` can either be an L1b filename (FITS or netCDF), in which case all of those parameters are read automatically from the metadata, or the parameters can be passed manually, with ``request`` specifying the desired wavelength channel.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
``request`` can either be an L1b filename (FITS or netCDF), in which case all of those parameters are read automatically from the metadata, or the parameters can be passed manually, with ``request`` specifying the desired wavelength channel.
``request`` can either be an L1b filename (FITS or netCDF), in which case all of those parameters
are read automatically from the metadata, or the parameters can be passed manually, with ``request`` specifying the desired wavelength channel.

ccd_temperature: `float`, optional.
The CCD temperature, in degrees Celsius, default is -60.
ccd_temperature : astropy.units.Quantity, optional
The CCD temperature, in degrees Celsius, default is -60.0 * u.deg_C.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The CCD temperature, in degrees Celsius, default is -60.0 * u.deg_C.
The CCD temperature, in degrees Celsius, default is ``-60.0 * u.deg_C``.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not resolve comments unless they are fixed.

Comment on lines 1 to 6
### Added
- Support for `ccd_temperature` as an Astropy Quantity in the `get_response` function.
### Changed
- Updated the `get_response` function signature to accept `ccd_temperature` as an Astropy Quantity.
- Modified the function to handle `ccd_temperature` inputs with and without units, converting them to degrees Celsius.
- Updated the docstring of the `get_response` function to reflect the new parameter type and units requirement.
Copy link
Contributor

Choose a reason for hiding this comment

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

This changelog is too verbose.

@Abinash-bit
Copy link
Contributor Author

In the last 2 commits 4 checks are failing and most of the tests are skipped , how can we proceed?

@nabobalis
Copy link
Contributor

nabobalis commented Dec 2, 2024

In the last 2 commits 4 checks are failing and most of the tests are skipped , how can we proceed?

We check why they are failing and address that problem.

The error is

../../.tox/py312/lib/python3.12/site-packages/sunkit_instruments/suvi/__init__.py:2: in <module>
    from .suvi import *  # NOQA
../../.tox/py312/lib/python3.12/site-packages/sunkit_instruments/suvi/suvi.py:8: in <module>
    from astropy.utils.decorators import quantity_input
E   ImportError: cannot import name 'quantity_input' from 'astropy.utils.decorators' (/home/runner/work/sunkit-instruments/sunkit-instruments/.tox/py312/lib/python3.12/site-packages/astropy/utils/decorators.py)

I would recommend checking the failed logs more often or at least running the unit test suite locally before you push changes.

@Abinash-bit
Copy link
Contributor Author

I think we are left with test_suvi.py and the data files that is L1B_NC and L1B_FITS.

@nabobalis
Copy link
Contributor

I think we are left with test_suvi.py and the data files that is L1B_NC and L1B_FITS.

You mean adding more tests?

@@ -23,7 +23,6 @@

PATH_TO_FILES = Path(__file__).parent / "data"


Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this

@@ -46,7 +45,6 @@ def _despike(image, dqf_mask, filter_width):
despiked_image[indices] = image_gaussian_filtered[indices]
return despiked_image


Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this

@@ -78,7 +76,6 @@ def despike_l1b_file(filename, filter_width=7):
despiked_image = _despike(image, dqf_mask, filter_width)
return sunpy.map.Map(despiked_image, header)


Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this

@Abinash-bit
Copy link
Contributor Author

I think we are left with test_suvi.py and the data files that is L1B_NC and L1B_FITS.

You mean adding more tests?

The test file says checks are skipped and it is skipped because the file can not get the L1B_NC and L1B_FITS files may be not sure.

@Abinash-bit
Copy link
Contributor Author

What happened to the unit changes?

Sorry could not get you, I have changed where ever there is a change you have requested.

But you also undid all of the changes which were the point of this pull request?

yes i know , i am sorry, changing again.

Now please suggest any changes.

Comment on lines 8 to 9


Copy link
Contributor

Choose a reason for hiding this comment

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

These lines should be added back.

l1b_nc_response = suvi.get_response(L1B_NC)
assert l1b_nc_response["wavelength_channel"] == 171
assert l1b_nc_response["ccd_temperature"] == ccd_temp_avg
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert l1b_nc_response["ccd_temperature"] == ccd_temp_avg
assert l1b_nc_response["ccd_temperature"] == (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C

@@ -24,15 +24,33 @@ def test_suvi_despiking_nc(L1B_NC):


def test_get_response_nc(L1B_NC):
header, _, _ = suvi.read_suvi(L1B_NC)
ccd_temp_avg = (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ccd_temp_avg = (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C

l1b_fits_response = suvi.get_response(L1B_FITS)
assert l1b_fits_response["wavelength_channel"] == 171
assert l1b_fits_response["ccd_temperature"] == ccd_temperature
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert l1b_fits_response["ccd_temperature"] == ccd_temperature
assert l1b_fits_response["ccd_temperature"] == (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C



def test_get_response_fits(L1B_FITS):
header, _, _ = suvi.read_suvi(L1B_FITS)
ccd_temperature = (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ccd_temperature = (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 * u.deg_C

@nabobalis
Copy link
Contributor

Now please suggest any changes.

I have a few more comments but there are some older ones still left unresolved.

@Abinash-bit
Copy link
Contributor Author

As per the old comments:

  1. You have asked why there is .3. in the changelog file name? which i have commented.
  2. You have asked about quantity decorators , i have added.
  3. The docstring comments are nearly fixed.
  4. Asked about ccd_temp_avg = (header["CCD_TMP1"] + header["CCD_TMP2"]) / 2.0 this line which is fixed by your suggested snippet.

I think the comments are addressed you can check once you get time.

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.

@@ -156,7 +156,8 @@ def get_response(request, spacecraft=16, ccd_temperature=-60.0, exposure_type="l
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
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

suvi.get_response should take units for ccd_temperature
2 participants