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

Add a review widget #371

Merged
merged 22 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3f86e09
Draft of tests for ReviewSettings
mwcraig Jun 13, 2024
e77feeb
Refactor title decoration and add draft review widget
mwcraig Jun 13, 2024
3a154f8
Refactor ChooseOrMakeNew and badges
mwcraig Jun 26, 2024
4061ae3
Update tests to match updated classes
mwcraig Jun 26, 2024
55bf455
Improve test coverage in ReviewSettings
mwcraig Jun 27, 2024
5a377b9
Fix logic in handling confirmation logic and test
mwcraig Jun 27, 2024
b949e09
Fix ruff command in tox.ini
mwcraig Jun 28, 2024
6f66ad5
Test for and fix a case where badges were not set properly
mwcraig Jun 28, 2024
6cb0b9a
Allow full settings to be updated from partial
mwcraig Jun 29, 2024
a07792e
Fix saving and tab status for settings with default values
mwcraig Jun 29, 2024
3e78c6c
Initial draft of review notebooks
mwcraig Jul 1, 2024
97ebbf4
Refactor setting FileChooser filename
mwcraig Jul 1, 2024
18bb921
Update logic when tab is selected
mwcraig Jul 1, 2024
e716fa7
Use a temporary settings directory in tests
mwcraig Jul 1, 2024
88a8668
Add new notebooks to jupyterlab launcher
mwcraig Jul 1, 2024
082f46f
Temporarily fix linting issue
mwcraig Jul 1, 2024
fe1fd5f
Ignore a photutils warning for now
mwcraig Jul 1, 2024
a631eb3
Update app launcher configuration
mwcraig Jul 3, 2024
d350c98
Apply suggestions from code review by @JuanCab
mwcraig Jul 15, 2024
0b20545
Clarify intent of test steps and remove cruft
mwcraig Jul 15, 2024
09e2fad
Address additional review comments
mwcraig Jul 15, 2024
4867a3b
Apply suggestions from code review
mwcraig Jul 16, 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
20 changes: 14 additions & 6 deletions .jp_app_launcher_stellarphot.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
- title: Saveable settings for testing
- title: 1 - Saveable settings
description: Settings for camera, observatory and passbands
source: ../stellarphot/saveable-settings.ipynb
source: ../stellarphot/1-initial-settings.ipynb
icon: ../stellarphot/stellarphot-logo.svg
cwd: not_used
type: notebook
catalog: Stellarphot settings
catalog: Stellarphot photometry

- title: Seeing profile
- title: 2 - Seeing profile
description: Choose aperture settings
source: ../stellarphot/photometry/01-viewer-seeing-template.ipynb
icon: ../stellarphot/stellarphot-logo.svg
cwd: not_used
type: notebook
catalog: Stellarphot photometry

- title: Comparison stars
- title: 3 - Comparison stars
description: Choose comparison stars
source: ../stellarphot/photometry/02-comp-star-plotter-template.ipynb
icon: ../stellarphot/stellarphot-logo.svg
cwd: not_used
type: notebook
catalog: Stellarphot photometry

- title: 4 - Review settings
description: Choose comparison stars
source: ../stellarphot/photometry/02-viewer-comparison-stars-template.ipynb
source: ../stellarphot/4-final-review-of-settings.ipynb
icon: ../stellarphot/stellarphot-logo.svg
cwd: not_used
type: notebook
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies = [
"astroquery",
"astrowidgets",
"bottleneck",
"camel-converter",
mwcraig marked this conversation as resolved.
Show resolved Hide resolved
"ccdproc",
"ginga",
"ipyautoui >=0.7.15",
Expand Down Expand Up @@ -125,6 +126,8 @@ select = [
"__init__.py" = ["E402", "F403"]
# Ignore F405 (variable may be from star imports) in docs/conf.py
"docs/conf.py" = ["F405"]
# Ignore F811 (redefinition of unused) in core for the moment
"core.py" = ["F811"]

[tool.codespell]
skip = '*.svg'
Expand Down Expand Up @@ -173,4 +176,6 @@ filterwarnings = [
'ignore:Deprecated in traitlets 4.1, use the instance:DeprecationWarning',
# Some WCS headers are issuing warnings
'ignore:RADECSYS=:',
# photutils changed the name of a function again
'ignore:The make_gaussian_sources_image function is deprecated',
]
32 changes: 5 additions & 27 deletions stellarphot/gui_tools/comparison_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,16 @@ def __init__(
self.target_coord = object_coordinate
self.observatory = observatory

# This function defines several attributes in addition to returning the box and
# image viewer. You should take a look at it to see what it does.
self.box, self.iw = self._viewer()

self.photometry_settings = PhotometryWorkingDirSettings()

if photom_apertures_file is not None:
# Set the source location file name to the name passed in
self._set_source_location_file_to_value(photom_apertures_file)
original_settings = self.source_locations.value.copy()
mwcraig marked this conversation as resolved.
Show resolved Hide resolved
original_settings["source_list_file"] = photom_apertures_file
self.source_locations.value = original_settings

self.overwrite_outputs = overwrite_outputs

Expand Down Expand Up @@ -469,30 +472,6 @@ def save(self):
# Update the save box title to reflect the save
self.source_and_title.decorate_title()

def _set_source_location_file_to_value(self, name=None):
# Right now the source location file name will not be set to the default name
# properly because of a bug in ipyautoui, so we set it manually here.
# Easier once/if https://github.com/maxfordham/ipyautoui/pull/323 is merged
# and released. Then we can just set the value of the widget directly like this:
#
# self.source_locations.value = {'source_list_file': name, ...rest of settings}
file_chooser = self.source_locations.di_widgets["source_list_file"]
if name is None:
# Use the default name
name = self.source_locations.model.model_fields["source_list_file"].default
# Make sure ipyautoui knows the value has changed
file_chooser.value = name

# Set the value to what we actually want
file_chooser.reset(".", name)
file_chooser._apply_selection()

# Because we have updated the value outside of ipyautoui, also force an update
# of the widget value.
current_value = self.source_locations.value.copy()
current_value["source_list_file"] = file_chooser.value
self.source_locations.value = current_value

def _viewer(self):
header = ipw.HTML(
value="""
Expand Down Expand Up @@ -529,7 +508,6 @@ def _viewer(self):
SourceLocationSettings, max_field_width="75px"
)

self._set_source_location_file_to_value()
self.source_and_title = SettingWithTitle(
"Source location settings", self.source_locations
)
Expand Down
13 changes: 13 additions & 0 deletions stellarphot/gui_tools/tests/test_seeing_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Observatory,
PhotometryApertures,
PhotometryWorkingDirSettings,
settings_files, # This import is needed for mocking
)
from stellarphot.settings.tests.test_models import (
TEST_CAMERA_VALUES,
Expand Down Expand Up @@ -64,6 +65,18 @@ def test_seeing_profile_object_creation():
assert isinstance(profile_widget.box, ipw.Box)


@pytest.fixture(autouse=True)
def fake_settings_dir(mocker, tmp_path):
# See test_settings_files.py for more information on this fixture.
# It makes a fake settings directory for each test to use.

# stellarphot is added to the name of the directory to make sure we start
# without a stellarphot directory for each test.
mocker.patch.object(
settings_files.PlatformDirs, "user_data_dir", tmp_path / "stellarphot"
)


def test_seeing_profile_properties(tmp_path):
# Here we make a seeing profile then load an image.
profile_widget = spf.SeeingProfileWidget(
Expand Down
72 changes: 72 additions & 0 deletions stellarphot/notebooks/1-initial-settings.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "3a7f0b18-4509-474e-b42e-a69edd22913b",
"metadata": {},
"outputs": [],
"source": [
"from stellarphot.settings import Camera, Observatory, PassbandMap\n",
"from stellarphot.settings.custom_widgets import ReviewSettings"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37494092-bd26-4dcb-a7d9-d587fd79ca45",
"metadata": {},
"outputs": [],
"source": [
"review = ReviewSettings([Camera, Observatory, PassbandMap])"
]
},
{
"cell_type": "markdown",
"id": "f25dc64e-e0b9-4673-b806-ef0e1f53f84c",
"metadata": {},
"source": [
"# Review or make key settings in the widget below "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe341afc-4171-4094-8165-82faa26706b3",
"metadata": {},
"outputs": [],
"source": [
"review"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7c58cd05-afff-4273-8607-69a0e93f4fa4",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
72 changes: 72 additions & 0 deletions stellarphot/notebooks/4-final-review-of-settings.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "3b91d12e-97ae-4d6d-970d-562b6bbfd683",
"metadata": {},
"outputs": [],
"source": [
"from stellarphot.settings import Camera, LoggingSettings, Observatory, PassbandMap, PhotometryApertures, PhotometryOptionalSettings, SourceLocationSettings\n",
"from stellarphot.settings.custom_widgets import ReviewSettings"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d57c16cc-c243-47f3-9747-94d6c6898621",
"metadata": {},
"outputs": [],
"source": [
"review = ReviewSettings([Camera, Observatory, PassbandMap, PhotometryApertures, SourceLocationSettings, PhotometryOptionalSettings, LoggingSettings])"
]
},
{
"cell_type": "markdown",
"id": "36db3d1f-d0d7-413e-ab77-766c6e3d02a1",
"metadata": {},
"source": [
"# Review or make key settings in the widget below "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39491574-cc9f-4d2b-963f-1b175336a16d",
"metadata": {},
"outputs": [],
"source": [
"review"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "629f505c-6fab-4bf9-a30a-130bf668d8ac",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 2 additions & 2 deletions stellarphot/photometry/tests/fake_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(self, noise_dev=1.0, seed=None):
self._sources = Table.read(data_file)
self.mean_noise = self.sources["amplitude"].max() / 100
self.noise_dev = noise_dev
self._stars = make_gaussian_sources_image(self.image_shape, self.sources)
self._stars = make_gaussian_sources_image(tuple(self.image_shape), self.sources)
self._noise = make_noise_image(
self._stars.shape, mean=self.mean_noise, stddev=noise_dev, seed=seed
)
Expand Down Expand Up @@ -194,7 +194,7 @@ def shift_FakeCCDImage(ccd_data, x_shift, y_shift):

# Make image
srcs = make_gaussian_sources_image(
shifted_ccd_data.image_shape, shifted_ccd_data.sources
tuple(shifted_ccd_data.image_shape), shifted_ccd_data.sources
)
background = make_noise_image(
srcs.shape, mean=shifted_ccd_data.mean_noise, stddev=shifted_ccd_data.noise_dev
Expand Down
Loading