astra.tasks.targets¶
Module Contents¶
Classes¶
DatabaseTarget |
A database target row as the output of a task. |
AstraSource |
A class to represent an analysis product from an analysis task in Astra. |
Functions¶
create_image_hdu(data, header, name=None, dtype=None, bunit=None, **kwargs) |
-
class
astra.tasks.targets.DatabaseTarget(model, task)¶ A database target row as the output of a task.
Parameters: - model – The database model class to use (e.g.,
astra.database.astradb.ApogeeNet). - task – The reference task that is producing the output.
-
copy_from(self, target)¶ Write a database output that points to the target given.
Parameters: target – An existing DatabaseTarget, or a SQLAlchemy ORM instance of a database result.
-
get_query(self, columns=None, full_output=False)¶
-
exists(self)¶ Return a boolean whether the database row exists.
-
read(self)¶ Read the row from the database.
-
write(self, data)¶ Write data to the database table for this task.
Parameters: data – A dictionary of data, where keys are table column names. This will be supplemented with the relevant database relationships (task primary key, parameter primary key, et cetera).
- model – The database model class to use (e.g.,
-
astra.tasks.targets.create_image_hdu(data, header, name=None, dtype=None, bunit=None, **kwargs)¶
-
class
astra.tasks.targets.AstraSource(task, **kwargs)¶ A class to represent an analysis product from an analysis task in Astra.
Parameters: task – The reference task that was used to analyse the spectrum. -
_path¶ Return the path of this astraSource target.
-
fs¶
-
fn¶
-
get_bitmask(self, spectrum)¶ Return a bitmask array, given the spectrum. The reason for this is because the BHM pipeline produces AND/OR bitmasks and the MWM pipeline produces a single bitmask.
-
_check_shapes(self, normalized_flux, normalized_ivar, model_flux, model_ivar, continuum, results_table)¶ Check that all input array shapes are consistent.
-
copy_from(self, source, use_symbolic_link=True)¶ Write an AstraSource object as a copy from an existing AstraSource object.
Parameters: source – An existing AstraSource object.
-
write(self, spectrum, normalized_flux, normalized_ivar, continuum, model_flux, model_ivar, results_table, **kwargs)¶ Write the image to the appropriate path.
Parameters: - spectrum – The spectrum that was used for analysis. Headers and relevant quality flags from this spectrum will be propagated.
- normalized_flux – A (N, P) shape array of the pseudo-continuum normalized observed flux, where N is the number of spectra and P is the number of pixels.
- normalized_ivar –
A (N, P) shape array of the inverse variance of the pseudo-continuum normalized observed flux, where N is the number of spectra and P is the number of pixels. For example, if the $1sigma$ Gaussian uncertainty in pseudo-continuum normalized flux in a pixel is $sigma_n$, then the inverse variance of the pseudo-continuum normalized flux is $1/(sigma_n^2)$.
Similarly if the $1sigma$ Gaussian uncertainty in un-normalized flux $y$ is $sigma$ and the continuum is $C$, then the pseudo-continuum normalized flux is $y/C$ and the inverse variance of the pseudo-continuum normalized flux is $(C/sigma)^2$.
- continuum – A (N, P) shape array of the continuum value used to pseudo-normalize the observations, where N is the number of spectra and P is the number of pixels.
- model_flux – A (N, P) shape array of the pseudo-continuum normalized model flux, where N is the number of spectra and P is the number of pixels.
- model_ivar – A (N, P) shape array of the inverse variance of the pseudo-continuum normalized model flux, where N is the number of spectra and P is the number of pixels. This gives a measure of the inverse variance in the model predictions, which is often not known. If no model uncertainty is known then this array should be set to a constant positive value (e.g., 1).
- results_table –
A
astropy.table.Tableof outputs from the analysis of the input spectra. This can contain any number of columns, but the naming convention of these columns should (as closely as possible) follow the conventions of other analysis tasks so that there is not great variation in names among identical columns (e.g.,R_CHI_SQandRCHISQandREDUCED_CHI_SQ).This table will be supplemented with the parameters and descriptions of the analysis task.
-
makedirs(self)¶ Create all parent folders if they do not exist.
-
open(self, mode='r')¶ Open the FileSystem target.
This method returns a file-like object which can either be read from or written to depending on the specified mode.
Parameters: mode (str) – the mode ropens the FileSystemTarget in read-only mode, whereaswwill open the FileSystemTarget in write mode. Subclasses can implement additional options. Usingbis not supported; initialize withformat=Nopinstead.
-
move(self, new_path, raise_if_exists=False)¶
-
move_dir(self, new_path)¶
-
remove(self)¶ Remove the resource at the path specified by this FileSystemTarget.
This method is implemented by using
fs.
-
copy(self, new_path, raise_if_exists=False)¶
-
__del__(self)¶
-
exists(self)¶ Returns
Trueif the path for this FileSystemTarget exists;Falseotherwise.This method is implemented by using
fs.
-
temporary_path(self)¶ A context manager that enables a reasonably short, general and magic-less way to solve the AtomicWrites.
- On entering, it will create the parent directories so the
temporary_path is writeable right away.
This step uses
FileSystem.mkdir(). - On exiting, it will move the temporary file if there was no exception thrown.
This step uses
FileSystem.rename_dont_move()
The file system operations will be carried out by calling them on
fs.The typical use case looks like this:
class MyTask(luigi.Task): def output(self): return MyFileSystemTarget(...) def run(self): with self.output().temporary_path() as self.temp_output_path: run_some_external_command(output_path=self.temp_output_path)
- On entering, it will create the parent directories so the
temporary_path is writeable right away.
This step uses
-
_touchz(self)¶
-
_trailing_slash(self)¶
-