Reconstructing three-dimensional (3-D) ocean temperature and salinity (thermohaline) fields from two-dimensional (2-D) satellite surface observations is critical for climate prediction (e.g., AMOC, ENSO), ocean acoustic propagation, and maritime security. While satellite altimetry and radiometry provide high-frequency, basin-wide sea surface measurements (such as Sea Level Anomaly [SLA] and Sea Surface Temperature [SST]), direct subsurface observation networks (e.g., Argo profiling floats) remain sparse and intermittent.
Traditional deep learning approaches rely on purely data-driven black-box architectures (e.g., 2-D CNNs), which often suffer from limited receptive fields, non-physical predictions (such as density inversions and abnormal thermal inversions), and finite difference truncation errors across discrete layers.
Phy-Ocean addresses these challenges by coupling a Swin Transformer spatial backbone with a Physics-Informed Neural Network (PINN) continuous coordinate decoder. By integrating the TEOS-10 equation of state directly into the loss function via PyTorch autograd, Phy-Ocean reconstructs continuous 3-D thermohaline fields constrained by hydrostatic and thermodynamic principles.
The dataset is sourced from the Copernicus Marine Service (CMEMS) and the International Argo Program.
- Spatial range: Temperate Pacific region (145°E–165°E, 30°N–40°N), depth 0–1000m. Open ocean without land cover.
- Time range: January 2013 to December 2021 (monthly mean, 108 months).
- Training set: 2013–2018 (72 months)
- Validation set: 2019–2020 (24 months)
- Test set: 2021 (12 months)
| Variable | Dataset / Source | Resolution | Depth | Purpose |
|---|---|---|---|---|
| SLA (Sea Level Anomaly) | cmems_obs-sl_glo_phy-ssh_my_allsat-l4-duacs-0.125deg_P1M-m | 0.125° | Surface | Input feature |
| SST (Sea Surface Temperature) | METOFFICE-GLO-SST-L4-REP-OBS-SST (OSTIA) | 0.05° | Surface | Input feature |
| SSS (Sea Surface Salinity) | cmems_obs-mob_glo_phy-sal_my_multi-oi_P7D-c | 0.25° | Surface | Input feature |
| Wind U/V (Scatterometer Wind) | cmems_obs-wind_glo_phy_my_l4_P1M | 0.25° | Surface | Input feature |
| Lon / Lat / Month | Coordinate grids & cyclic month encoding | Grid-aligned | Surface | Input feature |
| Potential temp & salinity (thetao, so) | cmems_mod_glo_phy_my_0.083deg_P1M-m (GLORYS12V1) | 1/12° (~0.083°) | 0–1000m (25 levels) | Training target |
| In-situ T/S profiles | International Argo Program / China Argo Centre | Profiles | 0–1000m | Independent test |
%%{init: {
'theme': 'base',
'themeVariables': {
'background': '#FFFFFF',
'primaryColor': '#FFFFFF',
'primaryBorderColor': '#CBD5E1',
'primaryTextColor': '#0F172A',
'secondaryColor': '#F8FAFC',
'tertiaryColor': '#FFFFFF',
'mainBkg': '#FFFFFF',
'clusterBkg': '#FFFFFF',
'clusterBorder': '#E2E8F0',
'lineColor': '#475569',
'textColor': '#0F172A',
'edgeLabelBackground': '#FFFFFF',
'fontFamily': 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
}
}}%%
flowchart TD
subgraph S1 [" "]
direction TB
H1["1. Surface Multi-Forcing Inputs<br/>(8 Channels)"]
I1["Dynamic Tracers: SST / SLA / SSS"]
I2["Boundary Forcing: Wind Stress (Wind U / V)"]
I3["Spatiotemporal: Lon, Lat / Month Period"]
H1 --> I1 --- I2 --- I3
end
subgraph S2 [" "]
direction TB
H2["2. Spatial Attention Backbone<br/>(Swin Transformer)"]
E1["Patch Embedding: Hidden Dimension C"]
E2["W-MSA / SW-MSA<br/>Local and Shifted Window Attention"]
E3["Surface Latent Feature Token Matrix F_surf"]
H2 --> E1 ==> E2 ==> E3
end
subgraph S3 [" "]
direction TB
H3["3. Continuous PINN Decoder<br/>(Implicit Neural Representation)"]
D1["Vertical Depth Variable<br/>z ∈ [0, 1000m] (requires_grad)"]
D2["Latent Concatenation: [F_surf, z] Representation"]
D3["Continuous MLP Decoder: Smooth Tanh Activation"]
H3 --> D1 --> D2 ==> D3
end
subgraph S4 [" "]
direction TB
H4["4. 3-D Thermohaline Field Prediction<br/>(0–1000m)"]
O1["Reconstructed Temperature T_hat<br/>(Mixed Layer / Thermocline)"]
O2["Reconstructed Salinity S_hat<br/>(Subsurface Halocline)"]
H4 --> O1 --- O2
end
subgraph S5 [" "]
direction TB
H5["5. Physics Priors & Adaptive Balancing<br/>(Closed Loop)"]
P1["Data Loss L_data: GLORYS12V1 Full-Depth MSE"]
P2["Thermal Monotonicity L_phy,T<br/>Autograd dT/dz ≤ 0"]
P3["Stratification Stability L_phy,rho<br/>TEOS-10 drho/dz ≥ 0"]
Opt["Adaptive Multi-Objective Balancing<br/>& Backpropagation"]
H5 --> P1 --- P2 --- P3 ==> Opt
end
I3 ==>|Surface Tensor X_surf| H2
E3 ==>|Latent Tokens F_surf| H3
D3 ==>|Continuous Depth Decoding| H4
O2 ==>|3-D Physical Validation| H5
Opt -. Closed-Loop Physical Gradient .-> H2
style S1 fill:#FFFFFF,stroke:#0284C7,stroke-width:1.5px,stroke-dasharray: 4 4,rx:8px,ry:8px
style S2 fill:#FFFFFF,stroke:#7C3AED,stroke-width:1.5px,stroke-dasharray: 4 4,rx:8px,ry:8px
style S3 fill:#FFFFFF,stroke:#059669,stroke-width:1.5px,stroke-dasharray: 4 4,rx:8px,ry:8px
style S4 fill:#FFFFFF,stroke:#D97706,stroke-width:1.5px,stroke-dasharray: 4 4,rx:8px,ry:8px
style S5 fill:#FFFFFF,stroke:#E11D48,stroke-width:1.5px,stroke-dasharray: 4 4,rx:8px,ry:8px
classDef headStyle1 fill:#0284C7,stroke:#0284C7,stroke-width:1.5px,color:#FFFFFF,rx:6px,ry:6px;
classDef headStyle2 fill:#7C3AED,stroke:#7C3AED,stroke-width:1.5px,color:#FFFFFF,rx:6px,ry:6px;
classDef headStyle3 fill:#059669,stroke:#059669,stroke-width:1.5px,color:#FFFFFF,rx:6px,ry:6px;
classDef headStyle4 fill:#D97706,stroke:#D97706,stroke-width:1.5px,color:#FFFFFF,rx:6px,ry:6px;
classDef headStyle5 fill:#E11D48,stroke:#E11D48,stroke-width:1.5px,color:#FFFFFF,rx:6px,ry:6px;
classDef inputStyle fill:#F0F9FF,stroke:#0284C7,stroke-width:1.5px,color:#0369A1,rx:6px,ry:6px;
classDef encStyle fill:#F5F3FF,stroke:#7C3AED,stroke-width:1.5px,color:#5B21B6,rx:6px,ry:6px;
classDef pinnStyle fill:#ECFDF5,stroke:#059669,stroke-width:1.5px,color:#047857,rx:6px,ry:6px;
classDef outStyle fill:#FFFBEB,stroke:#D97706,stroke-width:1.5px,color:#B45309,rx:6px,ry:6px;
classDef phyStyle fill:#FFF1F2,stroke:#E11D48,stroke-width:1.5px,color:#BE123C,rx:6px,ry:6px;
class H1 headStyle1;
class H2 headStyle2;
class H3 headStyle3;
class H4 headStyle4;
class H5 headStyle5;
class I1,I2,I3 inputStyle;
class E1,E2,E3 encStyle;
class D1,D2,D3 pinnStyle;
class O1,O2 outStyle;
class P1,P2,P3,Opt phyStyle;
The network models the 3-D ocean reconstruction as a neural operator problem fusing 2-D sea surface dynamics with continuous vertical depth
where DepthFourierEmbedding multi-scale harmonic coordinate embedding (
The latent representation is fused via a DeepONet Trunk-Branch Operator Fusion module with multiplicative and residual connections:
followed by decoupled dual prediction heads: a dedicated temperature head and an expanded 3-layer MLP salinity head capable of reconstructing non-monotonic S-shaped haloclines.
Spatial teleconnections are modeled via alternating local window multi-head self-attention (W-MSA) and shifted window self-attention (SW-MSA):
where
1. Dynamic Height Anomaly (SLA) Coupling (
2. Unified Sea Surface Dirichlet Boundary Anchor (
3. Continuous Profile Derivative Supervision (
4. Mixed Layer Isothermal Regularization (
5. Smooth Stratification Stability (Anti-Density-Inversion) (
6. Adaptive Multi-Objective Balancing (
where
physics-swin-ocean/
├── configs/
│ ├── __init__.py
│ └── default_config.py # Experiment, model, and physical loss hyperparameters
├── phy_ocean/ # Core Python Package (Phy-Ocean)
│ ├── __init__.py
│ ├── models/ # Deep learning architectures
│ │ ├── __init__.py
│ │ ├── swin_blocks.py # Swin Transformer basic building blocks (W-MSA/SW-MSA)
│ │ └── swin_ocean_pinn.py # Swin-Ocean-PINN complete end-to-end model
│ ├── losses/ # Physics & adaptive optimization losses
│ │ ├── __init__.py
│ │ ├── physics_loss.py # Analytical Autograd gradient and stratification losses
│ │ └── adaptive_loss.py # Adaptive multi-objective uncertainty weighting
│ ├── datasets/ # Data ingestion and IO
│ │ ├── __init__.py
│ │ ├── downloader.py # CMEMS subsetting wrapper module
│ │ └── ocean_dataset.py # NetCDF4 / Xarray multi-source satellite loader
│ ├── utils/ # Marine physics & evaluation metrics
│ │ ├── __init__.py
│ │ ├── teos10.py # Fully differentiable TEOS-10 seawater equation of state
│ │ └── metrics.py # RMSE, MAE, R2, and Mixed Layer Depth (MLD) utilities
│ └── visualization/ # Modular scientific plotting subpackage
│ ├── __init__.py
│ ├── profiles.py # Vertical profile comparison plotting
│ ├── ts_diagram.py # Temperature-Salinity (T-S) consistency diagram
│ ├── scatter_density.py # Hexbin scatter density & R2 evaluation
│ └── mld.py # Mixed Layer Depth (MLD) interface validation
├── tests/ # Automated unit and integration test suite
│ ├── __init__.py
│ └── test_pipeline.py # Comprehensive end-to-end verification without external data
├── checkpoints/ # Trained model checkpoint weights (.pth) (tracked via .gitkeep)
│ └── .gitkeep
├── data/ # Local NetCDF observation and reanalysis data (tracked via .gitkeep)
│ └── .gitkeep
├── results/ # High-resolution (300 DPI) figures and plots (tracked via .gitkeep)
│ └── .gitkeep
├── download_data.py # Automated data collection tool for Temperate Pacific CMEMS datasets
├── train.py # Model training entry point
├── evaluate.py # Model evaluation and layer-wise validation script
├── predict.py # Full 3-D volumetric inference & CF-compliant NetCDF exporter
├── visualize.py # Main CLI visualization orchestrator
├── demo_test.py # Quick verification entry point (delegates to tests/)
├── requirements.txt # Environment dependencies
├── setup.py # Python package installer
├── LICENSE # MIT License
├── README.md # English Documentation
└── README.zh.md # Chinese Documentation
git clone https://github.com/ldray857/physics-swin-ocean.git
cd physics-swin-oceanconda create -n phy_ocean python=3.10 -y
conda activate phy_oceanpip install -r requirements.txtThe project provides standard automated scripts to subset and download multi-source satellite observations and 3-D reanalysis for the Temperate Pacific open ocean (145°E–165°E, 30°N–40°N, depth 0.49–1000 m), with support for automatic yearly subdirectories (e.g. data/2017, data/2018, data/2019, data/2020 via --by_year, enabled by default):
# Preview subsetting parameters and yearly breakdown without downloading
python download_data.py --dry_run
# Download 2017–2020 four-year (48-month) all 5 variables partitioned by year into data/2017, data/2018, data/2019, data/2020
python download_data.py --output_dir data --start_time 2017-01-01 --end_time 2020-12-31 --targets all
# (Optional) Download into a single combined directory (legacy mode)
python download_data.py --output_dir data/2017_2020 --start_time 2017-01-01 --end_time 2020-12-31 --targets all --no_by_yearThis self-contained verification suite uses synthetic mini-batches to validate DeepONet forward inference, Autograd analytical differentiation, TEOS-10 density computation, and multi-objective backward pass:
python demo_test.pyTrain on the 2017–2020 four-year dataset with active physics constraints (supports both yearly subdirectories and single monolithic directories):
# Train on 2017-2020 four-year dataset (48 months: 36 train, 7 val, 5 test)
# Option A: Point to yearly partitioned directory (automatically concatenates along time)
python train.py --data_dir data --years 2017 2018 2019 2020 --epochs 100 --batch_size 4 --lr 3e-4
# Option B: Point to legacy combined directory
python train.py --data_dir data/2017_2020 --epochs 100 --batch_size 4 --lr 3e-4
# Optional: Log training progress to file
python train.py --data_dir data/2017_2020 --epochs 100 --batch_size 4 | Tee-Object -FilePath "train_2017_2020.log"Evaluate a trained model checkpoint on the independent test set partition:
python evaluate.py --data_dir data/2017_2020 --checkpoint checkpoints/swin_ocean_pinn_best.pth --mode test2017–2020 Benchmark Evaluation Results:
| Ocean Variable | 2019–2020 Baseline | 2017–2020 Latest Model | Relative Performance Gain |
|---|---|---|---|
| Potential Temperature | 28.2% error reduction, |
||
| Practical Salinity | 32.4% error reduction, |
The pipeline automatically exports two complementary CF-1.8 standard NetCDF4 data assets:
- GLORYS-Aligned Asset (35 layers): Exactly aligned with GLORYS12V1 vertical grid with both predictions and ground truth, ideal for 2D multidimensional raster slicing and residual analysis;
- Strictly Regular Voxel Asset (101 layers, 10m interval): Exploits continuous-coordinate PINN representations to reconstruct strictly equal-interval 10m vertical voxels, natively compatible with ArcGIS Pro 3.7 Voxel Layer without vertical distortion or irregular warnings.
# Export both aligned and 10m regular voxel NetCDF4 files in one pass
python predict.py --data_dir data/2017_2020 --checkpoint checkpoints/swin_ocean_pinn_best.pth --output_file data/2017_2020/pacific_reconstructed_3d_test.nc --mode test --regular_step 10.0Generate publication-quality 300 DPI figures (vertical profiles, T-S water mass consistency diagram, hexbin scatter density with
python visualize.py --data_dir data/2017_2020 --checkpoint checkpoints/swin_ocean_pinn_best.pth --output_dir results --mode testIf you find this codebase or methodology helpful in your research, please cite:
@article{wang2026cross,
title={Cross-scale 3-D thermohaline modeling via dual-residual swin transformer with multisource ocean observations},
author={Wang, An and Tang, Zhiwei and Huang, Zhanchao and Xia, Xiang-Gen and Su, Hua},
journal={International Journal of Digital Earth},
volume={19},
number={1},
pages={2607902},
year={2026},
publisher={Taylor \& Francis}
}
@article{shao2024attention,
title={Optimized Attention-enhanced Physics-guided Neural Network for Satellite-based Ocean Subsurface Temperature Predicting},
author={Shao, J. and Wu, Sensen and Chen, Y. and others},
journal={Remote Sensing of Environment / IEEE TGRS},
year={2024}
}- Project Title: 融合物理约束的 Swin Transformer 海洋三维温盐重建模型构建 (Physics-Constrained Swin Transformer for Ocean 3-D Temperature and Salinity Reconstruction)
- Support / Program: 2026年浙江大学大学生创新训练项目(也叫 SRTP 项目) / 2026 Zhejiang University Student Innovation Training Program (SRTP)
- Student Team: Primary work completed by Lei Di (Project Lead / 立项人), Hangyu Li, and Xubin Huang
- Advisors: Prof. Zhenhong Du (Primary Advisor / 主指导教师), Dr. Sensen Wu, Dr. Yijun Chen (School of Earth Sciences, Zhejiang University)
This project is open-sourced under the MIT License.