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
- 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.build_new_session_records() List[Path][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.
- 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
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
xml_record – A formatted string containing a well-formed and valid XML document for the data contained in the provided path
- Return type
- 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.
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
- 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
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.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.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 or Sharepoint).- 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.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 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. 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.
