Swath data lives on the satellite's curvilinear (n_lines, n_pixels)
geometry. For spectra, derivatives, comparisons with models, or combining
passes, you usually want the field on a regular grid. odsl-swot-regrid
resamples Expert or Unsmoothed swaths onto a lat/lon or Cartesian grid, with
sensible quality masking and corrections built in.
What you'll learn
- Regridding one granule onto a lat/lon grid, with a quicklook plot.
- Batch-regridding many granules onto one shared grid.
- Cartesian (metre-spaced) regional grids.
- What the quality/masking defaults do and how to change them.
Prerequisites: tutorial 1. Example: pass 13 over
the Gulf of America box -98 18 -80 31.
1. One file, lat/lon grid
odsl-swot-regrid \
--input "/spray/swot/versionD/cycle_020/SWOT_L2_LR_SSH_Expert_020_013_*.nc" \
--variable ssha_karin_2 \
--bbox -98 18 -80 31 --resolution-deg 0.02 \
--output ~/swot/grids/c020_p013_ssha.nc \
--plot
This defines a 0.02° grid over the box, resamples the (quality-masked, corrected) SSHA onto it with a Gaussian kernel of 20 km radius of influence (the defaults), and writes a NetCDF plus a PNG next to it. Grid cells with no swath pixels in range become NaN.
Options you'll touch most:
--resolution-deg— one value, or two (D_LON D_LAT).--method—gaussian(default),nearest,linear,bilinear, orkriging(requires thepykrigeextra).--radius-of-influence— search radius in metres (default 20000). Larger = smoother and fewer gaps; smaller = crisper and gappier.--plot,--cmap,--vmin/--vmax— quicklook cosmetics (default colormapRdBu_r, centred on zero;--no-center-zeroto disable).
The --input glob may match one file or many — with a single --output it
must resolve to one file; for many, see the next section.
2. Batch: many granules, one shared grid
To compare cycles cell-for-cell, every file must land on the same grid. Save the grid definition once and reuse it:
odsl-swot-regrid \
--input "/spray/swot/versionD/cycle_0*/SWOT_L2_LR_SSH_Expert_*_013_*.nc" \
--variable ssha_karin_2 \
--bbox -98 18 -80 31 --resolution-deg 0.02 \
--grid-file ~/swot/grids/gulf_002deg.nc \
--output-dir ~/swot/grids/pass013 \
--plot-dir ~/swot/grids/pass013/png
--grid-file— created on first use, loaded on every subsequent run (so a later run for pass 26 on the same grid just points at the same file;--overwrite-gridrebuilds it).--output-dir— one output NetCDF per input granule, named after it.--plot-dir— optional PNG per file.
Note the quotes around the glob — the tool expands wildcards itself, which keeps the command line short with hundreds of files.
3. Cartesian grids
For dynamics work where you want uniform metre spacing (spectra, gradients), build a local equal-area grid instead:
odsl-swot-regrid \
--input "/spray/swot/versionD/cycle_020/SWOT_L2_LR_SSH_Expert_020_013_*.nc" \
--grid-type cartesian --center-lon -89 --center-lat 25 \
--width-m 1500000 --height-m 1200000 --dx-m 2000 \
--output ~/swot/grids/c020_p013_cart.nc
The grid is centred at --center-lon/--center-lat with --dx-m spacing
(default 2000 m; --dy-m defaults to --dx-m), sized either by extent
(--width-m/--height-m) or by cell count (--nx/--ny). Cartesian grids
work with --grid-file and batch mode exactly like lat/lon grids.
4. What happens to the data on the way through
By default, before resampling, the tool:
| Step | Default | Switch |
|---|---|---|
| Quality mask | keep pixels with flag ≤ 2 (ssha_karin_2_qual) |
--max-quality, --no-quality-mask, --quality-variable none |
| Crossover quality mask | keep pixels with height_cor_xover_qual ≤ 1 |
--max-xover-quality, --no-xover-quality-mask |
| Ocean mask | drop land/lakes via depth_or_elevation |
--no-ocean-mask |
| Crossover correction | add height_cor_xover to SSHA |
--no-xover-correction |
| Internal-tide correction | add internal_tide_hret to SSHA |
--no-internal-tide-correction |
So the defaults give you corrected, ocean-only, good-quality SSHA — the same
conventions as the subset cubes in tutorial 4. For
non-SSHA variables (e.g. sig0_karin_2) the corrections don't apply, but
quality masking does.
For the Unsmoothed product add --product-type Unsmoothed (or let auto
detect it from the filename) and pick sides with --side left|right|both.
Troubleshooting
- Output is all NaN — your
--bboxdoesn't overlap the granule's swath (check withodsl-swot-swath-map, tutorial 3), or the radius of influence is too small for the grid spacing. - Blocky/duplicated-looking field —
--method nearestwith a coarse grid; switch togaussian. pykrigeimport error — kriging is an optional extra:pip install -e ".[kriging]".- Regridding is slow on big batches — raise
--nprocsfor pyresample's parallel kd-tree, and keep the bbox tight so the source subset stays small.
For swath-aligned 1 km OI (Unsmoothed KaRIn, no geographic rotation) and the 250 m FFT-tile catalog, see tutorial 8.