From 869af0d0035ddfe42a2e45b8d9c19bc003f7abd2 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 7 Jun 2023 12:41:28 -0500 Subject: [PATCH 01/35] Tweaked gitignore to avoid git archiving files from nova editor subdirectory. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index baa8981a..205d25f5 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ distribute-*.tar.gz # Other .cache +.nova .tox .*.sw[op] *~ From d67a29e871f73276d9eda90f3138a89beecdcc36 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Wed, 7 Jun 2023 14:16:23 -0500 Subject: [PATCH 02/35] Added missing docstrings for analysis, core, and source_detection code. --- CHANGES.rst | 11 +++-- stellarphot/analysis/exotic.py | 18 +++++++++ stellarphot/analysis/transit_fitting.py | 53 ++++++++++++++++++++++++- stellarphot/core.py | 42 +++++++++++++++++++- stellarphot/source_detection.py | 42 ++++++++++++++++++-- 5 files changed, 156 insertions(+), 10 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9b283039..de61be4e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -1.1.5 (2023-05-31) +1.3.9 (Unreleased) ------------------ New Features @@ -6,11 +6,15 @@ New Features Other Changes and Additions ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -+ Most functions are now linked to the documentation (some still need docstrings). [#92] ++ Old and redundant notebooks have been purged and bad references to `glowing-waffles` instead of `stellarphot` [#94] ++ Most functions are now linked to the documentation. [#90] ++ Many functions and classes that had missing documentation have now had docstrings added. Bug Fixes ^^^^^^^^^ -+ Runs without errors on current numpy (1.24.3) and astropy (5.3). + ++ Runs without errors on release version of astrowidgets (0.3.0) [#93] ++ Runs without errors on current numpy (1.24.3) and astropy (5.3). [#92] 1.1.2 (2022-10-18) @@ -19,7 +23,6 @@ Bug Fixes New Features ^^^^^^^^^^^^ - Other Changes and Additions ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/stellarphot/analysis/exotic.py b/stellarphot/analysis/exotic.py index 046e1017..07879ebf 100644 --- a/stellarphot/analysis/exotic.py +++ b/stellarphot/analysis/exotic.py @@ -124,6 +124,24 @@ def check_name(change): def validate_exposure_time(indicator_widget, value_widget): + """ Validates the exposure time input. + + Parameters + ---------- + indicator_widget : MyCheck widget + The widget that indicates to the user whether or not the value is + reasonable. + + value_widget: ipywidget + This widget should be generated by exotic_settings_widget. + + Returns + ------- + function + Function that will set the correct boolean value on the + indicator_widget to indicate if the value of the exposure time + is valid. + """ def check_exposure(change): # Valid Exposure time is greater than zero if change['new'] > 0: diff --git a/stellarphot/analysis/transit_fitting.py b/stellarphot/analysis/transit_fitting.py index c2f8c5ed..1471051c 100644 --- a/stellarphot/analysis/transit_fitting.py +++ b/stellarphot/analysis/transit_fitting.py @@ -33,8 +33,8 @@ class VariableArgsFitter(LevMarLSQFitter): """ - Allow fitting of functions with arbitrary number of positional - parameters. + Least squares fitter that fits functions with arbitrary number of positional parameters. + This is a modified version of the astropy.modeling.fitting.LevMarLSQFitter fitter. """ def __init__(self): super().__init__() @@ -89,6 +89,55 @@ def __call__(self, model, *args, weights=None, class TransitModelFit: + """ A class for handling transit model fits to observed light curves. + + Parameters + ---------- + batman_params : batman.TransitParams + Parameters for the batman transit model. If not provided, the + default parameters will be used. + + Attributes + ---------- + times : array-like + Times at which the light curve is observed. Must be set before + fitting. + + airmass : array-like + Airmass at each time. Must be set before fitting. + + width : array-like + Width of the star in pixels at each time. Must be set before fitting. + + spp : array-like + Sky per pixel at each time. Must be set before fitting. + + data : array-like + Observed fluxes. Must be set before fitting. + + model : astropy.modeling.Model + The model used for fitting. This is a combination of the batman + transit model and any other trends that are included in the fit. + This is set up when the ``setup_model`` method is called. + + weights : array-like + Weights to use for fitting. If not provided, all weights are + set to 1. + + detrend_parameters : set + Set of parameters to detrend by. This is set when the ``airmass``, + ``width``, or ``spp`` attributes are set. If all three are set, + then all three are used for detrending. If ``None`` of them are + set, then no detrending is done. + + BIC : float + Bayesian Information Criterion for the fit. This is calculated + after the fit is performed. + + n_fit_parameters : int + Number of parameters that were fit. This is calculated after the + fit is performed. + """ def __init__(self, batman_params=None): self._batman_params = batman.TransitParams() self._set_default_batman_params() diff --git a/stellarphot/core.py b/stellarphot/core.py index d29854fb..85907ec6 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -4,7 +4,47 @@ class Camera: - """docstring for Camera""" + """ + A class to represent a CCD-based camera. + + Parameters + ---------- + gain : float times u.electron / u.adu, + The gain of the camera in units of electrons per ADU. + read_noise : float times u.electron + The read noise of the camera in units of electrons. + dark_current : float times u.electron / u.second + The dark current of the camera in units of electrons per second. + + Attributes + ---------- + gain : float times u.electron / u.adu, + The gain of the camera in units of electrons per ADU. + read_noise : float times u.electron + The read noise of the camera in units of electrons. + dark_current : float times u.electron / u.second + The dark current of the camera in units of electrons per second. + + Notes + ----- + The gain, read noise, and dark current are all assumed to be constant + across the entire CCD. + + Examples + -------- + >>> from astropy import units as u + >>> from stellarphot import Camera + >>> camera = Camera(gain=1.0 * u.electron / u.adu, + ... read_noise=1.0 * u.electron, + ... dark_current=0.01 * u.electron / u.second) + >>> camera.gain + + >>> camera.read_noise + + >>> camera.dark_current + + + """ def __init__(self, gain=1.0 * u.electron / u.adu, read_noise=1.0 * u.electron, dark_current=0.01 * u.electron / u.second): diff --git a/stellarphot/source_detection.py b/stellarphot/source_detection.py index e1cbd11a..d8443721 100644 --- a/stellarphot/source_detection.py +++ b/stellarphot/source_detection.py @@ -16,12 +16,12 @@ def _fit_2dgaussian(data): """ - Fit a 2d Gaussian to data. + Fit a 2D Gaussian to data. - Written as a replace for functionality that was removed from + Written as a replacement for functionality that was removed from photutils. - Keep this private so we don't have to support it.... + This function will be kept private so we don't have to support it. Copy/pasted from https://github.com/astropy/photutils/pull/1064/files#diff-9e64908ff7ac552845b4831870a749f397d73c681d218267bd9087c7757e6dd4R285 @@ -50,6 +50,42 @@ def compute_fwhm(ccd, sources, fwhm_estimate=5, x_column='xcenter', y_column='ycenter', fit=True, sky_per_pix_avg=0): + """Computes the FWHM in both x and y directions of sources in an image. + + Parameters + ---------- + + ccd : numpy.ndarray + The CCD Image array. + + sources : astropy.table.Table + An astropy table of the positions of sources in the image. + + fwhm_estimate : float, optional + The initial guess for the FWHM of the sources in the image. + + x_column : str, optional + The name of the column in `sources` that contains the x positions + of the sources. + + y_column : str, optional + The name of the column in `sources` that contains the y positions + of the sources. + + fit : bool, optional + If ``True``, fit a 2D Gaussian to each source to estimate its FWHM. + + sky_per_pix_avg : float or array-like of float + Sky background to subtract before centroiding. + + Returns + ------- + + fwhm_x, fwhm_y : array-like of float + The FWHM of each source in the x and y directions. + + """ + fwhm_x = [] fwhm_y = [] for source in sources: From def44dd59245e817888f57ffc15377dd6c6812f2 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 8 Jun 2023 16:02:32 -0500 Subject: [PATCH 03/35] Revised docstrings in analysis package to be more complete (include returned values) --- stellarphot/analysis/exotic.py | 82 ++++++++++++++++++++++++- stellarphot/analysis/transit_fitting.py | 33 +++++++++- 2 files changed, 112 insertions(+), 3 deletions(-) diff --git a/stellarphot/analysis/exotic.py b/stellarphot/analysis/exotic.py index 07879ebf..8b01dcdc 100644 --- a/stellarphot/analysis/exotic.py +++ b/stellarphot/analysis/exotic.py @@ -40,7 +40,21 @@ class MyValid(ipw.Button): """ - A more compact indicator of valid entries. + A class containing a more compact indicator of valid entries based on ipywidgets + buton value. + + Parameters + ---------- + + value : ipywidgets.Button.value + Initial value of the indicator. + + Attributes + ---------- + + value : bool + Current value of the indicator. + """ value = Bool(False, help="Bool value").tag(sync=True) @@ -69,6 +83,13 @@ def get_tic_info(TIC_ID): TIC_ID : int 9 or 10 digit TIC ID number. + + Returns + ------- + + dict + Dictionary of information about the TIC object. + """ catalog_data = Catalogs.query_criteria(catalog="Tic", ID=TIC_ID) return catalog_data @@ -139,7 +160,7 @@ def validate_exposure_time(indicator_widget, value_widget): ------- function Function that will set the correct boolean value on the - indicator_widget to indicate if the value of the exposure time + indicator_widget to indicate if the value of the exposure time is valid. """ def check_exposure(change): @@ -157,6 +178,21 @@ def populate_TIC_boxes(tic_info, value_widget): """ Set the appropriate widget values given information pulled from MAST TIC. + + Parameters + ---------- + + tic_info : dict + Dictionary of information about the TIC object. + + value_widget: ipywidget + This widget should contain a 'candidate' key. + + Returns + ------- + + None + Sets values of planetary parameters of `candidate` in ``value_widget`` in place. """ # Match EXOTIC json keys to columns in the result returned from # astroquery @@ -185,6 +221,21 @@ def populate_TOI_boxes(toi, exotic_widget): """ Set the appropriate widget values given information pulled from MAST TIC. + + Parameters + ---------- + + toi : dict + Dictionary of information about the TIC object. + + exotic_widget: ipywidget + This widget should be generated by exotic_settings_widget. + + Returns + ------- + + None + Sets values of planetary parameters of `candidate` in ``exotic_widget`` in place. """ # Match EXOTIC json keys to columns in the result returned from # astroquery @@ -228,6 +279,17 @@ def populate_TOI_boxes(toi, exotic_widget): def exotic_settings_widget(): """ Generate a widget to enter (and store) settings for exotic. + + Parameters + ---------- + + None + + Returns + ------- + + ipywidget + Widget with settings for EXOTIC. """ # We rely on some global variables: @@ -348,6 +410,11 @@ def set_values_from_json_file(widget, json_file): json_file : str File with settings for the widget. + + Returns + ------- + None + Sets values of parameters of widget in place. """ with open(json_file) as f: input_values = json.load(f) @@ -371,6 +438,13 @@ def get_values_from_widget(exotic_widget, key=None): key : str, either "known" or "candidate", optional Indicates which case to use for EXOTIC. If ``None``, use the ``planet_type`` attribute of the ``exotic_widget``. + + Returns + ------- + + dict + Value of modified template_json[key], where template_json is a global variable. + """ if not key: key = exotic_widget.planet_type.value @@ -396,6 +470,10 @@ def generate_json_file_name(exotic_widget, key=None): Indicates which case to use for EXOTIC. If ``None``, use the ``planet_type`` attribute of the ``exotic_widget``. + Returns + ------- + str + Name of file to save settings to. """ if not key: key = exotic_widget.planet_type.value diff --git a/stellarphot/analysis/transit_fitting.py b/stellarphot/analysis/transit_fitting.py index 1471051c..d6fb2882 100644 --- a/stellarphot/analysis/transit_fitting.py +++ b/stellarphot/analysis/transit_fitting.py @@ -33,7 +33,7 @@ class VariableArgsFitter(LevMarLSQFitter): """ - Least squares fitter that fits functions with arbitrary number of positional parameters. + A callable class that can be used to fit functions with arbitrary number of positional parameters. This is a modified version of the astropy.modeling.fitting.LevMarLSQFitter fitter. """ def __init__(self): @@ -358,12 +358,27 @@ def setup_model(self, t0=0, depth=0, duration=0, duration : float Duration of the transit,in the same units as ``t0`` and ``period``. + period : float Period of the planet. Should be in the same units as ``t0`` and times used for fitting. inclination : float Inclination of the orbit, in degrees. + + airmass_trend : float + Coefficient for a linear trend in airmass. + + width_trend : float + Coefficient for a linear trend in stellar width. + + spp_trend : float + Coefficient for a linear trend in sky per pixel. + + Returns + ------- + None + Sets values for the model parameters. """ self._setup_transit_model() @@ -482,6 +497,22 @@ def model_light_curve(self, at_times=None, detrend_by=None): """ Calculate the light curve corresponding to the model, optionally detrended by one or more parameters. + + Parameters + ---------- + at_times : array-like + Times at which to calculate the model. If not provided, the + times used for fitting will be used. + + detrend_by : str or list of str + Parameter(s) to detrend by. If ``None``, no detrending is + done. If ``'all'``, all parameters that are set will be + used for detrending. + + Returns + ------- + model : array-like + Model light curve. """ zeros = np.zeros_like(self.times) airmass = self.airmass if self.airmass is not None else zeros From bb5089e03a20eafa08e6cb315077216532e6d8b8 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 8 Jun 2023 16:03:08 -0500 Subject: [PATCH 04/35] Revised docstrings for the photometry and visualization packages. --- .../differential_photometry/catalog_search.py | 80 +++++++- .../magnitude_transforms.py | 93 +++++++++- stellarphot/photometry.py | 172 ++++++++++++------ stellarphot/source_detection.py | 21 ++- 4 files changed, 297 insertions(+), 69 deletions(-) diff --git a/stellarphot/differential_photometry/catalog_search.py b/stellarphot/differential_photometry/catalog_search.py index 4cbbf29c..602a75b0 100644 --- a/stellarphot/differential_photometry/catalog_search.py +++ b/stellarphot/differential_photometry/catalog_search.py @@ -60,6 +60,12 @@ def catalog_search(frame_wcs_or_center, shape, desired_catalog, Return the items from catalog that are within the search radius and (optionally) within the field of view of a frame. + This function takes coordinate data from an image and a + catalog name and returns the positions of those stars. + Preconditions:frame_wcs is a WCS object, shape is tuple, list or array of + numerical values, desired_catalog is a string and radius is a numerical + value. + Parameters ---------- @@ -67,13 +73,37 @@ def catalog_search(frame_wcs_or_center, shape, desired_catalog, WCS of the image of interest. shape : tuple of int + Shape of the image of interest. + + desired_catalog : str + Name of the catalog to be searched. + + ra_column : str, optional + Name of the column in the catalog that contains the RA values. + Default is 'RAJ2000'. + + dec_column : str, optional + Name of the column in the catalog that contains the Dec values. + Default is 'DEJ2000'. + + radius : float, optional + Radius, in degrees, around which to search. Default is 0.5. + + clip_by_frame : bool, optional + If ``True``, only return items that are within the field of view + of the frame. Default is ``True``. + + padding : int, optional + Coordinates need to be at least this many pixels in from the edge + of the frame to be considered in the field of view. Default value + is 100. + + Returns + ------- + + astropy.table.Table + Table of catalog information for stars in the field of view. - Description: This function takes coordinate data from an image and a - catalog name and returns the positions of those stars. - Preconditions:frame_wcs is a WCS object, shape is tuple, list or array of - numerical values, desired_catalog is a string and radius is a numerical - value. - Postconditions: """ rad = radius * units.deg if isinstance(frame_wcs_or_center, SkyCoord): @@ -119,6 +149,22 @@ def catalog_clean(catalog, remove_rows_with_mask=True, must satisfy to be kept in the cleaned catalog. The criteria must be simple, beginning with a comparison operator and including a value. See Examples below. + + Returns + ------- + + astropy.table.Table + Table of catalog information for stars in the field of view. + + Examples + -------- + + >>> catalog_clean(catalog, remove_rows_with_mask=True, e_r_mag='<0.1') + >>> catalog_clean(catalog, remove_rows_with_mask=True, e_r_mag='<0.1', + ... e_B-V='>0.1') + >>> catalog_clean(catalog, remove_rows_with_mask=True, e_r_mag='<0.1', + ... e_B-V='>0.1', r_mag='>10') + """ comparisons = { @@ -168,6 +214,21 @@ def find_apass_stars(image_or_center, radius : float, optional Radius, in degrees, around which to search. Not needed if the first argument is an image. + + max_mag_error : float, optional + Maximum error in magnitude to allow. Default is 0.05. + + max_color_error : float, optional + Maximum error in color to allow. Default is 0.1. + + Returns + ------- + + all_apass : `astropy.table.Table` + Table of all APASS stars in the field of view. + + apass_lower_error : `astropy.table.Table` + Table of APASS stars in the field of view with errors lower than the specified values. """ if isinstance(image_or_center, SkyCoord): # Center was passed in, just use it. @@ -217,6 +278,13 @@ def filter_catalog(catalog, **kwd): kwd : key/value pairs, e.g. ``e_r_mag=0.1`` The key must be the name of a column and the value the *upper limit* on the acceptable values. + + Returns + ------- + + numpy.ndarray of bool + One value for each row in the catalog; values are ``True`` if the + row meets the criteria, ``False`` otherwise. """ good_ones = np.ones(len(catalog), dtype='bool') diff --git a/stellarphot/differential_photometry/magnitude_transforms.py b/stellarphot/differential_photometry/magnitude_transforms.py index 1bfcb276..a84b330e 100644 --- a/stellarphot/differential_photometry/magnitude_transforms.py +++ b/stellarphot/differential_photometry/magnitude_transforms.py @@ -13,21 +13,54 @@ __all__ = [ + 'f', 'get_cat', 'opts_to_str', 'calc_residual'. 'filter_transform', 'calculate_transform_coefficients', 'transform_magnitudes', - 'transform_to_catalog' + 'transform_to_catalog', ] def f(X, a, b, c, d, z): + """ + Calculate the calibrated magnitude from the instrumental magnitude and color. + + Parameters + ---------- + X : tuple of numpy.ndarray + The first element is an array of instrumental magnitudes, + the second is an array of colors. + a, b, c, d, z : float + Parameters of the fit. + + Returns + ------- + numpy.ndarray + Array of calibrated magnitudes. + """ mag_inst, color = X return a * mag_inst + b * mag_inst ** 2 + c * color + d * color**2 + z -# TODO: THIS SHOULD ALMOST CERTAINLY BE REPLACED def get_cat(image): + """ Get the APASS catalog entries within 1 degree of first object in + Astropy table 'image'. + + Parameters + ---------- + + image : astropy.table.Table + Table containing the image information. Must have columns + ``RA`` and ``Dec``. + + Returns + ------- + + astropy.table.Table + Table containing the APASS catalog entries within 1 degree of + first object in Astropy table. + """ our_coords = SkyCoord(image['RA'], image['Dec'], unit='degree') # Get catalog via cone search Vizier.ROW_LIMIT = -1 # Set row_limit to have no limit @@ -41,6 +74,20 @@ def get_cat(image): def opts_to_str(opts): + """Convert the options from a fit to a string. + + Parameters + ---------- + + opts : tuple of float + Options from a fit. + + Returns + ------- + + str + String representation of the options. + """ opt_names = ['a', 'b', 'c', 'd', 'z'] names = [] for name, value in zip(opt_names, opts): @@ -49,6 +96,25 @@ def opts_to_str(opts): def calc_residual(new_cal, catalog): + """Calculate the standard deviations of the residuals between + the new calibrated magnitude and the catalog magnitude. + + Parameters + ---------- + + new_cal : numpy.ndarray + New calibrated magnitudes. + + catalog : numpy.ndarray + Catalog magnitudes. + + Returns + ------- + + float + Standard deviation of the residual. + + """ resid = new_cal - catalog return resid.std() @@ -315,7 +381,6 @@ def transform_magnitudes(input_mags, catalog, catalog : astropy Table Table containing reference catalog of magnitudes and colors. - transform_catalog : astropy Table Table containing the reference catalog of magnitudes and colors to use in determining the transform coefficients. Can be the @@ -347,6 +412,21 @@ def transform_magnitudes(input_mags, catalog, gain : float, optional If not ``None``, adjust the instrumental magnitude by -2.5 * log10(gain), i.e. gain correct the magnitude. + + Returns + ------- + + our_cat_mags : astropy Table column + The calculated catalog magnitudes for the stars in ``input_mags``. + + good_match_all : numpy array + Boolean array indicating which stars in ``input_mags`` have a match + in the catalog. + + transforms : namedtuple + The coefficients of the transform. The coefficients are in the order + of ascending power, i.e. the coefficient ``ci`` is the coefficient + of the term ``x**i``. """ catalog_all_coords = SkyCoord(catalog['RAJ2000'], catalog['DEJ2000'], @@ -462,6 +542,13 @@ def transform_to_catalog(observed_mags_grouped, obs_mag_col, obs_filter, verbose: bool optional If ``True``, print additional output. + + Returns + ------- + + astropy.table.Table + Table containing the calibrated magnitudes and the fit parameters. + """ if obs_error_column is None: diff --git a/stellarphot/photometry.py b/stellarphot/photometry.py index 61b758aa..768c4fc7 100644 --- a/stellarphot/photometry.py +++ b/stellarphot/photometry.py @@ -19,7 +19,8 @@ __all__ = ['photutils_stellar_photometry', 'faster_sigma_clip_stats', 'find_too_close', 'clipped_sky_per_pix_stats', - 'add_to_photometry_table', 'photometry_on_directory'] + 'add_to_photometry_table', 'photometry_on_directory', + 'calculate_noise', 'find_times'] def photutils_stellar_photometry(ccd_image, sources, @@ -235,6 +236,13 @@ def clipped_sky_per_pix_stats(data, annulus, sigma=5, iters=5): iters : int, optional Maximum number of sigma clip iterations to perform. Iterations stop automatically if no pixels are rejected. + + Returns + ------- + + avg_sky_per_pix, med_sky_per_pix, std_sky_per_pix : astropy.units.Quantity + Average, median and standard deviation of the sky per pixel. + """ # Get a list of masks from the annuli # Use the 'center' method because then pixels are either in or out. To use @@ -294,6 +302,26 @@ def add_to_photometry_table(phot, ccd, annulus, apertures, fname='', gain : float, optional Gain, in electrons/ADU, of the camera that took the image. The gain is used in calculating the instrumental magnitude. + + bjd_coords : astropy SkyCoord object + Coordinates of the object of interest in the Barycentric Julian Date + frame. If not provided, the BJD column will not be added to the + photometry table. + + observatory_location : str + Name of the observatory where the images were taken. If not provided, + the BJD column will not be added to the photometry table. + + fwhm_by_fit : bool, optional + If ``True``, the FWHM will be calculated by fitting a Gaussian to + the star. If ``False``, the FWHM will be calculated by finding the + second moments of the light distribution. Default is ``True``. + + Returns + ------- + + None + The input table is modified in place. """ phot.rename_column('aperture_sum_0', 'aperture_sum') phot['aperture_sum'].unit = u.adu @@ -428,6 +456,27 @@ def photometry_on_directory(directory_with_images, object_of_interest, dark_current : float Dark current, in electron/sec. Used in the CCD equation to calculate error. + + bjd_coords : astropy SkyCoord object + Coordinates of the object of interest in the Barycentric Julian Date + frame. If not provided, the BJD column will not be added to the + photometry table. + + observatory_location : str + Name of the observatory where the images were taken. If not provided, + the BJD column will not be added to the photometry table. + + fwhm_by_fit : bool, optional + If ``True``, the FWHM will be calculated by fitting a Gaussian to + the star. If ``False``, the FWHM will be calculated by finding the + second order moments of the light distribution. Default is ``True``. + + Returns + ------- + + phot : astropy.table.Table + Table containing the photometry results. + """ ifc = ImageFileCollection(directory_with_images) phots = [] @@ -557,6 +606,62 @@ def calculate_noise(gain=1.0, read_noise=0.0, dark_current_per_sec=0.0, aperture_area=0, annulus_area=0, exposure=0, include_digitization=False): + """Computes the noise in a photometric measurement. + + This function computes the noise (in units of gain) in a photometric measurement using the + revised CCD equation from Collins et al (2017) AJ, 153, 77. The equation is: + + .. math:: + + \sigma = \sqrt{G \cdot F + A \cdot (1 + \frac{A}{B})\cdot [ G\cdot S + D \cdot t + R^2 + (0.289 G)^2]} + + where + :math:`\sigma` is the noise, + :math:`G` is the gain, + :math:`F` is the flux, + :math:`A` is the aperture area in pixels, + :math:`B` is the annulus area in pixels, + :math:`S` is the sky per pixel, + :math:`D` is the dark current per second, + :math:`R` is the read noise, + and :math:`t` is exposure time. + + Note: The :math:`(0.289 G)^2` term is "digitization noise" and is optional. + + Parameters: + ----------- + gain : float, optional + Gain of the CCD. In units of electrons per DN. + + read_noise : float, optional + Read noise of the CCD in electrons. + + dark_current_per_sec : float, optional + Dark current of the CCD in electrons per second. + + flux : float, optional + Flux of the source in electrons. + + sky_per_pix : float, optional + Sky per pixel in electrons. + + aperture_area : int, optional + Area of the aperture in pixels. + + annulus_area : int, optional + Area of the annulus in pixels. + + exposure : int, optional + Exposure time in seconds. + + include_digitization : bool, optional + Whether to include the digitization noise. Defaults to False. + + Returns: + -------- + float + The noise in the photometric measurement. + """ try: no_annulus = (annulus_area == 0).all() @@ -588,8 +693,7 @@ def calculate_noise(gain=1.0, read_noise=0.0, dark_current_per_sec=0.0, return np.sqrt(poisson_source + sky + dark + rn_error + digitization) -def find_times(phot_column, exposure, - ra=331.1170417, dec=81.5659444, +def find_times(phot_column, exposure, ra, dec, latitude=46.86678, longitude=263.54672): """ Returns a numpy array of barycentric Julian date times @@ -603,24 +707,25 @@ def find_times(phot_column, exposure, exposure : float; optional exposure time in seconds - RA : float; optional - Right ascension in degree format, default is for TIC-470127886 + RA : float + Right ascension in degree units - Dec : float; optional - Declination in degree format, default is for TIC-470127886 + Dec : float + Declination in degree units latitude : float; optional - latitude of the observatory, default is for Paul P. Feder Observatory + latitude of the observatory in degrees North, default is for Paul P. Feder Observatory longitude : float; optional - longitude of the observatory, default is for Paul P. Feder Observatory + longitude of the observatory in degree East of Greenwich (0 to 360), default + is for Paul P. Feder Observatory Returns ------- new_time : numpy array - array of barycentric times by Julian date + array of times in barycentric Julian date """ location = EarthLocation(lat=latitude, lon=longitude) @@ -636,49 +741,4 @@ def find_times(phot_column, exposure, new_time = bary_time.jd - return new_time - - -# ra=331.1170417, dec=81.5659444, latitude=46.86678, longitude=263.54672 -def find_bjd_mid_exposure(utc_times, exposure=0, - coords=None, location=None): - """ - Returns a numpy array of barycentric Julian date times - - Parameters - ---------- - - phot_column : `astropy.table.Column` of `astropy.times.Time` or numpy array - numpy array or column of observation dates/times. - - exposure : float; optional - exposure time in seconds - - coords : `astropy.coordinates.SkyCoord` - Ra/Dec of the object to be used for the light travel time - calculation. - - location: `astropy.coordinates.EarthLocation` - Location of the observatory. - - Returns - ------- - - new_time : numpy array - array of barycentric times by Julian date - - """ - location = EarthLocation(lat=latitude, lon=longitude) - ip_peg = SkyCoord(ra=[ra], dec=[dec], unit='degree') - - if coords is None or observatory_location is None: - raise ValueError - times = Time(phot_column, scale='utc', format='isot', location=location) - ltt_bary = times.light_travel_time(coords) - times_tdb = times.tdb - time_barycenter = times_tdb + ltt_bary - - # adjust to midpoint of exposure - bary_time = time_barycenter + exposure * u.second / 2 - - return bary_time.jd + return new_time \ No newline at end of file diff --git a/stellarphot/source_detection.py b/stellarphot/source_detection.py index d8443721..3c3ea520 100644 --- a/stellarphot/source_detection.py +++ b/stellarphot/source_detection.py @@ -25,6 +25,16 @@ def _fit_2dgaussian(data): Copy/pasted from https://github.com/astropy/photutils/pull/1064/files#diff-9e64908ff7ac552845b4831870a749f397d73c681d218267bd9087c7757e6dd4R285 + + Parameters + ---------- + data : array-like + The 2D array of data to fit. + + Returns + ------- + gfit : astropy.modeling.Model + The best-fit 2D Gaussian model. """ props = data_properties(data - np.min(data)) @@ -73,7 +83,9 @@ def compute_fwhm(ccd, sources, fwhm_estimate=5, of the sources. fit : bool, optional - If ``True``, fit a 2D Gaussian to each source to estimate its FWHM. + If ``True``, fit a 2D Gaussian to each source to estimate its FWHM. If + ``False``, estimate the FWHM of each source by computing the second + moments of its light distribution using photutils. sky_per_pix_avg : float or array-like of float Sky background to subtract before centroiding. @@ -136,7 +148,7 @@ def source_detection(ccd, fwhm=8, sigma=3.0, iters=5, within the image. Parameters - ---------------- + ---------- ccd : numpy.ndarray The CCD Image array. @@ -156,13 +168,14 @@ def source_detection(ccd, fwhm=8, sigma=3.0, iters=5, find_fwhm : bool, optional If ``True``, estimate the FWHM of each source by fitting a 2D Gaussian - to it. + to it. If ``False``, estimate the FWHM of each source by computing + the second moments of its light distribution. sky_per_pix_avg : float or array-like of float Sky background to subtract before centroiding. Returns - ----------- + ------- sources an astropy table of the positions of sources in the image. From 74cc196198499d83211fcb432c9d3261c4b6d85a Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Thu, 8 Jun 2023 16:07:08 -0500 Subject: [PATCH 05/35] Typo correction and removal of documentation causing pytest failures. --- stellarphot/differential_photometry/catalog_search.py | 9 --------- .../differential_photometry/magnitude_transforms.py | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/stellarphot/differential_photometry/catalog_search.py b/stellarphot/differential_photometry/catalog_search.py index 602a75b0..a286a23d 100644 --- a/stellarphot/differential_photometry/catalog_search.py +++ b/stellarphot/differential_photometry/catalog_search.py @@ -156,15 +156,6 @@ def catalog_clean(catalog, remove_rows_with_mask=True, astropy.table.Table Table of catalog information for stars in the field of view. - Examples - -------- - - >>> catalog_clean(catalog, remove_rows_with_mask=True, e_r_mag='<0.1') - >>> catalog_clean(catalog, remove_rows_with_mask=True, e_r_mag='<0.1', - ... e_B-V='>0.1') - >>> catalog_clean(catalog, remove_rows_with_mask=True, e_r_mag='<0.1', - ... e_B-V='>0.1', r_mag='>10') - """ comparisons = { diff --git a/stellarphot/differential_photometry/magnitude_transforms.py b/stellarphot/differential_photometry/magnitude_transforms.py index a84b330e..f6117f64 100644 --- a/stellarphot/differential_photometry/magnitude_transforms.py +++ b/stellarphot/differential_photometry/magnitude_transforms.py @@ -13,7 +13,7 @@ __all__ = [ - 'f', 'get_cat', 'opts_to_str', 'calc_residual'. + 'f', 'get_cat', 'opts_to_str', 'calc_residual', 'filter_transform', 'calculate_transform_coefficients', 'transform_magnitudes', From c3f0365bf86f06432d0ae743d44fa6d0b637f8c9 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Fri, 9 Jun 2023 10:56:46 -0500 Subject: [PATCH 06/35] Tweaks to differential photometry docstrings and comments. --- .../differential_photometry/catalog_search.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/stellarphot/differential_photometry/catalog_search.py b/stellarphot/differential_photometry/catalog_search.py index a286a23d..9ed6c0a2 100644 --- a/stellarphot/differential_photometry/catalog_search.py +++ b/stellarphot/differential_photometry/catalog_search.py @@ -228,24 +228,37 @@ def find_apass_stars(image_or_center, else: cen_wcs = image_or_center.wcs shape = image_or_center.shape - # use the catalog_search function to find the apass stars in the frame of the image read above + # use the catalog_search function to find the APASS stars in the frame of the image read above all_apass = catalog_search(cen_wcs, shape, 'II/336/apass9', ra_column='RAJ2000', dec_column='DEJ2000', radius=radius, clip_by_frame=False) - # Creates a boolean array of the apass stars that have well defined + # Creates a boolean array of the APASS stars that have well defined # magnitudes and color. apass_lower_error = (all_apass['e_r_mag'] < max_mag_error) & ( all_apass['e_B-V'] < max_color_error) - # create new table of apass stars that meet error restrictions + # create new table of APASS stars that meet error restrictions apass_lower_error = all_apass[apass_lower_error] return all_apass, apass_lower_error def find_known_variables(image): - # Get any known variable stars from a new catalog search of VSX + '''Get any known variable stars in image field from the VSX catalog. + + Parameters + ---------- + + image : `astropy.nddata.CCDData` + Image with a WCS. + + Returns + ------- + + vsx : `astropy.table.Table` + Table of known variable stars in the field of view. + ''' try: vsx = catalog_search(image.wcs, image.shape, 'B/vsx/vsx', ra_column='RAJ2000', dec_column='DEJ2000') From 92228381af9b30ee86b97d21742c79482a0cb00f Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Fri, 9 Jun 2023 11:04:00 -0500 Subject: [PATCH 07/35] Additional tweaks to differential photometry docstrings and comments. --- stellarphot/differential_photometry/magnitude_transforms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/differential_photometry/magnitude_transforms.py b/stellarphot/differential_photometry/magnitude_transforms.py index f6117f64..ba9a4b87 100644 --- a/stellarphot/differential_photometry/magnitude_transforms.py +++ b/stellarphot/differential_photometry/magnitude_transforms.py @@ -23,7 +23,7 @@ def f(X, a, b, c, d, z): """ - Calculate the calibrated magnitude from the instrumental magnitude and color. + Calculate the calibrated magnitudes from the instrumental magnitudes and colors. Parameters ---------- From 85dc3c3a8ed140e573028a5c1c5e0ffbd80cefd3 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Fri, 9 Jun 2023 11:49:36 -0500 Subject: [PATCH 08/35] Added docstrings to aij_plots and comparison_function in visualization package. --- .../notebooks/comp-stars-template.ipynb | 13 +- stellarphot/visualization/aij_plots.py | 17 + .../visualization/comparison_functions.py | 324 ++++++++++++++++-- 3 files changed, 322 insertions(+), 32 deletions(-) diff --git a/stellarphot/notebooks/comp-stars-template.ipynb b/stellarphot/notebooks/comp-stars-template.ipynb index 059f050b..a32622a2 100644 --- a/stellarphot/notebooks/comp-stars-template.ipynb +++ b/stellarphot/notebooks/comp-stars-template.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -8,6 +9,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -38,13 +40,14 @@ "from astropy.coordinates import SkyCoord\n", "\n", "from stellarphot.visualization.comparison_functions import (\n", - " read_file, set_up, match, mag_scale, in_field, wrap, make_markers,\n", + " read_file, set_up, crossmatch_APASS2VSX, mag_scale, in_field, wrap, make_markers,\n", " viewer\n", ")\n", "from stellarphot.visualization.seeing_profile_functions import set_keybindings" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -111,7 +114,7 @@ " directory_with_images=directory_with_images\n", " )\n", "\n", - "apass, vsx_apass_angle, targets_apass_angle = match(ccd, targets_from_file, vsx)\n", + "apass, vsx_apass_angle, targets_apass_angle = crossmatch_APASS2VSX(ccd, targets_from_file, vsx)\n", "\n", "apass_good_coord, good_stars = mag_scale(Cmag, apass, vsx_apass_angle,\n", " targets_apass_angle,\n", @@ -129,6 +132,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -149,6 +153,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -166,6 +171,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -211,6 +217,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -230,6 +237,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -270,6 +278,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ diff --git a/stellarphot/visualization/aij_plots.py b/stellarphot/visualization/aij_plots.py index b3e7ada5..e3ffdca3 100644 --- a/stellarphot/visualization/aij_plots.py +++ b/stellarphot/visualization/aij_plots.py @@ -31,13 +31,21 @@ def seeing_plot(raw_radius, raw_counts, binned_radius, binned_counts, HWHM, file_name : optional, string if entered, file will save as png with this name + gap : number the distance between the aperture and the inner annulus + annulus_width : number the distance between the inner and outer annulus figsize : tuple of int, optional Size of figure. + + Returns + ------- + + matplotlib.pyplot.figure + The figure object containing the seeing plot. """ if radius is None: radius = HWHM * 4 @@ -107,6 +115,9 @@ def plot_predict_ingress_egress(ingress_time, egress_time, end_line=1, egress_time : number the end of an exoplanet transit + end_line : number + offset to move the vertical lines + ingress_x_pos : number offset to center ingress label @@ -115,6 +126,12 @@ def plot_predict_ingress_egress(ingress_time, egress_time, end_line=1, labels_y_pos : number offset to move ingress and egress labels + + Returns + ------- + + None + Directly adds lines and labels to the current plot. """ ymin, ymax = plt.ylim() diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 1033e792..5c4c6ac9 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -27,7 +27,7 @@ from stellarphot.visualization.fits_opener import FitsOpener -__all__ = ['read_file', 'set_up', 'match', 'mag_scale', +__all__ = ['read_file', 'set_up', 'crossmatch_APASS2VSX', 'mag_scale', 'in_field', 'make_markers', 'wrap', 'ComparisonViewer'] DESC_STYLE = {"description_width": "initial"} @@ -58,20 +58,28 @@ def read_file(radec_file): return target_table -def set_up(sample_image_for_finding_stars, - directory_with_images='.'): - """ - Find known variable in the field of view and read sample image. +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. + 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 @@ -91,13 +99,35 @@ def set_up(sample_image_for_finding_stars, return ccd, vsx -def match(CCD, RD, vsx): - """ - Find APASS stars in FOV and matches APASS stars to VSX and - APASS to input targets. +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) + 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)) @@ -108,21 +138,50 @@ def match(CCD, RD, vsx): 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 + """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 @@ -143,8 +202,28 @@ def mag_scale(cmag, apass, v_angle, RD_angle, def in_field(apass_good_coord, ccd, apass, good_stars): - """ - Return apass stars in the field of view + """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) @@ -159,11 +238,36 @@ def in_field(apass_good_coord, ccd, apass, good_stars): 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. +def make_markers(iw, ccd, RD, vsx, ent, name_or_coord=None): + """Add markers for APASS, TESS targets, VSX. Also center on object/coordinate. + + Parameters + ---------- + + iw : `ginga.util.grc.RemoteClient` + Ginga widget. + + 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. + + ent : `astropy.table.Table` + Table with APASS stars in the field of view. + + name_or_coord : str or `astropy.coordinates.SkyCoord`, optional + Name or coordinates of the target. + + Returns + ------- + + None + Markers are added to the image in Ginga widget. """ iw.load_nddata(ccd) iw.zoom_level = 'fit' @@ -193,9 +297,19 @@ def make_markers(iw, ccd, RD, vsx, ent, use_skycoord=True, marker_name='APASS comparison') iw.marker = {'type': 'cross', 'color': 'red', 'radius': 6} + def wrap(imagewidget, outputwidget): - """ - Make the bits that let you click to select/deselect comparisons + """Utility function to let you click to select/deselect comparisons. + + Parameters + ---------- + + imagewidget : `ginga.util.grc.RemoteClient` + Ginga widget. + + outputwidget : `ipywidgets.Output` + Output widget for printing information. + """ def cb(viewer, event, data_x, data_y): i = imagewidget._viewer.get_image() @@ -242,6 +356,65 @@ def cb(viewer, event, data_x, data_y): class ComparisonViewer: + """A class to store an instance of the comparison viewer. + + Parameters + ---------- + + file : str, optional + File to open. + + directory : str, optional + Directory to open file from. + + target_mag : float, optional + Magnitude of the target. + + bright_mag_limit : float, optional + Bright magnitude limit for APASS stars. + + dim_mag_limit : float, optional + Dim magnitude limit for APASS stars. + + targets_from_file : str, optional + File with target information. + + object_coordinate : `astropy.coordinates.SkyCoord`, optional + Coordinates of the target. + + aperture_output_file : str, optional + File to save aperture information to. + + Attributes + ---------- + + target_mag : float + Magnitude of the target. + + bright_mag_limit : float + Bright magnitude limit for APASS stars. + + dim_mag_limit : float + Dim magnitude limit for APASS stars. + + targets_from_file : str + File with target information. + + tess_submission : `tess_stars2px.TessStars2Px` + Instance of the TESS submission class. + + target_coord : `astropy.coordinates.SkyCoord` + Coordinates of the target. + + box : `ipywidgets.Box` + Box containing the widgets. + + iw : `ginga.util.grc.RemoteClient` + Ginga widget. + + aperture_output_file : str + File to save aperture information to. + """ def __init__(self, file="", directory='.', @@ -286,9 +459,9 @@ def _init(self): directory_with_images=self._file_chooser.path.parent ) - apass, vsx_apass_angle, targets_apass_angle = match(self.ccd, - self.targets_from_file, - self.vsx) + apass, vsx_apass_angle, targets_apass_angle = crossmatch_APASS2VSX(self.ccd, + self.targets_from_file, + self.vsx) apass_good_coord, good_stars = mag_scale(self.target_mag, apass, vsx_apass_angle, targets_apass_angle, @@ -301,6 +474,15 @@ def _init(self): @property def variables(self): + """ Return a dictionary of the variables in the class. + + Returns + ------- + + our_vsx : dict + Dictionary of the variables in the class. + + """ comp_table = self.generate_table() new_vsx_mark = comp_table['marker name'] == 'VSX' idx, _, _ = comp_table['coord'][new_vsx_mark].match_to_catalog_sky(self.vsx['coords']) @@ -505,6 +687,20 @@ def _viewer(self): return box, iw def save_tess_files(self, button=None): + """ Save the TESS files. + + Parameters + ---------- + + button : ipywidgets.Button + The button that was clicked. + + Returns + ------- + + None + Button to save TESS file set to true (triggering action). + """ if self._field_name.value: self.tess_field_view() self.iw.save(self._field_name.value, overwrite=True) @@ -514,6 +710,13 @@ def save_tess_files(self, button=None): self.iw.save(self._zoom_name.value, overwrite=True) def generate_table(self): + """ Generate the table of stars to use for the aperture file. + + Returns + ------- + comp_table : astropy.table.Table + Table of stars to use for the aperture file. + """ try: all_table = self.iw.get_all_markers() except AttributeError: @@ -557,6 +760,14 @@ def generate_table(self): return comp_table def show_labels(self): + """ Show the labels for the stars. + + Returns + ------- + + None + Labels for the stars are shown. + """ plot_names = [] comp_table = self.generate_table() @@ -587,6 +798,14 @@ def show_labels(self): self.iw._marker = original_mark def remove_labels(self): + """ Remove the labels for the stars. + + Returns + ------- + + None + Labels for the stars are removed. + """ try: try: self.iw.remove_markers(marker_name=self._label_name) @@ -599,6 +818,22 @@ def remove_labels(self): def show_circle(self, radius=2.5 * u.arcmin, pixel_scale=0.56 * u.arcsec / u.pixel): + """ Show a circle around the target. + + Parameters + ---------- + + radius : float * u.arcmin, optional + Radius of circle. The default is 2.5*u.arcmin. + pixel_scale : float * u.arcsec / u.pixel, optional + Pixel scale of image. The default is 0.56*u.arcsec/u.pixel. + + Returns + ------- + + None + Circle is shown around the target. + """ radius_pixels = np.round((radius / pixel_scale).to(u.pixel).value, decimals=0) orig_marker = self.iw.marker @@ -611,22 +846,54 @@ def show_circle(self, self.iw.marker = orig_marker def remove_circle(self): + """Remove the circle around the target. + + Returns + ------- + + None + Circle is removed from the image. + """ try: self.iw.remove_markers(marker_name=self._circle_name) except AttributeError: self.iw.remove_markers_by_name(marker_name=self._circle_name) def tess_field_view(self): + """ Show the whole TESS field of view including circle around target, but hide labels. + + Returns + ------- + + None + Shows image as described above. + """ + # Show whole field of view self.iw.zoom_level = 'fit' # Show the circle self.show_circle() - # Turn of labels -- too cluttered + # Turn off labels -- too cluttered self.remove_labels() def tess_field_zoom_view(self, width=6 * u.arcmin): + """ Zoom in on the TESS field of view. + + Parameters + ---------- + + width : float * u.arcmin, optional + Width of field of view. The default is 6*u.arcmin. + + Returns + ------- + + None + Zooms in on the image as described above. + """ + # Turn off labels -- too cluttered self.remove_labels() @@ -643,6 +910,3 @@ def tess_field_zoom_view(self, width=6 * u.arcmin): # Show the circle self.show_circle() - - - From ac6b439815bf9c40e680c337a0e8e0ba74bacea8 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Fri, 9 Jun 2023 12:48:41 -0500 Subject: [PATCH 09/35] Updated docstrings to visualization package functions and classes. --- stellarphot/visualization/fits_opener.py | 20 ++++ .../visualization/multi_night_plots.py | 73 +++++++++++++- .../photometry_widget_functions.py | 20 ++++ .../visualization/seeing_profile_functions.py | 94 ++++++++++++++++--- stellarphot/visualization/transit_plots.py | 74 ++++++++++++++- 5 files changed, 265 insertions(+), 16 deletions(-) diff --git a/stellarphot/visualization/fits_opener.py b/stellarphot/visualization/fits_opener.py index 77949077..941ee24e 100644 --- a/stellarphot/visualization/fits_opener.py +++ b/stellarphot/visualization/fits_opener.py @@ -11,6 +11,26 @@ class FitsOpener: + """ A class to open FITS files and display them in an `astrowidgets.ImageWidget`. + + Attributes + ---------- + file_chooser : `ipyfilechooser.FileChooser` + The actual FileChooser widget. + + header : dict + The header of the selected FITS file. + + ccd : `astropy.nddata.CCDData` + The selected FITS file as a CCDData object. + + path : `pathlib.Path` + The path to the selected FITS file. + + register_callback : function, optional + A function that takes one argument. This function will be called when the + selected file changes. + """ def __init__(self, title="Choose an image", filter_pattern=None, **kwargs): self._fc = FileChooser(title=title, **kwargs) if not filter_pattern: diff --git a/stellarphot/visualization/multi_night_plots.py b/stellarphot/visualization/multi_night_plots.py index fec9c0e4..e17b28a9 100644 --- a/stellarphot/visualization/multi_night_plots.py +++ b/stellarphot/visualization/multi_night_plots.py @@ -14,9 +14,44 @@ def plot_magnitudes(mags=None, errors=None, times=None, source=None, night=None, ref_mag=0, alpha=0.25, y_range=None): - """ - Plot one night of magnitude data for one source, overlaying a rolling + """Plot one night of magnitude data for one source, overlaying a rolling mean and indication of mean/deviation. + + Parameters + ---------- + + mags : array of floats + Magnitudes of source. + + errors : array of floats + Errors on magnitudes. + + times : array-like + Times of observations. + + source : `~stellarphot.source.Source` + Source object. + + night : float + Night of observations. + + ref_mag : float + Reference magnitude of source. Default is 0. + + alpha : float + Alpha value for error bars. Default is 0.25. + + y_range : tuple + Range of y-axis. Default is None. + + Returns + ------- + + mean : float + Mean magnitude of source. + + std : float + Standard deviation of magnitudes. """ mean = np.nanmean(mags) std = np.nanstd(mags) @@ -63,8 +98,38 @@ def plot_magnitudes(mags=None, errors=None, times=None, def multi_night(sources, unique_nights, night, brightest_mag, mags, mag_err, uniform_ylim=True): - """ - Plot magnitude vs time data for several sources over several nights + """Plot magnitude vs time data for several sources over several nights. + + Parameters + ---------- + + sources : list + List of `~stellarphot.source.Source` objects. + + unique_nights : list + List of unique nights. + + night : array-like + Array of nights. + + brightest_mag : float + Brightest magnitude of sources. + + mags : array-like + Array of magnitudes. + + mag_err : array-like + Array of magnitude errors. + + uniform_ylim : bool + If True, use the median and median absolute deviation of the + magnitudes to set the y-axis range for each source. Default is True. + + Returns + ------- + + None + Generates a plot of magnitude vs time for each source. """ number_of_nights = len(unique_nights) diff --git a/stellarphot/visualization/photometry_widget_functions.py b/stellarphot/visualization/photometry_widget_functions.py index f0f1c542..2a89ae23 100644 --- a/stellarphot/visualization/photometry_widget_functions.py +++ b/stellarphot/visualization/photometry_widget_functions.py @@ -9,6 +9,26 @@ class PhotometrySettings: + """ + A class to hold the widgets for photometry settings. + + Attributes + ---------- + box : `~ipywidgets.VBox` + The box containing the widgets. + + image_folder : `~pathlib.Path` + The path to the folder containing the images. + + aperture_locations : `~pathlib.Path` + The path to the file containing the aperture locations. + + aperture_radius : int + The radius of the aperture. + + object_name : str + The name of the object. + """ def __init__(self): self._image_dir = FileChooser(title="Choose folder with images", show_only_dirs=True) self._aperture_file_loc = FileChooser(title='Choose aperture location file') diff --git a/stellarphot/visualization/seeing_profile_functions.py b/stellarphot/visualization/seeing_profile_functions.py index dc083f48..5e22f0c0 100644 --- a/stellarphot/visualization/seeing_profile_functions.py +++ b/stellarphot/visualization/seeing_profile_functions.py @@ -20,7 +20,8 @@ from stellarphot.visualization import seeing_plot from stellarphot.visualization.fits_opener import FitsOpener -__all__ = ['set_keybindings', 'box', 'SeeingProfileWidget'] +__all__ = ['set_keybindings', 'find_center', 'radial_profile', + 'find_hwhm', 'RadialProfile', 'box', 'SeeingProfileWidget'] desc_style = {"description_width": "initial"} @@ -31,8 +32,8 @@ def set_keybindings(image_widget, scroll_zoom=False): + Pan by click-and-drag or with arrow keys. + Zoom by scrolling or using the ``+``/``-`` keys. - + Adjust contrast by Ctrl-left click and drag; reset with - shift-right-click. + + Adjust contrast by Ctrl-right click and drag + + Reset contrast with shift-right-click. Any existing key bindings are removed. @@ -41,6 +42,16 @@ def set_keybindings(image_widget, scroll_zoom=False): image_widget : astrowidgets.ImageWidget Image widget on which to set the key bindings. + + scroll_zoom : bool + If True, zooming can be done by scrolling the mouse wheel. + Default is False. + + Returns + ------- + + None + Adds key bindings to the image widget. """ bind_map = image_widget._viewer.get_bindmap() # Displays the event map... @@ -94,6 +105,13 @@ def find_center(image, center_guess, cutout_size=30, max_iters=10): max_iters : int, optional Maximum number of iterations to go through in finding the center. + + Returns + ------- + + cen : array + The position of the star, in pixels, as found by the centroiding + algorithm. """ pad = cutout_size // 2 x, y = center_guess @@ -140,8 +158,7 @@ def find_center(image, center_guess, cutout_size=30, max_iters=10): def radial_profile(data, center, size=30, return_scaled=True): - """ - Construct a radial profile of a chunk of width ``size`` centered + """Construct a radial profile of a chunk of width ``size`` centered at ``center`` from image ``data`. Parameters @@ -149,11 +166,14 @@ def radial_profile(data, center, size=30, return_scaled=True): data : numpy array or CCDData Image data + center : list-like x, y position of the center in pixel coordinates, i.e. horizontal coordinate then vertical. + size : int, optional Width of the rectangular cutout to use in constructing the profile. + return_scaled : bool, optional If ``True``, return an average radius and profile, otherwise it is cumulative. Not at all clear what a "cumulative" radius @@ -164,8 +184,10 @@ def radial_profile(data, center, size=30, return_scaled=True): r_exact : numpy array Exact radius of center of each pixels from profile center. + ravg : numpy array Average radius of pixels in each bin. + radialprofile : numpy array Radial profile. """ @@ -194,9 +216,24 @@ def radial_profile(data, center, size=30, return_scaled=True): def find_hwhm(r, intensity): + """Estimate the half-width half-max from normalized, angle-averaged intensity profile. + + Parameters + ---------- + + r : array + Radius of each pixel from the center of the star. + + intensity : array + Normalized intensity at each radius. + + Returns + ------- + + r_half : float + Radius at which the intensity is 50% the maximum """ - Estimate HWHM from normalized, angle-averaged intensity profile. - """ + # Make the bold assumption that intensity decreases monotonically # so that we just need to find the first place where intensity is # less than 0.5 to estimate the HWHM. @@ -219,6 +256,23 @@ def find_hwhm(r, intensity): class RadialProfile: + """ Class to hold radial profile information for a star. + + Attributes + ---------- + + cen : tuple + x, y position of the center of the star. + + data : numpy array + Image data. + + FWHM : float + Full-width half-max of the radial profile. + + radius_values : numpy array + Radius values for the radial profile. + """ def __init__(self, data, x, y): self.cen = find_center(data, (x, y), cutout_size=30) self.data = data @@ -248,15 +302,33 @@ def radius_values(self): def box(imagewidget): - """ - Compatibility layer for older versions of the photometry notebooks. + """Compatibility layer for older versions of the photometry notebooks. + + Parameters + ---------- + + imagewidget : ImageWidget + ImageWidget instance to use for the seeing profile. + + Returns + ------- + + box : ipywidgets.Box + Box containing the seeing profile widget. """ return SeeingProfileWidget(imagewidget=imagewidget).box class SeeingProfileWidget: - """ - Build a widget for measuring the seeing profile of stars in an image. + """A class for storing an instance of a widget displaying the seeing profile of stars in an image. + + Parameters + ---------- + imagewidget : ImageWidget + ImageWidget instance to use for the seeing profile. + + width : int + Width of the seeing profile widget. """ def __init__(self, imagewidget=None, width=500): if not imagewidget: diff --git a/stellarphot/visualization/transit_plots.py b/stellarphot/visualization/transit_plots.py index e3e52aab..5c254f0a 100644 --- a/stellarphot/visualization/transit_plots.py +++ b/stellarphot/visualization/transit_plots.py @@ -5,6 +5,32 @@ def plot_many_factors(photometry, low, high, shift, scale): + """ Plots many factors of photometry against each other. + + Parameters + ---------- + + photometry : astropy.table.Table + The photometry table to plot. + + low : float + The lower bound of the y-axis. + + high : float + The upper bound of the y-axis. + + shift : float + The amount to shift the data by. + + scale : float + The amount to scale the data by. + + Returns + ------- + + None + Added features to the plot directly. + """ airmass = photometry['airmass'] / np.mean(photometry['airmass']) x = photometry['xcenter'] / np.mean(photometry['xcenter']) y = photometry['ycenter'] / np.mean(photometry['ycenter']) @@ -23,6 +49,29 @@ def plot_many_factors(photometry, low, high, shift, scale): def bin_data(data_set, num=3, error_set=None): + """ Bins data into groups of num. + + Parameters + ---------- + + data_set : array-like + The data to bin. + + num : int + The number of data points to bin together. Default is 3. + + error_set : array-like + The error on the data set. Default is None. + + Returns + ------- + + binned_set : array-like + The binned data set. + + error : array-like + The error on the binned data set. + """ binned_set = [] error = [] for i in range(0, len(data_set), num): @@ -34,11 +83,34 @@ def bin_data(data_set, num=3, error_set=None): def scale_and_shift(data_set, scale, shift, pos=True): + """ Scales and shifts data set passed in. + + Parameters + ---------- + + data_set : array-like + The data to scale and shift. + + scale : float + The amount to scale the data by. + + shift : float + The amount to shift the data by (in scaled units). + + pos : bool, optional + Is data displayed in positive or negative direction? Default is True. + + Returns + ------- + + data_set : array-like + The scaled and shifted data. + """ if not pos: data_set = 1 - scale * (data_set - data_set.min()) / (data_set.max() - data_set.min()) - else: data_set = 1 + scale * (data_set - data_set.min()) / (data_set.max() - data_set.min()) + data_set += shift return data_set From 4126d410b6e107f58191e64832ffe16ef0ebd38b Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Fri, 9 Jun 2023 13:14:57 -0500 Subject: [PATCH 10/35] Docstring updates made for io Package. --- stellarphot/io/aij.py | 102 ++++++++++++++++++++++++++++++++-- stellarphot/io/tess.py | 123 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 220 insertions(+), 5 deletions(-) diff --git a/stellarphot/io/aij.py b/stellarphot/io/aij.py index e7edcd89..0b5f062b 100644 --- a/stellarphot/io/aij.py +++ b/stellarphot/io/aij.py @@ -7,12 +7,13 @@ import numpy as np -__all__ = ['parse_aij_table', 'ApertureAIJ', 'ApertureFileAIJ', 'MultiApertureAIJ', 'Star', 'generate_aij_table'] +__all__ = [ 'ApertureAIJ', 'MultiApertureAIJ', 'ApertureFileAIJ', + 'generate_aij_table', 'parse_aij_table', 'Star'] class ApertureAIJ: """ - Represent the aperture information AstroImageJ saves. + Class to represent the aperture information AstroImageJ saves. """ def __init__(self): # Outer annulus radius @@ -52,7 +53,7 @@ def __eq__(self, other): class MultiApertureAIJ: """ - Represent the multi-aperture information that AstroImageJ saves + Class to represent the multi-aperture information that AstroImageJ saves """ def __init__(self): # Default values for these chosen to match AIJ defaults @@ -130,7 +131,17 @@ def __eq__(self, other): class ApertureFileAIJ: """ - Represent AstroImageJ aperture file. + Class to represent AstroImageJ aperture file. + + Methods + ------- + + read(file) + Read aperture file and return an ApertureFileAIJ object. + + write(file) + Write aperture file to disk. + """ def __init__(self): self.aperture = ApertureAIJ() @@ -275,6 +286,23 @@ def _is_comp(star_coord, comp_table): def generate_aij_table(table_name, comparison_table): + """ Generate an AIJ table from a stellarphot table and a comparison table. + + Parameters + ---------- + + table_name : `astropy.table.Table` + Table of stellarphot photometry. + + comparison_table : `astropy.table.Table` + Table of comparison star photometry. + + Returns + ------- + + base_table : `astropy.table.Table` + Table of photometry in AIJ format. + """ info_columns = { 'date-obs': 'DATE_OBS', 'airmass': 'AIRMASS', @@ -340,6 +368,13 @@ def parse_aij_table(table_name): table_name : str Name of the table. + + Returns + ------- + + stars : list + List of `Star` objects. + """ # Read in the raw table. @@ -388,6 +423,65 @@ def parse_aij_table(table_name): class Star(object): + """ A class for storing photometry for a single star. + + Attributes + ---------- + + airmass : `~astropy.units.Quantity` + Airmass at the time of observation. + + counts : `~astropy.units.Quantity` + Net counts in the aperture. + + ra : `~astropy.units.Quantity` + Right ascension of the star. + + dec : `~astropy.units.Quantity` + Declination of the star. + + error : `~astropy.units.Quantity` + Error in the net counts. + + sky_per_pixel : `~astropy.units.Quantity` + Sky brightness per pixel. + + peak : `~astropy.units.Quantity` + Peak counts in the aperture. + + jd_utc_start : `~astropy.units.Quantity` + Julian date of the start of the observation. + + mjd_utc_start : `~astropy.units.Quantity` + Modified Julian date of the start of the observation. + + jd_utc_mid : `~astropy.units.Quantity` + Julian date of the middle of the observation. + + mjd_utc_mid : `~astropy.units.Quantity` + Modified Julian date of the middle of the observation. + + jd_utc_end : `~astropy.units.Quantity` + Julian date of the end of the observation. + + mjd_utc_end : `~astropy.units.Quantity` + Modified Julian date of the end of the observation. + + exposure : `~astropy.units.Quantity` + Exposure time of the observation. + + magnitude : `~astropy.units.Quantity` + Magnitude of the star. + + snr : `~astropy.units.Quantity` + Signal-to-noise ratio of the star. + + magnitude_error : `~astropy.units.Quantity` + Error in the magnitude of the star. + + bjd_tdb : `~astropy.units.Quantity` + Barycentric Dynamical Time taking into account relativity. + """ def __init__(self, table, id_num): self._table = table self._table['DEC'].unit = u.degree diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 147ab2d5..281f3f18 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -18,13 +18,61 @@ __all__ = ["TessSubmission", "TOI", "TessTargetFile"] # Makes me want to vomit, but.... -DEFAULT_TABLE_LOCATION = "who.the.fuck.knows" +DEFAULT_TABLE_LOCATION = "who.the.heck.knows" TOI_TABLE_URL = "https://exofop.ipac.caltech.edu/tess/download_toi.php?output=csv" TIC_regex = re.compile(r"[tT][iI][cC][^\d]?(?P\d+)(?P\.\d\d)?") @dataclass class TessSubmission: + """ A data class to represent TESS submissions. + + Parameters + ---------- + + telescope_code: String + The telescope code, e.g. "SRO" or "TJO" + + filter: String + The filter used for the observations, e.g. "Ic" or "Rc" + + utc_start: String + The UTC date of the first observation, in YYYYMMDD format + + tic_id: int + The TIC ID of the target + + planet_number: int + The planet number, if applicable + + + Attributes + ---------- + base_name: String + The base name of the submission, e.g. "TIC123456789-01_20200101_SRO_Ic" + + seeing_profile: String + The name of the seeing profile file, e.g. "TIC123456789-01_20200101_SRO_Ic_seeing-profile.png" + + field_image: String + The name of the field image file, e.g. "TIC123456789-01_20200101_SRO_Ic_field.png" + + field_image_zoom: String + The name of the zoomed-in field image file, e.g. "TIC123456789-01_20200101_SRO_Ic_field-zoom.png" + + apertures: String + The name of the apertures file, e.g. "TIC123456789-01_20200101_SRO_Ic_measurements.apertures" + + tic_coord: SkyCoord + The SkyCoord of the target, from the TIC + + Methods + ------- + + from_header(header, telescope_code="", planet=0) + Create a TessSubmission from a FITS header + + """ telescope_code: str filter: str utc_start: int @@ -156,6 +204,59 @@ def invalid_parts(self): class TOI: + """ A class to hold information about a TOI (TESS Object of Interest). + + Parameters + ---------- + + tic_id: int + The TIC ID of the target. + + toi_table: str + The path to the TOI table. If not provided, the default table will be downloaded. + + allow_download: bool + Whether to allow the default table to be downloaded if it is not found. + + Attributes + ---------- + + tess_mag: float + The TESS magnitude of the target. + + tess_mag_error: float + The uncertainty in the TESS magnitude. + + depth: float + The transit depth of the target. + + depth_error: float + The uncertainty in the transit depth. + + epoch: float + The epoch of the transit. + + epoch_error: float + The uncertainty in the epoch of the transit. + + period: float + The period of the transit. + + period_error: float + The uncertainty in the period of the transit. + + duration: float + The duration of the transit. + + duration_error: float + The uncertainty in the duration of the transit. + + coord: SkyCoord + The coordinates of the target. + + tic_id: int + The TIC ID of the target. + """ def __init__(self, tic_id, toi_table=DEFAULT_TABLE_LOCATION, allow_download=True): path = Path(toi_table) if not path.is_file(): @@ -225,6 +326,26 @@ def tic_id(self): @dataclass class TessTargetFile: + """ A dataclass to hold information about a TESS target file. + + Parameters + ---------- + + coord : SkyCoord + The coordinates of the target. + + magnitude : float + The magnitude of the target. + + depth : float + The depth of the transit. + + file : str + The path to the target file. If not provided, a temporary file will be created. + + aperture_server : str + The URL of the aperture server. default: https://www.astro.louisville.edu/ + """ coord : SkyCoord magnitude : float depth : float From 574481bd883d10d414c43dbd31631ffd49b20f5d Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Fri, 9 Jun 2023 13:31:59 -0500 Subject: [PATCH 11/35] Tweaked the docstrings for calculate_noise to make a bit more compact. --- stellarphot/photometry.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/stellarphot/photometry.py b/stellarphot/photometry.py index 768c4fc7..f0fac42b 100644 --- a/stellarphot/photometry.py +++ b/stellarphot/photometry.py @@ -610,21 +610,14 @@ def calculate_noise(gain=1.0, read_noise=0.0, dark_current_per_sec=0.0, This function computes the noise (in units of gain) in a photometric measurement using the revised CCD equation from Collins et al (2017) AJ, 153, 77. The equation is: - .. math:: - \sigma = \sqrt{G \cdot F + A \cdot (1 + \frac{A}{B})\cdot [ G\cdot S + D \cdot t + R^2 + (0.289 G)^2]} - - where - :math:`\sigma` is the noise, - :math:`G` is the gain, - :math:`F` is the flux, - :math:`A` is the aperture area in pixels, - :math:`B` is the annulus area in pixels, - :math:`S` is the sky per pixel, - :math:`D` is the dark current per second, - :math:`R` is the read noise, - and :math:`t` is exposure time. + \sigma = \sqrt{G \cdot F + A \cdot (1 + \frac{A}{B})\cdot [ G\cdot S + D \cdot t + R^2 + (0.289 G)^2]} + + where :math:`\sigma` is the noise, :math:`G` is the gain, :math:`F` is the flux, + :math:`A` is the aperture area in pixels, :math:`B` is the annulus area in pixels, + :math:`S` is the sky per pixel, :math:`D` is the dark current per second, + :math:`R` is the read noise, and :math:`t` is exposure time. Note: The :math:`(0.289 G)^2` term is "digitization noise" and is optional. From ebd5236c4fed9178202b6fefb92909b920afb1a9 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Fri, 9 Jun 2023 13:45:14 -0500 Subject: [PATCH 12/35] Still tweaking calculate_noise docstring math, still not rendering correctly. --- stellarphot/photometry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stellarphot/photometry.py b/stellarphot/photometry.py index f0fac42b..5ae30bc1 100644 --- a/stellarphot/photometry.py +++ b/stellarphot/photometry.py @@ -610,9 +610,10 @@ def calculate_noise(gain=1.0, read_noise=0.0, dark_current_per_sec=0.0, This function computes the noise (in units of gain) in a photometric measurement using the revised CCD equation from Collins et al (2017) AJ, 153, 77. The equation is: + .. math:: - \sigma = \sqrt{G \cdot F + A \cdot (1 + \frac{A}{B})\cdot [ G\cdot S + D \cdot t + R^2 + (0.289 G)^2]} + \sigma = \sqrt{G \cdot F + A \cdot \left(1 + \frac{A}{B}\right)\cdot \left[ G\cdot S + D \cdot t + R^2 + (0.289 G)^2\right]} where :math:`\sigma` is the noise, :math:`G` is the gain, :math:`F` is the flux, :math:`A` is the aperture area in pixels, :math:`B` is the annulus area in pixels, From 18823e6cd97f67e10490f8951431981cf499c8b1 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:13:16 -0500 Subject: [PATCH 13/35] Working my way through Matt's comments on PR#97. --- stellarphot/analysis/exotic.py | 14 ++++---------- .../visualization/seeing_profile_functions.py | 4 ++-- stellarphot/visualization/transit_plots.py | 6 +++--- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/stellarphot/analysis/exotic.py b/stellarphot/analysis/exotic.py index 8b01dcdc..799adba6 100644 --- a/stellarphot/analysis/exotic.py +++ b/stellarphot/analysis/exotic.py @@ -43,12 +43,6 @@ class MyValid(ipw.Button): A class containing a more compact indicator of valid entries based on ipywidgets buton value. - Parameters - ---------- - - value : ipywidgets.Button.value - Initial value of the indicator. - Attributes ---------- @@ -87,8 +81,8 @@ def get_tic_info(TIC_ID): Returns ------- - dict - Dictionary of information about the TIC object. + `astropy.table.Table` + Astropy table withinformation about the TIC object. """ catalog_data = Catalogs.query_criteria(catalog="Tic", ID=TIC_ID) @@ -149,7 +143,7 @@ def validate_exposure_time(indicator_widget, value_widget): Parameters ---------- - indicator_widget : MyCheck widget + indicator_widget : `MyValid` widget The widget that indicates to the user whether or not the value is reasonable. @@ -161,7 +155,7 @@ def validate_exposure_time(indicator_widget, value_widget): function Function that will set the correct boolean value on the indicator_widget to indicate if the value of the exposure time - is valid. + is valid. This can be used as an observer for an ipywidget """ def check_exposure(change): # Valid Exposure time is greater than zero diff --git a/stellarphot/visualization/seeing_profile_functions.py b/stellarphot/visualization/seeing_profile_functions.py index 5e22f0c0..41b1e496 100644 --- a/stellarphot/visualization/seeing_profile_functions.py +++ b/stellarphot/visualization/seeing_profile_functions.py @@ -324,10 +324,10 @@ class SeeingProfileWidget: Parameters ---------- - imagewidget : ImageWidget + imagewidget : ImageWidget, optional ImageWidget instance to use for the seeing profile. - width : int + width : int, optional Width of the seeing profile widget. """ def __init__(self, imagewidget=None, width=500): diff --git a/stellarphot/visualization/transit_plots.py b/stellarphot/visualization/transit_plots.py index 5c254f0a..0f1a8824 100644 --- a/stellarphot/visualization/transit_plots.py +++ b/stellarphot/visualization/transit_plots.py @@ -10,7 +10,7 @@ def plot_many_factors(photometry, low, high, shift, scale): Parameters ---------- - photometry : astropy.table.Table + photometry : `astropy.table.Table` The photometry table to plot. low : float @@ -57,7 +57,7 @@ def bin_data(data_set, num=3, error_set=None): data_set : array-like The data to bin. - num : int + num : int, optional The number of data points to bin together. Default is 3. error_set : array-like @@ -69,7 +69,7 @@ def bin_data(data_set, num=3, error_set=None): binned_set : array-like The binned data set. - error : array-like + error : array-like, optional The error on the binned data set. """ binned_set = [] From ffd788b2833287cc4989636822e7cf405229331c Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:15:56 -0500 Subject: [PATCH 14/35] Fixed docstring error noted by matt. --- stellarphot/analysis/exotic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stellarphot/analysis/exotic.py b/stellarphot/analysis/exotic.py index 799adba6..f0769d73 100644 --- a/stellarphot/analysis/exotic.py +++ b/stellarphot/analysis/exotic.py @@ -219,8 +219,8 @@ def populate_TOI_boxes(toi, exotic_widget): Parameters ---------- - toi : dict - Dictionary of information about the TIC object. + toi : stellarphot.io.tess.TOI + Information about the TIC object. exotic_widget: ipywidget This widget should be generated by exotic_settings_widget. From 22e4deb9ef5d726852f3a081c4f2df2e56825778 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:16:21 -0500 Subject: [PATCH 15/35] Update stellarphot/analysis/transit_fitting.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/analysis/transit_fitting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/analysis/transit_fitting.py b/stellarphot/analysis/transit_fitting.py index d6fb2882..2aa322d2 100644 --- a/stellarphot/analysis/transit_fitting.py +++ b/stellarphot/analysis/transit_fitting.py @@ -89,7 +89,7 @@ def __call__(self, model, *args, weights=None, class TransitModelFit: - """ A class for handling transit model fits to observed light curves. + """Transit model fits to observed light curves. Parameters ---------- From fde3915587e70c05fcb6e2d63ba8e63997deaa8d Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:17:23 -0500 Subject: [PATCH 16/35] Update stellarphot/core.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/core.py b/stellarphot/core.py index 85907ec6..59b9ebd0 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -9,7 +9,7 @@ class Camera: Parameters ---------- - gain : float times u.electron / u.adu, + gain : `astropy.quantity.Quantity` The gain of the camera in units of electrons per ADU. read_noise : float times u.electron The read noise of the camera in units of electrons. From 88b57600716248ea54461b579f1d460995c960e3 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:21:01 -0500 Subject: [PATCH 17/35] Update stellarphot/core.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/core.py b/stellarphot/core.py index 59b9ebd0..5ae745e7 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -10,7 +10,7 @@ class Camera: Parameters ---------- gain : `astropy.quantity.Quantity` - The gain of the camera in units of electrons per ADU. + The gain of the camera in units such that the unit of the product `gain` times the image data matches the unit of the `read_noise`. read_noise : float times u.electron The read noise of the camera in units of electrons. dark_current : float times u.electron / u.second From 047e04427c771b55d28dd478ab6c4074ce2ec374 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:21:55 -0500 Subject: [PATCH 18/35] Update stellarphot/core.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/core.py b/stellarphot/core.py index 5ae745e7..a08ed01e 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -11,7 +11,7 @@ class Camera: ---------- gain : `astropy.quantity.Quantity` The gain of the camera in units such that the unit of the product `gain` times the image data matches the unit of the `read_noise`. - read_noise : float times u.electron + read_noise : `astropy.quantity.Quantity` The read noise of the camera in units of electrons. dark_current : float times u.electron / u.second The dark current of the camera in units of electrons per second. From b4a0774dfba3bc0454dcc766ae4209544321e16d Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:22:32 -0500 Subject: [PATCH 19/35] Update stellarphot/core.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/core.py b/stellarphot/core.py index a08ed01e..40575dcd 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -13,7 +13,7 @@ class Camera: The gain of the camera in units such that the unit of the product `gain` times the image data matches the unit of the `read_noise`. read_noise : `astropy.quantity.Quantity` The read noise of the camera in units of electrons. - dark_current : float times u.electron / u.second + dark_current : `astropy.quantity.Quantity` The dark current of the camera in units of electrons per second. Attributes From da8fe2cc9994005f9604784a9aa4fc41af3e01bd Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:23:03 -0500 Subject: [PATCH 20/35] Update stellarphot/core.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/core.py b/stellarphot/core.py index 40575dcd..94ca00fc 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -14,7 +14,7 @@ class Camera: read_noise : `astropy.quantity.Quantity` The read noise of the camera in units of electrons. dark_current : `astropy.quantity.Quantity` - The dark current of the camera in units of electrons per second. + The dark current of the camera in units such that, when multiplied by exposure time, the unit matches the unit of the `read_noise`. Attributes ---------- From 4e64db05ceff5ed1f682fbb84e4ce08be9478745 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:23:45 -0500 Subject: [PATCH 21/35] Update stellarphot/differential_photometry/magnitude_transforms.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/differential_photometry/magnitude_transforms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stellarphot/differential_photometry/magnitude_transforms.py b/stellarphot/differential_photometry/magnitude_transforms.py index ba9a4b87..356539f9 100644 --- a/stellarphot/differential_photometry/magnitude_transforms.py +++ b/stellarphot/differential_photometry/magnitude_transforms.py @@ -44,7 +44,8 @@ def f(X, a, b, c, d, z): def get_cat(image): - """ Get the APASS catalog entries within 1 degree of first object in + """ + Get the APASS catalog entries within 1 degree of first object in Astropy table 'image'. Parameters From 96492e25a8d89e43fa6c73f4fa13c3efa0dada2c Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:24:20 -0500 Subject: [PATCH 22/35] Update stellarphot/io/aij.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/aij.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stellarphot/io/aij.py b/stellarphot/io/aij.py index 0b5f062b..a94fc217 100644 --- a/stellarphot/io/aij.py +++ b/stellarphot/io/aij.py @@ -286,7 +286,8 @@ def _is_comp(star_coord, comp_table): def generate_aij_table(table_name, comparison_table): - """ Generate an AIJ table from a stellarphot table and a comparison table. + """ + Generate an AIJ table from a stellarphot table and a comparison table. Parameters ---------- From b0ddb657f8009667d13bf2234758d3fbd7bce829 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:24:48 -0500 Subject: [PATCH 23/35] Update stellarphot/io/aij.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/aij.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stellarphot/io/aij.py b/stellarphot/io/aij.py index a94fc217..e3f4ef1c 100644 --- a/stellarphot/io/aij.py +++ b/stellarphot/io/aij.py @@ -424,7 +424,8 @@ def parse_aij_table(table_name): class Star(object): - """ A class for storing photometry for a single star. + """ + A class for storing photometry for a single star. Attributes ---------- From 3492cac969e8de313a282d2974d0dd312b45a626 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:26:02 -0500 Subject: [PATCH 24/35] Update stellarphot/io/tess.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 281f3f18..d9c8d77a 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -48,7 +48,7 @@ class TessSubmission: Attributes ---------- - base_name: String + base_name: str The base name of the submission, e.g. "TIC123456789-01_20200101_SRO_Ic" seeing_profile: String From 14cad6dfa03982da85fe7d3f72f6773ba1189d74 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:26:25 -0500 Subject: [PATCH 25/35] Update stellarphot/io/tess.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index d9c8d77a..ce77ec96 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -51,7 +51,7 @@ class TessSubmission: base_name: str The base name of the submission, e.g. "TIC123456789-01_20200101_SRO_Ic" - seeing_profile: String + seeing_profile: str The name of the seeing profile file, e.g. "TIC123456789-01_20200101_SRO_Ic_seeing-profile.png" field_image: String From 4a6075779ef7d707a74d3ef284ca40349d78e5a6 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:26:49 -0500 Subject: [PATCH 26/35] Update stellarphot/io/tess.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index ce77ec96..bd2f4140 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -54,7 +54,7 @@ class TessSubmission: seeing_profile: str The name of the seeing profile file, e.g. "TIC123456789-01_20200101_SRO_Ic_seeing-profile.png" - field_image: String + field_image: str The name of the field image file, e.g. "TIC123456789-01_20200101_SRO_Ic_field.png" field_image_zoom: String From 6698bd9a2cae2ddef57c68dee370dee5e5f49689 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:27:08 -0500 Subject: [PATCH 27/35] Update stellarphot/io/tess.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index bd2f4140..cd9970d1 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -57,7 +57,7 @@ class TessSubmission: field_image: str The name of the field image file, e.g. "TIC123456789-01_20200101_SRO_Ic_field.png" - field_image_zoom: String + field_image_zoom: str The name of the zoomed-in field image file, e.g. "TIC123456789-01_20200101_SRO_Ic_field-zoom.png" apertures: String From fc58920ca4c943d92677f3059cae4e90ca757992 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:38:40 -0500 Subject: [PATCH 28/35] Implemented a variety of suggestions by Matt on PR#97. --- stellarphot/analysis/transit_fitting.py | 2 +- .../differential_photometry/catalog_search.py | 6 ----- .../magnitude_transforms.py | 5 ++-- stellarphot/io/aij.py | 26 ++++++++++++------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/stellarphot/analysis/transit_fitting.py b/stellarphot/analysis/transit_fitting.py index 2aa322d2..8f2258e6 100644 --- a/stellarphot/analysis/transit_fitting.py +++ b/stellarphot/analysis/transit_fitting.py @@ -366,7 +366,7 @@ def setup_model(self, t0=0, depth=0, duration=0, inclination : float Inclination of the orbit, in degrees. - airmass_trend : float + airmass_trend : float, optional Coefficient for a linear trend in airmass. width_trend : float diff --git a/stellarphot/differential_photometry/catalog_search.py b/stellarphot/differential_photometry/catalog_search.py index 9ed6c0a2..1fedb172 100644 --- a/stellarphot/differential_photometry/catalog_search.py +++ b/stellarphot/differential_photometry/catalog_search.py @@ -60,12 +60,6 @@ def catalog_search(frame_wcs_or_center, shape, desired_catalog, Return the items from catalog that are within the search radius and (optionally) within the field of view of a frame. - This function takes coordinate data from an image and a - catalog name and returns the positions of those stars. - Preconditions:frame_wcs is a WCS object, shape is tuple, list or array of - numerical values, desired_catalog is a string and radius is a numerical - value. - Parameters ---------- diff --git a/stellarphot/differential_photometry/magnitude_transforms.py b/stellarphot/differential_photometry/magnitude_transforms.py index 356539f9..e0e95ea3 100644 --- a/stellarphot/differential_photometry/magnitude_transforms.py +++ b/stellarphot/differential_photometry/magnitude_transforms.py @@ -424,10 +424,11 @@ def transform_magnitudes(input_mags, catalog, Boolean array indicating which stars in ``input_mags`` have a match in the catalog. - transforms : namedtuple + transforms : `astropy.modeling.FittableModel` The coefficients of the transform. The coefficients are in the order of ascending power, i.e. the coefficient ``ci`` is the coefficient - of the term ``x**i``. + of the term ``x**i``. Warning: This returns a namedtuple if the fit + fails. """ catalog_all_coords = SkyCoord(catalog['RAJ2000'], catalog['DEJ2000'], diff --git a/stellarphot/io/aij.py b/stellarphot/io/aij.py index e3f4ef1c..84f587fd 100644 --- a/stellarphot/io/aij.py +++ b/stellarphot/io/aij.py @@ -13,7 +13,7 @@ class ApertureAIJ: """ - Class to represent the aperture information AstroImageJ saves. + Represents the aperture information AstroImageJ saves. """ def __init__(self): # Outer annulus radius @@ -133,15 +133,6 @@ class ApertureFileAIJ: """ Class to represent AstroImageJ aperture file. - Methods - ------- - - read(file) - Read aperture file and return an ApertureFileAIJ object. - - write(file) - Write aperture file to disk. - """ def __init__(self): self.aperture = ApertureAIJ() @@ -173,6 +164,15 @@ def __eq__(self, other): return (self.aperture == other.aperture) and (self.multiaperture == other.multiaperture) def write(self, file): + """ + Write the aperture object to a file. + + Parameters + ---------- + + file : str + Name of the file to write. + """ p = Path(file) p.write_text(str(self)) @@ -181,6 +181,12 @@ def read(cls, file): """ Generate aperture object from file. Happily, each line is basically a path to an attribute name followed by a value. + + Parameters + ---------- + + file : str + Name of the file to read. """ # Make the instance to return From 5df1bdb6abf8d55b307738e13e365b13998832e4 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:41:46 -0500 Subject: [PATCH 29/35] Update stellarphot/io/tess.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index cd9970d1..4f443eaf 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -60,7 +60,7 @@ class TessSubmission: field_image_zoom: str The name of the zoomed-in field image file, e.g. "TIC123456789-01_20200101_SRO_Ic_field-zoom.png" - apertures: String + apertures: str The name of the apertures file, e.g. "TIC123456789-01_20200101_SRO_Ic_measurements.apertures" tic_coord: SkyCoord From 02a8573991ffa81c7572e63f67546617cab9abd5 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:42:32 -0500 Subject: [PATCH 30/35] Update stellarphot/io/tess.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 4f443eaf..84cdf331 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -63,7 +63,7 @@ class TessSubmission: apertures: str The name of the apertures file, e.g. "TIC123456789-01_20200101_SRO_Ic_measurements.apertures" - tic_coord: SkyCoord + tic_coord: `astropycoordinates.SkyCoord` The SkyCoord of the target, from the TIC Methods From 30c56c8fd244c6e48cc77283f4f884aba5899b54 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:44:37 -0500 Subject: [PATCH 31/35] Accepted this suggestion by Matt on PR#97. --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 84cdf331..89902045 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -64,7 +64,7 @@ class TessSubmission: The name of the apertures file, e.g. "TIC123456789-01_20200101_SRO_Ic_measurements.apertures" tic_coord: `astropycoordinates.SkyCoord` - The SkyCoord of the target, from the TIC + The SkyCoord of the target, from the TIC catalog. Methods ------- From c85aad10f3eb5f14c060d33b70e2f9377d7d0efb Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 14:58:19 -0500 Subject: [PATCH 32/35] Accepted various suggestions by Matt on PR#97. --- stellarphot/io/tess.py | 36 +++++++++++-------- stellarphot/photometry.py | 6 ++-- .../visualization/seeing_profile_functions.py | 12 +++++++ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 89902045..02aad016 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -25,7 +25,8 @@ @dataclass class TessSubmission: - """ A data class to represent TESS submissions. + """ + A data class to represent TESS submissions. Parameters ---------- @@ -65,13 +66,6 @@ class TessSubmission: tic_coord: `astropycoordinates.SkyCoord` The SkyCoord of the target, from the TIC catalog. - - Methods - ------- - - from_header(header, telescope_code="", planet=0) - Create a TessSubmission from a FITS header - """ telescope_code: str filter: str @@ -84,7 +78,20 @@ def __post_init__(self, *args, **kwargs): @classmethod def from_header(cls, header, telescope_code="", planet=0): - # Set some default dummy values + """ + Create a TessSubmission from a FITS header + + Parameters + ---------- + header: astropy.io.fits.Header + The FITS header to parse + + telescope_code: str + The telescope code, e.g. "SRO" or "TJO" + + planet: int + The planet number, if applicable + """ tic_id = 0 filter = "" @@ -212,10 +219,10 @@ class TOI: tic_id: int The TIC ID of the target. - toi_table: str + toi_table: str, optional The path to the TOI table. If not provided, the default table will be downloaded. - allow_download: bool + allow_download: bool, optional Whether to allow the default table to be downloaded if it is not found. Attributes @@ -326,12 +333,13 @@ def tic_id(self): @dataclass class TessTargetFile: - """ A dataclass to hold information about a TESS target file. + """ + A class to hold information about a TESS target file. Parameters ---------- - coord : SkyCoord + coord : `astropy.coordinates.SkyCoord` The coordinates of the target. magnitude : float @@ -340,7 +348,7 @@ class TessTargetFile: depth : float The depth of the transit. - file : str + file : str, optional The path to the target file. If not provided, a temporary file will be created. aperture_server : str diff --git a/stellarphot/photometry.py b/stellarphot/photometry.py index 5ae30bc1..bb7dba40 100644 --- a/stellarphot/photometry.py +++ b/stellarphot/photometry.py @@ -240,7 +240,7 @@ def clipped_sky_per_pix_stats(data, annulus, sigma=5, iters=5): Returns ------- - avg_sky_per_pix, med_sky_per_pix, std_sky_per_pix : astropy.units.Quantity + avg_sky_per_pix, med_sky_per_pix, std_sky_per_pix : `astropy.units.Quantity` Average, median and standard deviation of the sky per pixel. """ @@ -457,7 +457,7 @@ def photometry_on_directory(directory_with_images, object_of_interest, Dark current, in electron/sec. Used in the CCD equation to calculate error. - bjd_coords : astropy SkyCoord object + bjd_coords : `astropy.coordinates.SkyCoord` Coordinates of the object of interest in the Barycentric Julian Date frame. If not provided, the BJD column will not be added to the photometry table. @@ -474,7 +474,7 @@ def photometry_on_directory(directory_with_images, object_of_interest, Returns ------- - phot : astropy.table.Table + phot : `astropy.table.Table` Table containing the photometry results. """ diff --git a/stellarphot/visualization/seeing_profile_functions.py b/stellarphot/visualization/seeing_profile_functions.py index 41b1e496..2e17e406 100644 --- a/stellarphot/visualization/seeing_profile_functions.py +++ b/stellarphot/visualization/seeing_profile_functions.py @@ -258,6 +258,18 @@ def find_hwhm(r, intensity): class RadialProfile: """ Class to hold radial profile information for a star. + Parameters + ---------- + + data : numpy array + Image data. + + x : int + x position of the star. + + y : int + y position of the star. + Attributes ---------- From bbeb3a0b2ed1a6b1805a4f2862eebb359e206a35 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 15:16:07 -0500 Subject: [PATCH 33/35] To save time, went through Matt's suggestions in PR#97 and manually applied edits. --- stellarphot/io/tess.py | 2 +- stellarphot/photometry.py | 2 +- stellarphot/source_detection.py | 6 +-- stellarphot/visualization/aij_plots.py | 2 +- .../visualization/comparison_functions.py | 51 +++++++++++-------- .../visualization/multi_night_plots.py | 16 +++--- .../visualization/seeing_profile_functions.py | 2 +- 7 files changed, 45 insertions(+), 36 deletions(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 02aad016..2a6da1d8 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -351,7 +351,7 @@ class TessTargetFile: file : str, optional The path to the target file. If not provided, a temporary file will be created. - aperture_server : str + aperture_server : str, optional The URL of the aperture server. default: https://www.astro.louisville.edu/ """ coord : SkyCoord diff --git a/stellarphot/photometry.py b/stellarphot/photometry.py index bb7dba40..dfda94ad 100644 --- a/stellarphot/photometry.py +++ b/stellarphot/photometry.py @@ -303,7 +303,7 @@ def add_to_photometry_table(phot, ccd, annulus, apertures, fname='', Gain, in electrons/ADU, of the camera that took the image. The gain is used in calculating the instrumental magnitude. - bjd_coords : astropy SkyCoord object + bjd_coords : `astropy.coordinates.SkyCoord` Coordinates of the object of interest in the Barycentric Julian Date frame. If not provided, the BJD column will not be added to the photometry table. diff --git a/stellarphot/source_detection.py b/stellarphot/source_detection.py index 3c3ea520..45cc744b 100644 --- a/stellarphot/source_detection.py +++ b/stellarphot/source_detection.py @@ -65,10 +65,10 @@ def compute_fwhm(ccd, sources, fwhm_estimate=5, Parameters ---------- - ccd : numpy.ndarray + ccd : `astropy.nddata.CCDData` The CCD Image array. - sources : astropy.table.Table + sources : `astropy.table.Table` An astropy table of the positions of sources in the image. fwhm_estimate : float, optional @@ -87,7 +87,7 @@ def compute_fwhm(ccd, sources, fwhm_estimate=5, ``False``, estimate the FWHM of each source by computing the second moments of its light distribution using photutils. - sky_per_pix_avg : float or array-like of float + sky_per_pix_avg : float or array-like of float, optional Sky background to subtract before centroiding. Returns diff --git a/stellarphot/visualization/aij_plots.py b/stellarphot/visualization/aij_plots.py index e3ffdca3..c44c6fbe 100644 --- a/stellarphot/visualization/aij_plots.py +++ b/stellarphot/visualization/aij_plots.py @@ -44,7 +44,7 @@ def seeing_plot(raw_radius, raw_counts, binned_radius, binned_counts, HWHM, Returns ------- - matplotlib.pyplot.figure + `matplotlib.pyplot.figure` The figure object containing the seeing plot. """ if radius is None: diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 5c4c6ac9..0b47ba12 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -100,7 +100,8 @@ def set_up(sample_image_for_finding_stars, directory_with_images='.'): def crossmatch_APASS2VSX(CCD, RD, vsx): - """Find APASS stars in FOV and matches APASS stars to VSX and APASS to input targets. + """ + Find APASS stars in FOV and matches APASS stars to VSX and APASS to input targets. Parameters ---------- @@ -244,7 +245,7 @@ def make_markers(iw, ccd, RD, vsx, ent, name_or_coord=None): Parameters ---------- - iw : `ginga.util.grc.RemoteClient` + iw : `astrowidgets.ImageWidget` Ginga widget. ccd : `astropy.nddata.CCDData` @@ -304,7 +305,7 @@ def wrap(imagewidget, outputwidget): Parameters ---------- - imagewidget : `ginga.util.grc.RemoteClient` + imagewidget : `astrowidgets.ImageWidget` Ginga widget. outputwidget : `ipywidgets.Output` @@ -479,8 +480,8 @@ def variables(self): Returns ------- - our_vsx : dict - Dictionary of the variables in the class. + our_vsx : `astropy.table.Table` + Table of the variables in the class. """ comp_table = self.generate_table() @@ -687,12 +688,13 @@ def _viewer(self): return box, iw def save_tess_files(self, button=None): - """ Save the TESS files. + """ + Save the TESS files. Parameters ---------- - button : ipywidgets.Button + button : `ipywidgets.Button`, optional The button that was clicked. Returns @@ -710,11 +712,12 @@ def save_tess_files(self, button=None): self.iw.save(self._zoom_name.value, overwrite=True) def generate_table(self): - """ Generate the table of stars to use for the aperture file. + """ + Generate the table of stars to use for the aperture file. Returns ------- - comp_table : astropy.table.Table + comp_table : `astropy.table.Table` Table of stars to use for the aperture file. """ try: @@ -760,7 +763,8 @@ def generate_table(self): return comp_table def show_labels(self): - """ Show the labels for the stars. + """ + Show the labels for the stars. Returns ------- @@ -798,7 +802,8 @@ def show_labels(self): self.iw._marker = original_mark def remove_labels(self): - """ Remove the labels for the stars. + """ + Remove the labels for the stars. Returns ------- @@ -818,15 +823,16 @@ def remove_labels(self): def show_circle(self, radius=2.5 * u.arcmin, pixel_scale=0.56 * u.arcsec / u.pixel): - """ Show a circle around the target. + """ + Show a circle around the target. Parameters ---------- - radius : float * u.arcmin, optional - Radius of circle. The default is 2.5*u.arcmin. - pixel_scale : float * u.arcsec / u.pixel, optional - Pixel scale of image. The default is 0.56*u.arcsec/u.pixel. + radius : `astropy.units.Quantity`, optional + Radius of circle. The default is ``2.5*u.arcmin``. + pixel_scale : `astropy.units.Quantity`, optional + Pixel scale of image. The default is ``0.56*u.arcsec/u.pixel``. Returns ------- @@ -846,7 +852,8 @@ def show_circle(self, self.iw.marker = orig_marker def remove_circle(self): - """Remove the circle around the target. + """ + Remove the circle around the target. Returns ------- @@ -860,7 +867,8 @@ def remove_circle(self): self.iw.remove_markers_by_name(marker_name=self._circle_name) def tess_field_view(self): - """ Show the whole TESS field of view including circle around target, but hide labels. + """ + Show the whole TESS field of view including circle around target, but hide labels. Returns ------- @@ -879,13 +887,14 @@ def tess_field_view(self): self.remove_labels() def tess_field_zoom_view(self, width=6 * u.arcmin): - """ Zoom in on the TESS field of view. + """ + Zoom in on the TESS field of view. Parameters ---------- - width : float * u.arcmin, optional - Width of field of view. The default is 6*u.arcmin. + width : `astropy.units.Quantity`, optional + Width of field of view. The default is ``6*u.arcmin``. Returns ------- diff --git a/stellarphot/visualization/multi_night_plots.py b/stellarphot/visualization/multi_night_plots.py index e17b28a9..1c49e689 100644 --- a/stellarphot/visualization/multi_night_plots.py +++ b/stellarphot/visualization/multi_night_plots.py @@ -20,25 +20,25 @@ def plot_magnitudes(mags=None, errors=None, times=None, Parameters ---------- - mags : array of floats + mags : array of floats, optional Magnitudes of source. - errors : array of floats + errors : array of floats, optional Errors on magnitudes. - times : array-like + times : array-like, optional Times of observations. - source : `~stellarphot.source.Source` + source : `~stellarphot.source.Source`, optional Source object. - night : float + night : float, optional Night of observations. - ref_mag : float + ref_mag : float, optional Reference magnitude of source. Default is 0. - alpha : float + alpha : float, optional Alpha value for error bars. Default is 0.25. y_range : tuple @@ -121,7 +121,7 @@ def multi_night(sources, unique_nights, night, mag_err : array-like Array of magnitude errors. - uniform_ylim : bool + uniform_ylim : bool, optional If True, use the median and median absolute deviation of the magnitudes to set the y-axis range for each source. Default is True. diff --git a/stellarphot/visualization/seeing_profile_functions.py b/stellarphot/visualization/seeing_profile_functions.py index 2e17e406..f750ec97 100644 --- a/stellarphot/visualization/seeing_profile_functions.py +++ b/stellarphot/visualization/seeing_profile_functions.py @@ -43,7 +43,7 @@ def set_keybindings(image_widget, scroll_zoom=False): image_widget : astrowidgets.ImageWidget Image widget on which to set the key bindings. - scroll_zoom : bool + scroll_zoom : bool, optional If True, zooming can be done by scrolling the mouse wheel. Default is False. From 4cf22331c349acd5cb1d56d8a2abb8cd450ebbe3 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Mon, 12 Jun 2023 15:20:03 -0500 Subject: [PATCH 34/35] Removed unneeded variable new_time in photometry. --- stellarphot/photometry.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/stellarphot/photometry.py b/stellarphot/photometry.py index dfda94ad..47a842da 100644 --- a/stellarphot/photometry.py +++ b/stellarphot/photometry.py @@ -718,7 +718,7 @@ def find_times(phot_column, exposure, ra, dec, Returns ------- - new_time : numpy array + numpy array array of times in barycentric Julian date """ @@ -730,9 +730,7 @@ def find_times(phot_column, exposure, ra, dec, times_tdb = times.tdb time_barycenter = times_tdb + ltt_bary - #adjust to midpoint of exposure + # Adjust to midpoint of exposure bary_time = time_barycenter + exposure / 2 - new_time = bary_time.jd - - return new_time \ No newline at end of file + return bary_time.jd \ No newline at end of file From d2303880ee38e35e2ee5d8f00a3ce4a83a414fc3 Mon Sep 17 00:00:00 2001 From: Juan Cabanela Date: Tue, 13 Jun 2023 11:17:11 -0500 Subject: [PATCH 35/35] Update stellarphot/io/tess.py Accepted this suggestion by Matt on PR#97. Co-authored-by: Matt Craig --- stellarphot/io/tess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index 2a6da1d8..c9951daa 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -83,7 +83,7 @@ def from_header(cls, header, telescope_code="", planet=0): Parameters ---------- - header: astropy.io.fits.Header + header: `astropy.io.fits.Header` The FITS header to parse telescope_code: str