Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Technical temperature !science!  (Read 2184 times)

PatrikLundell

  • Bay Watcher
    • View Profile
Technical temperature !science!
« on: July 10, 2018, 06:42:11 am »

This thread is about the technical details of how and when temperature values appear in a fortress, but has little immediate practical use for a player.

I've made quite a few one year measurements of fortress temperature changes and their timing in embarks on worlds of different sizes and with different poles (South, Both, and None). Since I've used Lua scripts for this, any "code" notation is using Lua syntax. My conclusions are as per the below:

Freezing point:
  Water turns to ice when the temperature changes from 10001 to 10000, and thaws on a change from 10000 to 10001 (it has been suggested the transition was between 0 and -1).
 
Max Embark Temperature: Approximately 10000 + 3/4 * World Tile Temperature
  Detailed Max Embark Temperature:
    if temperature >= 0 then
      max_temperature = 10000 + math.floor (temperature / 4) * 3 + math.max (0, temperature % 4 - 1)
     
    else
      max_temperature = 10000 - math.floor (math.abs (temperature) / 4) * 3 - math.max (0, math.abs (temperature) % 4 - 1)
    end
   
Temperature Variation (i.e. how much lower the min temperature is compared to the max temperature):
  Dependent on Latitude, number of Poles, and world size.
  Unsurprisingly, worlds without poles do not have any seasonal temperature variation. 
  The variation is approximately linear from pole (0) to mid latitude (max) and between mid latitude and the equator (0).
  The lowest temperature is reached during mid winter and the highest during mid summer.
  The max variation is dependent on a Divisor for the mid latitude world tile, and the max variation is
  calculated as:
    max_variation = math.ceil (Divisor * 3 / 4).
  It can be noted that the minimum temperature of an embark is held for only 10 ticks for many embarks (all embarks whose
  divisor isn't evenly divisible by 4). This can result in flash freeze/thaws you might not even notice.
  So far no formula for determining the max Divisor for different world configurations has been found, so a table is used.
 
  The max variation for a world with at least one pole of a given size:
  - 17: 43 (Divisor 57)
  - 33: 46 (Divisor 61)
  - 65: 48 (Divisor 63)
  - 129: 48 (Divisor 64)
  - 257: 48 (Divisor 64)
 
  The temperature variation of a given latitude:
    The Divisor mentioned above is also the primary driver for temperature variation. Each latitude has a Divisor,
    and this divisor controls what the temperature variation is at that latitude, as well as when the temperature
    changes (although the algorithm for that isn't wholly straight forward or intuitive).
    The Divisor for a latitude is dependent on the Divisor of the mid latitude world tile and the number of world
    tiles from it to the pole/equator. I've been unable to find a formula that works for all sizes, resulting in 3
    formulae rather than one.
    If the world size is 17 the formula is:
      Divisor = math.floor (Max_Divisor / Steps * Latitude_Step + 0.4),
    while for a world size of 33 it becomes:
      Divisor = math.floor (Max_Divisor / Steps * Latitude_Step + 0.1),
    and the other sizes:
      Divisor = math.floor (Max_Divisor / Steps * Latitude_Step),
    where Latitude_Step is the number of world tiles from the pole/equator towards the mid latitude, starting with 0 for the
    pole/equator.
    The conversion from a Divisor to a temperature variation is the same as above, i.e. math.ceil (Divisor * 3 / 4).

Embark Temperature:
  The exact temperature of an embark at a particular point in time should be possible to calculate. As mentioned above, the
  logic has become somewhat odd:
  The temperature is checked only at discreet times, namely every half_year / Divisor ticks, rounded up to the next
  10 tick boundary. In addition to this, the temperature is changed only 3 out of every 4 checks (which is an effect
  of the temperature variation being only 3/4 of the Divisor). Note that there are slight exceptions to this general
  behavior.
   
  Once the Divisor has been the determined, the interval can be calculated, and based on that the exact time when
  the temperature is changed (and to what, when max temperature is available) should be possible to calculate.
  However, I've been unable to get an algorithm that provides the exact results, but I've come fairly close.
  The following Lua script function produces a temperature and timing that's usually exact, but the measured time
  can be 10 ticks later than the calculated one for some points (but not the min temperature ones):
 
Spoiler (click to show/hide)
 
PSV -> Generated World Temperature:
  PSV temperature values are changed on world gen as DF applies a latitude modifier as well as an elevation modifier
  to the PSV value. For the time being this examination will not try to produce formulae for those transformations
  (the author has tried in the past, settling for translation tables).
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: Technical temperature !science!
« Reply #1 on: July 13, 2018, 03:32:19 am »

Excellent research!

Poleless worlds not having temp variation was quite surprising, though!

Was able to find 10-tick freeze as well, via minecart on tile edge + track ramp using ice as supporting walls + pressure plate set to collapse support.

PS: the spoiler has extra code tag.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical temperature !science!
« Reply #2 on: July 13, 2018, 09:00:38 am »

If there are no latitudes, there's no base for seasonal variation, so I don't really find that surprising. The alternatives would be to either treat everything as if they were at the same latitude which would then either be fixed or "random", or have it random per world tile, so each tile would have its own seasonal cycle.

The extra code tag is there because the board SW is too stupid to respect a single code tag, and instead gobbles up the stuff inside square brackets thinking they're bullet points, or something. I haven't figured out when it permits a single code level to work and when it does not.
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: Technical temperature !science!
« Reply #3 on: July 14, 2018, 12:09:12 am »

Corrected the nether-cap wiki page with regards to freezing temp.
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical temperature !science!
« Reply #4 on: July 14, 2018, 04:49:01 am »

Corrected the nether-cap wiki page with regards to freezing temp.
Thanks Bumber. So that's where that transition point notion came from!
Logged

Saiko Kila

  • Bay Watcher
  • Dwarven alchemist
    • View Profile
Re: Technical temperature !science!
« Reply #5 on: July 15, 2018, 04:25:49 am »

Quote
The lowest temperature is reached during mid winter and the highest during mid summer.

And what about cold spells in spring or heat spells in winter? I mean periods when during winter there can be thawing, and during spring/autumn there's freezing. How does the temperature fluctuate? Do you have a curve for all 336 days for example (temperature on X axis, days on Y axis)? I'm interested how close to the lowest temperature the cold spell can be, because it's often way off from the mid winter - in the mid spring or mid autumn.

Also sometimes there are snowstorms - they are rare on my map, but maybe they are related to the temperature. I don't know why they are so rare, if the temperature is often below freezing.
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical temperature !science!
« Reply #6 on: July 15, 2018, 06:00:14 am »

As far as I've seen, temperature follows one of 65 different schedules (one for each possible Divisor), and every measurement I've made exactly matches the one it's predicted to match (i.e. down to the tick). Thus, it seems weather has no effect on temperature, nor are there any cold or warm spells in any of my measurements. I have no idea if there were any snow storms during any of them, though.

The measurements were made by embarking and running at an uncapped FPS (with bird people modded to not need to eat or drink, to avoid starvation. The bird part was a hold over from a failed attempt to use adventurer mode). A script checks the temperature at every tick, and when the temperature differs from the previous one the new temperature and the tick is written to a file. The contents of each of these files can be read by a spread sheet program that can produce a curve. I can zip the files up and provide a link to the zip if of interest.
Logged

Saiko Kila

  • Bay Watcher
  • Dwarven alchemist
    • View Profile
Re: Technical temperature !science!
« Reply #7 on: July 16, 2018, 03:09:30 am »

I've sent a PM.
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical temperature !science!
« Reply #8 on: July 16, 2018, 03:25:25 am »

The measurements can also be found here https://www.dropbox.com/s/dlbgi2ez10mwhns/temperature_measurements.zip?dl=0.

The file names should tell you which world parameters they use.

The first line contains longitude, latitude, and temperature of the world tile, while the rest contain temperature and tick. The first temperature value is an artefact of the measurement process as it records what the current temperature is when the measurements start two weeks into spring.

The two scripts are the ones I used to make measurements and to try to process the results. The latter one is in the state it happened to be when I finished, and contains various dead ends, failed attempts, and things for previous attempts to process the info.
Logged

Saiko Kila

  • Bay Watcher
  • Dwarven alchemist
    • View Profile
Re: Technical temperature !science!
« Reply #9 on: July 16, 2018, 07:44:40 am »

Thank you. I made charts but what's clear immediately, that there's no randomness to these lines. I was  expecting randomness, even if not much.

That means that the small differences between tiles on the map are decided on the lower level or the resolution is bigger. For example surface temperature in my embark for four corners just now are (2nd month, 16th day) : NW, SW, SE = 10000 urists, while NE = 9998 urists. This means that if the temperature for whole map rises by one degree, the parts other than in upper right quarter will be thawed. However, sometimes the temperature difference between hot spot and cold spot is bigger than 2 degrees (for example 3 degrees on 1st month, 15th day).
 
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: Technical temperature !science!
« Reply #10 on: July 16, 2018, 08:17:09 am »

Your embark probably has more than one biome on it. As far as I've been able to determine, a biome uses the temperature and temperature change "chart" of the parent world tile, not the embark world tile, so you can have temperatures "charts" for 3 different latitudes in an embark (as well as the temperature bases for 9 different world tiles). I haven't actually investigated temperature differences based on elevation within a single world tile's own biome, but expect the temperature to be fixed, as DF changes the world tile temperature based on the world tile elevation at world gen.

Another thing that seems to be "missing" from DF is the difference between inland and coastal climate, by the way.
Logged