Commit fbe76037 authored by Adam Reichold's avatar Adam Reichold
Browse files

Make use of multiple raster layers to have different distributions for different plant species.

parent 28d75ad9
Pipeline #83601 passed with stage
in 3 minutes and 21 seconds
......@@ -4,7 +4,7 @@ import struct
from osgeo import gdal, ogr
WIDTH, HEIGHT, DEPTH, LENGTH = 10000, 10000, 1, 1000
WIDTH, HEIGHT, DEPTH, LENGTH = 10000, 10000, 3, 1000
# based on the number of inflorescences per habitat type
# from the VOODOO flower survey, 2021 in France
......@@ -40,7 +40,9 @@ temp_data = driver.CreateDataSource("TEMP")
temp_data.CopyLayer(layer, "temp")
temp_layer = temp_data.GetLayer()
temp_layer.CreateField(ogr.FieldDefn("Weight", ogr.OFTReal))
temp_layer.CreateField(ogr.FieldDefn("Weight1", ogr.OFTReal))
temp_layer.CreateField(ogr.FieldDefn("Weight2", ogr.OFTReal))
temp_layer.CreateField(ogr.FieldDefn("Weight3", ogr.OFTReal))
for feature in temp_layer:
eunis = feature.GetField("Code_EUNIS")
......@@ -51,7 +53,9 @@ for feature in temp_layer:
if eunis and eunis in WEIGHTS:
weight = WEIGHTS[eunis]
feature.SetField("Weight", weight)
feature.SetField("Weight1", weight)
feature.SetField("Weight2", 1.0)
feature.SetField("Weight3", 1.0)
temp_layer.SetFeature(feature)
......@@ -59,7 +63,11 @@ driver = gdal.GetDriverByName("GTiff")
out_data = driver.Create("/vsimem/map", WIDTH, HEIGHT, DEPTH, gdal.GDT_Float32)
out_data.SetGeoTransform((x_low, LENGTH / WIDTH, 0, y_high, 0, -LENGTH / HEIGHT))
gdal.RasterizeLayer(out_data, [1], temp_layer, options=["ATTRIBUTE=Weight"])
gdal.RasterizeLayer(out_data, [1], temp_layer, options=["ATTRIBUTE=Weight1"])
gdal.RasterizeLayer(out_data, [2], temp_layer, options=["ATTRIBUTE=Weight2"])
gdal.RasterizeLayer(out_data, [3], temp_layer, options=["ATTRIBUTE=Weight3"])
sys.stdout.buffer.write(struct.pack("=QQQ", WIDTH, HEIGHT, DEPTH))
sys.stdout.buffer.write(out_data.GetRasterBand(1).ReadRaster())
sys.stdout.buffer.write(out_data.GetRasterBand(2).ReadRaster())
sys.stdout.buffer.write(out_data.GetRasterBand(3).ReadRaster())
......@@ -64,20 +64,20 @@ Note that the weights given by the map are also used to optimise the subdivison
}
};
let position: Box<dyn Fn(&mut Rng) -> Vector> = if let Some(landscape) = landscape {
let length = params.length;
let position_from_layer: Box<dyn Fn(&mut Rng, usize) -> Vector> =
if let Some(landscape) = landscape {
let length = params.length;
Box::new(move |rng| loop {
let position = position(rng);
Box::new(move |rng, layer| loop {
let position = position(rng);
if landscape.get(position.x / length, position.y / length, 0 /* TODO */) > rng.gen()
{
return position;
}
})
} else {
Box::new(position)
};
if landscape.get(position.x / length, position.y / length, layer) > rng.gen() {
return position;
}
})
} else {
Box::new(move |rng, _layer| position(rng))
};
\end{code}
The \emph{flower patches} are stationary entities which are positioned randomly and assigned to a specific process \inlinecode{dest} based on their position.
......@@ -140,7 +140,7 @@ As entities are identified by the rank of the process they are located at and th
continue;
}
let position = position(&mut rng);
let position = position_from_layer(&mut rng, flower_patch.species.0.into());
let dest = grid.location(&position);
let index = TaggedIndex::new(dest, flower_patch_indices[dest as usize]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment