[GRASS-SVN] r73311 - grass-addons/grass7/raster/r.spread.sod

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Sep 10 18:53:17 PDT 2018


Author: wenzeslaus
Date: 2018-09-10 18:53:16 -0700 (Mon, 10 Sep 2018)
New Revision: 73311

Modified:
   grass-addons/grass7/raster/r.spread.sod/CHANGELOG.md
   grass-addons/grass7/raster/r.spread.sod/Spore.cpp
   grass-addons/grass7/raster/r.spread.sod/Spore.h
   grass-addons/grass7/raster/r.spread.sod/main.cpp
   grass-addons/grass7/raster/r.spread.sod/raster.h
Log:
r.spread.sod: seasonality fixed, history added

Plus additional code compilation improvements and sync to lanternfly branch of
https://github.com/ncsu-landscape-dynamics/r.spread.pest/
commit 1ae5993.


Modified: grass-addons/grass7/raster/r.spread.sod/CHANGELOG.md
===================================================================
--- grass-addons/grass7/raster/r.spread.sod/CHANGELOG.md	2018-09-11 01:10:20 UTC (rev 73310)
+++ grass-addons/grass7/raster/r.spread.sod/CHANGELOG.md	2018-09-11 01:53:16 UTC (rev 73311)
@@ -4,14 +4,33 @@
 
 The format is based on [Keep a Changelog](http://keepachangelog.com/).
 
+## 2018-09-10 - Seasonality Fixes
+
+### Added
+
+- Save GRASS GIS history for all raster outputs (Vaclav Petras)
+ - The executed command with all parameters is stored in the matadata.
+
+### Changed
+
+- Seasonality parameter is checked for emptiness and empty string is
+  not allowed (Vaclav Petras)
+- Seasonality is now mostly handled in a separate class.
+
+### Fixed
+
+- Current month is now checked if it is in the season (Vaclav Petras)
+
 ## 2018-06-21 - Critical Temperature
 
 ### Added
 
-- Time-series of temperature raster maps specified as a text file.
-- Temperature rasters are used at a specified month to check against
-  a provided critical temperature and if the condition is met,
-  infected trees become susceptible again.
+- Critical temperature as the lowest temperature spores can survive
+  in a provided month (Vaclav Petras)
+ - Time-series of temperature raster maps specified as a text file.
+ - Temperature rasters are used at a specified month to check against
+   a provided critical temperature and if the condition is met,
+   infected trees become susceptible again.
 
 ### Changed
 

Modified: grass-addons/grass7/raster/r.spread.sod/Spore.cpp
===================================================================
--- grass-addons/grass7/raster/r.spread.sod/Spore.cpp	2018-09-11 01:10:20 UTC (rev 73310)
+++ grass-addons/grass7/raster/r.spread.sod/Spore.cpp	2018-09-11 01:53:16 UTC (rev 73311)
@@ -95,7 +95,7 @@
     generator.seed(random_seed);
 }
 
-void Sporulation::SporeRemove(Img& I, Img& S, const DImg temperature,
+void Sporulation::SporeRemove(Img& I, Img& S, const DImg& temperature,
                               double critical_temperature)
 {
     for (int i = 0; i < height; i++) {

Modified: grass-addons/grass7/raster/r.spread.sod/Spore.h
===================================================================
--- grass-addons/grass7/raster/r.spread.sod/Spore.h	2018-09-11 01:10:20 UTC (rev 73310)
+++ grass-addons/grass7/raster/r.spread.sod/Spore.h	2018-09-11 01:53:16 UTC (rev 73311)
@@ -48,7 +48,7 @@
     std::default_random_engine generator;
 public:
     Sporulation(unsigned random_seed, const Img &size);
-    void SporeRemove(Img& I, Img &S, const DImg temperature,
+    void SporeRemove(Img& I, Img& S, const DImg& temperature,
                      double critical_temperature);
     void SporeGen(const Img& I, const double *weather,
                   double weather_value, double rate);

Modified: grass-addons/grass7/raster/r.spread.sod/main.cpp
===================================================================
--- grass-addons/grass7/raster/r.spread.sod/main.cpp	2018-09-11 01:10:20 UTC (rev 73310)
+++ grass-addons/grass7/raster/r.spread.sod/main.cpp	2018-09-11 01:53:16 UTC (rev 73311)
@@ -135,7 +135,20 @@
                                     " value '" + text +"' provided");
 }
 
-typedef std::pair<int, int> Season;
+class Season
+{
+public:
+    Season(int start, int end)
+        : m_start_month(start), m_end_month(end)
+    {}
+    inline bool month_in_season(int month)
+    {
+        return month >= m_start_month && month <= m_end_month;
+    }
+private:
+    int m_start_month;
+    int m_end_month;
+};
 
 inline Season seasonality_from_option(const Option* opt)
 {
@@ -444,7 +457,8 @@
               " ending at the end of September");
     opt.seasonality->key_desc = "from,to";
     //opt.seasonality->options = "1-12";
-    opt.seasonality->answer = "1,12";
+    opt.seasonality->answer = const_cast<char*>("1,12");
+    opt.seasonality->required = YES;
     opt.seasonality->multiple = NO;
     opt.seasonality->guisection = _("Time");
 
@@ -462,7 +476,7 @@
     opt.spore_rate->type = TYPE_DOUBLE;
     opt.spore_rate->key = "spore_rate";
     opt.spore_rate->label = _("Spore production rate per week for each infected tree");
-    opt.spore_rate->answer = "4.4";
+    opt.spore_rate->answer = const_cast<char*>("4.4");
     opt.spore_rate->guisection = _("Spores");
 
     opt.radial_type = G_define_option();
@@ -469,7 +483,7 @@
     opt.radial_type->type = TYPE_STRING;
     opt.radial_type->key = "radial_type";
     opt.radial_type->label = _("Radial distribution type");
-    opt.radial_type->answer = "cauchy";
+    opt.radial_type->answer = const_cast<char*>("cauchy");
     opt.radial_type->options = "cauchy,cauchy_mix";
     opt.radial_type->guisection = _("Spores");
 
@@ -477,7 +491,7 @@
     opt.scale_1->type = TYPE_DOUBLE;
     opt.scale_1->key = "scale_1";
     opt.scale_1->label = _("Scale parameter for the first Cauchy distribution");
-    opt.scale_1->answer = "20.57";
+    opt.scale_1->answer = const_cast<char*>("20.57");
     opt.scale_1->guisection = _("Spores");
 
     opt.scale_2 = G_define_option();
@@ -490,7 +504,7 @@
     opt.kappa->type = TYPE_DOUBLE;
     opt.kappa->key = "kappa";
     opt.kappa->label = _("Concentration parameter for the von Mises distribution");
-    opt.kappa->answer = "2";
+    opt.kappa->answer = const_cast<char*>("2");
     opt.kappa->guisection = _("Spores");
 
     opt.gamma = G_define_option();
@@ -625,6 +639,9 @@
     file_exists_or_fatal_error(opt.weather_file);
 
     // Seasonality: Do you want the spread to be limited to certain months?
+    if (!opt.seasonality->answer || opt.seasonality->answer[0] == '\0')
+        G_fatal_error(_("The option %s cannot be empty"),
+                      opt.seasonality->key);
     Season season = seasonality_from_option(opt.seasonality);
 
     Direction pwdir = direction_enum_from_string(opt.wind->answer);
@@ -830,7 +847,7 @@
     // main simulation loop (weekly steps)
     for (int current_week = 0; ; current_week++, step == "month" ? dd_current.increasedByMonth() : dd_current.increasedByWeek()) {
         if (dd_current < dd_end)
-            if (season.first >= dd_current.getMonth() && dd_current.getMonth() <= season.second)
+            if (season.month_in_season(dd_current.getMonth()))
                 unresolved_weeks.push_back(current_week);
 
         // removal is out of sync with the actual runs but it does

Modified: grass-addons/grass7/raster/r.spread.sod/raster.h
===================================================================
--- grass-addons/grass7/raster/r.spread.sod/raster.h	2018-09-11 01:10:20 UTC (rev 73310)
+++ grass-addons/grass7/raster/r.spread.sod/raster.h	2018-09-11 01:53:16 UTC (rev 73311)
@@ -424,6 +424,11 @@
     for (int i = 0; i < height; i++)
         Rast_put_c_row(fd, data + (i * width));
     Rast_close(fd);
+    /* write metadata */
+    struct History history;
+    Rast_short_history(name, "raster", &history);
+    Rast_command_history(&history);
+    Rast_write_history(name, &history);
 }
 
 // convenient definitions, names for backwards compatibility



More information about the grass-commit mailing list