nexusLIMS.builder.record_builder#
Build Nexus records from metadata and datasets.
Builds NexusLIMS records.
- ivar XSD_PATH:
A string containing the path to the Nexus Experiment schema file, which is used to validate XML records built by this module
Module Contents#
Classes#
Result of building a NexusLIMS XML record. |
Functions#
Build a NexusLIMS XML record of an Experiment. |
|
Get a ReservationEvent representation of a Session. |
|
Build an XML string representation of each AcquisitionActivity for a session. |
|
Get files under a path that were last modified between the two given timestamps. |
|
Dump a record to an XML file. |
|
Validate an .xml record against the Nexus schema. |
|
Build records for new sessions from the database. |
|
Process new records (this is the main entrypoint to the record builder). |
|
Get the files that would be included for a record built for the supplied session. |
Data#
API#
- nexusLIMS.builder.record_builder.XSD_PATH#
Type: pathlib.Path
- class nexusLIMS.builder.record_builder.RecordBuildResult[source]#
Result of building a NexusLIMS XML record.
- Parameters:
xml_text – The serialized XML record string
activities – The AcquisitionActivity objects built during record construction
reservation_event – The ReservationEvent used to populate the record header
- xml_text#
Type: str
- activities#
‘field(…)’
Type: typing.List[nexusLIMS.schemas.activity.AcquisitionActivity]
- reservation_event#
Type: nexusLIMS.harvesters.reservation_event.ReservationEvent | None
- nexusLIMS.builder.record_builder.build_record(session: Session, sample_id: str | None = None, *, generate_previews: bool = True) RecordBuildResult[source]#
Build a NexusLIMS XML record of an Experiment.
Construct an XML document conforming to the NexusLIMS schema from a directory containing microscopy data files. Accepts either a
Sessionobject or an Instrument and date range (for backwards compatibility). For calendar parsing, currently no logic is implemented for a query that returns multiple records.- Parameters:
session – A
SessionorNone. If a value is provided,instrument,dt_from,dt_toanduserwill be ignored, and the values from the Session object will be used insteadsample_id – A unique identifier pointing to a sample identifier for data collected in this record. If None, a UUIDv4 will be generated
generate_previews – Whether to create the preview thumbnail images
- Returns:
result – A
RecordBuildResultcontaining the XML string, activities, and reservation event- Return type:
- nexusLIMS.builder.record_builder.get_reservation_event(session: Session) ReservationEvent[source]#
Get a ReservationEvent representation of a Session.
Handles the abstraction of choosing the right “version” of the
res_event_from_sessionmethod from the harvester specified in the instrument database. This allows for one consistent function name to call a different method depending on which harvester is specified for each instrument (currently just NEMO).- Parameters:
session – The
Sessionfor which to fetch a matchingReservationEventfrom the relevant harvester- Returns:
res_event – A
ReservationEventrepresentation of a reservation that matches the instrument and timespan specified insession.- Return type:
- nexusLIMS.builder.record_builder.build_acq_activities(instrument, dt_from, dt_to, generate_previews)[source]#
Build an XML string representation of each AcquisitionActivity for a session.
This includes setup parameters and metadata associated with each dataset obtained during a microscopy session. Unique AcquisitionActivities are delimited via clustering of file collection time to detect “long” breaks during a session.
- Parameters:
instrument (
Instrument) – One of the NexusLIMS instruments contained in theinstrument_dbdatabase. Controls what instrument calendar is used to get events.dt_from (datetime) – The starting timestamp that will be used to determine which files go in this record
dt_to (datetime) – The ending timestamp used to determine the last point in time for which files should be associated with this record
generate_previews (bool) – Whether or not to create the preview thumbnail images
- Returns:
activities (
listof)AcquisitionActivity– The list ofAcquisitionActivityobjects generated for the record
- nexusLIMS.builder.record_builder.get_files(path: Path, dt_from: datetime, dt_to: datetime) List[Path][source]#
Get files under a path that were last modified between the two given timestamps.
- Parameters:
- Returns:
files – A list of the files that have modification times within the time range provided (sorted by modification time)
- Return type:
List[Path]
- nexusLIMS.builder.record_builder.dump_record(session: Session, filename: Path | None = None, *, generate_previews: bool = True) Path[source]#
Dump a record to an XML file.
Writes an XML record for a
Sessioncomposed of information pulled from the appropriate reservation system as well as metadata extracted from the microscope data (e.g. dm3 or other files).- Parameters:
session (Session) – A
Sessionobject representing a unit of time on one of the instruments known to NexusLIMSfilename (Optional[Path]) – The filename of the dumped xml file to write. If None, a default name will be generated from the other parameters
generate_previews (bool) – Whether or not to create the preview thumbnail images
- Returns:
filename – The name of the created record that was returned
- Return type:
- nexusLIMS.builder.record_builder.validate_record(xml_filename)[source]#
Validate an .xml record against the Nexus schema.
- nexusLIMS.builder.record_builder.build_new_session_records(generate_previews: bool = True) tuple[List[Path], List[Session], List[List[AcquisitionActivity]], List[ReservationEvent | None]][source]#
Build records for new sessions from the database.
Uses
get_sessions_to_build()) and builds those records usingbuild_record()(saving to the NexusLIMS folder), and returns a list of resulting .xml files to be uploaded to CDCS.- Returns:
xml_files (typing.List[pathlib.Path]) – A list of record files that were successfully built and saved to centralized storage
sessions_built (typing.List[Session]) – Corresponding Session objects for each built XML file (same length and order)
activities_built (typing.List[typing.List[AcquisitionActivity]]) – Corresponding AcquisitionActivity lists for each built session
res_events_built (typing.List[ReservationEvent | None]) – Corresponding ReservationEvent for each built session
- nexusLIMS.builder.record_builder.process_new_records(*, dry_run: bool = False, dt_from: datetime | None = None, dt_to: datetime | None = None)[source]#
Process new records (this is the main entrypoint to the record builder).
Using
build_new_session_records(), process new records, save them to disk, and upload them to the NexusLIMS CDCS instance.- Parameters:
dry_run – Controls whether or not records will actually be built. If
True, session harvesting and file finding will be performed, but no preview images or records will be built. Can be used to see what would happen ifdry_runis set toFalse.dt_from – The point in time after which sessions will be fetched. If
None, no date filtering will be performed. This parameter currently only has an effect for the NEMO harvester.dt_to – The point in time before which sessions will be fetched. If
None, no date filtering will be performed. This parameter currently only has an effect for the NEMO harvester.