9#include "ConstantGrid.h"
13#include "IntensityMap.h"
19using FuelGrid = data::ConstantGrid<const fuel::FuelType*, FuelSize>;
20using ElevationGrid = data::ConstantGrid<ElevationSize>;
21using CellGrid = data::ConstantGrid<Cell, Topo>;
64 const string& perimeter,
75 const string& in_fuel,
76 const string& in_elevation);
113 [[nodiscard]]
constexpr const string&
proj4()
const
121 [[nodiscard]]
constexpr Idx
rows()
const
197 const Idx column)
const
199 const auto& p =
event.cell();
214 DurationSize start_time)
const;
221 template <
class Other>
222 [[nodiscard]] unique_ptr<data::GridMap<Other>>
makeMap(
const Other nodata)
const
224 return make_unique<data::GridMap<Other>>(*
cells_, nodata);
256 static Cell nodata{};
257 auto values = vector<Cell>{fuel.
data.size()};
258 vector<HashSize> hashes{};
263 for (Idx r = 0; r < fuel.
rows(); ++r)
265 for (Idx c = 0; c < fuel.
columns(); ++c)
267 const auto h = hashes.emplace_back(
Location(r, c).hash());
284 if (r >= 0 && r < fuel.
rows() && c >= 0 && c < fuel.
columns())
288 auto s =
static_cast<SlopeSize
>(INVALID_SLOPE);
289 auto a =
static_cast<AspectSize
>(INVALID_ASPECT);
291 if (r > 0 && r < fuel.
rows() - 1 && c > 0 && c < fuel.
columns() - 1)
295 for (
int i = -1; i < 2; ++i)
297 for (
int j = -1; j < 2; ++j)
300 auto actual_row =
static_cast<Idx
>(r - i);
301 auto actual_column =
static_cast<Idx
>(c + j);
302 auto cur_loc =
Location{actual_row, actual_column};
312 dem[3 * (i + 1) + (j + 1)] = 1.0 * v;
322 const MathSize dx = ((dem[2] + dem[5] + dem[5] + dem[8])
323 - (dem[0] + dem[3] + dem[3] + dem[6]))
325 const MathSize dy = ((dem[6] + dem[7] + dem[7] + dem[8])
326 - (dem[0] + dem[1] + dem[1] + dem[2]))
328 const MathSize key = (dx * dx + dy * dy);
329 auto slope_pct =
static_cast<float>(100 * (sqrt(key) / 8.0));
330 s = min(
static_cast<SlopeSize
>(MAX_SLOPE_FOR_DISTANCE),
static_cast<SlopeSize
>(round(slope_pct)));
331 static_assert(std::numeric_limits<SlopeSize>::max() >= MAX_SLOPE_FOR_DISTANCE);
332 MathSize aspect_azimuth = 0.0;
334 if (s > 0 && (dx != 0 || dy != 0))
336 aspect_azimuth = atan2(dy, -dx) * M_RADIANS_TO_DEGREES;
338 aspect_azimuth = (aspect_azimuth > 90.0) ? (450.0 - aspect_azimuth) : (90.0 - aspect_azimuth);
339 if (aspect_azimuth == 360.0)
341 aspect_azimuth = 0.0;
345 a =
static_cast<AspectSize
>(round(aspect_azimuth));
351#ifndef VLD_RPTHOOK_INSTALL
352 logging::check_equal(
cell.
row(), r,
"Cell row");
353 logging::check_equal(
cell.
column(), c,
"Cell column");
354 const auto v = values.at(h);
355 logging::check_equal(v.row(), r,
"Row");
356 logging::check_equal(v.column(), c,
"Column");
359 logging::check_equal(
cell.
slope(), s,
"Cell slope");
360 logging::check_equal(v.slope(), s,
"Slope");
363 logging::check_equal(
cell.
aspect(), a,
"Cell aspect");
364 logging::check_equal(v.aspect(), a,
"Aspect");
368 logging::check_equal(
cell.
aspect(), a,
"Cell aspect when slope is 0");
369 logging::check_equal(v.aspect(), 0,
"Aspect when slope is 0");
371 logging::check_equal(v.fuelCode(), f,
"Fuel");
376 logging::check_equal(
cell.
slope(), INVALID_SLOPE,
"Invalid Cell slope");
377 logging::check_equal(
cell.
aspect(), INVALID_ASPECT,
"Invalid Cell aspect");
378 logging::check_equal(
cell.
fuelCode(), INVALID_FUEL_CODE,
"Invalid Cell fuel");
379 logging::check_equal(v.slope(), INVALID_SLOPE,
"Invalid slope");
380 logging::check_equal(v.aspect(), INVALID_ASPECT,
"Invalid aspect");
381 logging::check_equal(v.fuelCode(), INVALID_FUEL_CODE,
"Invalid fuel");
399 string(fuel.
proj4()),
410 auto result = make_shared<sim::BurnedData>();
411 for (Idx r = 0; r <
rows(); ++r)
413 for (Idx c = 0; c <
columns(); ++c)
417 bool is_outer = 0 == r
422 (*result)[location.
hash()] = is_outer || fuel::is_null_fuel(cells.
at(location));
459 const string dir_out,
469 logging::note(
"Start elevation is %d",
elevation_);
A GridData<T, V, const vector<T>> that cannot change once initialized.
Definition ConstantGrid.h:27
constexpr T at(const Location &location) const noexcept override
Value for grid at given Location.
Definition ConstantGrid.h:34
constexpr MathSize xurcorner() const noexcept
Upper right corner X coordinate in meters.
Definition Grid.h:116
constexpr const string & proj4() const noexcept
Proj4 string defining coordinate system for this grid. Must be a UTM projection.
Definition Grid.h:132
constexpr MathSize cellSize() const noexcept
Cell size used for GridBase.
Definition Grid.h:72
constexpr MathSize yllcorner() const noexcept
Lower left corner Y coordinate in meters.
Definition Grid.h:108
constexpr MathSize xllcorner() const noexcept
Lower left corner X coordinate in meters.
Definition Grid.h:100
constexpr MathSize yurcorner() const noexcept
Upper right corner Y coordinate in meters.
Definition Grid.h:124
D data
Structure that holds data represented by this GridData.
Definition Grid.h:506
constexpr Idx rows() const noexcept
Number of rows in the GridBase.
Definition Grid.h:257
constexpr Idx columns() const noexcept
Number of columns in the GridBase.
Definition Grid.h:265
static constexpr FuelCodeSize safeCode(const FuelType *fuel)
Convert FuelType to its code, or 0 if nullptr.
Definition FuelType.h:62
A specific Event scheduled in a specific Scenario.
Definition Event.h:19
Map of the percentage of simulations in which a Cell burned in each intensity category.
Definition ProbabilityMap.h:31
A Position with a Slope, Aspect, and Fuel.
Definition Cell.h:20
static constexpr AspectSize aspect(const SpreadKey value) noexcept
Aspect (degrees)
Definition Cell.h:126
static constexpr FuelCodeSize fuelCode(const SpreadKey value) noexcept
Fuel.
Definition Cell.h:136
static constexpr SlopeSize slope(const SpreadKey value) noexcept
Slope (degrees)
Definition Cell.h:145
The area that a Model is run for, with Fuel, Slope, and Aspect grids.
Definition Environment.h:49
ElevationSize elevation_
Elevation at StartPoint.
Definition Environment.h:487
void resetBurnedData(sim::BurnedData *data) const noexcept
Reset with known non-fuel cells.
Definition Environment.h:239
Environment(const string dir_out, const FuelGrid &fuel, const ElevationGrid &elevation, const Point &point)
Load from rasters.
Definition Environment.h:458
Environment & operator=(const Environment &rhs) noexcept=default
Copy assignment.
sim::ProbabilityMap * makeProbabilityMap(DurationSize time, DurationSize start_time) const
Make a ProbabilityMap that covers this Environment.
Definition Environment.cpp:38
static Environment load(const string dir_out, const Point &point, const string &in_fuel, const string &in_elevation)
Load from rasters.
Definition Environment.cpp:23
shared_ptr< const sim::BurnedData > not_burnable_
BurnedData of cells that are not burnable.
Definition Environment.h:483
Cell offset(const sim::Event &event, const Idx row, const Idx column) const
Cell at Location with given hash.
Definition Environment.h:195
shared_ptr< sim::BurnedData > initializeNotBurnable(const CellGrid &cells) const
Creates a map of areas that are not burnable either because of fuel or the initial perimeter.
Definition Environment.h:405
constexpr const string & proj4() const
UTM projection that this uses.
Definition Environment.h:113
CellGrid * cells_
Cells representing Environment.
Definition Environment.h:479
unique_ptr< data::GridMap< Other > > makeMap(const Other nodata) const
Create a GridMap<Other> covering this Environment.
Definition Environment.h:222
Environment & operator=(Environment &&rhs) noexcept=default
Move assignment.
Environment(const string dir_out, CellGrid *cells, const ElevationSize elevation) noexcept
Construct from cells and elevation.
Definition Environment.h:436
constexpr Idx columns() const
Number of columns in grid.
Definition Environment.h:129
static Environment loadEnvironment(const string dir_out, const string &path, const Point &point, const string &perimeter, int year)
Load from rasters in folder that have same projection as Perimeter.
Definition Environment.cpp:46
Environment(Environment &&rhs) noexcept=default
Move constructor.
constexpr Cell cell(const Position< P > &position) const
Cell at given Location.
Definition Environment.h:170
static CellGrid * makeCells(const FuelGrid &fuel, const ElevationGrid &elevation)
Combine rasters into ConstantGrid<Cell, Topo>
Definition Environment.h:251
unique_ptr< sim::BurnedData > makeBurnedData() const
Create BurnedData and set burned bits based on Perimeter.
Definition Environment.h:230
Cell cell(const Idx row, const Idx column) const
Cell at given row and column.
Definition Environment.h:160
constexpr MathSize cellSize() const
Cell width and height (m)
Definition Environment.h:137
Environment(const Environment &rhs) noexcept=default
Copy constructor.
constexpr Idx rows() const
Number of rows in grid.
Definition Environment.h:121
unique_ptr< Coordinates > findCoordinates(const Point &point, bool flipped) const
Determine Coordinates in the grid for the Point.
Definition Environment.cpp:145
constexpr ElevationSize elevation() const
Elevation of the origin Point.
Definition Environment.h:145
Definition Location.h:229
A geographic location in lat/long coordinates.
Definition Point.h:13
A Position with a row and column.
Definition Location.h:57
constexpr Idx row() const noexcept
Row.
Definition Location.h:64
constexpr HashSize hash() const noexcept
Hash derived from row and column.
Definition Location.h:80
constexpr Idx column() const noexcept
Column.
Definition Location.h:72