From 3fe41f4fc28b5eb101c7f5158ef0913f272001ee Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Tue, 27 Jun 2023 12:14:08 -0500 Subject: [PATCH 01/10] Fixed error in evaluation of multiple angles as true/false (behavior changed in recent astropy?), now checks len()>0 to see if it should be processed. --- stellarphot/visualization/comparison_functions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 3c320208..88ac7b2f 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -9,7 +9,6 @@ from astropy.table import Table from astropy.coordinates import SkyCoord -from astropy import units as u from astropy.nddata import CCDData from astropy import units as u from astropy.coordinates.name_resolve import NameResolveError @@ -188,12 +187,12 @@ def mag_scale(cmag, apass, v_angle, RD_angle, """ high_mag = apass['r_mag'] < cmag + dimmer_dmag low_mag = apass['r_mag'] > cmag - brighter_dmag - if v_angle: + if len(v_angle)>0: good_v_angle = v_angle > 1.0 * u.arcsec else: good_v_angle = True - if RD_angle: + if len(RD_angle)>0: good_RD_angle = RD_angle > 1.0 * u.arcsec else: good_RD_angle = True From 4f76131d5b5a38c453b1cc6cc7ec4f84fda8a780 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Tue, 27 Jun 2023 12:22:11 -0500 Subject: [PATCH 02/10] Made GAIA data server NOT user configured, but rather a constant, in TessTargetFile. --- stellarphot/io/tess.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 83b324b1..1f228689 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -20,6 +20,7 @@ # Makes me want to vomit, but.... DEFAULT_TABLE_LOCATION = "who.the.heck.knows" TOI_TABLE_URL = "https://exofop.ipac.caltech.edu/tess/download_toi.php?output=csv" +GAIA_APERTURE_SERVER = "https://www.astro.louisville.edu/" TIC_regex = re.compile(r"[tT][iI][cC][^\d]?(?P\d+)(?P\.\d\d)?") @@ -406,9 +407,6 @@ class TessTargetFile: within 2.5 arcminutes the TESS target. If not provided, a temporary file will be created. - aperture_server : str, optional - The URL of the aperture server. default: https://www.astro.louisville.edu/ - Attributes ---------- @@ -442,9 +440,9 @@ class TessTargetFile: magnitude : float depth : float file : str = "" - aperture_server : str = "https://www.astro.louisville.edu/" def __post_init__(self): + self.aperture_server = GAIA_APERTURE_SERVER if not self.file: self.file = NamedTemporaryFile() self._path = Path(self.file.name) From 036b4bdd186da5863823c5f3ab0fbfb442e07524 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Tue, 27 Jun 2023 12:45:44 -0500 Subject: [PATCH 03/10] Made overwriting output files a configurable option for ComparisonViewer and fixed astrowidget ImageWidget missing feature (no overwrite on save). --- .../visualization/comparison_functions.py | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 88ac7b2f..34ee3c02 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -7,6 +7,8 @@ import numpy as np +import os + from astropy.table import Table from astropy.coordinates import SkyCoord from astropy.nddata import CCDData @@ -391,6 +393,9 @@ class ComparisonViewer: aperture_output_file : str, optional File to save aperture information to. Defaults to None. + overwrite_outputs: bool, optional + Whether to overwrite existing output files. Defaults to True. + Attributes ---------- @@ -409,6 +414,9 @@ class ComparisonViewer: iw : `ginga.util.grc.RemoteClient` Ginga widget. + overwrite_outputs: bool + Whether to overwrite existing output files. Defaults to True. + target_coord : `astropy.coordinates.SkyCoord` Coordinates of the target. @@ -431,7 +439,8 @@ def __init__(self, dim_mag_limit=17, targets_from_file=None, object_coordinate=None, - aperture_output_file=None): + aperture_output_file=None, + overwrite_outputs=True): self._label_name = 'labels' self._circle_name = 'target circle' @@ -449,6 +458,7 @@ def __init__(self, self.box, self.iw = self._viewer() self.aperture_output_file = aperture_output_file + self.overwrite_outputs = overwrite_outputs if file: self._file_chooser.set_file(file, directory=directory) @@ -563,7 +573,8 @@ def _make_observers(self): def _save_variables_to_file(self, button=None, filename=''): if not filename: filename = 'variables.csv' - self.variables.write(filename) + # Export variables as CSV (overwrite existing file if it exists) + self.variables.write(filename, overwrite=self.overwrite_outputs) def _show_label_button_handler(self, change): value = change['new'] @@ -579,8 +590,8 @@ def _show_label_button_handler(self, change): def _save_aperture_to_file(self, button=None, filename=''): if not filename: filename = self.aperture_output_file - - self.generate_table().write(filename) + # Export aperture file as CSV (overwrite existing file if it exists) + self.generate_table().write(filename, overwrite=self.overwrite_outputs) def _make_control_bar(self): self._show_labels_button = ipw.ToggleButton(description='Click to show labels') @@ -706,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: + os.remove(self._field_name.value) + try: + self.iw.save(self._field_name.value) + except: + print("Error saving full field image.") if self._zoom_name.value: self.tess_field_zoom_view() - self.iw.save(self._zoom_name.value, overwrite=True) + # Remove output file if it exists + if os.path.exists(self._zoom_name.value) and self.overwrite_outputs: + os.remove(self._zoom_name.value) + try: + self.iw.save(self._zoom_name.value) + except: + print("Error saving zoomed in full field image.") def generate_table(self): """ From ddba6d1cbfad10a2c00dc2978ef08e8324ec3c51 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 28 Jun 2023 15:41:59 -0500 Subject: [PATCH 04/10] Switched ComparisonViewer overwrites to use Pathlib (since already imported and more modern). --- stellarphot/visualization/comparison_functions.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 34ee3c02..c7dd24cc 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -7,8 +7,6 @@ import numpy as np -import os - from astropy.table import Table from astropy.coordinates import SkyCoord from astropy.nddata import CCDData @@ -718,8 +716,8 @@ def save_tess_files(self, button=None): if self._field_name.value: self.tess_field_view() # Remove output file if it exists - if os.path.exists(self._field_name.value) and self.overwrite_outputs: - os.remove(self._field_name.value) + if Path(self._field_name.value).exists() and self.overwrite_outputs: + Path(self._field_name.value).unlink() try: self.iw.save(self._field_name.value) except: @@ -728,8 +726,8 @@ def save_tess_files(self, button=None): if self._zoom_name.value: self.tess_field_zoom_view() # Remove output file if it exists - if os.path.exists(self._zoom_name.value) and self.overwrite_outputs: - os.remove(self._zoom_name.value) + if Path(self._zoom_name.value).exists() and self.overwrite_outputs: + Path(self._zoom_name.value).unlink() try: self.iw.save(self._zoom_name.value) except: From a2971aa08ce2cf5f2917e7470c53664cfb5a2aa5 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 28 Jun 2023 16:33:00 -0500 Subject: [PATCH 05/10] Added specific error to catch to try..except.. --- .../visualization/comparison_functions.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index c7dd24cc..d6b3fda2 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -572,7 +572,11 @@ def _save_variables_to_file(self, button=None, filename=''): if not filename: filename = 'variables.csv' # Export variables as CSV (overwrite existing file if it exists) - self.variables.write(filename, overwrite=self.overwrite_outputs) + try: + self.variables.write(filename, overwrite=self.overwrite_outputs) + except OSError: + print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten.") + def _show_label_button_handler(self, change): value = change['new'] @@ -589,7 +593,10 @@ def _save_aperture_to_file(self, button=None, filename=''): if not filename: filename = self.aperture_output_file # Export aperture file as CSV (overwrite existing file if it exists) - self.generate_table().write(filename, overwrite=self.overwrite_outputs) + try: + self.generate_table().write(filename, overwrite=self.overwrite_outputs) + except OSError: + print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten.") def _make_control_bar(self): self._show_labels_button = ipw.ToggleButton(description='Click to show labels') @@ -720,8 +727,8 @@ def save_tess_files(self, button=None): Path(self._field_name.value).unlink() try: self.iw.save(self._field_name.value) - except: - print("Error saving full field image.") + except OSError: + print(f"ERROR: Can't save full field image, likely because existing file ({self._field_name.value}) can not be overwritten.") if self._zoom_name.value: self.tess_field_zoom_view() @@ -730,8 +737,8 @@ def save_tess_files(self, button=None): Path(self._zoom_name.value).unlink() try: self.iw.save(self._zoom_name.value) - except: - print("Error saving zoomed in full field image.") + except OSError: + print(f"ERROR: Can't save zoomed image, likely because existing file ({self._zoom_name.value}) can not be overwritten.") def generate_table(self): """ From 826cecda163fd15c3df064fa31d859429679fa5f Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 28 Jun 2023 16:37:35 -0500 Subject: [PATCH 06/10] Made error message returned clearer. --- stellarphot/visualization/comparison_functions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index d6b3fda2..6af4350f 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -575,7 +575,7 @@ def _save_variables_to_file(self, button=None, filename=''): try: self.variables.write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten.") + print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") def _show_label_button_handler(self, change): @@ -596,7 +596,7 @@ def _save_aperture_to_file(self, button=None, filename=''): try: self.generate_table().write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten.") + print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") def _make_control_bar(self): self._show_labels_button = ipw.ToggleButton(description='Click to show labels') @@ -728,7 +728,7 @@ def save_tess_files(self, button=None): try: self.iw.save(self._field_name.value) except OSError: - print(f"ERROR: Can't save full field image, likely because existing file ({self._field_name.value}) can not be overwritten.") + print(f"ERROR: Can't save full field image, likely because existing file ({self._field_name.value}) can not be overwritten, set overwrite_outputs=True to address this.") if self._zoom_name.value: self.tess_field_zoom_view() @@ -738,7 +738,7 @@ def save_tess_files(self, button=None): try: self.iw.save(self._zoom_name.value) except OSError: - print(f"ERROR: Can't save zoomed image, likely because existing file ({self._zoom_name.value}) can not be overwritten.") + print(f"ERROR: Can't save zoomed image, likely because existing file ({self._zoom_name.value}) can not be overwritten, set overwrite_outputs=True to address this.") def generate_table(self): """ From d2795c3befd99d10a618ca5c9ca65aaf1efb55c2 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 28 Jun 2023 16:39:47 -0500 Subject: [PATCH 07/10] Another tweak to error messages. --- stellarphot/visualization/comparison_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 6af4350f..4b5d8e09 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -596,7 +596,7 @@ def _save_aperture_to_file(self, button=None, filename=''): try: self.generate_table().write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") + print(f"ERROR: Can't save aperatures to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") def _make_control_bar(self): self._show_labels_button = ipw.ToggleButton(description='Click to show labels') From 31d29433e9948fd7a55be5b3bca630889ba76ced Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 28 Jun 2023 16:40:18 -0500 Subject: [PATCH 08/10] Stupid typo. --- stellarphot/visualization/comparison_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 4b5d8e09..1bbf1327 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -596,7 +596,7 @@ def _save_aperture_to_file(self, button=None, filename=''): try: self.generate_table().write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save aperatures to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") + print(f"ERROR: Can't save apertures to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") def _make_control_bar(self): self._show_labels_button = ipw.ToggleButton(description='Click to show labels') From 3932ae8146bfa4447ab957290cf44e8bee074eba Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 28 Jun 2023 16:41:19 -0500 Subject: [PATCH 09/10] Grammar fix. --- stellarphot/visualization/comparison_functions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 1bbf1327..14a10261 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -575,7 +575,7 @@ def _save_variables_to_file(self, button=None, filename=''): try: self.variables.write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") + print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten. Set overwrite_outputs=True to address this.") def _show_label_button_handler(self, change): @@ -596,7 +596,7 @@ def _save_aperture_to_file(self, button=None, filename=''): try: self.generate_table().write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save apertures to file, likely because existing file ({filename}) can not be overwritten, set overwrite_outputs=True to address this.") + print(f"ERROR: Can't save apertures to file, likely because existing file ({filename}) can not be overwritten. Set overwrite_outputs=True to address this.") def _make_control_bar(self): self._show_labels_button = ipw.ToggleButton(description='Click to show labels') @@ -728,7 +728,7 @@ def save_tess_files(self, button=None): try: self.iw.save(self._field_name.value) except OSError: - print(f"ERROR: Can't save full field image, likely because existing file ({self._field_name.value}) can not be overwritten, set overwrite_outputs=True to address this.") + print(f"ERROR: Can't save full field image, likely because existing file ({self._field_name.value}) can not be overwritten. Set overwrite_outputs=True to address this.") if self._zoom_name.value: self.tess_field_zoom_view() @@ -738,7 +738,7 @@ def save_tess_files(self, button=None): try: self.iw.save(self._zoom_name.value) except OSError: - print(f"ERROR: Can't save zoomed image, likely because existing file ({self._zoom_name.value}) can not be overwritten, set overwrite_outputs=True to address this.") + print(f"ERROR: Can't save zoomed image, likely because existing file ({self._zoom_name.value}) can not be overwritten. Set overwrite_outputs=True to address this.") def generate_table(self): """ From 44a4ed45e53d57c9f5b5b1755ab7bb4a2e0ccf00 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 28 Jun 2023 17:17:39 -0500 Subject: [PATCH 10/10] Fixed to raise OSError instead of printing a message. --- stellarphot/visualization/comparison_functions.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 14a10261..553490a7 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -575,8 +575,7 @@ def _save_variables_to_file(self, button=None, filename=''): try: self.variables.write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save variables to file, likely because existing file ({filename}) can not be overwritten. Set overwrite_outputs=True to address this.") - + raise OSError(f"Existing file ({filename}) can not be overwritten. Set overwrite_outputs=True to address this.") def _show_label_button_handler(self, change): value = change['new'] @@ -596,7 +595,7 @@ def _save_aperture_to_file(self, button=None, filename=''): try: self.generate_table().write(filename, overwrite=self.overwrite_outputs) except OSError: - print(f"ERROR: Can't save apertures to file, likely because existing file ({filename}) can not be overwritten. Set overwrite_outputs=True to address this.") + raise OSError(f"Existing file ({filename}) can not be overwritten. Set overwrite_outputs=True to address this.") def _make_control_bar(self): self._show_labels_button = ipw.ToggleButton(description='Click to show labels') @@ -728,7 +727,7 @@ def save_tess_files(self, button=None): try: self.iw.save(self._field_name.value) except OSError: - print(f"ERROR: Can't save full field image, likely because existing file ({self._field_name.value}) can not be overwritten. Set overwrite_outputs=True to address this.") + raise OSError(f"Existing file ({self._field_name.value}) can not be overwritten. Set overwrite_outputs=True to address this.") if self._zoom_name.value: self.tess_field_zoom_view() @@ -738,7 +737,7 @@ def save_tess_files(self, button=None): try: self.iw.save(self._zoom_name.value) except OSError: - print(f"ERROR: Can't save zoomed image, likely because existing file ({self._zoom_name.value}) can not be overwritten. Set overwrite_outputs=True to address this.") + raise OSError(f"Existing file ({self._zoom_name.value}) can not be overwritten. Set overwrite_outputs=True to address this.") def generate_table(self): """