rail_pz_service.models package

Database table definitions and utility functions

class rail_pz_service.models.Algorithm(*, name, class_name, id)[source]

Bases: AlgorithmBase

Algorithm is wrapper for a specific RAIL class that implements a particular p(z) estimation algorithm.

This just defines the particular python class implementing the algorithm. The selection of a particular instance of the training Model and any non-default a parameters used to initialze an Estimator are handled in their own classes.

Parameters:
  • name (str)

  • class_name (str)

  • id (int)

col_names_for_table: ClassVar[list[str]] = ['id', 'name', 'class_name']

column names to use when printing the table

id: int

primary key

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class rail_pz_service.models.CatalogTag(*, name, class_name, id)[source]

Bases: CatalogTagBase

Defines what kind of catalog we are analyzing data from. Specifically what to expect for the names of the magnitude columns.

This is implemented in the rail.utils.catalog_utils module, which uses a catalog tag to set the default parameters for RAIL modules to match the catalog.

Parameters:
  • name (str)

  • class_name (str)

  • id (int)

col_names_for_table: ClassVar[list[str]] = ['id', 'name', 'class_name']

column names to use when printing the table

id: int

primary key

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class rail_pz_service.models.Dataset(*, name, path=None, data=None, n_objects, id, catalog_tag_id)[source]

Bases: DatasetBase

Color data about set of objects that can be used to obtain p(z) esimates.

It is asscoated with a CatalogTag that defines which columns names to expect.

It can either be stored in a file (for larger datasets) or as a python dict (for small datasets of a few objects, useful when uploading things on the fly

Parameters:
  • name (str)

  • path (str | None)

  • data (dict | None)

  • n_objects (int | None)

  • id (int)

  • catalog_tag_id (int)

catalog_tag_id: int

foreign key into catalog_tag table

col_names_for_table: ClassVar[list[str]] = ['id', 'name', 'n_objects', 'catalog_tag_id', 'path']

column names to use when printing the table

id: int

primary key

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class rail_pz_service.models.DownloadQuery(*, filename)[source]

Bases: BaseModel

Parameters needed to ask for a file download

Parameters:

filename (str)

filename: str

filename for output

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class rail_pz_service.models.Estimator(*, name, config=None, id, algo_id, catalog_tag_id, model_id)[source]

Bases: EstimatorBase

Combinination of an Algorithm to run a trained Model to apply to the data, and any specific configuration overrides.

Parameters:
  • name (str)

  • config (dict | None)

  • id (int)

  • algo_id (int)

  • catalog_tag_id (int)

  • model_id (int)

algo_id: int

foreign key into algorithm table

catalog_tag_id: int

foreign key into catalog_tag table

col_names_for_table: ClassVar[list[str]] = ['id', 'name', 'algo_id', 'catalog_tag_id', 'model_id']

column names to use when printing the table

id: int

primary key

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_id: int

foreign key into model table

class rail_pz_service.models.LoadDatasetQuery(*, name, path, data=None, catalog_tag_name)[source]

Bases: BaseModel

Parameters needed to load an dataset

Parameters:
  • name (str)

  • path (str | None)

  • data (dict | None)

  • catalog_tag_name (str)

catalog_tag_name: str
data: dict | None

Data for input

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str

Name for this Dataset, unique

path: str | None

Path to the input file

class rail_pz_service.models.LoadEstimatorQuery(*, name, model_name, config=None)[source]

Bases: BaseModel

Parameters needed to load an estimator

Parameters:
  • name (str)

  • model_name (str)

  • config (dict | None)

config: dict | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_name: str
name: str
class rail_pz_service.models.LoadModelQuery(*, name, path, algo_name, catalog_tag_name)[source]

Bases: BaseModel

Parameters needed to load a model

Parameters:
  • name (str)

  • path (str)

  • algo_name (str)

  • catalog_tag_name (str)

algo_name: str

Associated algorithm name

catalog_tag_name: str

Associated catalog tag name

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str

Name for this Model, unique

path: str

Path to the input file

class rail_pz_service.models.Model(*, name, path, id, algo_id, catalog_tag_id)[source]

Bases: ModelBase

Specific ML model that is trained to work with a specific Algorithm. On a particular type of data (CatalogTag)

Typically a Model is stored as a pickle file.

The rail.core.model.Model class provides a standard wrapper to store meta data such as the name of the python class that created the model, and the applicable CatalogTag to use the model with.

Parameters:
  • name (str)

  • path (str)

  • id (int)

  • algo_id (int)

  • catalog_tag_id (int)

algo_id: int

foreign key into algorithm table

catalog_tag_id: int

foreign key into catalog_tag table

col_names_for_table: ClassVar[list[str]] = ['id', 'name', 'algo_id', 'catalog_tag_id', 'path']

column names to use when printing the table

id: int

primary key

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class rail_pz_service.models.NameQuery(*, name)[source]

Bases: BaseModel

Parameters needed to ask for a row my name

Parameters:

name (str)

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str

Name of the row, unique

class rail_pz_service.models.Request(*, user=None, id, qp_file_path=None, estimator_id, dataset_id, time_created, time_started, time_finished)[source]

Bases: RequestBase

Basic processing unit in rail_pz_service. A Request to generate per-galaxy p(z) for all of the object in a particular Dataset using specific Estimator.

The output p(z) distribution will be stored in a qp file.

This also store some metadata including timestamps and the user who intiated the Request.

Parameters:
  • user (str | None)

  • id (int)

  • qp_file_path (str | None)

  • estimator_id (int)

  • dataset_id (int)

  • time_created (datetime)

  • time_started (datetime | None)

  • time_finished (datetime | None)

col_names_for_table: ClassVar[list[str]] = ['id', 'user', 'estimator_id', 'dataset_id', 'qp_file_path']

column names to use when printing the table

dataset_id: int

foreign key into dataset table

estimator_id: int

foreign key into estimator table

id: int

primary key

model_config: ClassVar[ConfigDict] = {'from_attributes': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

qp_file_path: str | None

path to the output file

time_created: datetime

timestamp of when the request was created in the DB

time_finished: datetime | None

timestamp of when the request processing was finished

time_started: datetime | None

timestamp of when the request processing started by an Estimator

class rail_pz_service.models.RequestCreate(*, user=None, estimator_name, dataset_name)[source]

Bases: RequestBase

Request Parameters that are used to create new rows but not in DB tables

Parameters:
  • user (str | None)

  • estimator_name (str)

  • dataset_name (str)

dataset_name: str

Name of the dataset

estimator_name: str

Name of the estimator

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].