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,
218 int max_value)
const;
225 template <
class Other>
226 [[nodiscard]] unique_ptr<data::GridMap<Other>>
makeMap(
const Other nodata)
const
228 return make_unique<data::GridMap<Other>>(*
cells_, nodata);
260 static Cell nodata{};
261 auto values = vector<Cell>{fuel.
data.size()};
262 vector<HashSize> hashes{};
267 for (Idx r = 0; r < fuel.
rows(); ++r)
269 for (Idx c = 0; c < fuel.
columns(); ++c)
271 const auto h = hashes.emplace_back(
Location(r, c).hash());
288 if (r >= 0 && r < fuel.
rows() && c >= 0 && c < fuel.
columns())
292 auto s =
static_cast<SlopeSize
>(INVALID_SLOPE);
293 auto a =
static_cast<AspectSize
>(INVALID_ASPECT);
295 if (r > 0 && r < fuel.
rows() - 1 && c > 0 && c < fuel.
columns() - 1)
299 for (
int i = -1; i < 2; ++i)
301 for (
int j = -1; j < 2; ++j)
304 auto actual_row =
static_cast<Idx
>(r - i);
305 auto actual_column =
static_cast<Idx
>(c + j);
306 auto cur_loc =
Location{actual_row, actual_column};
316 dem[3 * (i + 1) + (j + 1)] = 1.0 * v;
326 const MathSize dx = ((dem[2] + dem[5] + dem[5] + dem[8])
327 - (dem[0] + dem[3] + dem[3] + dem[6]))
329 const MathSize dy = ((dem[6] + dem[7] + dem[7] + dem[8])
330 - (dem[0] + dem[1] + dem[1] + dem[2]))
332 const MathSize key = (dx * dx + dy * dy);
333 auto slope_pct =
static_cast<float>(100 * (sqrt(key) / 8.0));
334 s = min(
static_cast<SlopeSize
>(MAX_SLOPE_FOR_DISTANCE),
static_cast<SlopeSize
>(round(slope_pct)));
335 static_assert(std::numeric_limits<SlopeSize>::max() >= MAX_SLOPE_FOR_DISTANCE);
336 MathSize aspect_azimuth = 0.0;
338 if (s > 0 && (dx != 0 || dy != 0))
340 aspect_azimuth = atan2(dy, -dx) * M_RADIANS_TO_DEGREES;
342 aspect_azimuth = (aspect_azimuth > 90.0) ? (450.0 - aspect_azimuth) : (90.0 - aspect_azimuth);
343 if (aspect_azimuth == 360.0)
345 aspect_azimuth = 0.0;
349 a =
static_cast<AspectSize
>(round(aspect_azimuth));
355#ifndef VLD_RPTHOOK_INSTALL
356 logging::check_equal(
cell.
row(), r,
"Cell row");
357 logging::check_equal(
cell.
column(), c,
"Cell column");
358 const auto v = values.at(h);
359 logging::check_equal(v.row(), r,
"Row");
360 logging::check_equal(v.column(), c,
"Column");
363 logging::check_equal(
cell.
slope(), s,
"Cell slope");
364 logging::check_equal(v.slope(), s,
"Slope");
367 logging::check_equal(
cell.
aspect(), a,
"Cell aspect");
368 logging::check_equal(v.aspect(), a,
"Aspect");
372 logging::check_equal(
cell.
aspect(), a,
"Cell aspect when slope is 0");
373 logging::check_equal(v.aspect(), 0,
"Aspect when slope is 0");
375 logging::check_equal(v.fuelCode(), f,
"Fuel");
380 logging::check_equal(
cell.
slope(), INVALID_SLOPE,
"Invalid Cell slope");
381 logging::check_equal(
cell.
aspect(), INVALID_ASPECT,
"Invalid Cell aspect");
382 logging::check_equal(
cell.
fuelCode(), INVALID_FUEL_CODE,
"Invalid Cell fuel");
383 logging::check_equal(v.slope(), INVALID_SLOPE,
"Invalid slope");
384 logging::check_equal(v.aspect(), INVALID_ASPECT,
"Invalid aspect");
385 logging::check_equal(v.fuelCode(), INVALID_FUEL_CODE,
"Invalid fuel");
403 string(fuel.
proj4()),
414 auto result = make_shared<sim::BurnedData>();
415 for (Idx r = 0; r <
rows(); ++r)
417 for (Idx c = 0; c <
columns(); ++c)
421 bool is_outer = 0 == r
426 (*result)[location.
hash()] = is_outer || fuel::is_null_fuel(cells.
at(location));
463 const string dir_out,
473 logging::note(
"Start elevation is %d",
elevation_);
476 logging::debug(
"Saving simulation area");
478 auto convert_to_slope =
480 const Cell& v) -> SlopeSize {
483 auto convert_to_aspect =
485 const Cell& v) -> AspectSize {
488 auto convert_to_area =
490 const ElevationSize v) -> ElevationSize {
492 return (v ==
elevation.nodataValue()) ? v : 3;
494 auto convert_to_fuelcode =
497 return lookup.fuelToCode(value);
502 convert_to_fuelcode);
511 static_cast<SlopeSize
>(INVALID_SLOPE));
516 static_cast<AspectSize
>(INVALID_ASPECT));
522 logging::debug(
"Done saving fuel grid");
526 const string dir_out_;
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
string saveToFile(const string &dir, const string &base_name, std::function< R(T value)> convert, const R no_data) const
Save GridMap contents to file based on settings.
Definition Grid.h:856
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
An FBP fuel type.
Definition FuelType.h:55
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:22
static const fuel::FuelLookup & fuelLookup() noexcept
Fuel lookup table.
Definition Settings.cpp:596
static bool saveSimulationArea() noexcept
Whether or not to save simulation area grids.
Definition Settings.cpp:672
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:538
void resetBurnedData(sim::BurnedData *data) const noexcept
Reset with known non-fuel cells.
Definition Environment.h:243
Environment(const string dir_out, const FuelGrid &fuel, const ElevationGrid &elevation, const Point &point)
Load from rasters.
Definition Environment.h:462
Environment & operator=(const Environment &rhs) noexcept=default
Copy assignment.
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:534
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:409
constexpr const string & proj4() const
UTM projection that this uses.
Definition Environment.h:113
CellGrid * cells_
Cells representing Environment.
Definition Environment.h:530
unique_ptr< data::GridMap< Other > > makeMap(const Other nodata) const
Create a GridMap<Other> covering this Environment.
Definition Environment.h:226
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:440
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:65
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:255
unique_ptr< sim::BurnedData > makeBurnedData() const
Create BurnedData and set burned bits based on Perimeter.
Definition Environment.h:234
sim::ProbabilityMap * makeProbabilityMap(DurationSize time, DurationSize start_time, int min_value, int low_max, int med_max, int max_value) const
Make a ProbabilityMap that covers this Environment.
Definition Environment.cpp:49
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:164
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