Data Collector

Emulate a field campaign by reading measurements from a raster at sample locations.

source

DataCollector

def DataCollector(
    fname_raster:str, # Path to the raster used as ground truth
    band:int=1, # Band to read
):

Emulate field measurements by reading a raster at sample locations.


source

DataCollector.get_values

def get_values(
    gdf:geopandas.geodataframe.GeoDataFrame, # Sample locations as `Point` or `MultiPoint` geometries
)->list: # Raster value at each point, in the order of `gdf.get_coordinates()`

Read the raster value of the cell under each point of gdf.


source

DataCollector.collect

def collect(
    gdf:geopandas.geodataframe.GeoDataFrame, # Sample locations as `Point` or `MultiPoint` geometries, indexed by `loc_id`
)->geopandas.geodataframe.GeoDataFrame: # One `Point` per row with its measured `value`, indexed by `loc_id`

Measure the raster at every point of gdf.

DataCollector stands in for a real field campaign. It treats a raster as the ground truth and reads the value under each sample location. Use it to test a sampling strategy before collecting real data. The example starts with a 10 by 10 grid over the raster:

fname_raster = './files/ground-truth-01-4326-simulated.tif'
gdf_grid = gridder(fname_raster, nrows=10, ncols=10)

Draw between 1 and 9 points in each grid cell:

sampler = Sampler(gdf_grid)
n = np.random.default_rng(0).integers(1, 10, size=len(gdf_grid))
sample_locs = sampler.sample(n, method='uniform', rng=0)

collect splits each MultiPoint into single points and reads the raster under each one. The result has one row per measurement. loc_id repeats for areas with several points:

dc_emulator = DataCollector(fname_raster)
samples_t0 = dc_emulator.collect(sample_locs)
test_eq(len(samples_t0), n.sum())
samples_t0.head()
geometry value
loc_id
0 POINT (-1.21382 43.26536) 0.103400
0 POINT (-1.2194 43.26891) 0.137387
0 POINT (-1.22288 43.26783) 0.098744
0 POINT (-1.21428 43.26705) 0.110955
0 POINT (-1.22325 43.26045) 0.000000
ax = samples_t0.plot(column='value', s=3, legend=True)
gdf_grid.boundary.plot(color=black, lw=0.5, ax=ax)
ax.axis('off');