Skip to content

Motion before a date

egms_client.asof

Ground motion as of a date: what the series said before a day, cell by cell.

The velocity of a release is one number over five years: the same before and after a landslide. This module reads the series of the L3 points and gives, for a cell and a date, two numbers kept apart:

  • velocity_long: the velocity from the first acquisition to the start of the window;
  • velocity_before: the velocity of the window, the last window_days before the date.

The two do not overlap: the window is not part of the long-term velocity.

and how far apart they are (change, and change_z in units of the noise of each point). A model can then ask whether the ground was speeding up before a day, with rows built "as of" that day.

Four rules:

  • Nothing after the date is read. Every number of a row uses only the acquisitions before its date: the long-term velocity and the seasonal cycle too. An acquisition on the day itself does not count, unless include_day=True: a feature that sees the day of a landslide measures the landslide, not what came before it.
  • The caller decides the instant. A row carries a date, or an aware datetime read as its UTC day. This module defines no convention for an event with no time.
  • Not measured is None, never zero, and a row says why in reasons. The minimums (min_points, min_acquisitions) have no default: a thin cell is the caller's choice, not a hidden one.
  • Signs are kept. The velocities are those of the component of the table (for the vertical one, negative is down).

How the numbers are made. For each point of the cell, a line with the annual cycle is fitted to its series before the window: its slope is the long-term velocity. That cycle is then taken off the window, and a line is fitted to it: its slope is the velocity before the date. Without that step a window of six months would read the season as a trend. The cell gets the median over its points. change_z divides each point's change by the standard error of its recent slope, from the scatter of its earlier series around the fit (the uncertainty of the long-term slope is left out, so it is a little too large); share_changed is the share of points beyond z, when z is given.

Limits. The series has one value every six days, and InSAR loses fast motion: a slope that fails in hours shows nothing before. The season needs a full year of series before the window (min_history_days). A change that began before the window is partly in the long-term velocity and in its cycle: a point that turned from -5 to -40 mm/year a year before the date reads -46 over the last six months, not -40. This is a description of the series, not an alert, and nobody has yet measured that it tells cells with a landslide from the others.

Needs the tables extra (pandas) for the table, and numpy.

MotionBefore dataclass

What the points of one cell said before one date. None: not measured.

Velocities and change in mm/year. points are the points of the table in the cell; points_used those with a complete series before the date. acquisitions_long counts the acquisitions before the window, acquisitions_before those of the window, from window_first to window_last.

Series

The series of a table, read once, for many cells and dates.

frame is an L3 table with its dates (tables.read_csv(path)): the columns easting and northing (EPSG:3035 metres) and one column per acquisition. Concatenate the tables of several tiles first.

points_in

points_in(cell: Cell) -> Any

The rows of the points whose centre is in the cell (min <= x < max).

before

before(cell: Cell, as_of: date | datetime, *, window_days: int, min_points: int, min_acquisitions: int, min_history_days: int = MIN_HISTORY_DAYS, include_day: bool = False, z: float | None = None) -> MotionBefore

One row: see :func:motion_before.

motion_before

motion_before(frame: Any, rows: Iterable[tuple[Cell, date | datetime]], *, window_days: int, min_points: int, min_acquisitions: int, min_history_days: int = MIN_HISTORY_DAYS, include_day: bool = False, z: float | None = None) -> list[MotionBefore]

For each cell and date, the velocity before the date next to the long-term one.

frame is an L3 table with its series (tables.read_csv), or a :class:Series already built from one. rows are pairs of a :class:~egms_client.cells.Cell (EPSG:3035 metres) and a date, or an aware datetime read as its UTC day.

window_days is how far back "before" goes (180, 365). A row has numbers only with at least min_points points and min_acquisitions acquisitions in the window (never fewer than 3), and at least min_history_days of series before the window; otherwise they are None and reasons says why. include_day counts an acquisition on the day itself. z gives share_changed: the share of points whose change is beyond z standard errors; without it the share is None.

No network and no file is read: fetching the table is a separate step.

to_frame

to_frame(rows: Iterable[MotionBefore]) -> Any

The rows as a pandas.DataFrame: None becomes NaN, never 0.