Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8b5be32
minor changes
jwarner8 Aug 7, 2026
7cc12cd
initial code lift/lodge
jwarner8 Aug 7, 2026
3cbc07f
final code lodge, initial refactor
jwarner8 Aug 7, 2026
262b813
tidy
jwarner8 Aug 7, 2026
01ba6ae
small fixes for end to end working example
jwarner8 Aug 13, 2026
6703a99
small fixes for end to end working example
jwarner8 Aug 13, 2026
1f28939
further clean-ups
jwarner8 Aug 13, 2026
2320f0a
add comments and tidyup
jwarner8 Aug 13, 2026
1dffed0
add README
jwarner8 Aug 13, 2026
2274347
fix coords not merging appropriately
jwarner8 Aug 13, 2026
fb85c6c
keep backup
jwarner8 Aug 13, 2026
6d1c8be
switch to reshape
jwarner8 Aug 13, 2026
ad2578c
add fill to prevent masked array
jwarner8 Aug 13, 2026
741923c
Merge branch 'main' into util_fastnetuk
jwarner8 Aug 14, 2026
1032179
add fill/reduce mask end of fix
jwarner8 Aug 14, 2026
fb19b63
fill masks ahead of stats
jwarner8 Aug 14, 2026
9e86f15
switch to local mask path
jwarner8 Aug 14, 2026
b4ee246
add mesh file
jwarner8 Aug 14, 2026
7b41620
remove old script out of repo
jwarner8 Aug 14, 2026
07797e5
update readme
jwarner8 Aug 14, 2026
6e4ae2b
remove readme aspects related to fill values and masking
jwarner8 Aug 14, 2026
ed02e61
remove fill value part
jwarner8 Aug 14, 2026
453ad00
add unit tests
jwarner8 Aug 14, 2026
38d6cf1
edits from code review
jwarner8 Aug 19, 2026
5a13dc0
update comment
jwarner8 Aug 19, 2026
a9a756f
make executable
jwarner8 Aug 20, 2026
2f86100
add description of grid in docstring
jwarner8 Aug 20, 2026
4e09f8f
clearer documentation on processing
jwarner8 Aug 20, 2026
e59b98b
add additional docstring comments
jwarner8 Aug 20, 2026
0258728
Merge branch 'main' into util_fastnetuk
jwarner8 Aug 20, 2026
5711aaf
Merge branch 'main' into util_fastnetuk
jwarner8 Aug 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/CSET/operators/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def _plot_and_save_spatial_plot(
# Add watermark with min/max/mean. Currently not user togglable.
# In the bbox dictionary, fc and ec are hex colour codes for grey shade.
axes.annotate(
f"Min: {np.min(cube.data):.3g} Max: {np.max(cube.data):.3g} Mean: {np.mean(cube.data):.3g}",
f"Min: {np.nanmin(cube.data.filled(np.nan)):.3g} Max: {np.nanmax(cube.data.filled(np.nan)):.3g} Mean: {np.nanmean(cube.data.filled(np.nan)):.3g}",
xy=(0.025, yinfopad),
xycoords="axes fraction",
xytext=(-5, 5),
Expand Down Expand Up @@ -1479,7 +1479,7 @@ def _plot_and_save_vector_plot(
# Add watermark with min/max/mean. Currently not user togglable.
# In the bbox dictionary, fc and ec are hex colour codes for grey shade.
axes.annotate(
f"Min: {np.min(cube_vec_mag.data):.3g} Max: {np.max(cube_vec_mag.data):.3g} Mean: {np.mean(cube_vec_mag.data):.3g}",
f"Min: {np.nanmin(cube_vec_mag.data.filled(np.nan)):.3g} Max: {np.nanmax(cube_vec_mag.data.filled(np.nan)):.3g} Mean: {np.nanmean(cube_vec_mag.data.filled(np.nan)):.3g}",
xy=(0.05, -0.05),
xycoords="axes fraction",
xytext=(-5, 5),
Expand Down Expand Up @@ -1615,7 +1615,10 @@ def _plot_and_save_histogram_series(
ax.set_ylabel(
f"Contribution to mean ({iter_maybe(cubes)[0].units})", fontsize=14
)
ax.set_xlim(vmin, vmax)
try:
ax.set_xlim(vmin, vmax)
except ValueError:
pass
ax.tick_params(axis="both", labelsize=12)

# Overlay grid-lines onto histogram plot.
Expand Down
189 changes: 189 additions & 0 deletions utils/proc_fastnetuk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# proc_fastnetuk.py

## About

The script `proc_fastnetuk.py` converts FastNetUK inference output into CSET-compatible NetCDF files.

FastNetUK output contains limited metadata and uses variable naming conventions that do not match those expected by CSET. Although the source files are described as UGRID data, the forecast fields are stored as flattened arrays representing a regular grid. This utility reshapes the flattened fields back onto a structured latitude-longitude grid.

The script performs the following preprocessing steps:

- Converts FastNetUK variable names to CSET/LFRic conventions.
- Rebuilds forecast metadata and coordinates.
- Reconstructs pressure-level information from variable names.
- Reshapes flattened fields onto the UKV latitude-longitude grid.
- Creates `forecast_period` and `forecast_reference_time` coordinates.
- Preserves valid times as a `time` auxiliary coordinate.
- Applies required unit conversions.
- Saves the result as CSET-ready NetCDF files.

No interpolation or scientific modification of the meteorological fields is performed other than the documented unit conversions.

> [!TIP]
> The script uses the grid definition stored in `ukv_mesh.nc` to reconstruct the latitude-longitude coordinates of the output data.

> [!TIP]
> Typical FastNetUK inference datasets require 30G memory due to reshaping and reconstruction of multiple variables.

## Usage

### Requirements

The script requires:

- Python
- Iris
- NumPy
- cf-units

Run with:

```bash
python fix_fastnetuk_ugrid.py \
--inputpath "<input_files>" \
--outputpath "<output_directory>"
```

### Required Arguments

- `--inputpath` - Input NetCDF file or wildcard pattern.
- `--outputpath` - Directory for processed output file.

If wildcards are used, quote the pattern so it is passed unchanged to Python. This script assumes each forecast is stored in one single file, and can be run on multiple files each containing a forecast.

## Processing Details

### Grid Reconstruction

FastNetUK variables are stored as flattened arrays.

The script reconstructs the original structured grid by reshaping forecast data using the dimensions:

```text
808 × 621
```

Latitude and longitude coordinates are obtained from the reference UKV mesh file:

```text
ukv_mesh.nc
```

No interpolation or regridding is performed.

### Metadata Reconstruction

Variable metadata is reconstructed from the source variable name.

Examples:

```text
t_850
u_500
v_250
2t
10u
sp
```

The script extracts:

- Variable identifier
- Pressure level (if present)

and rebuilds metadata required by CSET.

Variables that cannot be matched to the internal lookup table are skipped.

### Forecast Coordinates

Forecast metadata is reconstructed from the source time coordinate.

The following coordinates are generated:

- `forecast_reference_time`
- `forecast_period`

Valid times are retained as:

- `time`

The first time step is assumed to represent lead time zero.

### Pressure Levels

Variables containing pressure information in their name are given an explicit pressure dimension coordinate.

For example:

```text
t_850
```

becomes:

```text
temperature_at_pressure_levels
pressure = 850 hPa
```

A length-one pressure dimension is added so that multiple pressure levels can be concatenated later by Iris.

### Variable Renaming

Variables are translated to CSET/LFRic naming conventions using an internal lookup table.

Examples include:

| Source Name | Output Name |
|-------------|-------------|
| t | temperature_at_pressure_levels |
| u | zonal_wind_at_pressure_levels |
| v | meridional_wind_at_pressure_levels |
| w | vertical_wind_at_pressure_levels |
| q | vapour_specific_humidity_at_pressure_levels_for_climate_averaging |
| z | geopotential_height_at_pressure_levels |
| sp | surface_air_pressure |
| 10u | eastward_wind_at_10m |
| 10v | northward_wind_at_10m |
| lsm | land_binary_mask |
| 2t | temperature_at_screen_level |
| 2d | dew_point_temperature_at_screen_level |
| skt | grid_surface_temperature |
| tp | surface_microphysical_rainfall_rate |

### Unit Conversion

The following variable-specific adjustments are performed automatically.

#### Geopotential Height

FastNetUK geopotential is converted to geopotential height:

```python
height = geopotential / 9.81
```

#### Rainfall

Rainfall fields are converted from metres to millimetres:

```python
rainfall *= 1000.0
```

## Notes

- `ukv_mesh.nc` must be available when running the script.
- Variables not present in the lookup table are ignored.
- Pressure levels are inferred solely from variable names.
- The latitude-longitude grid is reconstructed by reshaping flattened fields and not by interpolation.
- The first valid time is assumed to be forecast lead time zero.

---

## Owners

The following people should be contacted for queries or issues with this utility:

- [jwarner8](https://github.com/jwarner8)
Loading