Skip to content

Commit

Permalink
Merge pull request #130 from JuanCab/gui_reorg
Browse files Browse the repository at this point in the history
Initial reorganization of code
  • Loading branch information
mwcraig authored Jul 15, 2023
2 parents f14fb05 + f365318 commit 9279bb8
Show file tree
Hide file tree
Showing 38 changed files with 293 additions and 266 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ New Features

Other Changes and Additions
^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ Major reorganizaiton of code including moving functions to new modules. [#130]


Bug Fixes
^^^^^^^^^
Expand Down
4 changes: 1 addition & 3 deletions stellarphot/differential_photometry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
from .magnitude_transforms import *
from .catalog_search import *
from .vsx_mags import *
from .aij_rel_fluxes import *
from .vsx_mags import *
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from .multi_night_plots import *
from .aij_plots import *
from .comparison_functions import *
from .fits_opener import *
from .comparison_functions import *
from .photometry_widget_functions import *
from .seeing_profile_functions import *
from .transit_plots import *
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import functools
from pathlib import Path

import pandas

import ipywidgets as ipw

import numpy as np
Expand All @@ -20,227 +18,18 @@
from astrowidgets.ginga import ImageWidget

from stellarphot.differential_photometry import *
from stellarphot.io import TessSubmission, TOI, TessTargetFile
from stellarphot.photometry import *
from stellarphot.visualization.seeing_profile_functions import set_keybindings
from stellarphot.visualization.fits_opener import FitsOpener
from stellarphot.io import TessSubmission, TOI, TessTargetFile
from stellarphot.gui_tools.seeing_profile_functions import set_keybindings
from stellarphot.gui_tools.fits_opener import FitsOpener
from stellarphot.utils.comparison_utils import read_file, set_up, crossmatch_APASS2VSX, mag_scale, in_field


__all__ = ['read_file', 'set_up', 'crossmatch_APASS2VSX', 'mag_scale',
'in_field', 'make_markers', 'wrap', 'ComparisonViewer']
__all__ = ['make_markers', 'wrap', 'ComparisonViewer']

DESC_STYLE = {"description_width": "initial"}


def read_file(radec_file):
"""
Read an AIJ radec file with target and/or comparison positions
Parameters
----------
radec_file : str
Name of the file
Returns
-------
`astropy.table.Table`
Table with target information, including a
`astropy.coordinates.SkyCoord` column.
"""
df = pandas.read_csv(radec_file, names=['RA', 'Dec', 'a', 'b', 'Mag'])
target_table = Table.from_pandas(df)
ra = target_table['RA']
dec = target_table['Dec']
target_table['coords'] = SkyCoord(ra=ra, dec=dec, unit=(u.hour, u.degree))
return target_table


def set_up(sample_image_for_finding_stars, directory_with_images='.'):
"""
Read in sample image and find known variables in the field of view.
Parameters
----------
sample_image_for_finding_stars : str
Name or URL of a FITS image of the field of view.
directory_with_images : str, optional
Folder in which the image is located. Ignored if the sample image
is a URL.
Returns
-------
ccd: `astropy.nddata.CCDData`
Sample image.
vsx: `astropy.table.Table`
Table with known variables in the field of view.
"""
if sample_image_for_finding_stars.startswith('http'):
path = sample_image_for_finding_stars
else:
path = Path(directory_with_images) / sample_image_for_finding_stars

ccd = CCDData.read(path)
try:
vsx = find_known_variables(ccd)
except RuntimeError:
vsx = []
else:
ra = vsx['RAJ2000']
dec = vsx['DEJ2000']
vsx['coords'] = SkyCoord(ra=ra, dec=dec, unit=(u.hour, u.degree))

return ccd, vsx


def crossmatch_APASS2VSX(CCD, RD, vsx):
"""
Find APASS stars in FOV and matches APASS stars to VSX and APASS to input targets.
Parameters
----------
CCD : `astropy.nddata.CCDData`
Sample image.
RD : `astropy.table.Table`
Table with target information, including a
`astropy.coordinates.SkyCoord` column.
vsx : `astropy.table.Table`
Table with known variables in the field of view.
Returns
-------
apass : `astropy.table.Table`
Table with APASS stars in the field of view.
v_angle : `astropy.units.Quantity`
Angular separation between APASS stars and VSX stars.
RD_angle : `astropy.units.Quantity`
Angular separation between APASS stars and input targets.
"""
apass, apass_in_bright = find_apass_stars(CCD)
ra = apass['RAJ2000']
dec = apass['DEJ2000']
apass['coords'] = SkyCoord(ra=ra, dec=dec, unit=(u.hour, u.degree))
apass_coord = apass['coords']

if vsx:
v_index, v_angle, v_dist = \
apass_coord.match_to_catalog_sky(vsx['coords'])
else:
v_angle = []

if RD:
RD_index, RD_angle, RD_dist = \
apass_coord.match_to_catalog_sky(RD['coords'])
else:
RD_angle = []

return apass, v_angle, RD_angle


def mag_scale(cmag, apass, v_angle, RD_angle,
brighter_dmag=0.44, dimmer_dmag=0.75):
"""
Select comparison stars that are 1) not close the VSX stars or to other
target stars and 2) fall within a particular magnitude range.
Parameters
----------
cmag : float
Magnitude of the target star.
apass : `astropy.table.Table`
Table with APASS stars in the field of view.
v_angle : `astropy.units.Quantity`
Angular separation between APASS stars and VSX stars.
RD_angle : `astropy.units.Quantity`
Angular separation between APASS stars and input targets.
brighter_dmag : float, optional
Maximum difference in magnitude between the target and comparison stars.
dimmer_dmag : float, optional
Minimum difference in magnitude between the target and comparison stars.
Returns
-------
apass_good_coord : `astropy.coordinates.SkyCoord`
Coordinates of the comparison stars.
good_stars : `astropy.table.Table`
Table with the comparison stars.
"""
high_mag = apass['r_mag'] < cmag + dimmer_dmag
low_mag = apass['r_mag'] > cmag - brighter_dmag
if len(v_angle)>0:
good_v_angle = v_angle > 1.0 * u.arcsec
else:
good_v_angle = True

if len(RD_angle)>0:
good_RD_angle = RD_angle > 1.0 * u.arcsec
else:
good_RD_angle = True

good_stars = high_mag & low_mag & good_RD_angle & good_v_angle
good_apass = apass[good_stars]
apass_good_coord = good_apass['coords']
return apass_good_coord, good_stars


def in_field(apass_good_coord, ccd, apass, good_stars):
"""
Return APASS stars in the field of view.
Parameters
----------
apass_good_coord : `astropy.coordinates.SkyCoord`
Coordinates of the comparison stars.
ccd : `astropy.nddata.CCDData`
Sample image.
apass : `astropy.table.Table`
Table with APASS stars in the field of view.
good_stars : `astropy.table.Table`
Table with the comparison stars.
Returns
-------
ent : `astropy.table.Table`
Table with APASS stars in the field of view.
"""
apassx, apassy = ccd.wcs.all_world2pix(
apass_good_coord.ra, apass_good_coord.dec, 0)
ccdx, ccdy = ccd.shape

xin = (apassx < ccdx) & (0 < apassx)
yin = (apassy < ccdy) & (0 < apassy)
xy_in = xin & yin
apass_good_coord[xy_in]
nt = apass[good_stars]
ent = nt[xy_in]
return ent


def make_markers(iw, ccd, RD, vsx, ent, name_or_coord=None):
"""
Add markers for APASS, TESS targets, VSX. Also center on object/coordinate.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import matplotlib.pyplot as plt

from stellarphot.io import TessSubmission
from stellarphot.visualization import seeing_plot
from stellarphot.visualization.fits_opener import FitsOpener
from stellarphot.gui_tools.fits_opener import FitsOpener
from stellarphot.plotting import seeing_plot

__all__ = ['set_keybindings', 'find_center', 'radial_profile',
'RadialProfile', 'box', 'SeeingProfileWidget']
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from astropy.table import Table
from astrowidgets import ImageWidget

from stellarphot.visualization import seeing_profile_functions as spf
from stellarphot.gui_tools import seeing_profile_functions as spf

# Make a few round stars
STARS = Table(dict(amplitude=[1000, 200, 300],
Expand Down
2 changes: 1 addition & 1 deletion stellarphot/io/tess.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,6 @@ def _retrieve_target_file(self):


def _build_table(self):
from stellarphot.visualization.comparison_functions import read_file
from stellarphot.utils.comparison_utils import read_file

self.table = read_file(self._path)
6 changes: 3 additions & 3 deletions stellarphot/notebooks/comp-star-plots.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": false
},
Expand All @@ -18,7 +18,7 @@
"\n",
"from stellarphot.io import parse_aij_table\n",
"\n",
"from stellarphot.visualization import multi_night\n",
"from stellarphot.plotting import multi_night\n",
"\n",
"from astropy.table import Table, Column"
]
Expand Down Expand Up @@ -239,7 +239,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
14 changes: 8 additions & 6 deletions stellarphot/notebooks/comp-stars-template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -39,11 +39,13 @@
"from astropy.table import Table\n",
"from astropy.coordinates import SkyCoord\n",
"\n",
"from stellarphot.visualization.comparison_functions import (\n",
" read_file, set_up, crossmatch_APASS2VSX, mag_scale, in_field, wrap, make_markers,\n",
" viewer\n",
"from stellarphot.utils.comparison_utils import (\n",
" read_file, set_up, crossmatch_APASS2VSX, in_field, mag_scale\n",
")\n",
"from stellarphot.gui_tools.comparison_functions import (\n",
" wrap, make_markers\n",
")\n",
"from stellarphot.visualization.seeing_profile_functions import set_keybindings"
"from stellarphot.gui_tools.seeing_profile_functions import set_keybindings"
]
},
{
Expand Down Expand Up @@ -324,7 +326,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 9279bb8

Please sign in to comment.