hmz2bio

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 10 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hmz2bio

hmz2bio is the climate step of the campaign-map pipeline. It reads an hmz2ter terrain file and gives every land hex a climate, a biome, and a surface, completing the terrain model's three layers (landform, surface, biome). It writes the result as JSON, with an optional PNG preview.

The model is deliberately simple and explainable: mean annual temperature from latitude and elevation, annual precipitation from latitude and the moisture the prevailing wind brings over the relief, and a biome from temperature and precipitation using Köppen-style thresholds. It uses no external climate data: the world is fictional and the map is rescaled, so real rainfall records don't apply.

Usage

go run ./cmd/hmz2bio [flags] <terrain.json>

Flags:

  • -top-lat <deg> is the latitude of the map's top edge, north positive. The default is 27.
  • -bottom-lat <deg> is the latitude of the map's bottom edge. The default is 7.
  • -wind-rays <n> is the number of rays traced for each wind (see Moisture and lift). The default is 5; at least 1.
  • -wind-spread <deg> is the largest offset of a wind's rays from its bearing, in degrees. The default is 20; at least 0.
  • -rivers <file> is an hmz2riv JSON file, used only to draw rivers on the preview. Optional; its grid must match.
  • -output <file> is the JSON file to write. Required.
  • -preview <file> is a PNG preview to write. Optional.
  • -preview-scale <n> sets how many raster pixels, in each direction, one preview pixel covers. The default is 8.
  • -version prints the version.

The command prints the time taken by each phase and the number of land hexes with each biome and surface. A full run on the Panama terrain takes under a second.

The terrain file is read with hmz2ter's own types, and the grid geometry comes from the hmz2ele package, rebuilt from the heightmap dimensions and apothem recorded in the terrain file.

Units

Elevations are real meters, as in the source; the campaign map scaled distances by about 3.4, but not heights. Temperature therefore uses real meters, which is right for a lapse rate. Distances along the wind are campaign kilometers (a hex is 10 km): the air crosses the campaign world, which is the size the players see. Orographic effects depend only on the height the air gains, which is the same in both worlds, so the gentler campaign slopes don't matter.

Placement and wind

The map spans 27°N at the top to 7°N at the bottom, about 20° for its 2,220 campaign km. A hex's latitude is interpolated linearly from the top edge (y = 0) to the bottom edge (y = the raster height) at the hex center's y, and rounded to 0.01°; everything else uses the rounded latitude.

The prevailing wind follows latitude bands:

Latitude Wind
up to 27° trade winds from 60° (east-north-east)
27° to 33° a linear blend of the two
33° and more westerlies from 255° (west-south-west)

South of the equator the bearings are mirrored north–south (south-east trades, west-north-west westerlies). With the Panama placement the whole map is in the trades: the Caribbean (east) side is windward and the Pacific (west) side is in the rain shadow of the cordillera.

Temperature

  • Mean annual temperature is the sea-level temperature for the latitude, from the table below, less 6.5 °C per 1,000 m of the hex's median elevation.
  • Annual range (warmest month minus coldest) is 1 °C + 0.33 °C per degree of latitude, split evenly about the mean. This is the only use of seasons.
Latitude 0° 10° 15° 20° 25° 30° 35° 40° 45° 50° 55° 60° 70° 80° 90°
Sea level, °C 27 27 26.5 25 22.5 20 17 14.5 12 8 4 0 −8 −16 −22

Tables are interpolated linearly in latitude, by distance from the equator, and held flat beyond their ends.

Precipitation

Annual precipitation is:

P = windward × (share + (1 − share) × moisture × (1 + 1.5 × lift / 1000))
  • windward is the precipitation on a windward coast at sea level for the latitude (table below).
  • share is the convective share: the part that falls whatever the wind does, standing in for the tropical wet season's storms, so leeward coasts aren't deserts.
  • moisture is the share of the sea air's moisture that the wind still carries when it reaches the hex.
  • lift is how far, in meters, the wind climbs onto the hex; windward slopes get more rain.
Latitude 0° 5° 10° 15° 20° 25° 30° 35° 40° 45° 50° 55° 60° 70° 80° 90°
Windward, mm 3,100 3,300 2,700 2,000 1,400 1,000 850 1,000 1,250 1,400 1,400 1,250 1,000 500 250 150
Latitude 0° 10° 20° 30°
Convective share 0.50 0.45 0.30 0.20
Moisture and lift

Each wind is traced along a fan of rays rather than a single line. With n rays (-wind-rays) and a spread of s degrees (-wind-spread), ray i (0-based) follows the wind's bearing plus the offset:

offset_i = −s + 2·s·i / (n − 1)

A single ray (n = 1) has offset 0, the wind's own bearing. The defaults, 5 rays and 20°, give the bearing −20°, −10°, 0°, +10°, and +20°: from 40° to 80° for the 60° trades.

A single ray made the map striped: every hex downwind of the same peak or gap, along the same line, inherited the same moisture, and the biome thresholds turned those lines into straight bands of color parallel to the wind. Averaging over a fan spreads a peak's rain shadow the way real wind does, so the bands become gradients; broad rain shadows behind whole ranges remain.

For each land hex, each wind that has weight at its latitude, and each of that wind's rays, along the ray's bearing:

  1. Trace upwind. From the hex center, step toward the ray's bearing, 5 campaign km (48 px at apothem 48) at a time, for at most 1,000 km. At each step, find the pixel containing the point and take the hex containing that pixel's center, as hmz2ter assigns pixels to hexes. The point's coordinates are rounded to 6 decimals before taking floor(x) and floor(y), so a point exactly on a pixel edge belongs to the pixel to its right or below, whatever the floating-point error. Both rules matter: a 5 km step is exactly one apothem, so on the trades' central 60° ray every other step lands exactly on a hex edge (which a pixel center never does), and every step's y is a whole number of pixels. Stop at the first point that is off the raster, in a hex not in the grid, or in salt water, cliffs, or badlands: the wind picks up moisture there, because the game world has sea beyond the border cuts and the map's edges.
  2. Build the profile: 0 m for the sea, then the median elevation of each hex stepped through, farthest first, then the hex's own median elevation. Lakes count at their surface elevation. A step can land in the same hex as the step before, or in the hex itself; it still counts.
  3. Moisture starts at 1 and, for each step along the profile, is multiplied by exp(−5 / 800 − rise / 1500), where rise is the height gained since the previous point, in meters (0 when descending). So 800 km of lowland takes away 63% of the moisture, and so does a climb of 1,500 m. Air that has crossed a mountain range arrives dry: the rain shadow.
  4. Lift is the hex's elevation minus the lowest point among the 6 profile points before it (30 km upwind), or 0 if none is lower. With fewer than 6 points before the hex, the sea's 0 m is among them.

A wind's moisture and lift are the means over its rays: the sums, in ray order (i from 0), divided by n. Where the trades and westerlies are blended, each wind's means are blended with the same weights. Moisture is rounded to 3 decimals and lift to the meter before computing precipitation.

Biomes

A land hex's biome comes from its rounded climate values (see Output), so it can be rederived from the JSON. The first rule that applies wins:

# Test Biome
1 warmest month below 0 °C clear (the surface is glacial-ice)
2 warmest month below 10 °C (the tree line) tundra if the warmest month at sea level for the latitude is also below 10 °C, else alpine
3 precipitation below half the aridity limit desert
4 precipitation below the aridity limit, mean at least 18 °C scrubland
5 precipitation below the aridity limit steppe
6 mean below 18 °C (montane), on hills, mountains, plateaus, or volcanic-highlands, sea-level coldest month at least 15 °C, lift at least 100 m, precipitation at least 1,000 mm cloud-forest
7 mean below 18 °C, sea-level coldest month at least 18 °C (the tropics) temperate-forest
8 mean at least 18 °C, precipitation at least 2,000 mm tropical-rainforest
9 mean at least 18 °C, precipitation at least 1,200 mm tropical-dry-forest
10 mean at least 18 °C savanna
11 mean below 4 °C boreal-forest
12 precipitation at least 2,000 mm temperate-rainforest
13 precipitation below 1.5 × the aridity limit grassland
14 otherwise temperate-forest
  • The aridity limit is Köppen's: 20 × T + 280 mm, where T is the mean annual temperature in °C.
  • The sea-level warmest and coldest months are the sea-level temperature for the hex's latitude ± half the annual range, with no lapse rate.
  • Tundra wins over alpine: tundra is cold from latitude, alpine from height. On the Panama placement there is no tundra; it needs about 60° of latitude.
  • Cloud forest is on the windward slopes of the tropical and subtropical mountains, where the rising air makes cloud; row 7 covers montane forest off those slopes (Central America's pine–oak forests).
  • Glacial ice needs a warmest month below 0 °C, about 4,100 m at 26°N, so the Panama map has none; Barú reaches 3,431 m.

Surfaces

Every land hex gets a surface:

  1. glacial-ice if the warmest month is below 0 °C, on any landform. Its biome is clear.
  2. Otherwise the hex is clear unless it can hold a wetland, which needs flats or plains and either:
    • hmz2ter's flat-surface flag with a median elevation of 60 m or less, which excludes the filled voids in the source (95 m and up on Panama); or
    • flats with the coast or river flag and a median elevation of 10 m or less: tidal flats and floodplains.
  3. A hex that can hold a wetland is:
    • salt-flats if its precipitation is below the aridity limit (coastal salt pans and inland playas);
    • mangroves if it has the coast flag and its coldest month is at least 15 °C;
    • bogs if its mean temperature is below 10 °C;
    • swamps (forested wetland) if its biome is a forest: boreal-forest, temperate-forest, temperate-rainforest, tropical-dry-forest, tropical-rainforest, or cloud-forest;
    • marshes otherwise.

The river flag adds no rain: 42% of land hexes have one, so a bonus would checkerboard the biomes, and a river carries water from elsewhere rather than making the hex's climate wetter. It only marks floodplain flats as able to hold a wetland.

Validation

After building, hmz2bio checks every hex against the terrain model's valid combinations (see the root README's "Terrain model" section) and exits with an error if any hex breaks them. In particular, an unset surface or biome on land is an error, clear is the biome if and only if the surface is glacial-ice, wetlands, mangroves, and salt flats are only on flats and plains, and mangroves need the coast flag. hmz2ter's flat-surface flag isn't one of the model's flags, but it is allowed on land here as the pipeline's hint; the final hex-map emitter drops it.

Results

On the Panama terrain (hmz2ter v0.1.0), 27°N to 7°N, with the default fan (5 rays, ±20°):

Biome Land hexes Share v0.1.0 (1 ray)
tropical-dry-forest 3,861 38.9% 3,869
scrubland 2,193 22.1% 2,152
savanna 1,524 15.4% 1,393
tropical-rainforest 1,298 13.1% 1,394
steppe 501 5.1% 458
desert 249 2.5% 330
temperate-forest 143 1.4% 156
cloud-forest 73 0.7% 95
grassland 53 0.5% 48
alpine 19 0.2% 19
Surface Land hexes v0.1.0 (1 ray)
clear 9,685 9,685
swamps 63 60
mangroves 62 61
salt-flats 62 56
marshes 42 52

No hex is glacial-ice, bogs, tundra, boreal-forest, or temperate-rainforest.

The south (7–15°N) is rainforest on the windward Caribbean slopes and the south-west coast, with dry forest in the Darién interior. The middle (15–21°N) is dry forest that turns to scrub and savanna in the rain shadows, which run diagonally down and to the left from the cordillera with the east-north-east trades. The north (23–27°N) is in the subtropical dry belt: a desert in the Chiriquí lowland behind Talamanca, steppe and montane forest on the highlands, cloud forest on their windward slopes, and alpine on the crest above about 2,600 m.

Compared with the single ray of v0.1.0, the fan removes the straight diagonal stripes of rainforest, dry forest, and savanna, most visibly in the Darién: the extremes soften (less rainforest and desert, more savanna and steppe), and cloud forest, which needs at least 100 m of lift, shrinks because lift is now averaged over rays that don't all climb the same slope. Temperatures don't depend on the wind, so alpine is unchanged. With -wind-rays 1, every hex is identical to v0.1.0's output.

Every count was cross-checked against an independent Python calculation, written from this README, with no mismatches.

Output

{
  "hmz2bio_version": "0.2.0",
  "terrain": { "file_name": "pandemokh-a48-terrain.json" },
  "hmz2ter_version": "0.1.0",
  "heightmap": { ... }, "grid": { ... }, "rivers": { ... }, "rules": { ... }, "method": { ... },
  "lakes": [ ... ], "volcanoes": [ ... ], "stats": { ... },
  "climate_rules": { "top_lat_deg": 27, "bottom_lat_deg": 7, "sea_level_temp_c": [ [0, 27], ... ], "lapse_rate_c_per_km": 6.5, ..., "wind_rays": 5, "wind_spread_deg": 20, ... },
  "climate_method": { "latitude": "...", "temperature": "...", "precipitation": "...", "biome": "...", "surface": "..." },
  "climate_stats": { "land_hexes": 9914, "biomes": { ... }, "surfaces": { ... } },
  "hexes": [
    { "col": 50, "row": 2, "landform": "hills", "surface": "clear", "biome": "savanna", "flags": [ "river" ], "center": 147,
      "pixels": 7982, "valid_pixels": 7982, "land_fraction": 1,
      "elevation": { "min": 102, "p5": 108, "median": 207, "p95": 449, "max": 593 }, "relief_m": 341,
      "climate": { "latitude_deg": 26.73, "temperature_c": 20.3, "warmest_c": 25.2, "coldest_c": 15.4,
                   "precipitation_mm": 1041, "moisture": 0.86, "lift_m": 207 } },
    ...
  ]
}

Every field of the hmz2ter file is carried through unchanged, including each hex's; hexes adds surface and biome on land and a climate object on land hexes only. climate_rules holds every setting and threshold above, including the fan's wind_rays and wind_spread_deg.

Climate values are rounded first to 6 decimals, which absorbs floating-point noise, and then half away from zero: latitude to 0.01°, temperatures to 0.1 °C, precipitation to 1 mm, moisture to 0.001, and lift to 1 m. The mean temperature, warmest, and coldest months are each rounded from the unrounded mean and range. Biomes and surfaces are chosen from the rounded values.

Preview

The preview is the hmz2ele preview with each hex refilled: land by its surface where it has one (mangroves bright teal-green, swamps teal, marshes aqua, bogs mauve, salt flats near-white, ice pale blue), and otherwise by its biome, from deep green (tropical rainforest) through olive (tropical dry forest), gold (savanna), tan (scrubland), straw (steppe), and sand (desert), with cloud forest misty blue-green, temperate forest mid-green, and alpine gray. Water, cliffs, and badlands are colored as in hmz2ter's preview, volcano hexes magenta, and rivers dark blue along hex edges.

License

MIT. See LICENSE.

Documentation

Index

Constants

View Source
const (
	GlacialIce hmz2ter.Surface = "glacial-ice"
	Marshes    hmz2ter.Surface = "marshes"
	Swamps     hmz2ter.Surface = "swamps"
	Bogs       hmz2ter.Surface = "bogs"
	Mangroves  hmz2ter.Surface = "mangroves"
	SaltFlats  hmz2ter.Surface = "salt-flats"
)

Surfaces beyond hmz2ter's clear.

View Source
const (
	Tundra              hmz2ter.Biome = "tundra"
	Alpine              hmz2ter.Biome = "alpine"
	Desert              hmz2ter.Biome = "desert"
	Scrubland           hmz2ter.Biome = "scrubland"
	Grassland           hmz2ter.Biome = "grassland"
	Steppe              hmz2ter.Biome = "steppe"
	Savanna             hmz2ter.Biome = "savanna"
	BorealForest        hmz2ter.Biome = "boreal-forest"
	TemperateForest     hmz2ter.Biome = "temperate-forest"
	TemperateRainforest hmz2ter.Biome = "temperate-rainforest"
	TropicalDryForest   hmz2ter.Biome = "tropical-dry-forest"
	TropicalRainforest  hmz2ter.Biome = "tropical-rainforest"
	CloudForest         hmz2ter.Biome = "cloud-forest"
)

Biomes beyond hmz2ter's clear.

View Source
const HexKm = 10

HexKm is a campaign hex's flat-to-flat height in campaign kilometers.

Variables

Surfaces and Biomes list every value in the terrain model, in order.

View Source
var Method = MethodInfo{
	Latitude:      "interpolated linearly from top_lat_deg at the raster's top edge to bottom_lat_deg at its bottom edge, at the hex center's y",
	Temperature:   "sea_level_temp_c at the latitude, less lapse_rate_c_per_km per km of median elevation; warmest and coldest months are the mean ± (annual_range_base_c + annual_range_per_deg_c × |latitude|) / 2",
	Precipitation: "windward_precip_mm × (convective_share + (1 − convective_share) × moisture × (1 + lift_gain_per_km × lift_m / 1000)); moisture starts at 1 over the sea (salt water, cliffs, badlands, or off the map) and each step_km upwind keeps exp(−step_km/rainout_km − rise/orographic_m); lift is the median elevation above the lowest point within lift_window_km upwind; each wind is traced along wind_rays bearings evenly spaced across ± wind_spread_deg of its bearing (one ray: the bearing itself), and moisture and lift are the means over the rays; the trades and westerlies are traced separately and blended by latitude; distances are campaign km, elevations real m",
	Biome:         "warmest month below ice → clear (glacial ice); below the tree line → tundra if the sea-level warmest month is also below it, else alpine; precipitation below arid_per_deg_mm × T + arid_base_mm → desert (under desert_share of it), scrubland (hot), or steppe; cooler than montane_below_c → cloud forest on hills, mountains, plateaus, and volcanic highlands where the sea-level coldest month is at least cloud_forest_coldest_min_c, lift at least cloud_forest_lift_m, and precipitation at least cloud_forest_min_mm, else temperate forest in the tropics (sea-level coldest month ≥ tropics_coldest_min_c); hot → tropical rainforest, tropical dry forest, or savanna by precipitation; otherwise boreal forest, temperate rainforest, grassland, or temperate forest",
	Surface:       "glacial ice with the biome; otherwise only flats and plains that are flat-surface with a median of at most flat_surface_max_m, or flats on a coast or river with a median of at most lowland_max_m, get a surface: salt flats if dry (below the aridity limit), mangroves on the coast if the coldest month is at least mangrove_coldest_min_c, bogs if cooler than bogs_below_c, swamps in a forest biome, marshes otherwise; the rest are clear",
}

Method is the model's description, as written to JSON.

Functions

func IsForest

func IsForest(b hmz2ter.Biome) bool

IsForest reports whether the biome is a forest.

func RenderPreview

func RenderPreview(g hmz2ele.Grid, hexes []HexJSON, rivers []hmz2riv.EdgeJSON, scale int) (*image.RGBA, error)

RenderPreview draws the hmz2ele preview, then fills each hex with its color (see hexColor), keeping the hex outlines. Rivers are drawn along hex edges.

func Validate

func Validate(hexes []HexJSON) error

Validate checks every hex against the terrain model's valid combinations and returns the problems found, or nil. Once the climate step has run, an unset surface or biome is an error.

The flat-surface flag is allowed on land although the model doesn't list it: it is hmz2ter's hint to this step, carried through for reference.

func Version

func Version() semver.Version

Types

type Climate

type Climate struct {
	// Latitude of the hex's center, in degrees, north positive.
	Latitude float64 `json:"latitude_deg"`
	// Temperature is the mean annual temperature, and Warmest and Coldest
	// the means of the warmest and coldest months, in °C.
	Temperature float64 `json:"temperature_c"`
	Warmest     float64 `json:"warmest_c"`
	Coldest     float64 `json:"coldest_c"`
	// Precipitation is the annual precipitation in mm.
	Precipitation float64 `json:"precipitation_mm"`
	// Moisture is the share of the sea air's moisture left when the
	// prevailing wind reaches the hex, and Lift the height in meters the
	// wind climbs onto the hex (see Rules).
	Moisture float64 `json:"moisture"`
	Lift     float64 `json:"lift_m"`
}

Climate is a land hex's climate. Values are rounded as written to JSON, and the biome and surface are chosen from the rounded values, so they can be checked from the output alone.

type Document

type Document struct {
	Hmz2bioVersion string      `json:"hmz2bio_version"`
	TerrainFile    TerrainInfo `json:"terrain"`
	hmz2ter.Terrain
	ClimateRules  Rules      `json:"climate_rules"`
	ClimateMethod MethodInfo `json:"climate_method"`
	ClimateStats  Stats      `json:"climate_stats"`
	Hexes         []HexJSON  `json:"hexes"`
}

Document is the climate output: every field of hmz2ter's terrain, plus the climate step's own. Hexes replaces the terrain's hexes with ones that carry their climate.

type HexJSON

type HexJSON struct {
	hmz2ter.HexJSON
	Climate *Climate `json:"climate,omitempty"`
}

HexJSON is one hex: hmz2ter's hex, with its surface and biome set, plus the climate of a land hex.

func Build

func Build(m *Map, r Rules) []HexJSON

Build gives every land hex its climate, biome, and surface. Other hexes are copied unchanged.

type Map

type Map struct {
	Grid  hmz2ele.Grid
	Hexes []hmz2ter.HexJSON
	// contains filtered or unexported fields
}

Map looks up hexes by column and row.

func NewMap

func NewMap(g hmz2ele.Grid, hexes []hmz2ter.HexJSON) *Map

NewMap indexes the hexes of the grid.

func (*Map) At

func (m *Map) At(x, y float64) *hmz2ter.HexJSON

At returns the hex of the pixel containing the raster point, or nil if the point is outside the raster or its hex isn't in the grid. A pixel belongs to the hex containing its center, as in hmz2ter; going through the pixel keeps points that fall exactly on a hex boundary (the trace often steps along one) from depending on floating-point noise.

func (*Map) Climate

func (m *Map) Climate(h *hmz2ter.HexJSON, r Rules) Climate

Climate returns a land hex's climate. Everything uses the latitude rounded as written to JSON.

func (*Map) Fan added in v0.2.0

func (m *Map) Fan(h *hmz2ter.HexJSON, from float64, r Rules) (moisture, lift float64)

Fan returns the moisture and lift a wind from the bearing brings to the hex: the means over the wind's rays (see Rules.WindOffsets), summed in ray order.

func (*Map) Profile

func (m *Map) Profile(h *hmz2ter.HexJSON, from float64, r Rules) []float64

Profile returns the elevations the wind crosses on its way to the hex, from a bearing (clockwise from north): 0 m for the sea it starts from, the elevation every StepKm upwind, farthest first, and the hex's own. The trace stops at the first sea, and after ReachKm.

type MethodInfo

type MethodInfo struct {
	Latitude      string `json:"latitude"`
	Temperature   string `json:"temperature"`
	Precipitation string `json:"precipitation"`
	Biome         string `json:"biome"`
	Surface       string `json:"surface"`
}

MethodInfo describes the parts of the model that Rules doesn't hold.

type Rules

type Rules struct {
	// TopLat and BottomLat are the latitudes of the raster's top and bottom
	// edges, in degrees, north positive. A hex's latitude is interpolated
	// from its center's y.
	TopLat    float64 `json:"top_lat_deg"`
	BottomLat float64 `json:"bottom_lat_deg"`

	// SeaLevelTemp is the mean annual temperature at sea level by latitude.
	// LapseRate cools it with the hex's median elevation.
	SeaLevelTemp Table   `json:"sea_level_temp_c"`
	LapseRate    float64 `json:"lapse_rate_c_per_km"`
	// The annual range, warmest month minus coldest, is RangeBase +
	// RangePerDeg × |latitude|, split evenly about the mean.
	RangeBase   float64 `json:"annual_range_base_c"`
	RangePerDeg float64 `json:"annual_range_per_deg_c"`

	// WindwardPrecip is the annual precipitation on a windward coast at
	// sea level, by latitude. ConvectiveShare is the part of it that falls
	// regardless of the wind (the tropical wet season's storms); the rest
	// depends on the moisture the wind brings.
	WindwardPrecip  Table `json:"windward_precip_mm"`
	ConvectiveShare Table `json:"convective_share"`

	// The prevailing wind blows from TradesFrom (a bearing, clockwise from
	// north) at latitudes up to TradesMaxLat and from WesterliesFrom beyond
	// WesterliesMinLat, blended linearly in between.
	TradesFrom       float64 `json:"trades_from_deg"`
	WesterliesFrom   float64 `json:"westerlies_from_deg"`
	TradesMaxLat     float64 `json:"trades_max_lat_deg"`
	WesterliesMinLat float64 `json:"westerlies_min_lat_deg"`
	// Each wind is traced along WindRays bearings, evenly spaced from
	// WindSpreadDeg on one side of its bearing to WindSpreadDeg on the other
	// (a single ray follows the bearing itself), and a hex's moisture and
	// lift are the means over the rays. A fan, rather than one ray, keeps a
	// single peak or gap upwind from striping the map along the wind.
	WindRays      int     `json:"wind_rays"`
	WindSpreadDeg float64 `json:"wind_spread_deg"`

	// Moisture: air leaves the sea saturated (1) and is traced upwind in
	// steps of StepKm, for at most ReachKm. Each step keeps
	// exp(−StepKm/RainoutKm − rise/OrographicM) of its moisture, where rise
	// is the height gained, so mountains wring the air dry and leave a rain
	// shadow behind them.
	StepKm      float64 `json:"step_km"`
	ReachKm     float64 `json:"reach_km"`
	RainoutKm   float64 `json:"rainout_km"`
	OrographicM float64 `json:"orographic_m"`
	// Lift is the hex's height above the lowest point within LiftWindowKm
	// upwind. Rain on the hex is multiplied by 1 + LiftGain × lift / 1000.
	LiftWindowKm float64 `json:"lift_window_km"`
	LiftGain     float64 `json:"lift_gain_per_km"`

	// A hex whose warmest month is below IceBelow is glacial ice, and below
	// TreeLineBelow is above the tree line: tundra if the warmest month
	// would be below TreeLineBelow at sea level at that latitude, and
	// alpine if not.
	IceBelow      float64 `json:"ice_warmest_below_c"`
	TreeLineBelow float64 `json:"tree_line_warmest_below_c"`

	// Aridity (Köppen): a hex is dry if its precipitation is below
	// AridPerDeg × T + AridBase, where T is its mean temperature, and a
	// desert below DesertShare of that. A dry hex at least HotMin is
	// scrubland, and steppe if cooler.
	AridPerDeg  float64 `json:"arid_per_deg_mm"`
	AridBase    float64 `json:"arid_base_mm"`
	DesertShare float64 `json:"desert_share"`
	HotMin      float64 `json:"hot_min_c"`

	// A humid hex cooler than MontaneBelow is montane. It is cloud forest
	// where the coldest month at sea level is at least
	// CloudForestColdestMin (the tropics and subtropics), on hills,
	// mountains, plateaus, or volcanic highlands, on a windward slope (lift
	// of at least CloudForestLift) with at least CloudForestMin. Otherwise,
	// in the tropics, where the coldest month at sea level is at least
	// TropicsColdestMin, it is temperate forest.
	MontaneBelow          float64 `json:"montane_below_c"`
	CloudForestColdestMin float64 `json:"cloud_forest_coldest_min_c"`
	CloudForestLift       float64 `json:"cloud_forest_lift_m"`
	CloudForestMin        float64 `json:"cloud_forest_min_mm"`
	TropicsColdestMin     float64 `json:"tropics_coldest_min_c"`
	// A humid hex at least HotMin, tropical or not, is tropical rainforest
	// with at least RainforestMin, tropical dry forest with at least
	// DryForestMin, and savanna with less.
	RainforestMin float64 `json:"rainforest_min_mm"`
	DryForestMin  float64 `json:"dry_forest_min_mm"`
	// A humid hex cooler than HotMin outside the tropics is boreal forest
	// below BorealBelow, temperate rainforest with at least RainforestMin,
	// grassland below GrasslandAridity × the aridity limit, and temperate
	// forest otherwise.
	BorealBelow      float64 `json:"boreal_below_c"`
	GrasslandAridity float64 `json:"grassland_aridity"`

	// Wetland surfaces (wetlands, mangroves, and salt flats) go only on
	// flats and plains that hmz2ter marked flat-surface with a median
	// elevation of at most FlatSurfaceMax, or on flats with the coast or
	// river flag and a median of at most LowlandMax.
	FlatSurfaceMax int `json:"flat_surface_max_m"`
	LowlandMax     int `json:"lowland_max_m"`
	// Such a hex is salt flats if it is dry (see AridBase), mangroves on
	// the coast if its coldest month is at least MangroveColdestMin, bogs
	// below BogsBelow, swamps in a forest biome, and marshes otherwise.
	MangroveColdestMin float64 `json:"mangrove_coldest_min_c"`
	BogsBelow          float64 `json:"bogs_below_c"`
}

Rules holds the climate model's settings and the thresholds that choose biomes and surfaces. Temperatures are in °C and precipitation in mm per year. Elevations are real meters, as in the source. Distances along the wind are campaign kilometers: the air crosses the campaign world, which is about 3.4 times the real one, while lift depends only on height gained.

func DefaultRules

func DefaultRules() Rules

DefaultRules returns the campaign's rules.

func (Rules) Arid

func (r Rules) Arid(t float64) float64

Arid returns the precipitation below which a hex of mean temperature t is dry.

func (Rules) Biome

func (r Rules) Biome(c Climate, landform hmz2ter.Landform) hmz2ter.Biome

Biome returns a land hex's biome, or clear if it is glacial ice.

func (Rules) Latitude

func (r Rules) Latitude(y float64, height int) float64

Latitude returns the latitude at raster row y of a raster that is height pixels tall.

func (Rules) Moisture

func (r Rules) Moisture(profile []float64) (moisture, lift float64)

Moisture returns the moisture left at the end of the profile, and the lift onto its last point.

func (Rules) Surface

func (r Rules) Surface(c Climate, biome hmz2ter.Biome, h *hmz2ter.HexJSON) hmz2ter.Surface

Surface returns a land hex's surface, given its climate and biome.

func (Rules) Validate

func (r Rules) Validate() error

Validate reports settings the model can't use.

func (Rules) Wet

func (r Rules) Wet(h *hmz2ter.HexJSON) bool

Wet reports whether a land hex can hold a wetland, mangrove, or salt-flat surface: flats or plains marked flat-surface, low enough to be more than a filled void in the source, or low flats on a coast or river.

func (Rules) Wind

func (r Rules) Wind(lat float64) (trades, westerlies, weight float64)

Wind returns the bearings the wind blows from at the latitude, as trades and westerlies, and the westerlies' weight, from 0 to 1.

func (Rules) WindOffsets added in v0.2.0

func (r Rules) WindOffsets() []float64

WindOffsets returns the offsets, in degrees, of a wind's rays from its bearing: WindRays values evenly spaced from −WindSpreadDeg to +WindSpreadDeg, or just 0 for a single ray.

type Stats

type Stats struct {
	LandHexes int                     `json:"land_hexes"`
	Biomes    map[hmz2ter.Biome]int   `json:"biomes"`
	Surfaces  map[hmz2ter.Surface]int `json:"surfaces"`
}

Stats counts land hexes by biome and surface.

func Summarize

func Summarize(hexes []HexJSON) Stats

Summarize counts the land hexes.

type Table

type Table [][2]float64

Table is a piecewise-linear function of latitude: each entry is [degrees from the equator, value], in increasing latitude. Values are interpolated between entries and held flat beyond the ends.

func (Table) At

func (t Table) At(lat float64) float64

At returns the table's value at the latitude, north or south.

type TerrainInfo

type TerrainInfo struct {
	FileName string `json:"file_name"`
}

TerrainInfo identifies the hmz2ter file the climate was built from.

Directories

Path Synopsis
cmd
hmz2bio command
Command hmz2bio gives every land hex of an hmz2ter terrain file a climate, a biome, and a surface, and writes the result as JSON, with an optional PNG preview.
Command hmz2bio gives every land hex of an hmz2ter terrain file a climate, a biome, and a surface, and writes the result as JSON, with an optional PNG preview.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL