
Process NetCDF rasters for a given year
process_year.RdThis function processes a directory of NetCDF files by extracting a specified variable (surface level only), cropping/masking to a polygon, and optionally downsampling to a target resolution. It outputs a single combined raster for the year and writes it to a temporary GeoTIFF file.
Arguments
- year_dir
Character. Path to the directory containing
.ncfiles for a single year.- polygon
An
sfpolygon object. Used for cropping and/or masking rasters.- crop
Logical. If
TRUE, crops rasters to the extent ofpolygon.- mask
Logical. If
TRUE, masks rasters to the interior ofpolygon.- downsample
Logical. If
TRUE, resamples rasters to a coarser grid of resolutionres.- res
Numeric (length 1 or 2). Target resolution for downsampling (map units of CRS).
- variable
Character. Variable name prefix to extract from NetCDF (e.g.
"sst"). The function appends"_zlev=0"to match surface data layers.- preliminary
Logical. If
TRUE, allows processing of files flagged as preliminary. IfFALSE(default), the function will stop if preliminary data are found.
Value
Character. Path to the combined yearly raster written to a temporary GeoTIFF,
or NULL if no valid rasters were processed.
Details
The function:
Scans
year_dirfor.ncfiles.Skips or replaces filenames with
_preliminary.ncdepending onpreliminary.Extracts the specified variable at surface depth (
zlev=0).Applies optional crop/mask/downsample steps.
Combines rasters and writes out a GeoTIFF file in the session temp directory.