nexusLIMS.builder package

Build records from Nexus sessions.

Submodules

nexusLIMS.builder.record_builder module

Builds NexusLIMS records.

nexusLIMS.builder.record_builder.XSD_PATH

A string containing the path to the Nexus Experiment schema file, which is used to validate XML records built by this module

Type

str

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 the instrument_db database. 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

nexusLIMS.builder.record_builder.build_new_session_records() List[Path][source]

Build records for new sessions from the database.

Uses get_sessions_to_build()) and builds those records using build_record() (saving to the NexusLIMS folder), and returns a list of resulting .xml files to be uploaded to CDCS.

Returns

xml_files – A list of record files that were successfully built and saved to centralized storage

Return type

List[Path]

nexusLIMS.builder.record_builder.build_record(session: Session, sample_id: Optional[str] = None, *, generate_previews: bool = True) str[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 Session object 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 Session or None. If a value is provided, instrument, dt_from, dt_to and user will be ignored, and the values from the Session object will be used instead

  • sample_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

xml_record – A formatted string containing a well-formed and valid XML document for the data contained in the provided path

Return type

str

nexusLIMS.builder.record_builder.dry_run_file_find(s: Session) List[Path][source]

Get the files that would be included for a record built for the supplied session.

Parameters

s (Session) – A session read from the database

Returns

files – A list of Paths containing the files that would be included for the record of this session (if it were not a dry run)

Return type

List[Path]

nexusLIMS.builder.record_builder.dry_run_get_sharepoint_reservation_event(s: Session) ReservationEvent[source]

Get the calendar event that would be used based off the supplied session.

Only implemented for the Sharepoint harvester.

Parameters

s – A session read from the database

Returns

res_event – A list of strings containing the files that would be included for the record of this session (if it were not a dry run)

Return type

ReservationEvent

nexusLIMS.builder.record_builder.dump_record(session: Session, filename: Optional[Path] = None, *, generate_previews: bool = True) Path[source]

Dump a record to an XML file.

Writes an XML record for a Session composed 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 Session object representing a unit of time on one of the instruments known to NexusLIMS

  • filename (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

Path

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
  • path – The file path in which to search for files

  • 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

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.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_session method 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 or Sharepoint).

Parameters

session – The Session for which to fetch a matching ReservationEvent from the relevant harvester

Returns

res_event – A ReservationEvent representation of a reservation that matches the instrument and timespan specified in session.

Return type

ReservationEvent

nexusLIMS.builder.record_builder.process_new_records(*, dry_run: bool = False, dt_from: Optional[datetime] = None, dt_to: Optional[datetime] = 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 if dry_run is set to False.

  • 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. All SharePoint events will always be fetched.

  • 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. All SharePoint events will always be fetched.

nexusLIMS.builder.record_builder.validate_record(xml_filename)[source]

Validate an .xml record against the Nexus schema.

Parameters

xml_filename (str or StringIO or BytesIO) – The path to the xml file to be validated (can also be a file-like object like StringIO or BytesIO)

Returns

validates – Whether the record validates against the Nexus schema

Return type

bool