Created
February 22, 2025 17:16
-
-
Save roguh/b6c8fd73dfa988cb40bf792c39fe298c to your computer and use it in GitHub Desktop.
USDA Hardiness Zones: described, programmatically defined, and serialized as JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"0": [-459.66999999999996, -60], "1": [-60, -50], "2": [-50, -40], "3": [-40, -30], "4": [-30, -20], "5": [-20, -10], "6": [-10, 0], "7": [0, 10], "8": [10, 20], "9": [20, 30], "10": [30, 40], "11": [40, 50], "12": [50, 60], "13": [60, 70]} | |
[[0, "A", -459.66999999999996, -65], [0, "B", -65, -60], [1, "A", -60, -55], [1, "B", -55, -50], [2, "A", -50, -45], [2, "B", -45, -40], [3, "A", -40, -35], [3, "B", -35, -30], [4, "A", -30, -25], [4, "B", -25, -20], [5, "A", -20, -15], [5, "B", -15, -10], [6, "A", -10, -5], [6, "B", -5, 0], [7, "A", 0, 5], [7, "B", 5, 10], [8, "A", 10, 15], [8, "B", 15, 20], [9, "A", 20, 25], [9, "B", 25, 30], [10, "A", 30, 35], [10, "B", 35, 40], [11, "A", 40, 45], [11, "B", 45, 50], [12, "A", 50, 55], [12, "B", 55, 60], [13, "A", 60, 65], [13, "B", 65, Infinity]] | |
[["0A", -459.66999999999996, -65], ["0B", -65, -60], ["1A", -60, -55], ["1B", -55, -50], ["2A", -50, -45], ["2B", -45, -40], ["3A", -40, -35], ["3B", -35, -30], ["4A", -30, -25], ["4B", -25, -20], ["5A", -20, -15], ["5B", -15, -10], ["6A", -10, -5], ["6B", -5, 0], ["7A", 0, 5], ["7B", 5, 10], ["8A", 10, 15], ["8B", 15, 20], ["9A", 20, 25], ["9B", 25, 30], ["10A", 30, 35], ["10B", 35, 40], ["11A", 40, 45], ["11B", 45, 50], ["12A", 50, 55], ["12B", 55, 60], ["13A", 60, 65], ["13B", 65, Infinity]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# > Between 1954 and 2019, the precise definitions of the unit degree Celsius and the Celsius temperature scale used absolute zero and the triple point of water. Since 2007, the Celsius temperature scale has been defined in terms of the kelvin, the SI base unit of thermodynamic temperature (symbol: K). Absolute zero, the lowest temperature, is now defined as being exactly 0 K and −273.15 C. | |
absolute_zero_celsius = -273.15 | |
def f_to_c(fahrenheit: float) -> float: | |
return (fahrenheit - 32) * 5 / 9 | |
def c_to_f(celsius: float) -> float: | |
return celsius * 9 / 5 + 32 | |
# The USDA hardiness zone is a geographical region with a certain average annual **minimum** temperature. | |
# The temperatures are bucketed into groups of 10 degrees Fahrenheit. | |
# The zones are further subdivided into an A/B zone, groups that differ by 5 degrees Fahrenheit. | |
# > A plant may be described as "hardy to zone 10": this means that the plant can withstand a minimum temperature of 30 to 40 F (−1.1 to 4.4 C). | |
# The starting range of each zone goes from -60F for zone 0 and 60F for zone 13. | |
# -60, -50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50, 60 | |
starts = list(range(-70, 60 + 1, 10)) | |
absolute_zero_fahrenheit = c_to_f(absolute_zero_celsius) | |
# 0 - Arctic and any colder areas. | |
# 13 - Central Africa and any hotter areas. | |
zones = {index: (starts[index], starts[index] + 10) for index in range(14)} | |
zones[0] = (absolute_zero_fahrenheit, -60) | |
all_zones_dict = { | |
(index, subzone): ( | |
starts[index] + (0 if subzone == "A" else 5), | |
starts[index] + (5 if subzone == "A" else 10), | |
) | |
for index in range(14) | |
for subzone in "AB" | |
} | |
# Zone 0A - all temperatures below -65F (down to absolute zero). | |
# Zone 13B - all temperatures above 65F (up to absolute heat). | |
# LIVING CREATURES AS WE KNOW CANNOT SURVIVE IN SUCH CONDITIONS. | |
all_zones_dict[(0, "A")] = (absolute_zero_fahrenheit, -65) | |
all_zones_dict[(13, "B")] = (65, float("inf")) | |
# Sorted list of all USDA hardiness zones | |
all_zones = [(*key, *value) for key, value in sorted(all_zones_dict.items())] | |
all_zones_str = [(str(key[0]) + key[1], *value) for key, value in sorted(all_zones_dict.items())] | |
import json | |
print(json.dumps(zones)) | |
print(json.dumps(all_zones)) | |
print(json.dumps(all_zones_str)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment