[GRASS-dev] creating new modules

I am interested in porting an ecosystem model (carbon balance model) to a grass module. Currently my simulation model consists of 4 .cpp files (essentially a “main” file, a vegetation parameters file, and climate file, and a io file), and then 3 associated header files. I found the link:

http://grass.itc.it/intro/modelintegration.html

Which describes simulation models that have been incorporated into grass.

But could also use some general advice as to “best practices” new module structure. Has anyone put together a grass module howto? Perhaps the programmers guide? I’ve been digging around on the wiki, but haven’t found what I’m looking for yet. What I am basically asking for is to be pointed to a well done example that I should follow as “simulation model module template”

Any suggestions?

Thanks,

Kirk

On Aug 5, 2006, at 11:03 PM, Helena Mitasova wrote:

On Aug 4, 2006, at 10:35 AM, Kirk R. Wythers wrote:

I am interested in porting an ecosystem model (carbon balance model) to a grass module. Currently my simulation model consists of 4 .cpp files (essentially a "main" file, a vegetation parameters file, and climate file, and a io file), and then 3 associated header files. I found the link:

http://grass.itc.it/intro/modelintegration.html

Which describes simulation models that have been incorporated into grass.

those models are pretty old and the integration was done mostly for GRASS4*
some have been rewritten from fortran code (including the not listed simwe) so they may not
be such good examples.

Thanks for the info Helena. I found a soil water model (MODFLOW) that a grass module has been written for

r.gmtg

However, the README file for it says that it was written for grass 5.4. Does anyone know if there are particular coding issue when writing a module for 6.1 relative to 5.4?

But could also use some general advice as to "best practices" new module structure. Has anyone put together a grass module howto? Perhaps the programmers guide? I've been digging around on the wiki, but haven't found what I'm looking for yet. What I am basically asking for is to be pointed to a well done example that I should follow as "simulation model module template"

I am curious to see whether somebody will provide it - I would love to have it too!

Helena

Any suggestions?

Thanks,

Kirk

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

On Aug 24, 2006, at 3:57 AM, Hamish wrote:

On Sun, 6 Aug 2006 16:46:12 -0500
"Kirk R. Wythers" <kwythers@umn.edu> wrote:

However, the README file for it says that it was written for grass
5.4. Does anyone know if there are particular coding issue when
writing a module for 6.1 relative to 5.4?

the raster format is unchanged, so not (m)any issues to worry about.

Thanks very much Hamish,

I think my approach is going to have to be "baby steps". I did look at r.example (recommended by Markus), which seems to read in a raster, does nothing to it, then writes a new raster. If I want to write a ecosystem model module for GRASS, then my goal is to figure out how to organize my model's code into the "does nothing" portion of r.example.

If you don't mind, like to describe my models data requirements, and then hear your thoughts as module design.

The goal here is to write a module r.pnet. PnET is a general ecosystem model that does carbon, water and nitrogen balance. It can output things like gross and net primary production, net ecosystem production, plant and ecosystem respiration, etc.

In it's present form PnET requires a file of vegetation parameters, and a file of climate parameters (climate inputs are temporal, i.e. daily time step would have one day of temps, precipitation, and solar radiation per line). However, on a spatial application such as this, climate will vary both temporally and spatially, therefore I will need a multidimensional data holder for climate inputs.

Presently the vegetation parameters are in individual files based on cover type (for example, one file for oak, one file for maple, one file for pine, one file for corn, etc...

I am envisioning a GRASS module that takes a input raster of land cover, and for each pixel, gets the vegetation parameters associated with the land cover type, gets climate data for the current time step (that day for example), then runs the PnET model for that pixel, then writes it's output, before moving on to the next pixel.

Perhaps a good start would be to write some over simplified PnET code into the "does nothing" portion of r.example and see if I can get anything working?

Thanks again,

Kirk

Kirk R. Wythers wrote:

I think my approach is going to have to be "baby steps". I did look
at r.example (recommended by Markus), which seems to read in a
raster, does nothing to it, then writes a new raster. If I want to
write a ecosystem model module for GRASS, then my goal is to figure
out how to organize my model's code into the "does nothing" portion
of r.example.

If you don't mind, like to describe my models data requirements, and
then hear your thoughts as module design.

The goal here is to write a module r.pnet. PnET is a general
ecosystem model that does carbon, water and nitrogen balance. It can
output things like gross and net primary production, net ecosystem
production, plant and ecosystem respiration, etc.

In it's present form PnET requires a file of vegetation parameters,
and a file of climate parameters (climate inputs are temporal, i.e.
daily time step would have one day of temps, precipitation, and solar
radiation per line). However, on a spatial application such as this,
climate will vary both temporally and spatially, therefore I will
need a multidimensional data holder for climate inputs.

Presently the vegetation parameters are in individual files based on
cover type (for example, one file for oak, one file for maple, one
file for pine, one file for corn, etc...

I am envisioning a GRASS module that takes a input raster of land
cover, and for each pixel, gets the vegetation parameters associated
with the land cover type, gets climate data for the current time step
(that day for example), then runs the PnET model for that pixel, then
writes it's output, before moving on to the next pixel.

Perhaps a good start would be to write some over simplified PnET code
into the "does nothing" portion of r.example and see if I can get
anything working?

Anything which can be done by filling in the do-nothing portion of
r.example can be done with r.mapcalc.

More generally, anything with a fixed number of inputs and outputs
where the value of each output cell only depends upon the
corresponding input cell and its immediate neighbours is probably best
done with r.mapcalc.

OTOH, if the outputs depend upon larger areas of the map, then it's
better to start with a module which has a similar structure. E.g.
r.grow, r.neighbors and r.mfilter all compute cell values based upon a
finite neigbourhood surrounding each cell (but only for one input map;
extending the concept to several maps wouldn't be difficult).

--
Glynn Clements <glynn@gclements.plus.com>

Kirk Wythers wrote:

The goal here is to write a module r.pnet. PnET is a general
ecosystem model that does carbon, water and nitrogen balance. It can
output things like gross and net primary production, net ecosystem
production, plant and ecosystem respiration, etc.

In it's present form PnET requires a file of vegetation parameters,
and a file of climate parameters (climate inputs are temporal, i.e.
daily time step would have one day of temps, precipitation, and solar

radiation per line). However, on a spatial application such as this,
climate will vary both temporally and spatially, therefore I will
need a multidimensional data holder for climate inputs.

Presently the vegetation parameters are in individual files based on
cover type (for example, one file for oak, one file for maple, one
file for pine, one file for corn, etc...

I am envisioning a GRASS module that takes a input raster of land
cover, and for each pixel, gets the vegetation parameters associated
with the land cover type, gets climate data for the current time step

(that day for example), then runs the PnET model for that pixel, then
writes it's output, before moving on to the next pixel.

Perhaps a good start would be to write some over simplified PnET code
into the "does nothing" portion of r.example and see if I can get
anything working?

How complicated is the PnET model? e.g. can you write a prototype using
r.mapcalc or a series of r.mapcalc commands? If the model is relatively
simple, that would be my first step.

Hamish

Kirk, I am not sure whether Massimiliano Cannata reads this list but he has
developed a set of modules, in fact entire environment that does quite a few
of tasks that you are discussing here. You may want to check the abstract for
HydroFOSS at foss4g2006.org (if it is not yet available it should be in
few days)
and see whether there are some lessons to be learned from his work or
whether you can coordinate the development.

Helena

Kirk Wythers wrote:

The goal here is to write a module r.pnet. PnET is a general
ecosystem model that does carbon, water and nitrogen balance. It can
output things like gross and net primary production, net ecosystem
production, plant and ecosystem respiration, etc.

In it's present form PnET requires a file of vegetation parameters,
and a file of climate parameters (climate inputs are temporal, i.e.
daily time step would have one day of temps, precipitation, and solar

radiation per line). However, on a spatial application such as this,
climate will vary both temporally and spatially, therefore I will
need a multidimensional data holder for climate inputs.

Presently the vegetation parameters are in individual files based on
cover type (for example, one file for oak, one file for maple, one
file for pine, one file for corn, etc...

I am envisioning a GRASS module that takes a input raster of land
cover, and for each pixel, gets the vegetation parameters associated
with the land cover type, gets climate data for the current time step

(that day for example), then runs the PnET model for that pixel, then
writes it's output, before moving on to the next pixel.

Perhaps a good start would be to write some over simplified PnET code
into the "does nothing" portion of r.example and see if I can get
anything working?

How complicated is the PnET model? e.g. can you write a prototype using
r.mapcalc or a series of r.mapcalc commands? If the model is relatively
simple, that would be my first step.

Hamish

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

Hi Kirk,

can you tell me where i can read about your model and if you have a
flow-chart of the main module in its actual .CPP form.
This kind of model is interesting for our research in University,
therefore i would be happy to help for the porting in GRASS GIS.

sincerely,
Yann

On 04/08/06, Kirk R. Wythers <kwythers@umn.edu> wrote:

I am interested in porting an ecosystem model (carbon balance model) to a
grass module. Currently my simulation model consists of 4 .cpp files
(essentially a "main" file, a vegetation parameters file, and climate file,
and a io file), and then 3 associated header files. I found the link:

http://grass.itc.it/intro/modelintegration.html

Which describes simulation models that have been incorporated into grass.

But could also use some general advice as to "best practices" new module
structure. Has anyone put together a grass module howto? Perhaps the
programmers guide? I've been digging around on the wiki, but haven't found
what I'm looking for yet. What I am basically asking for is to be pointed to
a well done example that I should follow as "simulation model module
template"

Any suggestions?

Thanks,

Kirk

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

Maxi,

Thanks for contribution to the wiki. I am very interested in your work with HydroFOSS. Since you likely have confronted already, many of the issues that I am struggling with, I would like to ask you a few questiions.

First off, how do you organize your meteorological data in time and space? For example, over a landscape there will be numerous observations for variables such as precipitation, temperature and solar radiation. The more I think about it, the more sophisticated the database requirements for this task seem to be.

Right now, I am leaning toward setting up vector layers (and associated postgresql tables) for variables such as vegetation type and soil type. For example, the model will need to know soil type at any given location and needs to access precipitation data through time in oder to calculate water availability. In turn, water availability through time will then be needed for photosynthesis calculations which will have further temporally dependent input requirements such as solar radiation, and temperature.

Keeping these data (both input and output) organized and accessible, through the model run seems to be my most challenging task at this point.

Any thoughts are much appreciated,

Kirk

On Sep 20, 2006, at 5:55 AM, Massimiliano Cannata wrote:

HI, I’ve just added some notes on the Wiki page…
for people interested in ETP, please take a look at http://w3.ist.supsi.ch:8001/geomatica/
hope it could be set up a working team on environmental modelling :wink:
Maxi

Kirk R. Wythers, Research Fellow
Dept. of Forest Resources
University of Minnesota
1530 Cleveland Ave N
Saint Paul, MN 55108
tel: 612.625.2261
email: kwythers@umn.edu


Scott W. Mitchell Scott_Mitchell@carleton.ca
Geomatics and Landscape Ecology Research Laboratory
Department of Geography and Environmental Studies
Carleton University, B349 Loeb Building
Ottawa, ON Canada K1S 5B6
+1-613-520-2600 ext 2695

Dr. Eng. Massimiliano Cannata
Responsabile Area Geomatica
Istituto Scienze della Terra
Scuola Universitaria Professionale della Svizzera Italiana
Via Trevano, c.p. 72
CH-6952 Canobbio-Lugano
Tel: +41 (0)58 666 62 14
Fax +41 (0)58 666 62 09

Sorry for my delay.
Inline some comments.

Kirk R. Wythers wrote:

Maxi,

Thanks for contribution to the wiki. I am very interested in your work with HydroFOSS. Since you likely have confronted already, many of the issues that I am struggling with, I would like to ask you a few questiions.

First off, how do you organize your meteorological data in time and space? For example, over a landscape there will be numerous observations for variables such as precipitation, temperature and solar radiation. The more I think about it, the more sophisticated the database requirements for this task seem to be.

Basically I used two external DB table: one for stations (with east, north, id) and one for values (with id, timestamp, value, parameter_type), then i run a query and import the result as vector with v.in.ascii
This is a dirty solution, and some discussion on series in grass are going on also for this propouse.

Right now, I am leaning toward setting up vector layers (and associated postgresql tables) for variables such as vegetation type and soil type. For example, the model will need to know soil type at any given location and needs to access precipitation data through time in oder to calculate water availability. In turn, water availability through time will then be needed for photosynthesis calculations which will have further temporally dependent input requirements such as solar radiation, and temperature.

Keeping these data (both input and output) organized and accessible, through the model run seems to be my most challenging task at this point.

For HydroFOSS running I just used a name convention for series handling: [series_name].[series_time]
in this way i loop trough time ($time_now & $time_last) and used the correct input in command running, e.g.:

r.mapcal 'landuse.$time_now=landuse.$time_last + 10'

Any thoughts are much appreciated,

Kirk

On Sep 20, 2006, at 5:55 AM, Massimiliano Cannata wrote:

HI, I've just added some notes on the Wiki page....
for people interested in ETP, please take a look at http://w3.ist.supsi.ch:8001/geomatica/
hope it could be set up a working team on environmental modelling :wink:
Maxi

Kirk R. Wythers, Research Fellow
Dept. of Forest Resources
University of Minnesota
1530 Cleveland Ave N
Saint Paul, MN 55108
tel: 612.625.2261
email: kwythers@umn.edu <mailto:kwythers@umn.edu>

------
Scott W. Mitchell Scott_Mitchell@carleton.ca <mailto:Scott_Mitchell@carleton.ca>
Geomatics and Landscape Ecology Research Laboratory
Department of Geography and Environmental Studies
Carleton University, B349 Loeb Building
Ottawa, ON Canada K1S 5B6
+1-613-520-2600 ext 2695

--

Dr. Eng. Massimiliano Cannata
Responsabile Area Geomatica
Istituto Scienze della Terra
Scuola Universitaria Professionale della Svizzera Italiana
Via Trevano, c.p. 72
CH-6952 Canobbio-Lugano
Tel: +41 (0)58 666 62 14
Fax +41 (0)58 666 62 09

--

Dr. Eng. Massimiliano Cannata
Responsabile Area Geomatica
Istituto Scienze della Terra
Scuola Universitaria Professionale della Svizzera Italiana
Via Trevano, c.p. 72
CH-6952 Canobbio-Lugano
Tel: +41 (0)58 666 62 14
Fax +41 (0)58 666 62 09