Open jpmullercir opened 3 months ago
Hello,
I think what you want to do is already possible, but you have to take into account the order of creation of elements in gama.
grids are created before the init block of the global is executed, thus you have to get your file paths directly at declaration.
In addition you will need to safeguard the use of maxSlope
in the aspects because it's going to be set to the correct value after.
Which will give us something like this for Test v1:
/**
* Name: Test
* Based on the internal empty template.
* Author: jpmuller
* Tags:
*/
model Test
global {
// GLOBAL VARIABLES
// simulation control
string parameter_name <- "../includes/test/parameters.json";
file parameterFile <- json_file(parameter_name);
map<string,unknown> parameters <- parameterFile.contents;
file bounds <- file(parameters["site"]);
file slopes <- file(parameters["pente"]);
geometry bounds_shape <- envelope(bounds); // the bounds of the whole system
int patch_length <- 100;
float slopeMax <- 0.0;
bool first <- true;
reflex step {
if first{
ask Patch overlapping bounds_shape {
inSite <- true;
// slope
list<Slope> slopelist <- Slope overlapping self;
float localSlopeMax <- 0.0;
if !empty(slopelist) {
slope <- slopelist mean_of (each.grid_value);
localSlopeMax <- slopelist max_of (each.grid_value);
}
slopeMax <- max(slopeMax,localSlopeMax);
}
first <- false;
write sample(slopeMax);
}
write "step";
}
}
// the patch species
grid Patch width: shape.width / patch_length height: shape.height / patch_length neighbors: 8 {
bool inSite <- false;
float slope;
aspect default {
if inSite {
color <- #black;
} else {
color <- #white;
}
}
aspect slope {
if inSite {
float depth <- slopeMax > 0 ? grid_value / slopeMax :0;
draw shape color: rgb(0,0,int(255 * depth));
}
}
}
grid Slope file: slopes {
init {
color <- #white;
}
// DISPLAY
aspect default {
float depth <- slopeMax > 0 ? grid_value / slopeMax :0;
draw shape color: rgb(255 * depth,255 * depth,255 * depth);
}
}
experiment Test {
output {
// the patch grid for system viewing
display Test type: java2D {
species Slope aspect: default refresh: false;
species Patch aspect: default refresh: true;
}
}
}
note that there seems to be a projection problem in your model as there's no overlap between your file GrandCoyer.shp
and Pente_GD_Coyer.tif
but that's probably related to the previous issue you posted
Describe the bug I would like the model to be entirely specified by a json file (including the files used to create grids and species.
To Reproduce A test project is provided with some attempt to make it work correctly...but it doesn't
Expected behavior A clear and concise description of what you expected to happen:
1) load the parameter file 2) create the grids and species depending on some files provided in the parameter file 3) run it
Screenshots gama project included Test.zip
Desktop (please complete the following information):