A Python script to automate the preparation of oceanographic datasets for submission to SOCAT (Surface Ocean CO₂ Atlas).
prep_SOCAT.py bridges two data infrastructure systems used in the ICOS (Integrated Carbon Observation System) ocean data pipeline, and requires a user-provided metadata template:
- QuinCE – quality control system where processed datasets are stored
- ICOS Carbon Portal – data repository providing persistent identifiers (PIDs/DOIs)
- OADS XML template – a dataset-specific metadata file pre-filled by the user (see XML template)
The script downloads a dataset from QuinCE, enriches it with metadata from the Carbon Portal, populates a SOCAT-compliant OADS XML metadata file, prepends the required SOCAT header to the TSV data file, and copies the resulting .tsv and .xml files to an output folder ready for SOCAT upload. The script runs on both Linux and Windows.
QuinCE API ──► Download dataset (zip)
│
▼
Unpack & read manifest.json + .tsv
│
▼
ICOS Carbon Portal (SPARQL) ──► Retrieve URI / PID
│
▼
OADS XML template ──► Populate with metadata ("TK" placeholders)
│
▼
Write SOCAT header to .tsv
│
▼
Move .tsv + .xml ──► output folder (SOCAT-ready)
│
▼
Clean up temporary files
- Python 3.x
icoscp_core– ICOS Carbon Portal clientrequests– HTTP library for the QuinCE APIos,sys,json,zipfile,tempfile,shutil,xml.etree.ElementTree,datetime– Python standard library (included with Python)
Install third-party dependencies:
pip install icoscp-core requestsSOCAT_prep/
├── prep_SOCAT.py # Main script
├── Data/
│ ├── credentials.json # QuinCE connection credentials (not committed)
│ └── <name>_template.xml # OADS XML template for the dataset
└── README.md
{
"url": "https://<quince-instance>/api/",
"username": "<your-username>",
"password": "<your-password>"
}Note: Keep
credentials.jsonout of version control (add it to.gitignore).
The OADS XML template (schema a0.2.2s) must be pre-filled with all static metadata (investigators, instruments, methods, etc.). Fields that the script fills in automatically are marked with the placeholder TK:
| XML tag | Source |
|---|---|
metadataRecordCreationDate |
Current date |
submissionDate |
manifest.json → last_touched |
metadataURL / datasetURL |
Carbon Portal URI |
datasetDOI |
Carbon Portal PID |
startDate / endDate |
manifest.json → SOCAT export bounds |
westernBounds … southernBounds |
manifest.json → SOCAT spatial bounds |
expocode |
manifest.json → dataset name |
python prep_SOCAT.py -n <dataset_name> -S <template_name> [options]| Flag | Description |
|---|---|
-n, --name |
Dataset name as stored in QuinCE (with or without .zip extension) |
-S, --SOCAT |
OADS XML template filename (with or without .xml extension), looked up in the data folder |
| Flag | Default | Description |
|---|---|---|
-t, --tmp |
System temp folder | Temporary working directory |
-o, --output |
Dataset name | Output folder for the final .tsv and .xml files |
-d, --data |
Data/ |
Folder containing credentials.json and the XML template |
-v, --version |
— | Print version and exit |
python prep_SOCAT.py -n 119920230901 -S 1199_template -d Data/ -o output/This will:
- Download
119920230901from QuinCE - Read
Data/1199_template.xmland fill in theTKfields - Query the Carbon Portal for the corresponding PID/URI
- Prepend the SOCAT header to the TSV file
- Write
output/119920230901.tsvandoutput/119920230901.xmlready for SOCAT upload
| Code | Category | Cause |
|---|---|---|
0 |
Success | |
2 |
Bad arguments | Missing -n or -S argument |
3 |
Setup / config error | Cannot create folder or load credentials.json |
4 |
Connection / download error | HTTP failure, network error, or empty response |
5 |
File I/O error | Cannot read/write XML template, zip, manifest, or output files |
6 |
Data error | SPARQL query to Carbon Portal failed or returned no results |
Current version: 1.1
- 1.1 – Output the SOCAT-ready
.tsvand.xmlfiles directly to the output folder instead of repacking into a zip archive. Added Windows compatibility (system-independent temp folder and path handling). Various bug fixes. - 1.0 – Initial release.
Jean Negrel (jean.negrel@norceresearch.no), NORCE Research AS, Bergen