Simulation model repository#

The model repository API provides source-neutral, read-only access to simulation-model parameters, production tables, and referenced files.

reader#

Read simulation models through a source-neutral interface.

class model_repository.reader.SimulationModelReader(source)[source]#

Source-neutral read-only interface for simulation-model data.

export_model_file(parameter, site, array_element_name, model_version=None, parameter_version=None, export_file_as_table=False, dest=None)[source]#

Export one model file or return a file-backed value as a table.

export_model_files(parameters=None, file_names=None, dest=None)[source]#

Export model files through the selected source.

classmethod from_files(simulation_models_path)[source]#

Create a reader for a checked-out model repository.

classmethod from_git(repository_path, revision, object_store=None)[source]#

Create a reader for one immutable revision of a Git repository.

classmethod from_memory(files)[source]#

Create a reader from in-memory model files.

get_array_elements(model_version, collection='telescopes')[source]#

Return array elements in a model version.

get_array_elements_of_type(array_element_type, model_version, collection)[source]#

Return non-design elements of one type.

get_design_model(model_version, array_element_name, collection='telescopes')[source]#

Return the design model for an array element.

get_model_parameter(parameter, site, array_element_name, parameter_version=None, model_version=None)[source]#

Read one model parameter by parameter or model version.

get_model_parameters(site, array_element_name, collection, model_version, parameter_names=None, context=None)[source]#

Read resolved parameters for an array element and model version.

Parameters:
parameter_namesiterable of str, optional

If supplied, read only these parameters. This is useful for callers that need a small subset of a model, such as coordinate transforms.

contextRunContext, optional

Application context. Its ignore_missing_design_model argument is honoured when present; the reader itself does not create a context.

get_model_parameters_for_all_model_versions(site, array_element_name, collection)[source]#

Read resolved parameters for an element across all model versions.

get_model_update_info(model_version)[source]#

Return update type and history declared by a production version.

Parameters:
model_versionstr

Production model version to inspect.

Returns:
dict

model_update and model_version_history values from the version metadata. Missing metadata yields None and an empty list.

get_model_versions(collection_name='telescopes')[source]#

Return available model versions.

get_parameter_table(parameter_data)[source]#

Return the validated Astropy table referenced by a model parameter.

get_parameter_table_records(parameter_data)[source]#

Return cached scalar records for a validated model-parameter table.

get_production_descriptions()[source]#

Return model-version descriptions from the selected source.

get_simulation_configuration_parameters(simulation_software, site, array_element_name, model_version)[source]#

Read CORSIKA or sim_telarray configuration parameters.

is_configured()[source]#

Return whether the selected source is configured for reads.

read_production_table(collection_name, model_version)[source]#

Read a production table.

property source_config#

Return the serializable source selection for worker processes.

property source_name#

Return a user-facing description of the selected source.

model_repository.reader.create_model_reader_from_source_config(source_config)[source]#

Recreate a reader from its serialized source configuration.

model_repository.reader.resolve_model_reader(model_reader=None, context=None)[source]#

Return the explicit, contextual, or environment-configured model reader.

model_repository.reader.with_resolved_model_reader(context)[source]#

Return a context that carries the resolved model reader.

An environment-configured source is attached to the context, so that serialized job specifications can rebuild the same reader in worker processes.

storage#

Read-only storage implementations for simulation model files.

class model_repository.storage.DirectoryStorage(root)[source]#

Read model files from a directory tree.

exists(path)[source]#

Return whether a repository-relative file exists.

iter_files(prefix)[source]#

List repository-relative regular files without following symlinks.

open(path)[source]#

Open a repository-relative file as a binary stream.

read_bytes(path)[source]#

Read a repository-relative file as bytes.

class model_repository.storage.GitStorage(repository, revision, object_store=None)[source]#

Read model files from a resolved commit in a local Git repository.

close()[source]#

Release the object store’s resources.

exists(path)[source]#

Return whether a repository-relative file exists (directories are not files).

iter_files(prefix)[source]#

List repository-relative files below a directory prefix.

open(path)[source]#

Open a repository-relative file as a binary stream.

read_bytes(path)[source]#

Read a repository-relative file as bytes.

class model_repository.storage.MemoryStorage(files)[source]#

Read model files from an in-memory mapping of paths to bytes.

exists(path)[source]#

Return whether a repository-relative file exists.

iter_files(prefix)[source]#

List repository-relative files below a directory prefix.

open(path)[source]#

Open a repository-relative file as a binary stream.

read_bytes(path)[source]#

Read a repository-relative file as bytes.

class model_repository.storage.ModelStorage(*args, **kwargs)[source]#

Common read-only interface for model repository storage.

exists(path)[source]#

Return whether a repository-relative file exists.

iter_files(prefix)[source]#

List repository-relative files below a directory prefix.

open(path)[source]#

Open a repository-relative file as a binary stream.

read_bytes(path)[source]#

Read a repository-relative file as bytes.

source#

Read simulation models through a storage-neutral source.

class model_repository.source.ModelSource(storage)[source]#

Read-only access to model data through a storage implementation.

export_model_files(parameters=None, file_names=None, dest=None)[source]#

Copy referenced model files to a destination directory.

get_model_update_info(model_version)[source]#

Return update type and history declared by a production version.

Parameters:
model_versionstr

Production model version.

Returns:
dict

model_update and model_version_history values from the version’s info.yml or info.yaml. Missing metadata yields None and an empty list.

get_model_versions(collection_name='telescopes')[source]#

Return semantically sorted production versions.

get_parameter_table(parameter_data)[source]#

Read and validate an ECSV table referenced by a parameter record.

get_production_descriptions()[source]#

Return model-version descriptions from production info files.

is_configured()[source]#

Return whether the source is ready for reads.

read_parameters(parameter_versions, collection_name, instrument=None, site=None)[source]#

Read and filter normalized parameter documents.

read_production_table(collection_name, model_version)[source]#

Return an aggregated production table for a collection and version.

static resolve_parameter_asset(parameter_data)[source]#

Resolve a file-valued parameter relative to its parameter directory.

property source_config#

Return the serializable storage configuration.

property source_name#

Return the storage’s user-facing identity.

files#

Read and combine production-table files from a model repository.

model_repository.files.collect_production_descriptions(info_files, read_info)[source]#

Collect sorted production descriptions using the supplied document reader.

model_repository.files.read_production_tables_from_documents(model_version, documents, collection_name=None)[source]#

Read and merge production tables from parsed repository documents.

documents contains (model_name, file_name, document) tuples. The representation is shared by filesystem and Git readers so that both sources apply patch history and production-table merging identically.

asset names#

Naming helpers for exported simulation-model assets.

model_repository.asset_names.get_export_file_name(parameter_data, fallback_instrument=None)[source]#

Return the deterministic exported name for a model asset.

ECSV assets are qualified with the instrument scope so that assets from different telescope designs can share one model directory safely. The original source value is kept separately when a parameter has already been qualified.

Parameters:
parameter_datadict

Model parameter metadata.

fallback_instrumentstr, optional

Instrument scope to use when the metadata does not contain one.

Returns:
str

Exported filename.

model_repository.asset_names.get_simtel_table_file_name(parameter_data)[source]#

Return the shared native sim_telarray filename for an ECSV parameter.

The model parameter identity is used instead of a telescope configuration filename. This allows identical tables used by several telescope models to share one generated native file.

Parameters:
parameter_datadict

Model parameter metadata.

Returns:
str or None

Shared native filename, or None when the parameter does not carry enough model identity metadata for safe sharing.

model_repository.asset_names.qualify_parameter_file_name(parameter_data, fallback_instrument=None)[source]#

Update ECSV parameter metadata with its deterministic exported name.

Git backend#

Git object-store adapter for simulation models.

class model_repository.git_backend.GitCommandObjectStore(repository_path)[source]#

Read objects from a local normal, bare, or mirror repository.

Small object reads share one persistent git cat-file --batch process, so reading many files costs one round trip each instead of one process each. The process is started on first use, restarted once after a failure, and stopped by close() or garbage collection. Calls are serialized by a lock and are safe across threads; a forked child starts its own process. open_blob streams through a separate process and never holds the blob in memory.

close()[source]#

Stop the persistent Git process; it is restarted on the next read.

iter_files(commit, prefix)[source]#

Return sorted blob paths below a tree prefix.

open_blob(commit, path)[source]#

Open a blob as a binary stream; the content is not held in memory.

read_blob(commit, path)[source]#

Read a blob into memory.

resolve_revision(revision)[source]#

Resolve a tag, ref, or SHA to a full commit SHA.

exception model_repository.git_backend.GitNotInstalledError[source]#

Raised when the Git executable is not installed.

class model_repository.git_backend.GitObjectStore[source]#

Interface used by GitStorage.

close()[source]#

Release resources held by the object store.

abstractmethod iter_files(commit, prefix)[source]#

Return file paths below prefix for commit.

abstractmethod open_blob(commit, path)[source]#

Return a binary stream for one blob.

abstractmethod read_blob(commit, path)[source]#

Return one blob as bytes.

abstractmethod resolve_revision(revision)[source]#

Resolve a ref or commit to a full commit ID.

model_repository.git_backend.run_git(repository, *args)[source]#

Run Git against a configured repository without owner validation.

subprocess.CalledProcessError is raised on failure; stderr holds Git’s message.

model_repository.git_backend.split_nul(data)[source]#

Split NUL-terminated Git output into non-empty, decoded entries.

parsing#

Parsing helpers shared by simulation-model sources.

model_repository.parsing.normalize_model_parameter(data)[source]#

Normalize the value and unit fields of a model-parameter document.

application model-reader factory#

Construct the configured simulation-model reader.

application.model_reader.create_model_reader(simulation_models_path=None, simulation_models_git_path=None, simulation_models_git_revision=None)[source]#

Create a reader for a filesystem or Git model source.

Parameters:
simulation_models_pathstr or Path, optional

Root of a checked-out simulation-model repository. When supplied, this source is selected. If omitted, SIMTOOLS_SIMULATION_MODELS_PATH is used when set.

simulation_models_git_pathstr or Path, optional

Local normal, bare, or mirror Git repository.

simulation_models_git_revisionstr, optional

Git tag, ref, or commit. The model-repository catalog ref is used when the Git path is set and this value is omitted.

Returns:
SimulationModelReader

Reader backed by the selected source.

application.model_reader.create_model_reader_from_configuration(configuration)[source]#

Create a model reader from an application or test configuration.

Parameters:
configurationdict

Mapping that may contain filesystem or Git model-source options.

Returns:
SimulationModelReader

Reader selected by the supplied source options.

application.model_reader.create_model_reader_from_source_config(source_config)[source]#

Recreate a model reader from a worker-serializable source configuration.

Parameters:
source_configdict

Configuration returned by SimulationModelReader.source_config.

Returns:
SimulationModelReader

Reader backed by the configured source.

Raises:
ValueError

If the source configuration is missing or unsupported.

Compatibility#

Check model release versions against the simtools dependency catalog.

model_repository.compatibility.get_contract(catalog)[source]#

Read a model range, including catalogs bundled with historical images.

model_repository.compatibility.validate_release(path, catalog, revision=None, development=False)[source]#

Check an exact release tag without changing the selected model checkout.