Developer guide
This page collects how oceanarray code is written: the principles, which layer owns what, the one idiom for each recurring job, the vocabulary, naming, and the rules for docstrings, CHANGELOG, branches and pull requests. Where a convention departs from common Python practice it is listed under 8. Known deviations from common practice with its reason. CONTRIBUTING.md covers licensing, credit and the development setup; this page is the code itself.
Some rules below are not yet true everywhere in the code. Each such place is named with the release or piece of work that fixes it (“planned”).
The guide is written for everyone who changes the code, people and AI coding assistants alike. Each rule is stated so it can be followed without asking; where a rule is unclear or does not fit a case, open an issue and the guide is updated.
1. Purpose and principles
oceanarray takes raw mooring instrument files to QC-flagged, gridded CF-NetCDF products and a report per mooring. It is a package meant to be used across institutions: one project’s paths, scripts and choices live in that project’s own repository, not here.
Two ways of working, both kept. Users either follow the prescribed
directory structure ({proc_dir}/{name}/{name}.mooring.yaml) and name a mooring
by its name, or keep their own directory structure and give full paths. Either
way, a mooring’s name is its name: key, never read from the YAML’s file
name or folder. Every change keeps both working, and the
tests cover both (Configuration files).
Correct, then maintainable, then fast. A slower function that is right beats a faster one that is nearly right; clear code beats clever code. Shorter code is preferred only when it is equally correct and equally clear.
Consistent. One name for one thing and one way to do each recurring job (sections 3–5), so code from different contributors reads alike and a reader learns each pattern once.
Provenance: never change data silently. Every value a stage changes, drops or
fills is recorded in the file: a history entry for what was done, attributes
for the settings that did it (thresholds, coefficients, the flag rule), so a file
can be reprocessed from itself. Never substitute a default when the right value
cannot be determined: store "UNK", or raise, or warn and record the
assumption. A plausible wrong number is worse than an error.
The originator’s data are kept. Values, flags and attributes from the
originator’s files are carried beside ours (<var>_qc_originator_mapped,
originator_*), never overwritten. An export may leave them out when the user
asks for that; the default keeps them.
Real data in tests. Fixtures are trimmed real instrument files, not synthetic
mocks. A numerical assertion checks a value that can be justified without running
the code (analytic case, invariant, a gsw cross-check).
Against bloat.
Search for an existing helper and extend it before writing a new one; never a second copy.
No defensive code for states the data model rules out; no
try/exceptthat only re-logs.No compatibility aliases or shims except for released public API.
No new module when an existing one fits; a table of cases over repeated
if/elif.Delete dead code found in a file you touch.
2. Layers and what each owns
Layer |
Where |
Owns |
|---|---|---|
API |
|
The verbs: |
Description |
|
The |
Readers |
|
Vendor file → canonical dataset, one module per format. Instrument formats
come from |
Pipeline |
|
The verbs’ bodies, one file per verb ( |
Writers |
|
Writing only: |
Foundation |
|
The mask rules (which flag values a rule hides; parse, combine, record),
the originator flag vocabulary (reads the packaged
|
Physics |
|
Seawater and current formulas shared by the readers, the pipeline and the pages. |
Analysis |
|
Physics on the products that is not a pipeline step: θ, σθ, speed and
direction, spectra, a site’s record over the years (computed once per page
and passed to every figure), and |
Plotters |
|
|
Reports |
|
Pages: context builders, panel registries, captions, templates. The shared
layer in |
Config |
|
The variable registry and defaults ( |
CLI |
|
One module per subcommand; argument parsing only. Nothing the CLI does is unavailable as a library function. |
Legacy |
|
RODB/RAPID-era reference code. Shipped, not linted, not covered; nothing imports it. |
Data between functions is xarray. Data passes between functions as an
xarray.Dataset (or DataArray), never a pandas DataFrame. pandas is fine
inside a function where it is the natural tool (parsing times, building a table
for a page).
What may import what. Checked by lint-imports (contracts in
pyproject.toml, run in the lint job) and, for legacy, by
tests/unit/test_package_boundaries.py:
Layers. Each part imports only the parts listed below it:
cli→reports→plotters→analysis→pipeline→readersandwriters→ the mooring YAML and its helpers (mooring,catalog,provenance,logger,paths,instruments,location,physics,history,inspect,mask_rules,originator_flags) →configand_deprecated→exceptions. The shared report layer (reports/_vendored/) may be used by every part and imports none of them.plotters/never imports areports/module directly (the shared report layer excepted). Indirect chains are not checked yet: they still reach the pages through the mooring and pipeline cycle below.Units have one door. Pipeline code gets the unit tables through
config/unit_tables.py, never fromreports/_vendored/directly.Nothing outside
legacy/importsoceanarray.legacy.
The imports that break a rule today are listed as exceptions in the contracts,
each marked “To change”: two cycles,
where the lower module imports back inside a function to avoid a circular import
at load time: mooring and pipeline
(pipeline.stack and pipeline.concat import mooring; mooring uses
pipeline.attribution), and mooring and config/validation.py. A cycle is fixed by
moving the shared pieces below both modules, not by deleting a line. A pull
request that removes an exception deletes its line; a new one fails the lint job.
pipeline/_run.py importing reports is allowed: run ends with the
report.
Not yet checked: anything imported across subpackages is public (no leading
_). A private helper is used inside its own subpackage only. Planned: about 20
places cross today (for example cli → reports._verb._resolve_*,
pipeline.raw_files → readers.nortek._parse_*). For each, first check
whether the helper sits in the right subpackage or belongs in a module shared
across subpackages, then make it public or move it.
3. One idiom per recurring job
Each job below has one helper. If the helper does not do what you need, extend it; do not write a second one.
3.1 Reading a file
Rule. Raw instrument files go through oceanarray.read (readers.read).
The format comes from file_type or is sniffed from the content; the suffix is
never used.
A new instrument format. Instrument readers belong in seasenselib, which
other packages share. Write the reader there when its maintainers can take it in;
otherwise write it in readers/ and move it to seasenselib later, leaving a
thin call behind. Formats that only oceanarray reads (OceanSITES, RODB) stay in
readers/.
Records without a time. Some raw files contain records whose time cannot be
read (a corrupted line, a header repeated mid-file). The reader removes them, in
the reader only, and stores how many it removed in n_records_without_time, so
no later stage has to check for missing times.
if file_type is None:
file_type = _sniff_text(path)
if file_type is None:
raise ReaderError(
f"{path.name}: cannot determine the file type from its content; "
"set file_type: in the instrument entry of the mooring YAML, or "
f"pass file_type= to read() (one of {sorted(params.ALL_FILE_TYPES)})."
)
Not. Guessing the format from the extension; xr.open_dataset on a raw
file in pipeline code; print("WARNING: …") in a reader.
3.2 Adding a variable
Rule. A variable exists once, in config/parameters.VARIABLES: label,
canonical CF units, standard_name, cmap, and valid_min/valid_max
only where a physical limit is known, with its source in a comment. Then, as
needed: QC thresholds (QC_GROSS_RANGE, QC_SPIKE, QC_FLAT_LINE), a color
(VAR_COLORS), and a non-canonical unit spelling in config/unit_tables with
evidence (a reader that emits it). Labels come from vlabel(var) and
vunit(var).
"temperature": {
"label": "Temperature",
"units": "degree_Celsius",
"standard_name": "sea_water_temperature",
"cmap": "RdBu_r",
"valid_min": -5.0, # legacy/OS1_variable_attributes.yaml TEMP
"valid_max": 42.0,
},
Not. A unit string typed into a label or caption ("m s⁻¹";
test_unit_label_literals.py fails on it); valid_min/valid_max copied
from the gross-range spans (those are for flagging only); an unknown unit passed
through (UnitsError).
3.3 Recording what was done
Rule. Every processing step adds one history entry with
history.append_history(ds, note) (timestamp and separator live there),
and writes the settings it used as structured attributes. The note is a sentence a
reader understands, with the values in it; it never contains "; " (the entry
separator; append_history cleans it).
history is read back by one set of parsers, and only to display it: the
processing tables on the pages show its entries. Captions and settings never parse
history; what they need comes from structured attributes. If a table is wrong,
fix what the stage writes, not the page. If attributes ever become limiting, the
next step is a sidecar file the captions read (a small file written next to the
data file, such as M2_2016_grid.json), not more parsing. A sidecar is for
convenience only: the provenance must still be complete in the NetCDF file, which
is what gets shared.
append_history(
ds_out,
f"flags: values flagged {mask_rules.rule_words(flags)} left out before gridding "
"(grid_mask_flags)",
)
Not. Writing ds.attrs["history"] directly; a setting recorded only in the
history text; a second history parser. Planned: the pages parse history
in more than one module today (reports/_captions.py, reports/_grid.py),
and one caption counts entries from it.
3.4 Raising, warning, logging
Rule.
Raise when the input is wrong and continuing would write a wrong file:
MooringErrorfor a problem in the mooring YAML or the input,ReaderErrorfor a file a reader cannot read,UnitsErrorfor an unknown unit,StageErrorfor a file at the wrong stage. Every error about the user’s input derives fromOceanarrayErrorand keeps its built-in base (ValueError,RuntimeError); the CLI catchesOceanarrayErrorand prints one line. A package bug (e.g. an inconsistent table shipped with oceanarray) raises a built-in error such asRuntimeError, so it shows a traceback. The base and the general errors are inexceptions.py; an error tied to one module stays beside it (OceanSitesError,CaldipError,UnitsError).User input or caller mistake. A problem with the user’s input (the YAML and its content, a file, a stage) raises an
OceanarrayErrorsubclass. A caller’s programming mistake (a wrong argument value or combination) raises a plainValueErrororTypeError, as in Python. A helper that does not know the mooring may raiseValueError; the stage boundary then re-raises it asMooringErrorwith the mooring’s name.WARNING (
log.warning) for every data problem the user should act on: data dropped, a value assumed, a key ignored. Also recorded in the file when it changed the data.INFO: one line per step. DEBUG: per instrument.
Each module logs through
logging.getLogger(__name__). Configuring logging belongs to whoever runs the code: the CLI sets up the console once (logger.configure_console, stderr), and a Python user does the same or uses their own setup. Library code never sets levels or adds console handlers. Results go to stdout.Stages 1–3 also write their own log file with full DEBUG detail, next to their output, whether they are run from the CLI or from Python.
warnings.warnonly withDeprecationWarning, for deprecated names.
Message style: what (instrument and serial), what is wrong, what to do; lazy
% arguments in log calls.
raise MooringError(
f"{entry.get('instrument', 'unknown')} s/n "
f"{paths.safe_serial(entry.get('serial', 'unknown'))}: {n} record(s) "
"with no time in the stage-1 file; re-run stage 1 (the reader now "
"drops them)"
)
Not. print in library code; a broad except that swallows;
UserWarning for a data problem; an error class that does not derive from
OceanarrayError.
3.5 Old file names and layouts
Rule. Files written by a released version keep working. Renamed variables are
mapped on read in one table per rename, through one helper; e.g. the identity
scalars renamed in 0.6.1 (OLD_IDENTITY_NAMES) through
pipeline._stage.normalize_identity_names (to be renamed
canonical_identity_names, see 5. Naming). A compatibility branch names
the version it serves and goes when that version is no longer supported.
def nominal_depth_text(ds: xr.Dataset) -> str:
ds = normalize_identity_names(ds)
if "instrument_depth" in ds.variables:
return f"{float(ds['instrument_depth'].values):.0f} m"
return "?"
Not. ds.get("InstrDepth", ds.get("instrument_depth")) at a call site;
compatibility for unreleased development builds.
3.6 Display formatting
Rule. One helper per displayed quantity:
Shown |
Helper |
|---|---|
Nominal depth of one instrument |
|
Serial |
|
Durations in a table column |
|
Position |
|
Axis label / unit |
|
Flag words |
|
Not. f"{depth:.0f} m" or a unit written at the call site. User-facing text
says “depth”, never “slot” or an index.
3.7 Figures
Rule. draw_<what>(ds, …, width_in=W) -> Figure | None in plotters/:
drawn at the width of its place on the page, never resized after; None means
“not applicable to this file”. The report adapter _make_<what>_b64 calls
render_b64, which applies the report style, encodes and closes the figure. A
plotter may use pyplot (plt.subplots); render_b64 closes every figure it
encodes, and the test suite checks that none is left open. A plotter does not call
plt.style.use. Physics (θ, σθ, speed) comes from analysis/, computed once
per page and passed in. Choices the caption must state (levels, windows, limits)
are made once, in the page context, and passed to both the figure and its caption;
the caption never recomputes them.
Why two steps. draw_* knows nothing about where the figure goes; the
_b64 adapter embeds it in the page, so a report is one HTML file that can be
passed around whole. Writing PNG files instead is another adapter around the same
draw_* functions.
One masking rule. Every figure hides flagged values through
pipeline/masking.py (default: flag 4 hidden, suspect kept), so the pages, the
grid and the captions agree on what was left out.
Hiding is not showing. Masking decides which values are left out of a line,
a statistic or the grid. A figure that shows flags (colored markers on suspect
points, the flag rows) is a different job: it reads the flag variable through
marker_flags and draws every flagged point, including the ones masking hides
elsewhere.
def test_temperature_trajectory_none_without_temperature():
"""No temperature -> the trajectory panel is not applicable (None), not a KeyError."""
assert draw_temperature_trajectory(_velocity_only_ds()) is None
Not. A draw_*_fig name (test_private_names.py); a colormap chosen in the
plotter (design_tokens.CMAPS by quantity); a caption that parses history; a
figure that drops flags itself. Planned: plotters/helpers.py,
plotters/current.py, plotters/spectrum.py, plotters/diagnostic.py and
reports/_read.py still drop QC_BAD_FLAGS (3, 4, 9) directly; the fix moves
them to masking and retires QC_BAD_FLAGS.
Planned: draw_* returns the figure plus a small record of what it drew, and
captions read that record.
3.8 Pages
Rule. A page’s layout is an ordered list of sections, each naming the panels
(figures and tables) under its heading. The shared layer calls this list a
Profile, made of Section entries that name Panel ids
(reports/_vendored/page_model). Each page module (reports/_mooring.py,
reports/_stack.py, …) defines its own panels. A panel that applies but has
nothing to show says why (unavailable_if returns the reason). Templates lay out what the context built; they do not compute. Captions
sit above the figure or table, the source: line below; a highlighted cell has
its criterion in the caption.
"steps": Panel(
"steps",
render=lambda c: render_template("_history_steps.html", rows=c.steps),
kind="html",
caption=STACK_CAPTIONS["steps"],
unavailable_if=lambda c: None if c.steps else _html_helpers.NO_HISTORY,
),
Not. Arithmetic or filtering in a template (do it in the context builder);
hand-written <table> HTML in a new oceanarray template (use the table macros
the shared layer already provides); a panel that shows nothing without saying why.
Nothing in reports/_vendored/ is edited here: a change to the shared layer is
made in ctdcast and copied back. If a macro you need is missing, ask for it there.
3.9 Mooring YAML keys
Rule. Every top-level key is listed in KNOWN_KEYS in
oceanarray/mooring.py and documented in The mooring YAML file.
mooring.check reports an unknown top-level key as a WARNING; inside a block
(caldip, qc_*, stack, grid) every shape mistake is an ERROR naming
the allowed set. The YAML key, the Python keyword and the CLI flag are the same
word (pmin, --pmin).
Each mooring YAML stands alone. A setting shared by many moorings is written into each mooring’s YAML, never inherited from an array file or a parent file at run time, so one file is enough to reprocess its mooring. Planned: a command that writes such a setting into every mooring YAML of an array at once.
The YAML says what, the run says where (paths). The mooring YAML holds facts
and settings, never a path. Input locations (raw-data root, sensor catalog, caldip
set, bathymetry) come from the call or a CLI flag, optionally from a project or
user configuration file (planned). Keeping paths out of the YAML makes it
portable: the same file works on any machine and with any directory layout.
Planned: two keys still hold a path relative to the YAML, sensor_catalog and
caldip.root; until they move to the run, a new key never adds a third.
Not. A key read by the pipeline but missing from KNOWN_KEYS; a path of
any kind in the YAML. Planned: caldip.root and sensor_catalog are still
YAML keys. Planned for 0.7.0: an unknown top-level key becomes an ERROR, after
a survey of real mooring YAMLs.
3.10 Configuration defaults
Rule. A default is a constant in config/parameters.py with a #: comment
saying what it is and its unit. The defaults are read-only: nothing assigns to
params.X at run time (modules import it as
from oceanarray.config import parameters as params). A value is overridden, from lowest to highest priority,
by:
the default in
config/parameters.py;the mooring YAML;
the instrument’s entry in the YAML;
the call (keyword argument) or the CLI flag.
Where more than one of these can give a value, one resolve_<what> returns it in
that order and names where it came from in its error. What was used is recorded in
the output (deployment_settings, stack_mask_flags). A function signature
defaults to None and reads the constant, rather than repeating its value.
if given is not None:
value, where = given, "the call"
else:
from_yaml = (mooring.get("stack") or {}).get("dt_seconds")
...
Environment switches (3.13 Debug switches) are read when they are used, never at import.
Not. A literal default in a function signature that duplicates a constant;
defaults in a second table; reassigning a parameter to change one call’s behavior.
Planned for 0.7.0: reports/_verb.py passes SIGMA_GRID as an argument
instead of swapping the module value; OCEANARRAY_RAISE_ON_PLOT_ERROR is read at
render time instead of at import.
3.11 Deprecations
Rule. Only released public API is deprecated rather than changed. A renamed
Python name goes in _deprecated.RENAMED and is wrapped with
_deprecated.alias; a renamed CLI flag uses cli._deprecate.DeprecatedAlias
with help=argparse.SUPPRESS. The removal release is one constant,
_deprecated.REMOVED_IN; the migration page lists every entry (a test checks
it). A name deprecated during 0.7.x (0.7.0, 0.7.1, …) is removed in 0.8.0: the
next minor release, never a patch release.
vars = _deprecated.alias("oceanarray.inspect.vars", variables)
attrs = _deprecated.alias("oceanarray.inspect.attrs", attributes)
Not. An alias for something never released; a second spelling of the removal
version. Planned: REMOVED_IN is also defined in cli/_deprecate.py,
logger.LOG_FN_DEPRECATED writes “0.7.0” out, and the moved-module aliases
in pipeline/clock and pipeline/pressure write “0.8.0” out (the
mechanism has one removal release; these need the next one).
3.12 Tests
Rule.
Fixtures are trimmed real files: the
dune2_1_2026raw/proc set, the M2 OSNAP East moorings (egM2_concat, the site’s former name), OSNAP cuts (tests/fixtures/, 8 MB).Report pages are compared with golden HTML (
tests/fixtures/golden/), a saved copy of each page that a new render must match. The embedded figures (each a PNG image stored in the page as base64 text), the timestamps and the version number are blanked out before comparing, because they differ between machines and runs. Re-baseline withREBASELINE_GOLDEN=1 pytestonly after looking at the change; the golden diff is part of the review.dune2_pagesandegm2_site(tests/unit/conftest.py) build pages once per session; read them, never write into them.conftestforcesRAISE_ON_PLOT_ERRORon, so a broken figure fails a test instead of disappearing.Markers:
slow(more than about 5 s) andlocal(needs a developer’s machine), both excluded from CI; no test uses them today.Convention tests:
test_unit_label_literals,test_filename_literals,test_private_names,test_package_boundaries,test_doc_package_refs,test_vendored,test_base_css_no_vendored_dup,test_plot_guard,test_stub_reason. A settled idiom gets such a test.
Not. assert result is not None on a function that returns None on
failure; a value copied from the code’s own output as the expected value; a mock of
a stage when a fixture exists.
3.13 Debug switches
Environment variables for looking at a rendered page; all off unless noted.
Variable |
Effect |
|---|---|
|
Every label made by |
|
Each figure records its draw function, |
|
Turns off the |
|
A figure that fails raises instead of rendering a stub. |
4. Vocabulary
One meaning per term. Rows marked two meanings are still used two ways in the code; they are settled in the module naming review.
The places, from largest to smallest:
Term |
Meaning |
In the code |
|---|---|---|
array |
The set of moorings one year page shows (OSNAP East 2016), from
|
|
subarray |
A named group of moorings within an array (the Cape Farewell array). |
|
site |
One position, across all the moorings placed there (M2, CF5); joined by
|
|
mooring |
One physical mooring, from deployment to recovery ( |
|
deployment |
Only the act of deploying or the period in the water (“deployed
2016-08-05”, “the 2016–2018 deployment”). Never one mooring. The
OceanSITES |
|
The rest:
Term |
Meaning |
In the code |
|---|---|---|
originator |
Whoever produced the data files we read (a data center, a PI). Their values, flags and attributes are kept beside ours. |
|
oceanarray |
Our processing, where a flag source is named (“oceanarray flags”, not “processing flags”). |
|
source |
What a page or product was made from (stage files, the YAML). Not the data
provider. Two meanings: the YAML |
|
serial |
The instrument’s serial number. Two meanings: the |
|
nominal depth |
The design depth from the mooring YAML (m, positive down). |
|
depth |
Two meanings: depth computed from pressure ( |
|
pressure / bin pressure |
Measured (or stage-3 interpolated, flag 8) sea pressure in dbar; an ADCP bin’s pressure from the head pressure, range and tilt. |
|
HAB |
Height above bottom (m) of the sensor: write |
|
stage 1 / 2 / 3 |
Read to CF-NetCDF / clock and trim / QC, rotation, derived. A file’s stage
is its |
|
level |
One row of a stack: an instrument, or one ADCP bin. Not a grid pressure level. |
|
stack |
One mooring on a common time axis (nearest sample within ±dt/2). |
|
grid |
One mooring’s stack interpolated in pressure. |
|
Stack cat |
A site’s stacks joined end to end in time, levels matched by depth. |
|
Grid cat |
The Stack cat interpolated in pressure. Built from the Stack cat, not by joining the moorings’ grids. |
|
flags |
Unqualified, “flags” means oceanarray’s flags ( |
|
mask flags |
The flags a stack page hides and the grid leaves out (default 4). |
|
valid_min / valid_max |
CF attributes on each data variable in the output files, set from
|
|
gross range |
QC test spans (fail / suspect); for flagging only. |
|
slot |
The width class of a figure on a page ( |
|
5. Naming
Modules: named for what they hold (
mooring.py,masking.py); a verb’s body has the verb’s name inpipeline/; a set of alternatives is a plural agent noun in its own subpackage (readers/,gridders/). Never named for a kind of code: notools,utilities,utils,helpers,misc. A package’s__init__.pylists the names it re-exports in__all__, right after its imports; a plain module has no__all__: a leading underscore marks what is private, and the API page shows the rest. A test fails if a plain module defines one.Public functions are named by kind:
Kind
Name
Example
read or write a file
read_<what>,write_<what>read_mooringa processing verb
the verb
stack,grida computed quantity
a bare noun (as in
gsw)potential_temperature(ds)convert form
to_<form>,from_<form>to_oceansitesthe one accepted form
canonical_<thing>canonical_identity_namespick among sources by priority
resolve_<what>resolve_mooringtext for display
<what>_textserial_textcells of a table
<what>_cellsduration_cellsyes or no
is_<state>,has_<thing>is_path_componentproblems found
check_<what>, returning a list of problemsmooring.checka figure
draw_<what>, returning a Figure or Nonedraw_instrument_rosea page
generate_<what>_pagegenerate_gridcat_pageNo word with two spellings (British and American) in a public name:
canonical_,_rename_, notnormalize/normalise.coloris the one exception.Private helpers: leading
_, one verb per job. The docstring is one line plus a typed signature; a reason the code cannot show goes in a#comment at the line it explains.Name
Returns
_read_<what>(path)an object read from a file
_parse_<what>(text)a typed value from a string in hand, no I/O
_resolve_<what>(…)the one value that applies, from several sources by priority
_format_<what>(value)a display string
_build_<what>(…)rows, a dict or a dataset
_render_<what>(…)an HTML fragment
_make_<what>_b64(…)a base64 PNG for a page (
_b64sfor a list)_has_<what>,_is_<what>a bool
_apply_<what>(ds, …)the dataset after one processing step
_add_<what>(…)the target with variables, attributes or flags added
_rename_<what>(ds),_to_canonical_<form>(ds)renamed variables; a foreign layout in ours
a noun (
_time_axis_bounds)a computed result
Retired prefixes
_fmt_,_normalize_,_sanitize_,_get_,_find_,_load_,_clean_,_plot_failtest_private_names.py. A private helper is used inside its own subpackage only (section 2).Constants and tables:
UPPER_SNAKE, whole words, no type suffix.Files: every stage and product suffix comes from
paths(test_filename_literals.py); YAML files are.yaml.CLI: verbs with one meaning each (
init,validate,process,run,report,list,concat,export,stamp,plot,animate); short flags only-o,-n,-v;--stageis a list. CLI verbs and flags follow conventions shared with the sibling packages: propose a new verb or flag in an issue before adding it.Units in names. Data variables never carry a unit in their name (the unit is their
unitsattribute). Settings, keywords and scalar attributes that hold a number with a unit carry it as a suffix, spelled one way:_seconds,_hours,_days,_m,_dbar,_deg,_percent. Pressure is always in dbar (never Pa, never m) and depth and heights in m. Pressure and depth keys and flags may leave the suffix out because their unit never varies (pmin,--pmin); a stored attribute always carries it (pmin_dbar). Times always carry it (--dt-seconds).The same word everywhere: the CLI flag, the Python keyword, the YAML key and the file attribute name the same thing the same way (
--pmin,pmin=,pmin:,pmin_dbar).YAML keys: lowercase snake for our own words, no spaces or hyphens; a key naming a format’s entity is spelled as the format spells it (
platform_code).
Planned renames.
plotters/helpers.pyis split by what it holds:plotters/styles.py(mooring and level styling, legends, axes),plotters/roses.py(current roses),plotters/_data.py(reading a dataset for a figure:masked,ruled,as_dataset,marker_flags,nominal_depths,tilt_limits) andplotters/_labels.py(serial_text,nominal_depth_text,duration_words,short_names);tukey_smoothmoves toanalysis/.normalize_identity_namesbecomescanonical_identity_names; the old name stays as a deprecated alias until 0.8.0.0.7.0: everything about the data provider is named
originator_*:source_citation,source_doi,source_license,source_acknowledgementbecomeoriginator_*, andsource_filemerges intooriginator_file(files with the old names are still read). “Source” keeps only<field>_source(where a value came from). The YAMLsource:block becomesoriginator:(the old key still accepted, with a warning).With the shared report layer: the line under a figure or table that names the function that made it changes from
source:tocode:; the page model’sProfileandSectionbecomeLayoutandPart.0.7.0: the
p_start/p_endkeywords becomepmin/pmax(old keywords deprecated).
Names that do not follow the table yet (renamed in the module naming review):
compute_* and calc_* become bare nouns (compute_adcp_bin_pressure,
calc_psal); format_* and *_label display helpers become *_text
(format_ddm, format_durations, unit_label, cruise_label);
generate_*_report becomes generate_*_page (array); plot_title,
plot_climatology and plot_deployment_boundaries become draw_*; the
_s and _pct suffixes become _seconds and _percent
(dt_s, offset_s, oxygen_saturation_pct, …).
6. Docstrings, comments, CHANGELOG, branches, pull requests
Docstrings (numpy style, rendered by Sphinx with the Read the Docs theme):
Public functions: one-line summary,
ParametersandReturnswith types,Raiseswhen it raises; a “why” sentence only when the code cannot show it.Private helpers: one line saying what comes back; the signature carries the types. A reason the code cannot show goes in a
#comment at that line.Never restate the code. A docstring longer than its function is a sign to cut.
Module docstring: what the module holds, in two or three lines.
def format_ddm(value: float, *, is_lat: bool) -> str:
"""Return a position as degrees and decimal minutes with a hemisphere letter.
The value is rounded once, to the nearest hundredth of a minute, and only then
split into degrees and minutes, so the minutes never read ``60.00′``.
Parameters
----------
value : float
Latitude or longitude in signed decimal degrees.
is_lat : bool
True for a latitude (two-digit degrees, ``N``/``S``); False for a
longitude (three-digit degrees, ``E``/``W``).
Returns
-------
str
For example ``"65° 43.91′ N"`` or ``"027° 48.00′ W"``.
"""
Comments and docstrings make no references to tools, local notes, plan or handoff files, or machine paths: they describe the code. No filler adjectives. Never “slot” for a depth in user-facing text.
CHANGELOG: one CHANGELOG.md, edited in each pull request: one line per
user-visible change, under 200 characters, with the PR number; a short why only
when the reader must act. Breaking changes also go in the migration page.
Branches: every branch starts from main. Keep few branches open at once.
Stack a branch on another only when it needs that branch’s code; then merge from
the bottom up, and after each squash merge rebase the next branch with
git rebase --onto main <old base>. Two branches that touch the same files
without depending on each other are not open together: merge one before starting
the other.
Pull requests: one logical change each. Title [TYPE] title with one of
FEAT, FIX, REFACTOR, DOC, TEST, CI, CLEANUP
(CLEANUP for maintenance: dead code, docstrings, releases). Pull requests are
squash-merged, and the squash commit’s title is the PR title, so commit messages on
the branch follow no fixed form. Body:
## Summary: two or three sentences.## What's changed: short one-line bullets.## Breaking changes: only if there are any.## Tests: what was run.
Each paragraph and bullet is one line (GitHub wraps it). No references to local notes, rulings, patch names or tags.
A pull request that renames, moves or fixes something this guide names also updates the guide: the name, the “Planned” note, or the row in 8. Known deviations from common practice.
Review: request a Copilot review on every pull request before merging. Each comment is fixed or resolved; one resolved without a fix gets a one-line reply saying why, so the next reader knows it was weighed. The review adds to CI and to a human reviewer; it replaces neither.
7. Tests and CI
Job |
Runs |
Notes |
|---|---|---|
unit |
|
coverage gate 58 % (Ubuntu 3.11); an example that needs files on disk is
marked |
integration |
|
golden pipeline tests with |
wheel |
builds the wheel, installs it in a fresh environment and opens every packaged data file |
catches files missing from the package |
lint |
|
|
docs |
executes |
pull requests touching |
pypi |
build, |
on a published GitHub Release |
tests/legacy/ does not run in CI: it covers the reference code in legacy/.
Python versions. A Python version is supported for at least 3 years after its
release (SPEC 0). The floor (requires-python, now 3.11) is raised only in a
minor release, and only when that version stops working with a core dependency
(numpy, xarray, gsw) or something breaks on it. CI tests the floor and the newest
release.
Locally, before handing over a change: ruff format --check ., ruff check .
(whole repository), lint-imports and pytest. AGENTS.md at the top of
the repository points coding assistants to this guide. The full local run (unit + integration, not
local) is about 1900 tests in 5 minutes; the first test to build the session
pages takes about 20 s.
To format on save in VS Code, install the Ruff extension and add to
.vscode/settings.json:
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
}
}
Planned: a type checker (pyright, basic mode) on pipeline/, readers/ and
writers/, advisory for one release before it can fail a build; the docs built
with -W --keep-going once the current warnings are cleared. The coverage gate
stays at 58 % until coverage has been measured per module.
8. Known deviations from common practice
Two tables: conventions kept on purpose, with the reason, and conventions that are decided to change. A row of the second table is deleted by the pull request that makes the change.
Kept on purpose
Our convention |
Common practice |
Reason |
|---|---|---|
Vendored report layer: |
A shared dependency |
The shared layer still changes often, and a separate package would need a release for every change. Revisited once it has been stable for a few months. |
Golden HTML tests on the rendered pages |
Assert on structure, not on whole rendered output |
The page is the product; a structural change must keep it green and a visual change is a reviewable diff. PNGs masked (cross-platform). |
CI unit tests run on an editable install; version from git tags via setuptools-scm |
Test the built wheel |
setuptools-scm keeps the version in one place; the |
Deprecation shims for one release ( |
Same |
Released public API only. |
|
Delete, or move to an archive repository |
Reference for the RAPID heritage; nothing imports it. |
Project scripts in each project’s repository, not entry points |
Entry points in the package |
oceanarray serves many institutions and holds no single project’s paths, scripts or choices. |
Notebooks not linted; only |
Notebooks tested |
Exploratory. |
One |
Changelog fragments (towncrier) |
One regular contributor; one line per entry. Revisited when a second regular contributor appears. |
Squash merges; PR titles |
Conventional commits on |
One reviewable unit per PR; the squash title is the PR title (section 6). |
Older oceanarray templates with hand-written tables |
All tables from the shared macros |
New templates use the shared macros (section 3.8); the older ones move over when they are next reworked. |
Coverage gate 58 %; |
Higher gate, nothing omitted |
Held until coverage is measured per module. |
Large plotter modules ( |
Modules of a few hundred lines |
Splitting a plotter module only moves code; its figures share one set of styles and helpers. |
Defaults in |
Immutable defaults |
Read-only by rule: settings are passed in through the override order (section 3.10), never by reassigning a default. |
A broad |
Catch specific exceptions |
A page renders with a stub that names the cause instead of failing whole
( |
To change
Our convention now |
Common practice |
What it becomes |
When |
|---|---|---|---|
One registry module |
One module per domain |
A package |
naming review |
|
Short functions |
A |
after 0.7.0 |
Private helpers imported across subpackages |
Private means module-internal |
Public, or moved to the subpackage that uses them (section 2) |
naming review |
Annotations checked by ruff |
A type checker in CI |
pyright on |
planned |
An unknown top-level YAML key is a WARNING |
Unknown keys rejected |
An ERROR, after a survey of real mooring YAMLs |
0.7.0 |
|
Settings passed in |
Passed as an argument (section 3.10) |
planned |
Import-time side effects: |
No side effects at import |
The switch read at render time (3.13); the level set when a log file or console is attached (3.4) |
0.7.0 |
Docstrings longer than the code |
Proportionate docstrings |
Trimmed (section 6) |
planned |
Some figures drop |
One rule |
Every figure masks through |
planned |
Paths in the YAML: |
Configuration separate from location |
From the call, a CLI flag or a user configuration file (section 3.9) |
planned |
Docs build without |
Warnings as errors |
|
planned |