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

Fixes to ComparisonViewer for release version of ImageWidget #108

Merged
merged 12 commits into from
Jun 29, 2023

Conversation

JuanCab
Copy link
Contributor

@JuanCab JuanCab commented Jun 27, 2023

Apparently the release version of astrowidgets does NOT support overwrite as an option to saving an ImageWidget, I implemented the same functionality via the os package. I also implemented an implementation-wide parameter to allow overwriting on all output files.

Also fixed an issue where if v_angle: was triggering an exception as ambiguous (I suspect this was a new behavior added in a recent version of astropy), instead of having v_angle evaluate as true is not empty. I replaced it with a check of if len(v_angle): which evaluates the desired way.

I also went into the code for retrieving GAIA stars and made the server a constant instead of a parameter to be passed in (it is still a public attribute and can be seen).

JuanCab added 3 commits June 27, 2023 12:14
…changed in recent astropy?), now checks len()>0 to see if it should be processed.
…wer and fixed astrowidget ImageWidget missing feature (no overwrite on save).
Copy link
Contributor

@mwcraig mwcraig left a comment

Choose a reason for hiding this comment

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

A couple really minor PEP8 changes and one other change I'm happy to implement if you want.

@@ -707,11 +717,23 @@ def save_tess_files(self, button=None):
"""
if self._field_name.value:
self.tess_field_view()
self.iw.save(self._field_name.value, overwrite=True)
# Remove output file if it exists
if os.path.exists(self._field_name.value) and self.overwrite_outputs:
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to switch this to pathlib instead. I can do that later in a separate PR if you prefer,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll get this addressed shortly.

self.iw.save(self._field_name.value, overwrite=True)
# Remove output file if it exists
if os.path.exists(self._field_name.value) and self.overwrite_outputs:
os.remove(self._field_name.value)
Copy link
Contributor

Choose a reason for hiding this comment

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

pathlib can also do the remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll get this addressed shortly.

stellarphot/visualization/comparison_functions.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

Still need to pathlib things, but close.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make the GAIA aperture server hardcoded. Seemed to make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed redundant import, fixed if v_angle: to not evaluate as ambiguous in current astropy, added a parameter to allow overwriting of all output files by ComparisonViewer.

@@ -707,11 +717,23 @@ def save_tess_files(self, button=None):
"""
if self._field_name.value:
self.tess_field_view()
self.iw.save(self._field_name.value, overwrite=True)
# Remove output file if it exists
if os.path.exists(self._field_name.value) and self.overwrite_outputs:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll get this addressed shortly.

self.iw.save(self._field_name.value, overwrite=True)
# Remove output file if it exists
if os.path.exists(self._field_name.value) and self.overwrite_outputs:
os.remove(self._field_name.value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll get this addressed shortly.

stellarphot/visualization/comparison_functions.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

I have made the switch from os to pathlib and checked the new code by running comparison viewer and triggering the overwrite situation. It is working. pytest cleared it as well.

Copy link
Contributor

@mwcraig mwcraig left a comment

Choose a reason for hiding this comment

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

Apparently I'm a little fussy today -- what do you think about removing the try/except?

Path(self._field_name.value).unlink()
try:
self.iw.save(self._field_name.value)
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually it is better to not use a bare except, I think, in case you accidentally capture an error message that is really a bug. I think we could get away with no try/except here, anticipating that if an error is raised it will probably be for something real, and should be reported to the user with the exception details/traceback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh crap, I forgot to capture the specific error. I ended up wrapping all the file creation calls that could fail due to attempting to overwrite a file without permission with a try..except OSError. That should be specific enough. I notice the errors still show up on the Jupyterlab log page, so may not really be much easier for users.

Copy link
Contributor Author

@JuanCab JuanCab left a comment

Choose a reason for hiding this comment

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

Now raises an OSError returning a custom message if it attempts to overwrite a file without permission.

@mwcraig mwcraig merged commit cc11354 into feder-observatory:main Jun 29, 2023
@JuanCab JuanCab deleted the Fixes_for_Modern_Astropy branch June 29, 2023 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants