Usage of rain data time series in gama hydro models other than random data generation inputs

105 views
Skip to first unread message

Yosef

unread,
Jul 25, 2019, 10:58:59 PM7/25/19
to GAMA
Hi all, I´m new to GAMA and I have very low programming skills, but I´m attracted to the platform and am eager to use it my research. I need some guidance and how to do about with these issues/questions.

1. I´m analyzing the "Flood Simulation" and the "Water flow with watershed" examples. Is there any way to get these models to use a time series rain data .csv file  (with two columns, col1= date_time, and col2= rain obs) in the simulations. I have tried to follow the import *.csv example with no avail.
2. In the Water flow with watershed example, the watershed gets rain from random rain input every 20 cycles. e.g. 


float rain <- rnd(10.0) update: every(20#cycle) ? rnd(10.0) : 0.0;

Instead of a random rain input, I´ll like to use my *.csv file with the rain data as a means for the watershed to get water in the river.

3. I´ll also like to apply this same data set as input rain in the case of the flood simulation model, which also as the adding of random rain input. e.g.

//Reflex to add water among the water cells

   reflex adding_input_water {

     float water_input <- rnd(100)/100;

      ask river_cells parallel: parallel{

         water_height <- water_height + water_input;

      }

   }


4. How should I express these lines to import and use my data instead of using random rain?


Thanks for your support,

yosef

Benoit Gaudou

unread,
Jul 25, 2019, 11:52:50 PM7/25/19
to gama-p...@googlegroups.com
Dear,

I think that first of all, you need to take inspiration from the model "CSV File Import.gaml", to read you csv and get a matrix with all you data.

Now you will need to able to link the time of the simulation to the date_time column of the matrix (to be able to get the value corresponding to the current day/month/hour ...
You need to identify what is the frequency of your data and the length of a step.

When you are able to get the corresponding value from the matrix, instead of rnd value you can get the value from the matrix.

For example, in the flooding model :
- you need to execute the addition of water only every ...( for example every day, by adding the when: facet ) : 

   reflex adding_input_water when: every(#day) {

      float water_input <- matrixVlue;

      ask river_cells parallelparallel{

         water_height <- water_height + water_input;

      }

   }


Hope it helps.


Cheers


Benoit



--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/64641bd9-750a-491e-a183-9c9708f516e8%40googlegroups.com.

Yosef

unread,
Jul 26, 2019, 6:46:37 AM7/26/19
to GAMA
Hi  Benoit Thanks for your keen guidance. I was able to import the rain data matrix following the CSV tutorials in gama, but now I´m encountering the following situation when running my imported CSV, I get the following error from the image I have attached, I have also attached the code below. This error is preventing the model from executing


global {

/** Insert the global definitions, variables and actions here */

file RN15_file <- csv_file("../includes/rn15_data.csv", ",");

matrix RN15_matrix <- matrix(RN15_file); //convert the file into a matrix

float RN15_number <- RN15_matrix[1,0]; // extract specific data 

list<string> RN15_DateTime <- RN15_matrix column_at 0;

list<float> RN15_rn15 <- RN15_matrix column_at 1;

// Checking the imported .csv file

init{

// the most easy way is by using the "write" statement. This statement prints values in the monitor 

write RN15_number

write RN15_DateTime;

write RN15_rn15;

}

}


experiment rainCSV_Trial_2 {

/** Insert here the definition of the input and output of the model */

output

display  rainCSV_Trial_2_display type: opengl

chart "15 min Rainfall Observations" type: series{

datalist "DateTime" value: RN15_DateTime;

data "rn15" value: RN15_rn15;

}

}

}

}


Below is the error output. I know nil values are zero. Yes indeed,  there are zero values in my matrix. If this is causing the problem; is there any way for GAMA to handle nil values in a matrix, or would I just need to deal with it by deleting those rows, even if it means that the action would reduce my data?

2 occurrences in 2 agents at cycle 0: Java error: nil value detected
in chart '15 min Rainfall Observations' type: series  {
datalist 'DateTime' value: RN15_DateTime ;
data 'rn15' value: RN15_rn15 ;
}

NullPointerException: null
msi.gama.outputs.layers.charts.ChartDataSourceList.updatevalues(ChartDataSourceList.java:99)
msi.gama.outputs.layers.charts.ChartDataSet.updatedataset(ChartDataSet.java:323)
msi.gama.outputs.layers.charts.ChartJFreeChartOutput.step(ChartJFreeChartOutput.java:167)
msi.gama.outputs.layers.charts.ChartLayerStatement._step(ChartLayerStatement.java:704)
msi.gama.outputs.layers.AbstractLayerStatement.step(AbstractLayerStatement.java:84)
msi.gama.runtime.ExecutionScope.step(ExecutionScope.java:414)
msi.gama.outputs.LayeredDisplayOutput.step(LayeredDisplayOutput.java:439)
in agents Simulation 0, rainCSV_Trial_20

Thanks again for your kind help
yosef
To unsubscribe from this group and stop receiving emails from it, send an email to gama-p...@googlegroups.com.
Screen Shot 2019-07-26 at 11.40.29.png

Benoit Gaudou

unread,
Jul 26, 2019, 8:24:50 AM7/26/19
to gama-p...@googlegroups.com
If you want to plot the values over time, you can simply write something like:
- at each step of the simulation (cycle n° i), you will plot the i-th value of RN15_rn15
(notice that (cycle < length(RN15_rn15)) ? RN15_rn15[cycle] : 0 : will simply plot 0 when you reach the end of the list RN15_rn15)

experiment rainCSV_Trial_2 {

/** Insert here the definition of the input and output of the model */

output { 

display  rainCSV_Trial_2_display type: opengl

chart "15 min Rainfall Observations" type: series{

data "rn15" value: (cycle < length(RN15_rn15)) ? RN15_rn15[cycle] : 0 ;

}

}

}

}


To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/a4ecbc59-5c59-4db1-ba75-558150b6c4e7%40googlegroups.com.

Yosef

unread,
Jul 27, 2019, 9:47:02 AM7/27/19
to GAMA
Thanks, buddy. I'll perform the changes as per your advice. Any other issues I may encounter, I’ll let you know.

Thanks,
yosef

Yosef

unread,
Sep 10, 2019, 6:09:05 AM9/10/19
to GAMA
Hi Benoit, I have been trying to use my rain data matrix as input rain to my model. I have this line of code from the watershed model in which the only water my river gets is from this rain data as shown below:

float water_input <- rain update: every(10#cycle) ? rnd(10.0) : 0.0;


I´ll like my river to receive water directly from my rain matrix without the data been subjected to the facets update every(X#cycle) ? rnd(X) : 0.0.

If I use the following lines:


1. float water_input <- rain update: water_input + rain;


or


2. float water_input <- rain;


no rainwater flows to the river. Can you kindly guide in how I should modify my line of code in order for the river to receive this rain data, taking into account I don't want the matrix (the rain data) to be affected by -> ... updateevery(10#cycle) ? rnd(10.0) : 0.0;


Thanks,

yosef

Yosef

unread,
Sep 10, 2019, 9:22:50 PM9/10/19
to GAMA
Hi Benoit,

To inform you that I was able to solve the issue.

Thanks!

Yosef

unread,
Dec 2, 2019, 1:22:39 AM12/2/19
to GAMA

Dear Benoit/Patrick, I have another enquiry on this same topic. In the example model in GAMA: “Water flow in a river graph, using water flow in a river” I´m trying to get the poi – outlet under section “reflex water_flow” to give water to the river, but from the values of a rain matrix. I have twisted and turned this requirement without any avail, reason why after so many trials and failure I’m requested your help on this matter. Can you kindly guide with the correct syntax for getting the poi – outlet to give water instead from values in the matrix?


Warm regards,

Yosef

Benoit Gaudou

unread,
Dec 3, 2019, 4:32:21 AM12/3/19
to gama-p...@googlegroups.com
Hi,
If you want to link a poi and a value from a matrix, you will need to assign a number to each poi.
After that, you will need to access the i-th value of a given row of the matrix.

Cheers

Benoit

To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gama-platform/774454b4-a277-4fda-9294-b7612ba599c9%40googlegroups.com.

Yosef

unread,
Dec 3, 2019, 9:50:42 AM12/3/19
to GAMA
Hi Benoit, thanks again for your response. You have confirmed what I actually began doing yesterday.

Regards,
Yosef
Reply all
Reply to author
Forward
0 new messages