include/terraingen/albedo/crater_albedo_options.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | |||
| 3 | /// @file | ||
| 4 | /// @brief The options of `CraterAlbedo`: retention, rays, oblique impacts, texture and the | ||
| 5 | /// reflectance zones of new craters. | ||
| 6 | #pragma once | ||
| 7 | |||
| 8 | #include "terraingen/albedo/maturity.h" | ||
| 9 | #include "terraingen/layers/craters/crater.h" | ||
| 10 | #include "terraingen/layers/craters/rays.h" | ||
| 11 | #include "terraingen/layers/fade.h" | ||
| 12 | #include "terraingen/random/value_distribution.h" | ||
| 13 | |||
| 14 | #include <array> | ||
| 15 | #include <cstdint> | ||
| 16 | #include <optional> | ||
| 17 | |||
| 18 | namespace terraingen { | ||
| 19 | |||
| 20 | /// How long a crater keeps its immature, bright material, by diameter, after Werner and | ||
| 21 | /// Medvedev (2010): `smallMyr` up to `smallDiameter`, a power law of diameter up to `midDiameter`, | ||
| 22 | /// `midMyr` up to `largeDiameter` and `largeMyr` beyond, every time multiplied by `scale`. | ||
| 23 | 1 | struct RayRetention { | |
| 24 | double smallDiameter = 1000.0; ///< At or below this diameter (m), `smallMyr`. | ||
| 25 | double smallMyr = 5.0; ///< Retention of small craters, Myr. | ||
| 26 | double midDiameter = 5000.0; ///< From this diameter (m) to `largeDiameter`, `midMyr`. | ||
| 27 | double midMyr = 750.0; ///< Retention of mid-sized craters, Myr. | ||
| 28 | double largeDiameter = 50000.0; ///< Above this diameter (m), `largeMyr`. | ||
| 29 | double largeMyr = 750.0; ///< Retention of large craters, Myr. | ||
| 30 | double scale = 1.0; ///< Multiplies every time. | ||
| 31 | |||
| 32 | /// The retention time in Myr of a crater `diameter` meters across. | ||
| 33 | double Myr(double diameter) const; | ||
| 34 | |||
| 35 | bool operator==(const RayRetention& other) const { | ||
| 36 | return smallDiameter == other.smallDiameter && smallMyr == other.smallMyr && | ||
| 37 | midDiameter == other.midDiameter && midMyr == other.midMyr && | ||
| 38 | largeDiameter == other.largeDiameter && largeMyr == other.largeMyr && | ||
| 39 | scale == other.scale; | ||
| 40 | } | ||
| 41 | bool operator!=(const RayRetention& other) const { | ||
| 42 | return !(*this == other); | ||
| 43 | } | ||
| 44 | }; | ||
| 45 | |||
| 46 | /// Checks ray retention settings. | ||
| 47 | /// @throws std::invalid_argument naming the first field out of its range, or for diameters that | ||
| 48 | /// do not increase. | ||
| 49 | void ValidateRayRetention(const RayRetention& retention); | ||
| 50 | |||
| 51 | /// How oblique impacts shape a crater's rays. Each crater gets an impact angle from the | ||
| 52 | /// horizontal with P(< theta) = sin^2 theta and a downrange direction, `headingDegrees` or uniform | ||
| 53 | /// at random. | ||
| 54 | 1043 | struct ObliqueImpacts { | |
| 55 | bool enabled = true; ///< Whether impacts can be oblique; otherwise all vertical. | ||
| 56 | std::optional<double> headingDegrees; ///< Downrange, degrees counter-clockwise from east. | ||
| 57 | double asymmetricDegrees = 45.0; ///< Below this angle rays are longer downrange. | ||
| 58 | double forbiddenDegrees = 25.0; ///< Below this angle rays near uprange are dropped. | ||
| 59 | double butterflyDegrees = 10.0; ///< Below this angle rays near downrange are dropped too. | ||
| 60 | /// Downrange over uprange ejection speed, at least 1. | ||
| 61 | ValueDistribution downrangeSpeedRatio{ValueDistribution::Uniform(1.2, 1.4)}; | ||
| 62 | double zoneHalfWidthDegrees = 45.0; ///< Half width of a forbidden zone, in [0, 180]. | ||
| 63 | |||
| 64 | /// The most a ray's length can be multiplied by: (1 + a)^2 / (1 + a^2 / 2) for the highest | ||
| 65 | /// speed ratio's asymmetry a; 1 when disabled. | ||
| 66 | double MaxStretch() const; | ||
| 67 | |||
| 68 | bool operator==(const ObliqueImpacts& other) const { | ||
| 69 | return enabled == other.enabled && headingDegrees == other.headingDegrees && | ||
| 70 | asymmetricDegrees == other.asymmetricDegrees && | ||
| 71 | forbiddenDegrees == other.forbiddenDegrees && | ||
| 72 | butterflyDegrees == other.butterflyDegrees && | ||
| 73 | downrangeSpeedRatio == other.downrangeSpeedRatio && | ||
| 74 | zoneHalfWidthDegrees == other.zoneHalfWidthDegrees; | ||
| 75 | } | ||
| 76 | bool operator!=(const ObliqueImpacts& other) const { | ||
| 77 | return !(*this == other); | ||
| 78 | } | ||
| 79 | }; | ||
| 80 | |||
| 81 | /// The impact that formed a crater, as `ObliqueImpacts` draws it. | ||
| 82 | struct CraterImpact { | ||
| 83 | double angleDegrees = 90.0; ///< From the horizontal. | ||
| 84 | double heading = 0.0; ///< Downrange, radians counter-clockwise from east. | ||
| 85 | double speedRatio = 1.0; ///< Downrange over uprange ejection speed. | ||
| 86 | }; | ||
| 87 | |||
| 88 | /// Checks oblique impact settings. | ||
| 89 | /// @throws std::invalid_argument naming the first field out of its range, or for an invalid speed | ||
| 90 | /// ratio distribution or one that can be below 1, or angles out of order (butterfly <= forbidden | ||
| 91 | /// <= asymmetric). | ||
| 92 | void ValidateObliqueImpacts(const ObliqueImpacts& oblique); | ||
| 93 | |||
| 94 | /// The rays of a crater: narrow streaks of immature material running out from the rim, | ||
| 95 | /// after Elliott et al. (2018), at uniform azimuths, fading linearly to their ends and broken by | ||
| 96 | /// value noise. | ||
| 97 | struct CraterRays { | ||
| 98 | bool enabled = true; ///< Whether craters have rays. | ||
| 99 | /// Rays per crater, 0 to 64. | ||
| 100 | ValueDistribution count{ValueDistribution::Normal(10.7, 3.1).Clamped(6.0, 20.0)}; | ||
| 101 | double lengthCoefficient = 6.59; ///< Coefficient of `ElliottMedianRayLength`. | ||
| 102 | double lengthExponent = 1.27; ///< Exponent of `ElliottMedianRayLength`. | ||
| 103 | /// Natural log of a ray's length over the median. | ||
| 104 | ValueDistribution lengthSpread{ValueDistribution::Uniform(-0.356, 0.468)}; | ||
| 105 | /// Angular width 2 radii from the center, in (0, 180) degrees; the width there holds beyond. | ||
| 106 | ValueDistribution widthDegrees{ValueDistribution::Normal(22.0, 8.3).Clamped(5.4, 38.6)}; | ||
| 107 | double excess = 0.048; ///< Maturity excess at the rim, in OMAT; >= 0. | ||
| 108 | double patchiness = 0.5; ///< Most of the excess the noise takes away, in [0, 1]. | ||
| 109 | double patchRadii = 0.5; ///< Noise wavelength, in crater radii; positive. | ||
| 110 | ObliqueImpacts oblique{}; ///< How oblique impacts shape the rays. | ||
| 111 | /// Takes the rays' number, directions and widths from this layout (`RayDirections`) in place | ||
| 112 | /// of `count` and `widthDegrees`, so they lie over secondaries with the same layout; unset | ||
| 113 | /// draws them per crater as before. | ||
| 114 | std::optional<RayLayout> layout; | ||
| 115 | |||
| 116 | /// The median ray length from the center, in meters, of a crater `diameter` meters across. | ||
| 117 | double MedianLength(double diameter) const; | ||
| 118 | |||
| 119 | bool operator==(const CraterRays& other) const { | ||
| 120 | return enabled == other.enabled && count == other.count && | ||
| 121 | lengthCoefficient == other.lengthCoefficient && | ||
| 122 | lengthExponent == other.lengthExponent && lengthSpread == other.lengthSpread && | ||
| 123 | widthDegrees == other.widthDegrees && excess == other.excess && | ||
| 124 | patchiness == other.patchiness && patchRadii == other.patchRadii && | ||
| 125 | oblique == other.oblique && layout == other.layout; | ||
| 126 | } | ||
| 127 | bool operator!=(const CraterRays& other) const { | ||
| 128 | return !(*this == other); | ||
| 129 | } | ||
| 130 | }; | ||
| 131 | |||
| 132 | /// Checks ray settings. | ||
| 133 | /// @throws std::invalid_argument naming the first field out of its range, or for invalid | ||
| 134 | /// distributions, a count that can be below 0 or above 64, widths outside (0, 180) degrees, or an | ||
| 135 | /// invalid oblique impact or layout. | ||
| 136 | void ValidateCraterRays(const CraterRays& rays); | ||
| 137 | |||
| 138 | /// The texture of fresh craters' bright material, keyed to each crater and off by default: radial | ||
| 139 | /// streaks breaking ejecta, rays, interiors and the bright proximal reflectance zone into | ||
| 140 | /// filaments, a lobed ejecta edge, and walls brighter than floors. | ||
| 141 | 2 | struct CraterAlbedoTexture { | |
| 142 | /// Share of the excess the radial streaks take away between filaments, in [0, 1]; 0 for none. | ||
| 143 | double streaks = 0.0; | ||
| 144 | double streakWidthDegrees = 3.0; ///< Typical width of a filament around the crater; positive. | ||
| 145 | double streakLengthRadii = 1.5; ///< Typical length of a filament outward, in radii; positive. | ||
| 146 | /// How far beyond the rim the ejecta stay continuous before breaking into filaments, in radii; | ||
| 147 | /// the streaks ramp in over that distance, and 0 streaks them from the rim. | ||
| 148 | double continuousRadii = 0.0; | ||
| 149 | /// How far the ejecta's edge wanders in and out, as a share of its reach, in [0, 0.9]; 0 keeps | ||
| 150 | /// it circular. | ||
| 151 | double lobes = 0.0; | ||
| 152 | int lobeCount = 8; ///< Typical number of lobes around a crater, 1 to 64. | ||
| 153 | double floorShare = 1.0; ///< Interior excess on the floor over that at the rim, in [0, 1]. | ||
| 154 | std::uint32_t seed = 0; ///< Varies every crater's texture. | ||
| 155 | |||
| 156 | bool operator==(const CraterAlbedoTexture& other) const { | ||
| 157 | return streaks == other.streaks && streakWidthDegrees == other.streakWidthDegrees && | ||
| 158 | streakLengthRadii == other.streakLengthRadii && | ||
| 159 | continuousRadii == other.continuousRadii && lobes == other.lobes && | ||
| 160 | lobeCount == other.lobeCount && floorShare == other.floorShare && seed == other.seed; | ||
| 161 | } | ||
| 162 | bool operator!=(const CraterAlbedoTexture& other) const { | ||
| 163 | return !(*this == other); | ||
| 164 | } | ||
| 165 | }; | ||
| 166 | |||
| 167 | /// Checks crater albedo texture settings. | ||
| 168 | /// @throws std::invalid_argument naming the first field out of its range. | ||
| 169 | void ValidateCraterAlbedoTexture(const CraterAlbedoTexture& texture); | ||
| 170 | |||
| 171 | /// One reflectance zone around new small craters: a share of craters has it, it changes the | ||
| 172 | /// reflectance relative to the pre-impact surface by `change`, and it reaches | ||
| 173 | /// `coefficient` D^`exponent` meters from the center times `scale`, both drawn per crater, with | ||
| 174 | /// a ragged edge of fingers pulled in by up to `raggedness` of the reach, lasting `retentionMyr`. | ||
| 175 | struct ReflectanceZone { | ||
| 176 | double share = 1.0; ///< Share of craters with the zone, in [0, 1]. | ||
| 177 | ValueDistribution change{}; ///< Relative reflectance change, above -1. | ||
| 178 | double coefficient = 1.0; ///< Reach law coefficient, m; positive. | ||
| 179 | double exponent = 1.0; ///< Reach law exponent; positive. | ||
| 180 | ValueDistribution scale{}; ///< Reach multiplier; positive and bounded. | ||
| 181 | double raggedness = 0.0; ///< Reach fingers pull in, in [0, 1). | ||
| 182 | double fingerWidthDegrees = 10.0; ///< Typical finger width; positive. | ||
| 183 | double feather = 0.3; ///< Share of the reach fading out, in (0, 1]. | ||
| 184 | /// How long the zone lasts (Myr), fading like the bright material; unset lasts as long as the | ||
| 185 | /// bright material, and a zone outlasting it ends with it. | ||
| 186 | std::optional<double> retentionMyr; | ||
| 187 | |||
| 188 | bool operator==(const ReflectanceZone& other) const { | ||
| 189 | return share == other.share && change == other.change && coefficient == other.coefficient && | ||
| 190 | exponent == other.exponent && scale == other.scale && | ||
| 191 | raggedness == other.raggedness && fingerWidthDegrees == other.fingerWidthDegrees && | ||
| 192 | feather == other.feather && retentionMyr == other.retentionMyr; | ||
| 193 | } | ||
| 194 | bool operator!=(const ReflectanceZone& other) const { | ||
| 195 | return !(*this == other); | ||
| 196 | } | ||
| 197 | }; | ||
| 198 | |||
| 199 | /// Checks a reflectance zone. | ||
| 200 | /// @throws std::invalid_argument naming the first field out of its range, or for an invalid change | ||
| 201 | /// that can reach -1 or a scale that can be non-positive or unbounded. | ||
| 202 | void ValidateReflectanceZone(const ReflectanceZone& zone); | ||
| 203 | |||
| 204 | /// Topographic shadows in the distal reflectance zones (Speyerer et al. 2016): ground below a jet | ||
| 205 | /// from the rim that drops no faster than `jetAngleDegrees` fades the zones; illustrative values. | ||
| 206 | 6 | struct ZoneShadows { | |
| 207 | bool enabled = false; ///< Whether the distal zones have shadows; needs the ground. | ||
| 208 | double jetAngleDegrees = 3.0; ///< Steepest descent of the jet, in (0, 90) degrees. | ||
| 209 | double depth = 0.5; ///< Depth below the jet of full shadow (m); positive. | ||
| 210 | int azimuths = 720; ///< Rays around a crater, 8 to 8192. | ||
| 211 | int radialSamples = 400; ///< Samples along a ray, 8 to 8192. | ||
| 212 | |||
| 213 | bool operator==(const ZoneShadows& other) const { | ||
| 214 | return enabled == other.enabled && jetAngleDegrees == other.jetAngleDegrees && | ||
| 215 | depth == other.depth && azimuths == other.azimuths && | ||
| 216 | radialSamples == other.radialSamples; | ||
| 217 | } | ||
| 218 | bool operator!=(const ZoneShadows& other) const { | ||
| 219 | return !(*this == other); | ||
| 220 | } | ||
| 221 | }; | ||
| 222 | |||
| 223 | /// The four reflectance zones around new small craters in LROC temporal pairs (Robinson et al. | ||
| 224 | /// 2015; Speyerer et al. 2016), off by default: proximal high and low, distal high and low, inner | ||
| 225 | /// zones covering outer ones. | ||
| 226 | struct CraterReflectanceZones { | ||
| 227 | bool enabled = false; ///< Whether craters get the zones. | ||
| 228 | double maxDiameter = 50.0; ///< Largest crater with zones (m); the fits stop near 43 m. | ||
| 229 | double matureDepth = 1.0; ///< Depth of mature regolith (m); not negative. | ||
| 230 | double excavationRatio = 0.1; ///< Excavation depth over diameter; positive. | ||
| 231 | /// PHRZ: +12% +/- 9% to a median 1.5 D (mean 2.1 D) from the center. | ||
| 232 | ReflectanceZone proximalHigh{1.0, | ||
| 233 | {ValueDistribution::Normal(0.12, 0.09).Clamped(0.01, 0.5)}, | ||
| 234 | 1.5, | ||
| 235 | 1.0, | ||
| 236 | {ValueDistribution::LogNormal(1.0, 0.82).Clamped(0.4, 5.0)}, | ||
| 237 | 0.3, | ||
| 238 | 25.0, | ||
| 239 | 0.3, | ||
| 240 | {}}; | ||
| 241 | /// PLRZ: -9% +/- 4%, in nearly all craters, to a median 2.9 D (mean 3.2 D); lasting as long as | ||
| 242 | /// the top centimeters is an inference from Robinson et al.'s (2015) discussion. | ||
| 243 | ReflectanceZone proximalLow{1.0, | ||
| 244 | {ValueDistribution::Normal(-0.09, 0.04).Clamped(-0.2, -0.01)}, | ||
| 245 | 2.9, | ||
| 246 | 1.0, | ||
| 247 | {ValueDistribution::LogNormal(1.0, 0.44).Clamped(0.5, 3.0)}, | ||
| 248 | 0.3, | ||
| 249 | 20.0, | ||
| 250 | 0.3, | ||
| 251 | 0.081}; | ||
| 252 | /// DHRZ: +1% to +4% in 24% of craters, to 0.52 D^2.5 m. | ||
| 253 | ReflectanceZone distalHigh{0.24, | ||
| 254 | {ValueDistribution::Uniform(0.01, 0.04)}, | ||
| 255 | 0.52, | ||
| 256 | 2.5, | ||
| 257 | {ValueDistribution::Constant(1.0)}, | ||
| 258 | 0.5, | ||
| 259 | 8.0, | ||
| 260 | 0.4, | ||
| 261 | 0.081}; | ||
| 262 | /// DLRZ: -2% to -6% in 84% of craters, ray-like, to 5.03 D^2 m. | ||
| 263 | ReflectanceZone distalLow{0.84, | ||
| 264 | {ValueDistribution::Uniform(-0.06, -0.02)}, | ||
| 265 | 5.03, | ||
| 266 | 2.0, | ||
| 267 | {ValueDistribution::Constant(1.0)}, | ||
| 268 | 0.6, | ||
| 269 | 8.0, | ||
| 270 | 0.6, | ||
| 271 | 0.081}; | ||
| 272 | ZoneShadows shadows{}; ///< Shadows of rises in the distal zones; off by default. | ||
| 273 | std::uint32_t seed = 0; ///< Varies every crater's zones. | ||
| 274 | |||
| 275 | /// The farthest any zone reaches from the center of a crater `diameter` meters across. | ||
| 276 | double MaxReach(double diameter) const; | ||
| 277 | |||
| 278 | /// The four zones from the innermost: proximal high and low, then distal high and low. | ||
| 279 | 8835 | std::array<const ReflectanceZone*, 4> All() const { | |
| 280 | 8835 | return {&proximalHigh, &proximalLow, &distalHigh, &distalLow}; | |
| 281 | } | ||
| 282 | |||
| 283 | bool operator==(const CraterReflectanceZones& other) const { | ||
| 284 | return enabled == other.enabled && maxDiameter == other.maxDiameter && | ||
| 285 | matureDepth == other.matureDepth && excavationRatio == other.excavationRatio && | ||
| 286 | proximalHigh == other.proximalHigh && proximalLow == other.proximalLow && | ||
| 287 | distalHigh == other.distalHigh && distalLow == other.distalLow && | ||
| 288 | shadows == other.shadows && seed == other.seed; | ||
| 289 | } | ||
| 290 | bool operator!=(const CraterReflectanceZones& other) const { | ||
| 291 | return !(*this == other); | ||
| 292 | } | ||
| 293 | }; | ||
| 294 | |||
| 295 | /// Checks crater reflectance zones. | ||
| 296 | /// @throws std::invalid_argument naming the first field out of its range, or for an invalid zone. | ||
| 297 | void ValidateCraterReflectanceZones(const CraterReflectanceZones& zones); | ||
| 298 | |||
| 299 | /// The bright material of fresh craters, in optical maturity (OMAT) over the background's: | ||
| 300 | /// an interior excess, ejecta falling as a power of distance, and rays. Excesses fade with age | ||
| 301 | /// over the retention time, add over overlapping craters and are capped; the albedo then moves | ||
| 302 | /// with maturity (`ReflectanceAtMaturity`). The defaults are Tycho's. | ||
| 303 | 1343 | struct CraterAlbedoOptions { | |
| 304 | std::uint32_t seed = 0; ///< Seed of the per-crater draws. | ||
| 305 | /// The craters with bright material at all. | ||
| 306 | CraterSelection selection{}; | ||
| 307 | double share = 1.0; ///< Share of selected craters with bright material. | ||
| 308 | |||
| 309 | double backgroundMaturity = 0.202; ///< OMAT of the background; positive. | ||
| 310 | double maxMaturity = 0.42; ///< Cap on OMAT; >= `backgroundMaturity`. | ||
| 311 | double interiorExcess = 0.132; ///< Excess inside the rim. | ||
| 312 | double ejectaExcess = 0.076; ///< Excess of the ejecta at the rim. | ||
| 313 | double ejectaExponent = 3.0; ///< The ejecta excess falls as (r / R)^-this. | ||
| 314 | double ejectaReachRadii = 3.0; ///< Where the ejecta excess reaches 0, in radii; > 1. | ||
| 315 | CraterRays rays{}; ///< The rays. | ||
| 316 | CraterAlbedoTexture texture{}; ///< Filaments, lobes and wall brightness; off by default. | ||
| 317 | CraterReflectanceZones zones{}; ///< Zones around new small craters; off by default. | ||
| 318 | RayRetention retention{}; ///< Retention time T by diameter. | ||
| 319 | double fadeExponent = 1.0; ///< Excesses fade as max(0, 1 - t / T)^this. | ||
| 320 | /// Reflectance of the optical maturity origin (`ReflectanceAtMaturity`). | ||
| 321 | double originReflectance = kOpticalMaturityOriginReflectance; | ||
| 322 | ResolutionFade fade{}; ///< How craters too small to resolve fade out. | ||
| 323 | |||
| 324 | bool operator==(const CraterAlbedoOptions& other) const { | ||
| 325 | return seed == other.seed && selection == other.selection && share == other.share && | ||
| 326 | backgroundMaturity == other.backgroundMaturity && maxMaturity == other.maxMaturity && | ||
| 327 | interiorExcess == other.interiorExcess && ejectaExcess == other.ejectaExcess && | ||
| 328 | ejectaExponent == other.ejectaExponent && | ||
| 329 | ejectaReachRadii == other.ejectaReachRadii && rays == other.rays && | ||
| 330 | texture == other.texture && zones == other.zones && retention == other.retention && | ||
| 331 | fadeExponent == other.fadeExponent && originReflectance == other.originReflectance && | ||
| 332 | fade == other.fade; | ||
| 333 | } | ||
| 334 | bool operator!=(const CraterAlbedoOptions& other) const { | ||
| 335 | return !(*this == other); | ||
| 336 | } | ||
| 337 | }; | ||
| 338 | |||
| 339 | /// Checks crater albedo options. | ||
| 340 | /// @throws std::invalid_argument naming the first field out of its range, or for invalid zones, | ||
| 341 | /// rays, retention, fade or selection, or a maturity cap below the background. | ||
| 342 | void ValidateCraterAlbedoOptions(const CraterAlbedoOptions& options); | ||
| 343 | |||
| 344 | } // namespace terraingen | ||
| 345 |