# Matching observations Matching samples a gridded source at the positions and times of point observations: cruise stations, floats, ship tracks. ```python import pandas as pd from seagrid import ostia df = pd.read_csv("stations.csv", parse_dates=["time"], index_col="time") df["sst"] = ostia.match(df.lon, df.lat, df.index) ``` Each observation is put in its grid cell once. The observations are then grouped by the source's time step and every time step is opened only once. With a monthly product (`timetype="monthly"`), all stations in June 2010 are matched to the June 2010 field. A time step that is missing gives NaN and a warning in the `seagrid.match` log. ## Options `nei=9` : Use the nearest finite value among the nine nearest cells, for observations next to the coast or to cloud gaps. `days_behind=1, days_ahead=1` : Also sample the days around each observation. The result has one column per day. `max_distance=10_000` : NaN for observations more than 10 km from the nearest cell centre (for example, outside a regional grid). ## The Match class {class}`seagrid.match.Match` holds the grid lookup, so you can reuse it for several variables, and it also works with 2.x-style modules and with functions that return a Dataset: ```python from seagrid.match import Match mt = Match("modis", dskw={"timetype": "8day", "resolution": "4km"}) df["chl"] = mt.sample(df.lon, df.lat, df.index, "chlor_a", nei=9) i, j = mt.ll2ij(df.lon, df.lat) # grid columns and rows ``` On a regular grid the cell is the one that contains the observation. On other grids it is the cell with the nearest centre on the sphere, so tracks that cross the antimeridian need no special care.