Introduction
OPUS is the Outer Planets Unified Search tool of the Ring-Moon Systems Node of NASA’s Planetary Data System. It lets a scientist search the Ring-Moon Systems Node’s holdings by observation metadata – when an observation was taken, what it was pointed at, what geometry it covers – and then retrieve the data files that match.
Who this guide is for
This guide is the manual for working on OPUS. It assumes:
a competent Python developer, who is new to this codebase;
no prior knowledge of OPUS – every term OPUS coins is defined here on first use;
familiarity with the PDS holdings format – PDS3 volumes and PDS4 bundles, labels, index tables, and the shape of an archive directory tree. This guide does not re-teach those. It does say precisely which parts of a holdings tree OPUS reads and what it does with each of them, because that is an OPUS decision rather than a PDS one.
It favors architecture and contracts over restating what the code already says. Where a module’s own docstring is the authoritative description of something, this guide points at it rather than copying it, because a copy goes stale and a cross-reference does not.
Two other documents sit beside it. The Public Web API guide
documents the HTTP interface an OPUS server offers, and is written for people using
OPUS rather than developing it. CONTRIBUTING.md in the repository root, reproduced
under Contributing, describes how to propose a change.
How to read it
The chapters are in reading order, and the order is deliberate:
Orientation – this chapter, Repository Layout and Environment Setup get a checkout working and say where everything is.
The whole system at once – Architecture is the one-page map of the two programs and the database between them. Read it before either subsystem.
The import pipeline – The Import Pipeline and the pages under it, covering how holdings become tables, how to run a run, what each module does, how it is tested without holdings, and how to add to it.
The database – The OPUS Database and the pages under it describe the thing the two programs share: the schema itself, the JSON every table is created from, the OPUS ID, and the data dictionary.
The web application – The Web Application and the pages under it, from how a request is served to how to add an app.
The two shared packages – The Configuration File is the file every OPUS process is configured by, and The opus_support Module is what the two programs convert values with so that they agree.
Testing it, and the third program – Testing covers the three suites and what each one needs, and The Log Analyzer the log analyzer.
Running a server is not in this guide at all. User Guide is the separate guide for that: installing OPUS, importing the holdings, putting a web server in front of it, and operating it, without assuming anything about how OPUS is built.
Working on it – Coding Conventions and Contributing, then the generated API Reference.
What the distribution contains
rms-opus is one Python distribution holding three programs – two of which share a
database – and two supporting packages:
opus_importThe import pipeline. It reads PDS3 volumes and PDS4 bundles out of the Ring-Moon Systems Node’s holdings, computes one row of metadata per observation, and writes the OPUS database. It runs as
opus_import, or equivalentlypython -m opus_import.opus_appThe Django project. It serves the OPUS user interface and the public web API out of the database the import pipeline wrote. It runs under a WSGI server, and its management commands are run with
opus_manage, which is Django’s own command line with the settings module already named.opus_configThe configuration loader. It reads the one TOML file an installation is configured by and hands it to the other packages as frozen dataclasses.
opus_supportConversions both programs need and neither owns: units, times, spacecraft clock counts, angles and orbit numbers. It is internal to this distribution.
opus_log_analyzerA separate program that turns a server’s Apache access logs into reports on how OPUS is being used. It runs as
opus_log_analyzer, or equivalentlypython -m opus_log_analyzer; its error-log companion isopus_error_analyzer.
What OPUS reads out of the holdings
The import is index-driven, and this is the single most important fact about it. A
run never walks an archive looking for data products and never opens one. Everything it
computes comes from the index tables an archive ships, and everything it records about a
file – size, checksum, image dimensions – comes from an rms-pdsfile shelf rather
than from the filesystem.
Concretely, for one PDS3 volume or PDS4 bundle:
The primary index. One row per observation, or per group of observations where an
instrument records several phases in one row. opus_import.config_bundle_info names
the file to look for, and opus_import.steps.do_import searches the bundle’s
metadata directories – and, for PDS3, the volume’s own INDEX/index directory
– for it. This is the spine of the import: every observation OPUS holds for that bundle
comes from a row of this file.
The index’s own label. Read alongside the rows, because some instruments record per-file information as label keywords rather than as table columns.
The associated metadata files beside it. These are discovered, not configured:
import_one_index() lists the same directories
and takes every file whose name starts with the bundle id and ends with
SUMMARY.LBL, SUPPLEMENTAL_INDEX.LBL or INVENTORY.LBL, ignoring any name
containing 999 because those are the cumulative files. Each kind is joined to the
primary index on the primary file specification:
File |
What it contributes |
|---|---|
|
Extra columns for the same observations – at most one row each. |
|
Ring geometry, at most one row per observation. Fills |
|
Sky (right ascension and declination) geometry, at most one row per observation. |
|
Surface geometry, one row per target per observation, so these are collected
into a per-observation dictionary keyed by target name. Fills
|
|
The list of targets each observation covers. It is CSV rather than a fixed-width
PDS table, so it is parsed with |
The shelves. rms-pdsfile answers which files an observation has
(opus_products()), and its info shelves supply each file’s size, checksum and, for
an image, its width and height. Those values fill obs_files.
Nothing else in the tree is read. There are no data files in the picture at all, which is exactly why the whole pipeline can be tested against a few megabytes of checked-in metadata; see The Mini-Holdings Import Fixture.
OPUS vocabulary
OPUS coins a small number of terms and reuses a few PDS ones with a narrower meaning. Every one of them appears throughout this guide.
- Bundle
OPUS’s word for the unit an import run is asked for: a PDS4 bundle or a PDS3 volume. The command line,
opus_import.config_bundle_infoand thebundle_idcolumn all use it in that widened sense, soCOISS_2002– a PDS3 volume – is a “bundle” here. Where a passage means specifically one or the other, it says PDS3 volume or PDS4 bundle.- Observation
One row of a bundle’s primary index, expanded by phase (below) if the instrument produces more than one observation per row. It is the unit everything else in OPUS is counted in: one observation has one row in
obs_general, one OPUS ID, and one entry in a result set.- Phase
An extra dimension some instruments add to an index row. Cassini VIMS records an infrared and a visible observation in one row, so its obs class returns two phase names and every field method is called once per phase. Most instruments have a single, empty, phase name. See
phase_names.- OPUS ID
The stable, human-readable identifier of one observation, such as
co-iss-n1635813867. It is derived byrms-pdsfilefrom the observation’s primary file specification, is unique across the whole database, and is what the public API and the cart identify observations by. OPUS ID Format describes the format mission by mission.- Primary file specification
The path, relative to the holdings root, of an observation’s primary data file. It is what the OPUS ID is derived from and what every other index file is cross-referenced on, so it must be computable from the primary index alone. See
primary_filespec.- Obs class
A class in the
opus_import.obshierarchy. One instance is created per bundle, and itsfield_obs_<table>_<column>methods compute the columns of that bundle’s rows. The Obs Class Hierarchy describes the hierarchy.- Field method
A method named
field_obs_<table>_<column>on an obs class. The import calls it once per column per observation; whatever it returns, after validation, is what goes in the database.- Table schema
The JSON file under
src/opus_import/table_schemas/that defines one OPUS table: its columns, their SQL types, where each value comes from, and how the search form presents it. It is the single description of the database. Table Schemas documents every key.obs_tableA table holding observation metadata, one row per observation.
obs_generalis the master: every observation has a row there and every other table’s rows hang off it. Anobs_table corresponds one-for-one to a “Constraints” category in the user interface.- Mult table
mult, the table of permitted values for every enumerated column, besidemult_field, which names each column’s mult field, andmult_group, which holds each field’s groups. Anobs_column whose value comes from a fixed set stores the integer id of one of its field’smultrows rather than the value itself, which is what makes the checkbox searches fast. “Mult” is short for multiple choice.- Slug
The short field id an API call names a field by –
time1,RINGGEOringradius1– as distinct from the SQL column name. The mapping lives inparam_info.- Fresh import, append
The two ways an import writes, chosen by the state of the schema it writes into. A fresh import, into a schema not yet served, creates the observation tables with only the keys a load needs and leaves the rest for finalization; an append, into a finished schema, loads into the tables with their keys in place and marks the schema
appendinguntil it is finalized and marked ready again. Either way there is one set of tables, the one the web application reads.- Bundle registry
The
import_bundletable, which records each bundle an import takes on and whether it finished. Finalization and the step that marks a schema ready both refuse while any bundle in it is notdone.- Search results
The rows of the
search_resultstable holding the ids of the observations one search matched, in sort order, under the search’suser_searchesid. The web application stores them the first time anyone makes the search, and every later query for the search reads them;opus_manage pruneremoves the searches unused the longest.- Trigger
A value a user can search for that makes a further table of search parameters relevant – choosing the Cassini mission reveals the Cassini mission table. The
partablestable records them.
Runtime and dependencies
OPUS needs Python 3.12 or later and MySQL 8.0.19 or later. The database
backend is written against an abstraction (opus_import.importdb) that keeps
room for another brand, but MySQL is the only brand implemented.
The dependencies worth knowing about before reading any code:
Django 5.2 – the web application. OPUS uses Django’s ORM only for reading; every OPUS table is created by the import pipeline rather than by a migration, and the heavier queries are assembled by
opus_app.apps.tools.sql_builderinstead.rms-pdsfile, rms-pdstable, rms-pdsparser – the Ring-Moon Systems Node’s own libraries for finding files in the holdings and for reading PDS3 labels and index tables.
rms-julian – time conversions, which
opus_support.time_parsingbuilds on.mysqlclient – the MySQL driver. It has no Linux wheel, so installing OPUS compiles it and needs the MySQL client development headers.
pdfkit and qrcode – used by the help pages to offer a PDF and a citation QR code.
pdfkitshells out towkhtmltopdf, which is why PDF generation is skipped on platforms that do not have it.
The JavaScript and CSS front end is served as static assets with no build step. There is no bundler.