arlmet.extract_subset#
- arlmet.extract_subset(path, dest, *, bbox=None, bbox_crs=None, levels=None, variables=None, overwrite=True)[source]#
Extract a spatial/vertical subset from an ARL file into a new ARL file.
- Parameters:
dest (
str|PathLike[str]) – Output ARL file. Must not bepath.bbox (
tuple[float,float,float,float] |None) – Geographic bounding box(west, south, east, north)in degrees. On a projected grid the crop is the smallest rectangle of cells that holds the box’s part on the grid (arlmet.Grid.window_from_bbox()).bbox_crs (
Any) – The coordinate reference systembboxis in ("EPSG:32612", anythingpyproj.CRS.from_user_input()takes), making the box(xmin, ymin, xmax, ymax)in its units; the default is degrees (arlmet.Grid.window_from_bbox()).levels (
Iterable[int] |None) – Integer ARL level indices to keep, which must include 0, the surface. Output levels are compacted and renumbered from zero while preserving the selected level heights.variables (
str|Iterable[str] |None) – Variable names to keep, as the file spells them ("TEMP", not"temp"); a single string is one name. ADIF*name the file holds is accepted, but naming it selects nothing: aDIF*record is written with its parent record, when the parent is selected. All variables are included by default.overwrite (
bool) – Replace an existingdest. With False an existingdestis returned as it is, without reading the input, so a rerun skips finished work; nothing checks that it came from the same inputs and arguments.
- Returns:
The output path,
Path(dest). Open it withFileoropen_dataset()to read the subset.- Return type:
- Raises:
TypeError – If
levelsholds anything but integers (a string, or 1.5).ValueError – If
destis the same file aspath, the cropped grid is too small to hold the ARL index record,levelsleaves out level 0 (the surface: the output is renumbered from zero, so the lowest kept level would become the surface),variablesis empty or names a variable the file does not hold (every unknown name is listed, also when others are known), or the selected levels and variables leave no record in any time step, so there is nothing to write.
Notes
The subset is written to a temporary file next to
destand renamed into place once complete, so an interrupted run never leaves a truncated file under the final name.Without a horizontal crop (
bboxis None or covers the whole grid), the selected records are copied byte for byte, with only their level numbers and the index records rewritten, which is much faster than unpacking and re-packing them. A crop re-packs each record’s window. Either way eachDIF*record is written right after the record it corrects, and the index record lists the records in that order.Examples
>>> import arlmet >>> out = arlmet.extract_subset( ... "met.arl", ... "subset.arl", ... bbox=(-114.0, 39.0, -110.0, 42.0), ... levels=[0, 1, 2], ... ) >>> ds = arlmet.open_dataset(out)