diff --git a/stellarphot/__init__.py b/stellarphot/__init__.py index ceb5cd2b..c4aa5244 100644 --- a/stellarphot/__init__.py +++ b/stellarphot/__init__.py @@ -17,6 +17,10 @@ class UnsupportedPythonError(Exception): + """ + Wraps an exception to raise if a user tries to use stellarphot + with an unsupported version of Python. + """ pass diff --git a/stellarphot/analysis/exotic.py b/stellarphot/analysis/exotic.py index f0769d73..325f64d7 100644 --- a/stellarphot/analysis/exotic.py +++ b/stellarphot/analysis/exotic.py @@ -99,7 +99,7 @@ def make_checker(indicator_widget, value_widget): Parameters ---------- - indicator_widget : MyCheck widget + indicator_widget : `~stellarphot.analysis.MyValid` widget The widget that indicates to the user whether or not the value is reasonable. @@ -143,7 +143,7 @@ def validate_exposure_time(indicator_widget, value_widget): Parameters ---------- - indicator_widget : `MyValid` widget + indicator_widget : `~stellarphot.analysis.MyValid` widget The widget that indicates to the user whether or not the value is reasonable. @@ -219,10 +219,10 @@ def populate_TOI_boxes(toi, exotic_widget): Parameters ---------- - toi : stellarphot.io.tess.TOI + toi : `~stellarphot.io.tess.TOI` Information about the TIC object. - exotic_widget: ipywidget + exotic_widget: ipywidget This widget should be generated by exotic_settings_widget. Returns diff --git a/stellarphot/analysis/transit_fitting.py b/stellarphot/analysis/transit_fitting.py index 8f2258e6..95a4d251 100644 --- a/stellarphot/analysis/transit_fitting.py +++ b/stellarphot/analysis/transit_fitting.py @@ -33,8 +33,10 @@ class VariableArgsFitter(LevMarLSQFitter): """ - 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. + 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): super().__init__() @@ -89,56 +91,55 @@ def __call__(self, model, *args, weights=None, class TransitModelFit: - """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. + """ + Transit model fits to observed light curves. 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. + BIC : float + Bayesian Information Criterion for the fit. This is calculated + after the fit is performed. data : array-like Observed fluxes. Must be set before fitting. - model : astropy.modeling.Model + 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. + n_fit_parameters : int + Number of parameters that were fit. This is calculated after the + fit is performed. + + spp : array-like + Sky per pixel at each time. Must be set before fitting. + + times : array-like + Times at which the light curve is observed. Must be set before + fitting. + + width : array-like + Width of the star in pixels at each time. Must be set before fitting. + 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): + """ + Initialize the transit model fit. + + Parameters + ---------- + batman_params : batman.TransitParams + Parameters for the batman transit model. If not provided, the + default parameters will be used. + """ self._batman_params = batman.TransitParams() self._set_default_batman_params() self._times = None @@ -486,6 +487,28 @@ def _detrend(self, model, detrend_by): return detrended def data_light_curve(self, data=None, detrend_by=None): + """ + Function to return data light curve, optionally detrended by one or + more parameters. + + Parameters + ---------- + + data : array-like, optional + Data to use for calculating the light curve. If not provided, + the data 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 + ------- + + data : array-like + Data light curve, detrended if requested. + """ data = data if data is not None else self.data if detrend_by is not None: @@ -497,18 +520,18 @@ 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 diff --git a/stellarphot/core.py b/stellarphot/core.py index 94ca00fc..edaeef17 100644 --- a/stellarphot/core.py +++ b/stellarphot/core.py @@ -7,23 +7,19 @@ class Camera: """ A class to represent a CCD-based camera. - Parameters + Attributes ---------- + 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`. + 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 : `astropy.quantity.Quantity` - 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 - ---------- - 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. + dark_current : `astropy.quantity.Quantity` + The dark current of the camera in units such that, when multiplied + by exposure time, the unit matches the unit of the `read_noise`. Notes ----- @@ -48,6 +44,22 @@ class Camera: def __init__(self, gain=1.0 * u.electron / u.adu, read_noise=1.0 * u.electron, dark_current=0.01 * u.electron / u.second): + """ + Initializes a Camera object instance. + + Parameters + ---------- + 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 : `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 such that, when multiplied by + exposure time, the unit matches the unit of the `read_noise`. + """ super().__init__() self.gain = gain self.read_noise = read_noise diff --git a/stellarphot/differential_photometry/aij_rel_fluxes.py b/stellarphot/differential_photometry/aij_rel_fluxes.py index 40c4566f..910e7a13 100644 --- a/stellarphot/differential_photometry/aij_rel_fluxes.py +++ b/stellarphot/differential_photometry/aij_rel_fluxes.py @@ -37,19 +37,19 @@ def calc_aij_relative_flux(star_data, comp_stars, the `star_data` and the position in the `comp_stars` table is too large. - in_place : ``bool``, optional + in_place : bool, optional If ``True``, add new columns to input table. Otherwise, return new table with those columns added. - coord_column : ``str``, optional + coord_column : str, optional If provided, use this column to match comparison stars to coordinates. If not provided, the coordinates are generated with SkyCoord. - flux_column_name : ``str``, optional + flux_column_name : str, optional If provided, use this column to find flux. If not provided, the column 'aperture_net_flux' is used. - star_id_column : ``str``, optional + star_id_column : str, optional Name of the column that provides a unique identifier for each comparison star. diff --git a/stellarphot/differential_photometry/catalog_search.py b/stellarphot/differential_photometry/catalog_search.py index 1fedb172..9506b6ad 100644 --- a/stellarphot/differential_photometry/catalog_search.py +++ b/stellarphot/differential_photometry/catalog_search.py @@ -26,9 +26,9 @@ def in_frame(frame_wcs, coordinates, padding=0): Parameters ---------- - frame_wcs : astropy WCS object + frame_wcs : `astropy.wcs.WCS` WCS for the image. - coordinates : astropy.coordinates.SkyCoord + coordinates : `astropy.coordinates.SkyCoord` Coordinate(s) whose position will be checked to see if they are in the field of view. padding : int, optional @@ -39,7 +39,7 @@ def in_frame(frame_wcs, coordinates, padding=0): Returns ------- - numpy.ndarray of bool + `numpy.ndarray` of bool One value for each input coordinate; values are ``True`` if the coordinate was in the field of view, ``False`` otherwise. @@ -63,7 +63,7 @@ def catalog_search(frame_wcs_or_center, shape, desired_catalog, Parameters ---------- - frame_wcs : astropy.wcs.WCS + frame_wcs : `astropy.wcs.WCS` WCS of the image of interest. shape : tuple of int @@ -95,7 +95,7 @@ def catalog_search(frame_wcs_or_center, shape, desired_catalog, Returns ------- - astropy.table.Table + `astropy.table.Table` Table of catalog information for stars in the field of view. """ @@ -133,10 +133,12 @@ def catalog_clean(catalog, remove_rows_with_mask=True, Parameters ---------- - catalog : astropy.Table + catalog : `astropy.table.Table` Table of catalog information. There are no restrictions on the columns. + remove_rows_with_mask : bool, optional If ``True``, remove rows in which one or more of the values is masked. + other_restrictions: dict, optional Key/value pairs in which the key is the name of a column in the catalog and the value is the criteria that values in that column @@ -147,7 +149,7 @@ def catalog_clean(catalog, remove_rows_with_mask=True, Returns ------- - astropy.table.Table + `astropy.table.Table` Table of catalog information for stars in the field of view. """ @@ -191,7 +193,7 @@ def find_apass_stars(image_or_center, Get APASS data from Vizer. Parameters - --------- + ---------- image_or_center : `astropy.nddata.CCDData` or `astropy.coordinates.SkyCoord` Either an image with a WCS (from which the RA/Dec will be extracted) or coordinate of @@ -239,7 +241,8 @@ def find_apass_stars(image_or_center, def find_known_variables(image): - '''Get any known variable stars in image field from the VSX catalog. + """ + Get any known variable stars in image field from the VSX catalog. Parameters ---------- @@ -252,7 +255,7 @@ def find_known_variables(image): 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') @@ -270,7 +273,7 @@ def filter_catalog(catalog, **kwd): Parameters ---------- - catalog : astropy Table + catalog : `astropy.table.Table` Table whose values are to be filtered. kwd : key/value pairs, e.g. ``e_r_mag=0.1`` @@ -280,7 +283,7 @@ def filter_catalog(catalog, **kwd): Returns ------- - numpy.ndarray of bool + `numpy.ndarray` of bool One value for each row in the catalog; values are ``True`` if the row meets the criteria, ``False`` otherwise. """ diff --git a/stellarphot/differential_photometry/magnitude_transforms.py b/stellarphot/differential_photometry/magnitude_transforms.py index e0e95ea3..be08ea5c 100644 --- a/stellarphot/differential_photometry/magnitude_transforms.py +++ b/stellarphot/differential_photometry/magnitude_transforms.py @@ -27,15 +27,17 @@ def f(X, a, b, c, d, z): 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 + `numpy.ndarray` Array of calibrated magnitudes. """ mag_inst, color = X @@ -51,14 +53,14 @@ def get_cat(image): Parameters ---------- - image : astropy.table.Table + image : `astropy.table.Table` Table containing the image information. Must have columns ``RA`` and ``Dec``. Returns ------- - astropy.table.Table + `astropy.table.Table` Table containing the APASS catalog entries within 1 degree of first object in Astropy table. """ @@ -75,7 +77,8 @@ def get_cat(image): def opts_to_str(opts): - """Convert the options from a fit to a string. + """ + Convert the options from a fit to a string. Parameters ---------- @@ -97,16 +100,17 @@ def opts_to_str(opts): def calc_residual(new_cal, catalog): - """Calculate the standard deviations of the residuals between + """ + Calculate the standard deviations of the residuals between the new calibrated magnitude and the catalog magnitude. Parameters ---------- - new_cal : numpy.ndarray + new_cal : `numpy.ndarray` New calibrated magnitudes. - catalog : numpy.ndarray + catalog : `numpy.ndarray` Catalog magnitudes. Returns @@ -123,30 +127,31 @@ def calc_residual(new_cal, catalog): def filter_transform(mag_data, output_filter, g=None, r=None, i=None, transform=None): - ''' + """ Transform SDSS magnitudes to BVRI using either the transforms from Jester et al or Ivezic et al. Parameters ---------- - mag_data : astropy.table.Table + mag_data : `astropy.table.Table` Table containing ``g``, ``r`` and ``i`` magnitudes (or at least) those required to transform to the desired output filter. + output_filter : 'B', 'V', 'R' or 'I' Filter for which magnitude should be calculated. Note that *case matters* here. + g, r, i : str Name of column in table for that magnitude. + transform : 'jester' or 'ivezic' Transform equations to use. - Description: This function impliments the transforms in - 'A Comparison of SDSS Standard Returns ------- - astropy.table.Column + `astropy.table.Column` Output transformed magnitudes as a table column Notes @@ -161,7 +166,7 @@ def filter_transform(mag_data, output_filter, The Future Of Photometric, Spectrophotometric And Polarimetric Standardization, ASP Conference Series 364, p. 165 (2007) http://aspbooks.org/custom/publications/paper/364-0165.html - ''' + """ supported_transforms = ['jester', 'ivezic'] if transform not in supported_transforms: raise ValueError('Transform {} is not known. Must be one of ' @@ -236,37 +241,47 @@ def calculate_transform_coefficients(input_mag, catalog_mag, color, Parameters ---------- - input_mag : numpy array or astropy Table column + input_mag : `numpy.ndarray` or `astropy.table.Column` Input magnitudes; for example, instrumental magnitudes. - catalog_mag : numpy array or astropy Table column + + catalog_mag : `numpy.ndarray` or `astropy.table.Column` Catalog (or reference) magnitudes; the magnitudes to which the input_mag will eventually be transformed. - color : numpy array or astropy Table column + + color : `numpy.ndarray` or `astropy.table.Column` Colors to use in determining transform coefficients. - input_mag_error : numpy array or astropy Table column, optional + + input_mag_error : `numpy.ndarray` or `astropy.table.Column`, optional Error in input magnitudes. Default is zero. - catalog_mag_error : numpy array or astropy Table column, optional + + catalog_mag_error : `numpy.ndarray` or `astropy.table.Column`, optional Error in catalog magnitudes. Default is zero. + faintest_mag_for_transform : float, optional If this is not ``None``, the magnitude of the faintest catalog stars to use in computing transform coefficients. + order : int, optional Order of the polynomial fit to use in correcting for color. + sigma : float, optional Value of sigma to use to reject outliers while fitting using sigma clipping. + gain : float, optional If not ``None``, adjust the instrumental magnitude by -2.5 * log10(gain), i.e. gain correct the magnitude. + verbose : bool, optional If ``True``, print some diagnostic information. + extended_output : bool, optional If ``True``, return additional information. Returns ------- - filtered_data : `~numpy.ma.core.MaskedArray` + filtered_data : `numpy.ma.core.MaskedArray` The data, with the mask set ``True`` for the data that was *omitted* from the fit. @@ -375,14 +390,14 @@ def transform_magnitudes(input_mags, catalog, Parameters ---------- - input_mags : astropy Table + input_mags : `astropy.table.Table` Table which contains a column with instrumental magnitudes, i.e. -2.5 * log10(net_counts / exposure_time). - catalog : astropy Table + catalog : `astropy.table.Table` Table containing reference catalog of magnitudes and colors. - transform_catalog : astropy Table + transform_catalog : `astropy.table.Table` Table containing the reference catalog of magnitudes and colors to use in determining the transform coefficients. Can be the same table as ``catalog`` if desired. @@ -417,17 +432,17 @@ def transform_magnitudes(input_mags, catalog, Returns ------- - our_cat_mags : astropy Table column + our_cat_mags : `astropy.table.Column` The calculated catalog magnitudes for the stars in ``input_mags``. - good_match_all : numpy array + good_match_all : `numpy.ndarray` Boolean array indicating which stars in ``input_mags`` have a match in the catalog. 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``. Warning: This returns a namedtuple if the fit + of the term ``x**i``. Warning: This returns a namedtuple if the fit fails. """ catalog_all_coords = SkyCoord(catalog['RAJ2000'], @@ -502,7 +517,7 @@ def transform_to_catalog(observed_mags_grouped, obs_mag_col, obs_filter, Parameters ---------- - observed_magnitudes_grouped : astropy.table.Table group + observed_magnitudes_grouped : `astropy.table.Table` An astropy table, grouped by whatever you want that sepearates the data into data from just one image. BJD of the center of the observatory is one reasonable choice @@ -526,13 +541,13 @@ def transform_to_catalog(observed_mags_grouped, obs_mag_col, obs_filter, ``('r_mag', 'i_mag')`` then the calculated color will be the ``r_mag`` column minus the ``i_mag`` column. - a_delta, b_delta, c_delta, d_delta : flt, optional + a_delta, b_delta, c_delta, d_delta : float, optional Range allowed in fitting for each of the parameters ``a``, ``b``, ``c``, and ``d``. Use ``1E-6`` to fix a parameter. - a_cen : flt, optional + a_cen : float, optional Center of range for the fitting parameter ``a``. - zero_point_range : tuple of flt, optional + zero_point_range : tuple of float, optional Range to which the value of the zero point is restricted in fitting to observed magnitudes. in_place : bool, optional @@ -548,7 +563,7 @@ def transform_to_catalog(observed_mags_grouped, obs_mag_col, obs_filter, Returns ------- - astropy.table.Table + `astropy.table.Table` Table containing the calibrated magnitudes and the fit parameters. """ diff --git a/stellarphot/io/aij.py b/stellarphot/io/aij.py index 84f587fd..316a9b1d 100644 --- a/stellarphot/io/aij.py +++ b/stellarphot/io/aij.py @@ -14,8 +14,30 @@ class ApertureAIJ: """ Represents the aperture information AstroImageJ saves. + + Attributes + ---------- + backplane : bool + Not sure what this does but stellarphot doesn't use it. Default: False + + radius : float + Aperture radius. Default: 15.0 + + rback1 : float + Inner annulus radius. Default: 27.0 + + rback2 : float + Outer annulus radius. Default: 41.0 + + removebackstars : bool + Whether to remove stars in the annulus from the photometry. Default: True + """ def __init__(self): + """ + Initialize and set default values for the attributes of the aperture object instance. + """ + # Outer annulus radius self.rback2 = 41.0 @@ -53,9 +75,48 @@ def __eq__(self, other): class MultiApertureAIJ: """ - Class to represent the multi-aperture information that AstroImageJ saves + Multi-aperture information that AstroImageJ saves. + + Attributes + ---------- + + absmagapertures : list + List of absolute magnitudes of the apertures. + + apfwhmfactor : float + Factor to multiply the aperture radius by relative to the FWHM. Default: 1.4 + + centroidstar : list + List of booleans indicating whether the aperture is a centroid star. + + decapertures : list + List of Declinations of the apertures. + + isalignstar : list + List of booleans indicating whether the aperture is an alignment star. + + isrefstar : list + List of booleans indicating whether the aperture is a reference star. + + naperturesmax : float + Maximum number of apertures. Default: 1000 + + raapertures : list + List of Right Ascensions of the apertures. + + usevarsizeap : bool + Whether to use variable size apertures. Default: False + + xapertures : list + List of x positions of the apertures. + + yapertures : list + List of y positions of the apertures. """ def __init__(self): + """ + Initialize and set default values for the attributes of the multi-aperture object instance. + """ # Default values for these chosen to match AIJ defaults # They are not used by stellarphot self.naperturesmax = 1000 @@ -133,8 +194,19 @@ class ApertureFileAIJ: """ Class to represent AstroImageJ aperture file. + Attributes + ---------- + + aperture : `~stellarphot.io.ApertureAIJ` + Aperture information. +` + multiaperture : `~stellarphot.io.MultiApertureAIJ` + Multi-aperture information. """ def __init__(self): + """ + Initialize the AstroImageJ aperture file instance. + """ self.aperture = ApertureAIJ() self.multiaperture = MultiApertureAIJ() @@ -179,7 +251,7 @@ def write(self, file): @classmethod def read(cls, file): """ - Generate aperture object from file. Happily, each line is basically a path + Generate aperture object from file. Each line is basically a path to an attribute name followed by a value. Parameters @@ -221,7 +293,7 @@ def from_table(cls, aperture_table, default_centroidstar=True, y_size=4096): """ - Create an `stellarphot.io.ApertureFileAIJ` from a stellarphot aperture + Create an `~stellarphot.io.ApertureFileAIJ` from a stellarphot aperture table and info about the aperture sizes. Parameters @@ -238,7 +310,13 @@ def from_table(cls, aperture_table, outer_annulus : number Outer radius of annulus. + + Returns + ------- + apAIJ: `~stellarphot.io.ApertureFileAIJ` + ApertureFileAIJ object representing the aperture table. """ + # Create the instance apAIJ = cls() @@ -433,62 +511,74 @@ class Star(object): """ A class for storing photometry for a single star. + Parameters + ---------- + + table : `astropy.table.Table` + Table of photometry for a single star. + + id_num : int + ID number of the star. + Attributes ---------- - airmass : `~astropy.units.Quantity` + airmass : `astropy.units.Quantity` Airmass at the time of observation. - counts : `~astropy.units.Quantity` - Net counts in the aperture. + bjd_tdb : `astropy.units.Quantity` + Midpoint of the exposure as barycentric Julian date in Barycentric Dynamical Time. - ra : `~astropy.units.Quantity` - Right ascension of the star. + counts : `astropy.units.Quantity` + Net counts in the aperture. - dec : `~astropy.units.Quantity` + dec : `astropy.units.Quantity` Declination of the star. - error : `~astropy.units.Quantity` + 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. + exposure : `astropy.units.Quantity` + Exposure time of the observation. - jd_utc_start : `~astropy.units.Quantity` - Julian date of the start of the observation. + id: int + ID number of the star. - mjd_utc_start : `~astropy.units.Quantity` - Modified Julian date of the start of the observation. + jd_utc_end : `astropy.units.Quantity` + Julian date of the end of the observation. - jd_utc_mid : `~astropy.units.Quantity` + 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_start : `astropy.units.Quantity` + Julian date of the start of the observation. - jd_utc_end : `~astropy.units.Quantity` - Julian date of the end of the observation. + magnitude : `astropy.units.Quantity` + Magnitude of the star. + + magnitude_error : `astropy.units.Quantity` + Error in the magnitude of the star. - mjd_utc_end : `~astropy.units.Quantity` + mjd_utc_end : `astropy.units.Quantity` Modified Julian date of the end of the observation. - exposure : `~astropy.units.Quantity` - Exposure time of the observation. + mjd_utc_mid : `astropy.units.Quantity` + Modified Julian date of the middle of the observation. - magnitude : `~astropy.units.Quantity` - Magnitude of the star. + mjd_utc_start : `astropy.units.Quantity` + Modified Julian date of the start of the observation. - snr : `~astropy.units.Quantity` - Signal-to-noise ratio of the star. + peak : `astropy.units.Quantity` + Peak counts in the aperture. - magnitude_error : `~astropy.units.Quantity` - Error in the magnitude of the star. + ra : `astropy.units.Quantity` + Right ascension of the star. + + sky_per_pixel : `astropy.units.Quantity` + Sky brightness per pixel. - bjd_tdb : `~astropy.units.Quantity` - Barycentric Dynamical Time taking into account relativity. + snr : `astropy.units.Quantity` + Signal-to-noise ratio of the star. """ def __init__(self, table, id_num): self._table = table diff --git a/stellarphot/io/tess.py b/stellarphot/io/tess.py index c9951daa..bacd7c6d 100644 --- a/stellarphot/io/tess.py +++ b/stellarphot/io/tess.py @@ -64,7 +64,7 @@ class TessSubmission: apertures: str The name of the apertures file, e.g. "TIC123456789-01_20200101_SRO_Ic_measurements.apertures" - tic_coord: `astropycoordinates.SkyCoord` + tic_coord: `astropy.coordinates.SkyCoord` The SkyCoord of the target, from the TIC catalog. """ telescope_code: str @@ -213,26 +213,11 @@ 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, optional - The path to the TOI table. If not provided, the default table will be downloaded. - - allow_download: bool, optional - 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. + coord: `astropy.coordinates.SkyCoord` + The coordinates of the target. depth: float The transit depth of the target. @@ -240,6 +225,12 @@ class TOI: depth_error: float The uncertainty in the transit depth. + duration: float + The duration of the transit. + + duration_error: float + The uncertainty in the duration of the transit. + epoch: float The epoch of the transit. @@ -252,19 +243,32 @@ class TOI: 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. + tess_mag: float + The TESS magnitude of the target. - coord: SkyCoord - The coordinates of the target. + tess_mag_error: float + The uncertainty in the TESS magnitude. tic_id: int The TIC ID of the target. """ def __init__(self, tic_id, toi_table=DEFAULT_TABLE_LOCATION, allow_download=True): + """ + Initialize a TOI object. + + Parameters + ---------- + + tic_id: int + The TIC ID of the target. + + toi_table: str, optional + The path to the TOI table. If not provided, the default table will be downloaded. + + allow_download: bool, optional + Whether to allow the default table to be downloaded if it is not found. + + """ path = Path(toi_table) if not path.is_file(): if not allow_download: @@ -353,6 +357,32 @@ class TessTargetFile: aperture_server : str, optional The URL of the aperture server. default: https://www.astro.louisville.edu/ + + + Attributes + ---------- + + aperture_server : str + The URL of the aperture server. + + coord : `astropy.coordinates.SkyCoord` + The coordinates 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. + + magnitude : float + The magnitude of the target. + + target_file : str + The path to the target file. + + target_table : `astropy.table.Table` + The target table. + """ coord : SkyCoord magnitude : float diff --git a/stellarphot/photometry.py b/stellarphot/photometry.py index 47a842da..dd2f86a7 100644 --- a/stellarphot/photometry.py +++ b/stellarphot/photometry.py @@ -33,12 +33,12 @@ def photutils_stellar_photometry(ccd_image, sources, Parameters ---------- - ccd_image : `~ccdproc.CCDData` + ccd_image : `ccdproc.CCDData` Image on which to perform aperture photometry. - sources : `~astropy.table.Table` + sources : `astropy.table.Table` Table of extracted sources. Assumed to be the output of - `~photutils.daofind()` source extraction function. + `photutils.daofind()` source extraction function. aperture_radius : float Radius of aperture(s) in pixels. @@ -64,7 +64,7 @@ def photutils_stellar_photometry(ccd_image, sources, Returns ------- - phot_table : `~astropy.table.Table` + phot_table : `astropy.table.Table` Astropy table with columns for flux, x/y coordinates of center, RA/dec coordinates of center, sky background per pixel, net flux, aperture and annulus radii used, and flux error. @@ -226,7 +226,7 @@ def clipped_sky_per_pix_stats(data, annulus, sigma=5, iters=5): data : `astropy.nddata.CCDData` CCD image on which the annuli are defined. - annulus : photutils annulus + annulus : `photutils.CircularAnnulus` One or more annulus (of any shape) from photutils. sigma : float, optional @@ -280,17 +280,17 @@ def add_to_photometry_table(phot, ccd, annulus, apertures, fname='', Parameters ---------- - phot : astropy.table.Table + phot : `astropy.table.Table` An astropy Table with raw photometry data in it (generated by `photutils.aperture_photometry`). - ccd : astropy.nddata.CCDData + ccd : `astropy.nddata.CCDData` Image on which photometry is being done. - annulus : photutils annulus + annulus : `photutils.CircularAnnulus` One or more annulus (of any shape) from photutils. - apertures : photutils apertures + apertures : `photutils.CircularAperture` One or more apertures (of any shape) from photutils. fname : str, optional @@ -442,7 +442,7 @@ def photometry_on_directory(directory_with_images, object_of_interest, star_ids : array-like Unique identifier for each source in ``star_locs``. - camera : `stellarphot.Camera` object + camera : `~stellarphot.Camera` Camera object which has gain, read noise and dark current set. gain : float @@ -606,14 +606,15 @@ 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. + """ + 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 \left(1 + \frac{A}{B}\right)\cdot \left[ G\cdot S + D \cdot t + R^2 + (0.289 G)^2\right]} + \\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, @@ -622,8 +623,9 @@ def calculate_noise(gain=1.0, read_noise=0.0, dark_current_per_sec=0.0, Note: The :math:`(0.289 G)^2` term is "digitization noise" and is optional. - Parameters: - ----------- + Parameters + ---------- + gain : float, optional Gain of the CCD. In units of electrons per DN. @@ -651,9 +653,10 @@ def calculate_noise(gain=1.0, read_noise=0.0, dark_current_per_sec=0.0, include_digitization : bool, optional Whether to include the digitization noise. Defaults to False. - Returns: - -------- - float + Returns + ------- + + noise : float The noise in the photometric measurement. """ @@ -695,10 +698,10 @@ def find_times(phot_column, exposure, ra, dec, Parameters ---------- - phot_column : astropy Table column or numpy array + phot_column : `astropy.table.Column` or numpy array numpy array or column of observation dates from the photometry table - exposure : float; optional + exposure : float, optional exposure time in seconds RA : float @@ -707,10 +710,10 @@ def find_times(phot_column, exposure, ra, dec, Dec : float Declination in degree units - latitude : float; optional + latitude : float, optional latitude of the observatory in degrees North, default is for Paul P. Feder Observatory - longitude : float; optional + longitude : float, optional longitude of the observatory in degree East of Greenwich (0 to 360), default is for Paul P. Feder Observatory diff --git a/stellarphot/source_detection.py b/stellarphot/source_detection.py index 45cc744b..fb2d6c8c 100644 --- a/stellarphot/source_detection.py +++ b/stellarphot/source_detection.py @@ -33,7 +33,7 @@ def _fit_2dgaussian(data): Returns ------- - gfit : astropy.modeling.Model + gfit : `astropy.modeling.Model` The best-fit 2D Gaussian model. """ props = data_properties(data - np.min(data)) @@ -60,7 +60,8 @@ 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. + """ + Computes the FWHM in both x and y directions of sources in an image. Parameters ---------- @@ -150,7 +151,7 @@ def source_detection(ccd, fwhm=8, sigma=3.0, iters=5, Parameters ---------- - ccd : numpy.ndarray + ccd : `astropy.nddata.CCDData` The CCD Image array. fwhm : float, optional @@ -177,9 +178,9 @@ def source_detection(ccd, fwhm=8, sigma=3.0, iters=5, Returns ------- - sources - an astropy table of the positions of sources in the image. - If `find_fwhm` is ``True``, includes a column called ``FWHM``. + sources: `astropy.table.Table` + A table of the positions of sources in the image. If `find_fwhm` is + ``True``, includes a column called ``FWHM``. """ mean, median, std = sigma_clipped_stats(ccd, sigma=sigma, maxiters=iters) daofind = DAOStarFinder(fwhm=fwhm, threshold=threshold * std) diff --git a/stellarphot/visualization/aij_plots.py b/stellarphot/visualization/aij_plots.py index c44c6fbe..673c7d76 100644 --- a/stellarphot/visualization/aij_plots.py +++ b/stellarphot/visualization/aij_plots.py @@ -109,22 +109,22 @@ def plot_predict_ingress_egress(ingress_time, egress_time, end_line=1, """ Parameters ---------- - ingress_time : number + ingress_time : float the beginning of an exoplanet transit - egress_time : number + egress_time : float the end of an exoplanet transit - end_line : number + end_line : float offset to move the vertical lines - ingress_x_pos : number + ingress_x_pos : float offset to center ingress label - egress_x_pos : number + egress_x_pos : float offset to center egress label - labels_y_pos : number + labels_y_pos : float offset to move ingress and egress labels Returns diff --git a/stellarphot/visualization/comparison_functions.py b/stellarphot/visualization/comparison_functions.py index 0b47ba12..9137ea75 100644 --- a/stellarphot/visualization/comparison_functions.py +++ b/stellarphot/visualization/comparison_functions.py @@ -59,7 +59,8 @@ def read_file(radec_file): def set_up(sample_image_for_finding_stars, directory_with_images='.'): - """Read in sample image and find known variables in the field of view. + """ + Read in sample image and find known variables in the field of view. Parameters ---------- @@ -151,7 +152,8 @@ def crossmatch_APASS2VSX(CCD, RD, vsx): 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 @@ -203,7 +205,8 @@ 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 ---------- @@ -240,7 +243,8 @@ def in_field(apass_good_coord, ccd, apass, good_stars): def make_markers(iw, ccd, RD, vsx, ent, name_or_coord=None): - """Add markers for APASS, TESS targets, VSX. Also center on object/coordinate. + """ + Add markers for APASS, TESS targets, VSX. Also center on object/coordinate. Parameters ---------- @@ -300,7 +304,8 @@ def make_markers(iw, ccd, RD, vsx, ent, name_or_coord=None): def wrap(imagewidget, outputwidget): - """Utility function to let you click to select/deselect comparisons. + """ + Utility function to let you click to select/deselect comparisons. Parameters ---------- @@ -357,34 +362,8 @@ 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. + """ + A class to store an instance of the comparison viewer. Attributes ---------- @@ -401,7 +380,7 @@ class ComparisonViewer: targets_from_file : str File with target information. - tess_submission : `tess_stars2px.TessStars2Px` + tess_submission : `~stellarphot.io.TessSubmission` Instance of the TESS submission class. target_coord : `astropy.coordinates.SkyCoord` @@ -425,6 +404,36 @@ def __init__(self, targets_from_file=None, object_coordinate=None, aperture_output_file=None): + """ + Initializes an instance of the ComparisonViewer class. + + Parameters + ---------- + + file : str, optional + File to open. Defaults to "". + + directory : str, optional + Directory to open file from. Defaults to '.'. + + target_mag : float, optional + Magnitude of the target. Defaults to 10. + + bright_mag_limit : float, optional + Bright magnitude limit for APASS stars. Defaults to 8. + + dim_mag_limit : float, optional + Dim magnitude limit for APASS stars. Defaults to 17. + + targets_from_file : str, optional + File with target information. Defaults to None. + + object_coordinate : `astropy.coordinates.SkyCoord`, optional + Coordinates of the target. Defaults to None. + + aperture_output_file : str, optional + File to save aperture information to. Defaults to None. + """ self._label_name = 'labels' self._circle_name = 'target circle' @@ -451,7 +460,7 @@ def __init__(self, def _init(self): """ - Some initialization needs to be defered until a file is chosen. + Handles aspects of initialization that need to be defered until a file is chosen. """ if self.tess_submission is not None: self._tess_object_info.layout.visibility = "visible" @@ -475,7 +484,8 @@ def _init(self): @property def variables(self): - """ Return a dictionary of the variables in the class. + """ + Return a dictionary of the variables in the class. Returns ------- @@ -831,6 +841,7 @@ def show_circle(self, 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``. diff --git a/stellarphot/visualization/fits_opener.py b/stellarphot/visualization/fits_opener.py index 941ee24e..a1dfe49c 100644 --- a/stellarphot/visualization/fits_opener.py +++ b/stellarphot/visualization/fits_opener.py @@ -15,15 +15,16 @@ class FitsOpener: Attributes ---------- + + ccd : `astropy.nddata.CCDData` + The selected FITS file as a CCDData object. + 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. @@ -32,6 +33,20 @@ class FitsOpener: selected file changes. """ def __init__(self, title="Choose an image", filter_pattern=None, **kwargs): + """ + Initializes an instance of the FitsOpener class, which is a wrapper around + the `ipyfilechooser.FileChooser` widget that (if no `filter_pattern` is given) + defaults to showing only FITS files. + + Parameters + ---------- + + title : str, optional + The title of the FileChooser widget. The default is "Choose an image". + + filter_pattern : str, optional + The filter pattern to use for the FileChooser widget. The default is None, + """ self._fc = FileChooser(title=title, **kwargs) if not filter_pattern: self._fc.filter_pattern = ['*.fit*', '*.fit*.[bg]z'] @@ -115,7 +130,7 @@ def load_in_image_widget(self, image_widget): def set_file(self, file, directory=None): """ - Set the selected file of the ``FileChooser`` to be the input file. + Set the selected file of the `ipyfilechooser.FileChooser` to be the input file. Parameters ---------- @@ -126,7 +141,7 @@ def set_file(self, file, directory=None): directory : Path-like, optional Directory the file is in. The default value is the current directory of the - ``FileChooser``. + `ipyfilechooser.FileChooser`. """ if directory is None: directory = self._fc.selected_path diff --git a/stellarphot/visualization/multi_night_plots.py b/stellarphot/visualization/multi_night_plots.py index 1c49e689..88b20a7c 100644 --- a/stellarphot/visualization/multi_night_plots.py +++ b/stellarphot/visualization/multi_night_plots.py @@ -14,7 +14,8 @@ 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 @@ -98,7 +99,8 @@ 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 ---------- diff --git a/stellarphot/visualization/photometry_widget_functions.py b/stellarphot/visualization/photometry_widget_functions.py index 2a89ae23..771bb302 100644 --- a/stellarphot/visualization/photometry_widget_functions.py +++ b/stellarphot/visualization/photometry_widget_functions.py @@ -14,22 +14,28 @@ class PhotometrySettings: 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` + aperture_locations : `pathlib.Path` The path to the file containing the aperture locations. aperture_radius : int The radius of the aperture. + box : `ipywidgets.VBox` + The box containing the widgets. + + ifc : `ccdproc.ImageFileCollection` + The image file collection for the images. + + image_folder : `pathlib.Path` + The path to the folder containing the images. + object_name : str The name of the object. """ def __init__(self): + """ + Initialize an instance of the PhotometrySettings widget. + """ self._image_dir = FileChooser(title="Choose folder with images", show_only_dirs=True) self._aperture_file_loc = FileChooser(title='Choose aperture location file') self._aperture_settings_loc = FileChooser(title='Choose file with aperture settings') diff --git a/stellarphot/visualization/seeing_profile_functions.py b/stellarphot/visualization/seeing_profile_functions.py index f750ec97..c4b4e465 100644 --- a/stellarphot/visualization/seeing_profile_functions.py +++ b/stellarphot/visualization/seeing_profile_functions.py @@ -40,7 +40,7 @@ def set_keybindings(image_widget, scroll_zoom=False): Parameters ---------- - image_widget : astrowidgets.ImageWidget + image_widget : `astrowidgets.ImageWidget` Image widget on which to set the key bindings. scroll_zoom : bool, optional @@ -92,7 +92,7 @@ def find_center(image, center_guess, cutout_size=30, max_iters=10): Parameters ---------- - image : numpy array or CCDData + image : `astropy.nddata.CCDData` or numpy array Image containing the star. center_guess : array or tuple @@ -158,13 +158,14 @@ 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 ---------- - data : numpy array or CCDData + data : `astropy.nddata.CCDData` or numpy array Image data center : list-like @@ -186,7 +187,7 @@ def radial_profile(data, center, size=30, return_scaled=True): Exact radius of center of each pixels from profile center. ravg : numpy array - Average radius of pixels in each bin. + Average radius in pixels used in constructing profile. radialprofile : numpy array Radial profile. @@ -216,7 +217,8 @@ 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. + """ + Estimate the half-width half-max from normalized, angle-averaged intensity profile. Parameters ---------- @@ -256,7 +258,8 @@ def find_hwhm(r, intensity): class RadialProfile: - """ Class to hold radial profile information for a star. + """ + Class to hold radial profile information for a star. Parameters ---------- @@ -282,14 +285,53 @@ class RadialProfile: FWHM : float Full-width half-max of the radial profile. + profile_size : int + Size of the cutout used to construct the radial profile. + radius_values : numpy array Radius values for the radial profile. + + r_exact : numpy array + Exact radius of center of each pixels from profile center. + + ravg : numpy array + Average radius in pixels used in constructing profile. + """ def __init__(self, data, x, y): + """ + Initialize the radial profile object instance. Sets the center + of the star and the image data. + + Parameters + ---------- + + data : numpy array + Image data. + + x : int + x position of the star. + + y : int + y position of the star. + + + """ self.cen = find_center(data, (x, y), cutout_size=30) self.data = data def profile(self, profile_size): + """ + Construct the radial profile of the star. Sets + ``r_exact``, ``ravg``, and ``radialprofile`` attributes. + + Parameters + ---------- + + profile_size : int + Size of the cutout to use in constructing the profile. + + """ self.profile_size = profile_size self.r_exact, self.ravg, self.radialprofile = ( radial_profile(self.data, @@ -314,29 +356,31 @@ 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 : `astrowidgets.ImageWidget` ImageWidget instance to use for the seeing profile. Returns ------- - box : ipywidgets.Box + box : `ipywidgets.VBox` Box containing the seeing profile widget. """ return SeeingProfileWidget(imagewidget=imagewidget).box class SeeingProfileWidget: - """A class for storing an instance of a widget displaying 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, optional + imagewidget : `astrowidgets.ImageWidget`, optional ImageWidget instance to use for the seeing profile. width : int, optional