RepoExportContext¶
- class lsst.daf.butler.RepoExportContext(butler: DirectButler, backend: RepoExportBackend, *, directory: ResourcePathExpression | None = None, transfer: str | None = None)¶
Bases:
object
Public interface for exporting a subset of a data repository.
Instances of this class are obtained by calling
Butler.export
as the value returned by that context manager:with butler.export(filename="export.yaml") as export: export.saveDataIds(...) export.saveDatasets(...)
- Parameters:
- butler
lsst.daf.butler.direct_butler.DirectButler
Butler to export from.
- backend
RepoExportBackend
Implementation class for a particular export file format.
- directory
ResourcePathExpression
, optional Directory to pass to
Datastore.export
. Can beNone
to use the current working directory.- transfer
str
, optional Transfer mode to pass to
Datastore.export
.
- butler
Methods Summary
saveCollection
(name)Export the given collection.
saveDataIds
(dataIds, *[, elements])Export the dimension records associated with one or more data IDs.
saveDatasets
(refs, *[, elements, rewrite])Export one or more datasets.
saveDimensionData
(element, records)Export the given dimension records associated with one or more data IDs.
Methods Documentation
- saveCollection(name: str) None ¶
Export the given collection.
- Parameters:
- name
str
Name of the collection.
- name
Notes
RUN
collections are also exported automatically when any dataset referencing them is exported. They may also be explicitly exported this method to export the collection with no datasets. Duplicate exports of collections are ignored.Exporting a
TAGGED
orCALIBRATION
collection will cause its associations with exported datasets to also be exported, but it does not export those datasets automatically.Exporting a
CHAINED
collection does not automatically export its child collections; these must be explicitly exported or already be present in the repository they are being imported into.
- saveDataIds(dataIds: Iterable[DataCoordinate], *, elements: Iterable[str | DimensionElement] | None = None) None ¶
Export the dimension records associated with one or more data IDs.
- Parameters:
- dataIdsiterable of
DataCoordinate
Data IDs to export. For large numbers of data IDs obtained by calls to
Registry.queryDataIds
, it will be much more efficient if these are expanded to include records (i.e.DataCoordinate.hasRecords
returnsTrue
) prior to the call tosaveDataIds
via e.g.Registry.queryDataIds(...).expanded()
.- elementsiterable of
DimensionElement
orstr
, optional Dimension elements whose records should be exported. If
None
, records for all dimensions will be exported.
- dataIdsiterable of
- saveDatasets(refs: Iterable[DatasetRef], *, elements: Iterable[str | DimensionElement] | None = None, rewrite: Callable[[FileDataset], FileDataset] | None = None) None ¶
Export one or more datasets.
This automatically exports any
DatasetType
,RUN
collections, and dimension records associated with the datasets.- Parameters:
- refsiterable of
DatasetRef
References to the datasets to export. Their
DatasetRef.id
attributes must not beNone
. Duplicates are automatically ignored. Nested data IDs must haveDataCoordinate.hasRecords
returnTrue
. If any reference is to a component dataset, the parent will be exported instead.- elementsiterable of
DimensionElement
orstr
, optional Dimension elements whose records should be exported; this is forwarded to
saveDataIds
when exporting the data IDs of the given datasets.- rewritecallable, optional
A callable that takes a single
FileDataset
argument and returns a modifiedFileDataset
. This is typically used to rewrite the path generated by the datastore. IfNone
, theFileDataset
returned byDatastore.export
will be used directly.
- refsiterable of
Notes
At present, this only associates datasets with
RUN
collections. Other collections will be included in the export in the future (onceRegistry
provides a way to look up that information).
- saveDimensionData(element: str | DimensionElement, records: Iterable[dict | DimensionRecord]) None ¶
Export the given dimension records associated with one or more data IDs.
- Parameters:
- element
str
orDimensionElement
DimensionElement
orstr
indicating the logical table these records are from.- records
Iterable
[DimensionRecord
ordict
] Records to export, as an iterable containing
DimensionRecord
ordict
instances.
- element