# Resampling {func}`seagrid.regrid` moves data from one grid to another. It works on any xarray object whose last two dimensions span a grid and keeps the leading dimensions (`time`, `depth`, ...). Every data source offers the same for one time step: ```python import seagrid from seagrid import grids, modis target = grids.cbiomes_halfdeg() chl = modis.regrid(target, "2010-06-01", "chlor_a", timetype="monthly") same = seagrid.regrid(modis.open_dataset("2010-06-01", "chlor_a"), target) ``` ## Methods `method="bin"` (the default) : Every source cell goes into the target cell that contains its centre, and the target value is a statistic of the finite values in it: `stat="mean"` (default), `"sum"`, `"count"`, `"min"` or `"max"`. Use it from a finer to a coarser grid. It is pyresample's {class}`~pyresample.bucket.BucketResampler`, and gives the same result as the 2.x `coarsegrid`. `method="nearest"` : Every target cell takes the nearest source value within a search radius. Use it from a coarser to a finer grid and for categorical fields such as Longhurst provinces. With `fill=True`, target cells that no source cell falls into (when the target is finer than the source) are filled by nearest neighbour. ## Many time steps {class}`seagrid.resample.BinResampler` computes which target cell every source cell belongs to once, and reuses it: ```python from seagrid.resample import BinResampler rs = BinResampler(modis.grid("4km"), target) for dtm in modis.dtm_vec("monthly", "2010-01-01", "2010-12-01"): field = modis.open_dataarray(dtm, "chlor_a", timetype="monthly") binned = rs.average(field.squeeze().values) n = rs.count(field.squeeze().values) # number of valid source cells ``` ## Grids Wherever a grid is expected you can pass a {class}`~seagrid.grids.Grid`, a pyresample `AreaDefinition` or `GridDefinition`, a grid name from the settings (`"nasa_l3_9km"`), an xarray object with `lat`/`lon`, or a data source; {func}`seagrid.grids.as_grid` converts them.