Spectrum1d

class snappl.spectrum1d.Spectrum1d(id=None, data_dict=None, provenance=None, diaobject=None, diaobject_position=None, band=None, mjd_start=None, mjd_end=None, epoch=None, no_database=False, dbclient=None, filepath=None, base_dir=None, base_path=None, full_filepath=None, no_base_path=False)[source]

Bases: PathedObject

A class to store and save single-epoch 1d transient spectra.

Spectrum1d schema are defined here:

Properties of a Spectrum1d object include:
  • filepath : pathlib.Path ; path relative to the base path of the spectrum1d file

  • full_filepath : pathlib.Path ; absolute path on the system to the spectrum1d file

  • base_path : base path for lightcurves; usually will be Config value system.paths.lightcurves

  • base_dir : synonym for base_path

  • data_dict : the full dict described the schema wiki page linked above

  • meta : data_dict[‘meta’]

  • combined: data_dict[‘combined’]

  • combined_meta: data_dict[‘combined’][‘meta’]

  • combined_data: data_dict[‘combined’][‘data’]

  • individual: data_dict[‘indivdual’]

  • id : UUID, the id of the spectrum

  • provenance_id : UUID, the id of the spectrum’s provenance

  • diaobject_id : UUID, the id of the object for which this is a spectrum

  • diaobject_position_id : UUID or None, the id of the object’s improved position if any

  • band : str, the band

  • mjd_start : float, the MJD of the earliest component image

  • mjd_end : float, the MJD + exposure time (in days) of the latest component image

  • epoch : integer, the average MJD in millidays (i.e. MJD * 1000) of the comonent image MJDs

  • images : list of Image, the component images

Instantiate a Spectrum1d

Parameters:
  • id (UUID or str or NOne) – ID of this lightcurve. If None, one will be generated, and thereafter aavilable in the id property.

  • data_dict (dict) –

    Must follow the format on

    You must give one of data_dict or filepath; it is bad form to specify both.

  • filepath (Path or str, default None) – File path to find the lightcurve, realtive to base dir. You must specify either data_dict or filepath; it is bad form to specify both.

  • base_dir (Path or str, default None) – Base directory that filepath is relative to. If None (which is what you want if you’re writing things to the database), will use the config value of “system.paths.spectra1d”.

  • provenance (Provenance or UUID or str or None) – The provenance of this lightcurve. You may also set data_dict[‘meta’][‘provenance_id’] to the UUID of the provenance instead of passing it here.

  • diaobject (DiaObject or UUID or str or None) – The DiaObject this is a spectrum for. You may also set data_dict[‘meta’][‘diaobject_id’] to the UUID of the diaboject instead of passing it here.

  • diaobject_position_id (dict or UUID or str or None) – Either the improved position as returned form DiaObject.get_position(), or the value of the id from the dictionary returned by that call. You may also set data_dict[‘meta’][‘diaobject_position_id’]

Attributes Summary

band

combined

combined_data

combined_meta

data_dict

epoch

images

individual

meta

mjd_end

mjd_start

Methods Summary

find_spectra([provenance, provenance_tag, ...])

Search the database for spectra.

generate_filepath([filetype])

Classes that have default filepaths should override this function to set self._filepath.

get_spectrum1d(spectrum1d_id[, dbclient])

Get a Specrum1d from the database.

read_data([filepath, dbclient])

Reads the file.

save_to_db([write, dbclient])

Save spectrum to db.

write_file([filepath])

Writes the file

Attributes Documentation

band
combined
combined_data
combined_meta
data_dict
epoch
images
individual
meta
mjd_end
mjd_start

Methods Documentation

classmethod find_spectra(provenance=None, provenance_tag=None, process=None, dbclient=None, diaobject=None, **kwargs)[source]

Search the database for spectra.

Must pass either provenance, or both of (provenance_tag and process). All the rest are optional; omitted parameters will just not be used to filter the list of returned spectra.

Parameters:
  • provenance (Provenance or UUID or str, default None) – The Provenance, or the id of the Provenacne, of the lightcurve you want. You must pass either provenance or provenance_tag. (If you pass both, provenance_tag will be ignored).

  • provenance_tag (str, default None) – The provenance tag used to find the provenance of the lightcurves you want. Ignored if provenance is not None. Requires process.

  • process (str, default None) – The process used together with provenance_tag to find the provenance of the lightcurves you want. Required if provenance_tag is not None.

  • dbclient (SNPITDBClient or None) – The connection to the database (optional). If you don’t pass one, will use the cached connection, or will make a new one based on what’s in the config.

  • diaobject (DiaObject or UUID or str or None) – The DiaObject, or the ID of the object, you want spectra for.

  • band (str) – The band of the images that went into the spectrum

  • mjd_start (float The earliesr mjd, and latest mjd,) – of the individual images that went into the exposure. (mjd_end is actually the mjd of the final image, plus it’s exposure time converted to days).

  • mjd_end (float The earliesr mjd, and latest mjd,) – of the individual images that went into the exposure. (mjd_end is actually the mjd of the final image, plus it’s exposure time converted to days).

  • mjd_start_min (float) – Use these if you want to search a range of times.

  • mjd_start_max (float) – Use these if you want to search a range of times.

  • mjd_end_min (float) – Use these if you want to search a range of times.

  • mjd_end_max (float) – Use these if you want to search a range of times.

  • order_by (str or list, default None) – By default, the returned images are not sorted in any particular way. Put a keyword here to sort by that value (or by those values). Options include ‘id’, ‘provenance_id’, ‘observation_id’, ‘sca’, ‘ra’, ‘dec’, ‘filepath’, ‘width’, ‘height’, ‘mjd’, ‘exptime’. Not all of these are necessarily useful, and some of them may be null for many objects in the database.

  • limit (int, default None) – Only return this many objects at most.

  • offset (int, default None) – Useful with limit and order_by ; offset the returned value by this many entries. You can make repeated calls to find_objects to get subsets of objects by passing the same order_by and limit, but different offsets each time, to slowly build up a list.

Return type:

List of spectra

generate_filepath(filetype='hdf5')[source]

Classes that have default filepaths should override this function to set self._filepath.

classmethod get_spectrum1d(spectrum1d_id, dbclient=None)[source]

Get a Specrum1d from the database.

Parameters:
  • spectrum1d_id (UUID or str that can be converted to a UUID) – The id of the spectrum to fetch.

  • dbclient (SNPITDBClient or None) – The connection to the database web server. If None, a new one will be made that logs you in using the information in Config.

Return type:

Spectrum1d

read_data(filepath=None, dbclient=None)[source]

Reads the file.

Populates self._data_dict

Parameters:

filepath (str or pathlib.Path, default None) – The full path to write the file to. If None, then will use the base_path and filepath passed at object construction.

save_to_db(write=False, dbclient=None)[source]

Save spectrum to db.

Parmaters

writebool, default False

If write=True, then also write the file. If not, then you must call write_file() first. (If you call write() and then call this with write=True, you’ll get a file exists error.)

dbclientSNPITDBClient, default None

The connection to the database web server. If None, a new one will be made that logs you in using the information in Config.

returns:

dict

rtype:

the row of the database saved, for informational purposes

write_file(filepath=None)[source]

Writes the file

Parameters:

filepath (str or pathlib.Path, default None) – The full path to write the file to. If None, then will use the base_path and filepath passed at object construction, or if those were None, will generate a standard filepath used for the database files. If you’re writing to the database, you usually want this to be None.