adler.objectdata.objectdata_utilities
Attributes
Functions
|
Gets a table of data based on a SQL query. Table is pulled from either the RSP or a local SQL database: |
|
Retrieves information from the data_table and forces it to be a specified type. |
|
Retrieves information from a dictionary and forces it to be a specified type. |
|
Checks to see if data_val populated properly and prints a helpful warning if it didn't. |
|
Convenience function for converting timestamps between formats and scales. |
|
Function for checking if column exists in a given table in a given database connection. |
|
Function for adding a column to a given table in a given database if it does not exist. |
|
Function for performing pre-processing steps on the obs_sbn table in the MPC file format. |
|
Converts a flux measurement (with units of nanoJanskys) and its associated error |
|
Function for generating the CSV files that summarise the contents of the outlier detection SQLite database. |
|
Returns a pyvo.dal.TAPService object linked to the RSP if provided with the desired API path and valid API token. For use with querying the RSP remotely. |
Module Contents
- get_data_table(sql_query, service=None, sql_filename=None)[source]
Gets a table of data based on a SQL query. Table is pulled from either the RSP or a local SQL database: this behaviour is controlled by the service and sql_filename parameters, one of which must be supplied.
- Parameters:
sql_query (str) – The SQL query made to the RSP or SQL database.
service (pyvo.dal.tap.TAPService object or None) – TAPService object linked to the RSP. Default=None.
sql_filename (str or None) – Filepath to a SQL database. Default=None.
- Returns:
data_table – Data table containing the results of the SQL query.
- Return type:
DALResultsTable or Pandas dataframe
- get_from_table(data_table, column_name, data_type, table_name='default')[source]
Retrieves information from the data_table and forces it to be a specified type.
- Parameters:
data_table (DALResultsTable or Pandas dataframe) – Data table containing columns of interest.
column_name (str) – Column name under which the data of interest is stored.
data_type (type) – Data type. Should be int, float, str or np.ndarray.
table_name (str) – Name of the table. This is mostly for more informative error messages. Default=”default”.
- Returns:
data_val – The data requested from the table cast to the type required.
- Return type:
str, float, int or nd.array
- get_from_dictionary(data_dict, key_name, data_type, table_name='default')[source]
Retrieves information from a dictionary and forces it to be a specified type.
- Parameters:
data_dict (dict or dict-like object) – Dictionary containing columns of interest.
key_name (str) – Key name under which the data of interest is stored.
data_type (type) – Data type. Should be int, float, str or np.ndarray.
table_name (str) – Name of the table or dictionary. This is mostly for more informative error messages. Default=”default”.
- Returns:
data_val – The data requested from the dictionary cast to the type required.
- Return type:
str, float, int or nd.array
- check_value_populated(data_val, data_type, column_name, table_name)[source]
Checks to see if data_val populated properly and prints a helpful warning if it didn’t. Usually this will trigger because the RSP or Cassandra database hasn’t populated that field for this particular object.
- Parameters:
data_val (str, float, int or nd.array) – The value to check.
data_type (type) – Data type. Should be int, float, str or np.ndarray.
column_name (str) – Column name under which the data of interest is stored.
table_name (str) – Name of the table. This is mostly for more informative error messages. Default=”default”.
- Returns:
data_val – Either returns the original data_val or an np.nan if it detected that the value was not populated.
- Return type:
str, float, int, nd.array or np.nan
- convertTime(timestamps, input_fmt='mjd', input_scale='utc', output_fmt='mjd', output_scale='tai')[source]
Convenience function for converting timestamps between formats and scales.
- Parameters:
timestamps (float, int or nd.array) – Timestamp(s) to be converted.
input_fmt (str) – Input format of timestamps. See https://docs.astropy.org/en/latest/api/astropy.time.Time.html for allowable formats. Default ‘mjd’.
input_scale (str) – Input scale of timestamps. See https://docs.astropy.org/en/latest/api/astropy.time.Time.html for allowable scales. Default ‘utc’.
output_fmt (str) – Desired format of output values. See https://docs.astropy.org/en/latest/api/astropy.time.Time.html for allowable formats. Default ‘mjd’.
output_scale (str) – Desired scale of output values. See https://docs.astropy.org/en/latest/api/astropy.time.Time.html for allowable scales. Default ‘tai’.
- Returns:
output_timestamps – The output timestamps in the desired format and scale as an astropy.time.Time object.
- Return type:
astropy.time.Time object
- sqlite_column_exists(conn, table, column)[source]
Function for checking if column exists in a given table in a given database connection.
- Parameters:
conn (sqlite3.Connection object) – The connection to the database that we wish to check for a given column.
table (str) – The name of the table we wish to check for the given column in.
column (str) – The name of the column we wish to check for.
- Returns:
result – Boolean flag for whether the collect exists or not.
- Return type:
bool
- add_column_if_not_exists(conn, table, column, coltype)[source]
Function for adding a column to a given table in a given database if it does not exist.
- Parameters:
conn (sqlite3.Connection object) – The connection to the database that we wish to add the column to in the given table.
table (str) – The name of the table we wish add the column to.
column (str) – The name of the column we wish to add.
coltype (str) – SQlite datatype for the column we wish to add. See https://sqlite.org/datatype3.html
- Return type:
None
- mpc_file_preprocessing(sql_filename)[source]
Function for performing pre-processing steps on the obs_sbn table in the MPC file format. The function strips the leading ‘L’ from the band in the obs_sbn file; adds a mjd_tai column with the observation time in MJD in the TAI scale; and checks the topocentricDist, heliocentricDist and phaseAngle are present (renaming columns if need be).
- Parameters:
sql_filename (str) – Filepath to the local SQL database.
- Return type:
None
- flux_to_magnitude(flux, flux_err=np.nan)[source]
Converts a flux measurement (with units of nanoJanskys) and its associated error into AB magnitudes. If no flux error is provided, the returned magnitude error will be NaN.
- Parameters:
flux (float or astropy.units.Quantity) – Flux value in nanoJanskys (can be specified with Astropy units of nanoJanskys (u.nJy).
flux_err (float or astropy.units.Quantity, optional) – Flux error with units of nanoJanskys (u.nJy). Default is np.nan (dimensionless), in which case the magnitude error will be returned as NaN.
- Returns:
magnitude (float) – The flux converted into AB magnitude (unitless scalar).
magnitude_err (float) – The propagated uncertainty in AB magnitude (unitless scalar). Returns NaN if flux_err is not provided.
- generate_summary_csvs(sql_filepath, output_file_root, output_cols=['ssObjectId'], filter_list=['u', 'g', 'r', 'i', 'z', 'y'])[source]
Function for generating the CSV files that summarise the contents of the outlier detection SQLite database.
- Parameters:
sql_filepath (str) – Filepath to the SQLite database
output_file_root (str) – Desired path for the output file. Default in example notebook is f”{output_dir}/{planetoid.AdlerData.modelId}”.
output_cols (list of str, optional) – List of columns desired for output file. Default: [“ssObjectId”]. If default chosen, only DISTINCT ssObjectIds will be written out.
filter_list (list of str, optional) – A comma-separated list of the filters of interest.
- get_tap_service_api(rsp_tap_path, api_token_path)[source]
Returns a pyvo.dal.TAPService object linked to the RSP if provided with the desired API path and valid API token. For use with querying the RSP remotely.
- Parameters:
rsp_tap_path (str) – End of the API url, ‘ssotap’ for DP0.3, ‘tap’ for DP1. Set by schema choice in AdlerPlanetoid.
api_token_path (str) – User-provided path to their RSP TAP API token. If specified as, e.g., ‘~/.rsp_tap.token’ this will be expanded by the code.
- Returns:
rsp_tap_service – TAPService object linked to the RSP.
- Return type:
pyvo.dal.TAPService