arlmet.File#

class arlmet.File(path, mode='r', *, source=None, grid=None, vertical_axis=None)[source]#

Read or write an ARL meteorology file.

Parameters:
  • path (str | PathLike[str]) – Location of the ARL file on disk.

  • mode (Literal['r', 'w']) – File mode. Read mode scans the file immediately; write mode expects the caller to provide source, grid, and vertical_axis before creating records.

  • source (str | None) – Four-character ARL source identifier used when writing.

  • grid (Grid | None) – Horizontal grid metadata used when writing.

  • vertical_axis (VerticalAxis | None) – Vertical axis metadata used when writing: the surface and at most 99 levels above it, the most a record’s header numbers.

Variables:
  • path (pathlib.Path) – Filesystem path for the ARL file.

  • mode ({"r", "w"}) – Active file mode.

  • variables (VariableAccessor) – Lazy accessor for variable-wise views inherited from RecordCollection.

Examples

>>> import arlmet
>>> with arlmet.File("met.arl") as met:
...     met.times[0]
Timestamp('2024-07-18 00:00:00')

Attributes

grid

Horizontal grid metadata; set it in write mode before creating records.

handle

Open binary handle to the file, reopened if the file cache closed it.

record_length

Length in bytes of each record in the file, from the grid.

records

All DataRecords in the file, in times order.

size

Size of the file on disk, in bytes.

source

ARL source identifier; set it in write mode before creating records.

times

Return a sorted list of timestamps in the file.

vertical_axis

Vertical coordinate metadata; set it in write mode before creating records.

Methods

add_record(time, variable, level, *, forecast)

Add one writable DataRecord, creating its RecordSet if needed.

check()

Return what is wrong with this file that opening it does not catch.

close()

Flush pending writes and close the managed binary file handle.

create_grid(nx, ny, *, pole_lat, pole_lon, ...)

Create and attach the horizontal grid metadata for a writable file.

create_recordset(time, *[, forecast])

Create a writable RecordSet for one valid time.

extract_subset(dest, *[, bbox, bbox_crs, ...])

Write a spatial/vertical subset of this file to a new ARL file.

flush()

Write pending record sets to disk and release their in-memory data.

sample_points(points, variables, *[, time, ...])

Sample fields from this file at arbitrary lon/lat/z points.

to_dataset(*[, drop_variables, bbox, ...])

Project this file into the simplified analysis Dataset representation.