Export cell values

63 views
Skip to first unread message
Assigned to youce...@gmail.com by me

zaatour wajdy

unread,
Dec 11, 2019, 7:42:36 AM12/11/19
to GAMA
Hello, everyone,
I want to know how to calculate the values corresponding to each cell of the grid. In my case, I am loading images (tif) where each cell represents the value of a plant density, I want to download these values (in csv for example).

model NDVI

/* Insert your model definition here */
global{
    
 file modis_data <- file("../includes/NDVIn1.tif");
  float MAX_FOOD <- 1.0;
  
    grid  terrain_cell file:modis_data neighbors:8 {//file: MODIS_DATA{
   // Grid representing the environment with food proportion to ndvi of satelite fig
  //  list<float> mouvementProb; // liste qui done les probailite de deplacement vers une autre cellules
    float foodProd <- rnd(10)/10 ;/*Precipitation/50 ;*/
float food <- grid_value min: 0.0 max:MAX_FOOD ;
rgb color <- rgb(int(255 * (1-1.5*food)), 255, int(255 * (1 - 1.5*food))) update: rgb(int(255 * (1-1.5*food)), 255, int(255 * (1 - 1.5*food)));
}
    
    }
    experiment simulation type: gui{
    output
    {
    
        display main_display{
            grid terrain_cell lines: # black;   // size: { 1, 0.5 } position: { 0, 0 };
            
   }         
}

Thank you very much. 

Youcef Sklab

unread,
Dec 11, 2019, 11:03:57 AM12/11/19
to GAMA
Hi,
There is a model in the library that shows how to export data to a csv file. It is named: Save to CSV.gaml (in Data Exportation folder).

Please have a look at it and let us know if it works. 


Best,
Youcef

zaatour wajdy

unread,
Dec 11, 2019, 1:00:36 PM12/11/19
to gama-p...@googlegroups.com
Dear youssef,
Thank you for your answer.
Indeed, what I'm looking for is to find a way to calculate the values of the cells (food) line by line and have the results in a table with the same grid size (1350 cells).

Wajdi

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/nGPBc4waAYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/b0030941-aa3e-445f-bf75-7b11a7e88f54%40googlegroups.com.

Youcef Sklab

unread,
Dec 12, 2019, 6:16:02 AM12/12/19
to GAMA
Dear Wadji, 
I am not sur that I have understood what you want to do. 
What do you mean by "line by line”?  a sort of the sum of the cells food values line by line? So, as a result, you will have a list with the same size of the grid rows?  

Youcef
To unsubscribe from this group and all its topics, send an email to gama-platform+unsubscribe@googlegroups.com.

zaatour wajdy

unread,
Dec 12, 2019, 7:49:59 AM12/12/19
to gama-p...@googlegroups.com
Dear Youcef,
In this model, I have integrated a tif-type map, each cell of this map corresponds to a food value (between 0 and 1), I want to create a list whose values are those of the map and I will download them as a csv file. So first I need to read all the values of each cell and then save them.


model NDVI

/* Insert your model definition here */
global{
   
 file modis_data <- file("../includes/NDVIn1.tif");
  float MAX_FOOD <- 1.0;
    int dim_grille_width;
    int dim_grille_height;
   list<float> a;

    grid  terrain_cell file:modis_data neighbors:8 {//file: MODIS_DATA{
   // Grid representing the environment with food proportion to ndvi of satelite fig
  //  list<float> mouvementProb; // liste qui done les probailite de deplacement vers une autre cellules
    float foodProd <- rnd(10)/10 ;/*Precipitation/50 ;*/
float food <- grid_value min: 0.0 max:MAX_FOOD ;
init{
        dim_grille_height <- matrix(terrain_cell).rows;
        dim_grille_width <- matrix(terrain_cell).columns;
        loop times: length(terrain_cell){a<<0.0;}
}
reflex compt{
loop i from: 0 to: length(terrain_cell) - 1 {
a[i] <- terrain_cell(i).food ;
write(a[i]);
}
save a to: "../results/a.csv" type:csv rewrite: false;

}
rgb color <- rgb(int(255 * (1-1.5*food)), 255, int(255 * (1 - 1.5*food))) update: rgb(int(255 * (1-1.5*food)), 255, int(255 * (1 - 1.5*food)));
}
   
    }
    experiment simulation type: gui{
    output
    {
   
        display main_display{
            grid terrain_cell lines: # black;   // size: { 1, 0.5 } position: { 0, 0 };
           
   }        
}

}
        Thank u,

Wajdi

To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/nGPBc4waAYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/8f1bac17-388f-4556-a877-1baf7a282aed%40googlegroups.com.

Youcef Sklab

unread,
Dec 12, 2019, 9:33:17 AM12/12/19
to GAMA
hi,
In the model bellow, I save the values of the attribute "food" of all the cells by keeping the same representation in the csv file (rows and columns). I hope that is what you are looking for.
----------

model NDVI


/* Insert your model definition here */

global {

file modis_data <- file("../includes/NDVIn1.tif");

float MAX_FOOD <- 1.0;

map<int, list<terrain_cell>> grid_rows ;

list<float> food_values ;

bool saved <- false;

}


grid terrain_cell file: modis_data neighbors: 8 { 


float foodProd <- rnd(10) / 10; /*Precipitation/50 ;*/

float food <- grid_value ; //min: 0.0 max: MAX_FOOD;


reflex compt when: !saved{

grid_rows <- (terrain_cell  group_by (terrain_cell(each).grid_y));

 

loop i from: 0 to: length(grid_rows)-1 { 

     food_values <- [];

  food_values <<+ grid_rows[i] collect each.food;

save food_values to: "../results/food_values_row_by_row.csv" type:"csv" rewrite: false header:false;

     }

     saved <- true;

}

rgb color <- rgb(int(255 * (1 - 1.5 * food)), 255, int(255 * (1 - 1.5 * food))) update: rgb(int(255 * (1 - 1.5 * food)), 255, int(255 * (1 - 1.5 * food)));

}


experiment simulation type: gui {

output {

display main_display {

grid terrain_cell lines: #black; // size: { 1, 0.5 } position: { 0, 0 };

}

}

}


------

Cheers
Youcef



To unsubscribe from this group and all its topics, send an email to gama-platform+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/nGPBc4waAYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platform+unsubscribe@googlegroups.com.

zaatour wajdy

unread,
Dec 12, 2019, 10:38:54 AM12/12/19
to gama-p...@googlegroups.com
Thank u Youcef ! That's what I'm looking for!
----------

To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/nGPBc4waAYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "GAMA" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gama-platform/nGPBc4waAYw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/1b3b5d6e-9f68-4e7a-ba24-8275dd13e4dd%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages