Skip to content

Commit

Permalink
Merge pull request #108 from JuanCab/Fixes_for_Modern_Astropy
Browse files Browse the repository at this point in the history
Fixes to ComparisonViewer for release version of ImageWidget
  • Loading branch information
mwcraig authored Jun 29, 2023
2 parents 15daf7d + 44a4ed4 commit cc11354
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
6 changes: 2 additions & 4 deletions stellarphot/io/tess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<star>\d+)(?P<planet>\.\d\d)?")


Expand Down Expand Up @@ -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
----------
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 35 additions & 9 deletions stellarphot/visualization/comparison_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -392,6 +391,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
----------
Expand All @@ -410,6 +412,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.
Expand All @@ -432,7 +437,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'
Expand All @@ -450,6 +456,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)
Expand Down Expand Up @@ -564,7 +571,11 @@ 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)
try:
self.variables.write(filename, overwrite=self.overwrite_outputs)
except OSError:
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']
Expand All @@ -580,8 +591,11 @@ 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)
try:
self.generate_table().write(filename, overwrite=self.overwrite_outputs)
except OSError:
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')
Expand Down Expand Up @@ -707,11 +721,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 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 OSError:
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()
self.iw.save(self._zoom_name.value, overwrite=True)
# Remove output file if it exists
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 OSError:
raise OSError(f"Existing file ({self._zoom_name.value}) can not be overwritten. Set overwrite_outputs=True to address this.")

def generate_table(self):
"""
Expand Down

0 comments on commit cc11354

Please sign in to comment.