- Mauna Loa CO2 trend and 2030 projection
- Temperature anomalies against a reference decade
- Household carbon footprint
- Warming trend and a hidden cycle
- Zero-dimensional energy balance model after a CO2 doubling
- Acceleration of the sea level rise by QR least squares
- Planck feedback and climate sensitivity
- Hot summers: shift of the mean and return period
- Amplitude and phase of the annual temperature cycle
- Dates of the remaining 1.5 C carbon budget
- Seasonal decomposition of a monthly temperature
- Temperature between sparse stations
- When are the hot days a regime?
- Non linear effects on the temperature
- Shifts in a temperature record
- Temperature between weather stations
Mauna Loa CO2 trend and 2030 projection
Fit the annual Mauna Loa CO2 means with a line and an exponential, project 2030, and convert the result to radiative forcing and atmospheric carbon stock.
#1. Mauna Loa annual mean CO2 in ppm, years counted from 2000; -> "[yr]" "[14, 15, 16, 17, 18, 19, 20, 21, 22, 23]"; -> "[co2]" "[397.12, 399.41, 403.08, 405.22, 407.61, 410.07, 412.44, 414.70, 418.53, 421.08]"; #2. Linear trend in ppm per year and exponential fit for the projection; -> "[lin]" (stat fit [yr] [co2] "linear"); json load "rx_co2lin" [lin]; -> "[exp]" (stat fit [yr] [co2] "exp"); json load "rx_co2exp" [exp]; -> "[c2030]" (math eval (json select "rx_co2exp" /expression) "{\"x\": 30}"); #3. Radiative forcing 5.35 ln C/C0 against 280 ppm and atmospheric carbon stock 2.124 GtC per ppm; -> "[dF]" (math calc "5.35*ln([c2030]/280)"); concat "trend = " (math round (json select "rx_co2lin" /b) 3) " ppm/yr, growth = " (math round (math calc (concat "100*" (json select "rx_co2exp" /b))) 3) " %/yr, 2030 = " (math round [c2030] 1) " ppm, forcing = " (math round [dF] 2) " W/m2, stock = " (math round (math calc "[c2030]*2.124") 0) " GtC"
trend = 2.616 ppm/yr, growth = 0.64 %/yr, 2030 = 440.1 ppm, forcing = 2.42 W/m2, stock = 935 GtC
- Remove the seasonal cycle of monthly data with
dsp detrendanddsp spectrum - Turn the forcing into warming with a climate sensitivity
Temperature anomalies against a reference decade
Compute the baseline of a reference decade, the anomalies of the recent decade, and test with a Welch t-test whether the warming is significant.
#1. Annual mean temperature of a station in degC, reference decade 1994-2003 and recent decade 2014-2023; -> "[ref]" "[11.8, 12.1, 11.5, 12.0, 12.3, 12.2, 12.4, 11.9, 12.5, 12.8]"; -> "[now]" "[12.9, 13.2, 13.1, 12.8, 13.4, 13.3, 13.0, 13.6, 13.9, 13.7]"; #2. Baseline and anomalies of the recent years; -> "[base]" (stat mean [ref]); -> "[anom]" (vector sub [now] (vector scale "[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]" [base])); #3. Is the warming significant? Welch t-test between the two decades; -> "[t]" (stat ttest_2 [now] [ref]); json load "rx_ttest" [t]; concat "baseline = " (math round [base] 2) " degC, mean anomaly = +" (math round (stat mean [anom]) 2) " degC, max anomaly = +" (math round (stat max [anom]) 2) " degC, t = " (math round (json select "rx_ttest" /t) 2) ", p = " (math round_sig (json select "rx_ttest" /p_value) 2)
baseline = 12.15 degC, mean anomaly = +1.14 degC, max anomaly = +1.75 degC, t = 6.93, p = 0.0000018
- Get the trend in degC per decade with
stat fit - Smooth the series with
dsp moving_average
Household carbon footprint
Turn a year of car fuel, flights, electricity, gas heating billed in BTU and methane into CO2 equivalent, then into tonnes of carbon.
#1. Yearly activity data of a household: car, two long-haul flights, electricity, gas heating billed in BTU; -> "[car]" (math calc "12000*6.5/100*2.31"); -> "[fly]" (math calc "2*6000*0.152"); -> "[elec]" (math calc "4200*0.056"); -> "[gas]" (math calc (concat (unit convert 30.7e6 "BTU" "kWh") "*0.227")); #2. Methane from waste, 15 kg CH4 converted with the GWP100 of 27.9; -> "[ch4]" (math calc "15*27.9"); #3. Total in tonnes of CO2 equivalent and in tonnes of carbon, share of the largest item; -> "[items]" (concat "[" [car] ", " [fly] ", " [elec] ", " [gas] ", " [ch4] "]"); -> "[tot]" (stat sum [items]); concat "total = " (math round (math calc "[tot]/1000") 2) " t CO2e = " (math round (math calc "[tot]/1000*12/44") 2) " t C, largest item = " (math round (math calc (concat "100*" (stat max [items]) "/[tot]")) 1) " %"
total = 6.32 t CO2e = 1.72 t C, largest item = 32.3 %
- Compare with the 2 t per person target
- Put the items in a JSON object and sort them with
json sort
Zero-dimensional energy balance model after a CO2 doubling
Compute the emission temperature of the Earth with the Stefan-Boltzmann law, the radiative forcing of a CO2 doubling (Myhre formula), then integrate the energy balance C dT/dt = F - lambda T of a 100 m ocean mixed layer to see the warming after 10, 30 and 60 years.
#1. Emission temperature of the Earth: solar constant 1361 W/m2, albedo 0.30; -> "[sigma]" (const get "sigma"); -> "[Te]" (math calc "(1361*(1-0.30)/(4*[sigma]))^0.25"); #2. Radiative forcing of an abrupt CO2 doubling, Myhre formula 5.35 ln C/C0; -> "[F]" (math calc "5.35*ln(560/280)"); #3. Feedback parameter and mixed layer of 100 m: heat capacity per year; -> "[lambda]" 1.2; -> "[C]" (math calc "1025*3990*100/3.156e7"); #4. Energy balance model C dT/dt = F - lambda T over 60 years; json load "rx_ebm" (num ode "{\"T\": \"([F]-[lambda]*T)/[C]\"}" "{\"T\": 0}" 0 60 "{\"points\": 7}"); #5. Warming after 10, 30 and 60 years against the equilibrium; -> "[ecs]" (/ [F] [lambda]); concat "Te = " (math round [Te] 1) " K | forcing 2xCO2 = " (math round [F] 2) " W/m2 | ECS = " (math round [ecs] 2) " K, tau = " (math round (/ [C] [lambda]) 1) " years | T10 = " (math round (json select "rx_ebm" "/T/[1]") 2) " K, T30 = " (math round (json select "rx_ebm" "/T/[3]") 2) " K, T60 = " (math round (json select "rx_ebm" "/T/[6]") 2) " K"
Te = 254.6 K | forcing 2xCO2 = 3.71 W/m2 | ECS = 3.09 K, tau = 10.8 years | T10 = 1.87 K, T30 = 2.9 K, T60 = 3.08 K
Acceleration of the sea level rise by QR least squares
The satellite record of the global mean sea level is fitted with a quadratic a + b t + c t^2. The script builds the design matrix, solves the least squares problem with a Householder QR decomposition (R b = Q^T y, stable even when t^2 is large), and gets the rate, the acceleration 2c, the residual and the level reached in 2050.
#1. Global mean sea level by satellite altimetry, mm, every 3 years since 1993; -> "[t]" "0,3,6,9,12,15,18,21,24,27,30"; -> "[y]" "[0, 8.1, 15.0, 24.2, 33.0, 40.9, 51.2, 61.3, 73.0, 86.1, 99.4]"; #2. Design matrix of the quadratic model a + b t + c t^2; -> "[X]" ""; for (-> "[i]" 1) (<= [i] (atom size [t] ",")) (++ "[i]") { -> "[ti]" (atom get [t] [i] ","); -> "[X]" (concat [X] (if (> [i] 1) {","} {""}) "[1," [ti] "," (math calc "[ti]^2") "]"); }; -> "[X]" (concat "[" [X] "]"); #3. Householder QR, then the triangular system R b = Q^T y; json load "rx_p4e_qr" (matrix qr [X]); -> "[b]" (matrix solve (json select "rx_p4e_qr" "/R") (matrix mul (matrix transpose (json select "rx_p4e_qr" "/Q")) [y])); json unload "rx_p4e_qr"; #4. Rate b + 2 c t in 2008, acceleration 2c, residual and level in 2050, t = 57; -> "[rate]" (vector dot [b] "[0, 1, 30]"); -> "[acc]" (vector dot [b] "[0, 0, 2]"); -> "[res]" (vector norm (vector sub (matrix mul [X] [b]) [y])); concat "coefficients a, b, c = " [b] [_n_] "rate in 2008 = " (math round [rate] 2) " mm/yr, acceleration = " (math round [acc] 4) " mm/yr2, residual norm = " (math round [res] 2) " mm, level in 2050 = " (math round (vector dot [b] "[1, 57, 3249]") 0) " mm above 1993"
coefficients a, b, c = [0.9055944055944333,2.138352758352755,0.037347837347837434] rate in 2008 = 3.26 mm/yr, acceleration = 0.0747 mm/yr2, residual norm = 2.37 mm, level in 2050 = 244 mm above 1993
- Compare with the normal equations X^T X b = X^T y:
matrix condshows why QR is preferred. - Add a sine of period 1 year to the design matrix to remove the seasonal cycle of monthly data.
Planck feedback and climate sensitivity
The script extracts the Stefan-Boltzmann constant from the physics library, gets the effective emission temperature of the Earth with a fourth root, the Planck feedback 4 sigma Te^3, the net feedback after water vapour, lapse rate, albedo and cloud feedbacks, then the forcing of a CO2 doubling, the equilibrium climate sensitivity and the warming committed at 420 ppm.
#1. Stefan-Boltzmann constant of the physics library, value extracted from the text; -> "[sigma]" (string regexp_extract (constant physics_stefan_boltzmann) "[0-9.]+(E-?[0-9]+)?" 0); #2. Effective emission temperature Te = fourth root of S 1 - albedo / 4 sigma; -> "[Te]" (math nroot (math calc "1361*(1-0.30)/(4*[sigma])") 4); #3. Planck feedback 4 sigma Te^3 and the other feedbacks: water vapour, lapse rate, albedo, clouds, W/m2/K; -> "[l0]" (math calc "4*[sigma]*[Te]^3"); -> "[lambda]" (math calc "[l0]-(1.8-0.5+0.35+0.42)"); #4. Forcing of a CO2 doubling and of 420 ppm against 280 ppm, 5.35 ln C/C0; -> "[F2x]" (math calc "5.35*ln(2)"); -> "[F]" (math calc (concat "5.35*" (math log (math calc "420/280")))); concat "sigma = " [sigma] ", Te = " (math round [Te] 2) " K, Planck feedback = " (math round [l0] 3) " W/m2/K, net feedback = " (math round [lambda] 3) " W/m2/K, F2x = " (math round [F2x] 2) " W/m2, ECS = " (math round (math calc "[F2x]/[lambda]") 2) " K, equilibrium warming at 420 ppm = " (math round (math calc "[F]/[lambda]") 2) " K"
sigma = 5.6703744191844314E-8, Te = 254.58 K, Planck feedback = 3.742 W/m2/K, net feedback = 1.672 W/m2/K, F2x = 3.71 W/m2, ECS = 2.22 K, equilibrium warming at 420 ppm = 1.3 K
- Draw the warming against the cloud feedback from 0 to 1 W/m2/K with
plot function: the tail of high sensitivities. - Add the ocean heat uptake to get the transient response with
num ode.
Hot summers: shift of the mean and return period
Ten recent summer anomalies of a station are ranked, tested against the 1961-1990 climate with a z-test (the climatological standard deviation is known), and the return period of a +2.1 K summer is computed in the old and in the current climate with the complementary error function: the risk ratio of an attribution study.
#1. Summer JJA temperature anomalies of a station against 1961-1990, last 10 years, known sigma 0.6 K; -> "[jja]" "[0.9, 1.4, 0.7, 2.1, 1.1, 1.6, 0.8, 2.4, 1.3, 1.9]"; -> "[sigma]" 0.6; #2. Ranking of the summers, hottest last; -> "[rank]" (math order_double [jja]); #3. z-test: has the mean shifted from 0?; -> "[z]" (stat ztest [jja] 0 [sigma]); #4. Probability of a summer above +2.1 K in the old climate and now, 0.5 erfc x / sigma sqrt 2; -> "[p_old]" (math calc (concat "0.5*" (math erfc (math calc "2.1/([sigma]*sqrt(2))")))); -> "[p_new]" (math calc (concat "0.5*" (math erfc (math calc (concat "(2.1-" (stat mean [jja]) ")/([sigma]*sqrt(2))"))))); concat "ordered = " [rank] [_n_] "z-test = " [z] [_n_] "summer above +2.1 K: return period " (math round (math calc "1/[p_old]") 0) " years in 1961-1990, " (math round (math calc "1/[p_new]") 1) " years now, risk ratio = " (math round (math calc "[p_new]/[p_old]") 0)
ordered = [0.7,0.8,0.9,1.1,1.3,1.4,1.6,1.9,2.1,2.4]
z-test = {"z": 7.484057129065165, "p_value": 7.20626055562942E-14}
summer above +2.1 K: return period 4299 years in 1961-1990, 7.8 years now, risk ratio = 553- Use
stat ttestif the standard deviation must be estimated from the sample. - Fit a GEV law to the yearly maxima instead of a normal law on the summer means.
Amplitude and phase of the annual temperature cycle
The twelve monthly normals of a station are projected on the first harmonic. The script gets the annual mean, the amplitude with hypot, the phase with atan2, the date of the warmest day of the fitted cycle and its lag after the summer solstice, a signature of the thermal inertia of the site.
#1. Monthly mean temperatures of a mid-latitude station, degC, January to December; -> "[T]" "2.1,3.4,6.9,10.2,14.1,17.6,19.8,19.3,15.9,11.4,6.3,2.9"; -> "[a]" 0; -> "[b]" 0; #2. First harmonic: a1 and b1 by projection on cos and sin at mid-month; for (-> "[m]" 1) (<= [m] 12) (++ "[m]") { -> "[x]" (math calc "2*pi*([m]-0.5)/12"); -> "[Tm]" (atom get [T] [m] ","); -> "[a]" (math calc "[a]+[Tm]*cos([x])/6"); -> "[b]" (math calc "[b]+[Tm]*sin([x])/6"); }; #3. Amplitude and phase of the annual cycle, date of the maximum; -> "[amp]" (math hypot [a] [b]); -> "[phase]" (math calc (concat "mod(" (math atan2 [b] [a]) "+2*pi, 2*pi)")); -> "[day]" (math round (math calc "[phase]/(2*pi)*365") 0); #4. Annual mean and date of the warmest day of the fitted cycle; concat "annual mean = " (math round (math avg (concat "[" [T] "]")) 2) " degC, amplitude = " (math round [amp] 2) " K, phase = " (math round (math rad_to_deg [phase]) 1) " deg, warmest day of the fit = " (date add "2025-01-01" "DAY" [day]) ", lag after the solstice = " (date nb_day "2025-06-21" (date add "2025-01-01" "DAY" [day])) " days"
annual mean = 10.83 degC, amplitude = 8.78 K, phase = 198.1 deg, warmest day of the fit = 2025-07-21, lag after the solstice = 30 days
- Compare a coastal and a continental station: the coast has a smaller amplitude and a longer lag.
- Get the same harmonic with
dsp spectrumon several years of daily data.
Dates of the remaining 1.5 C carbon budget
From the remaining carbon budget for 1.5 C and the current CO2 emissions, the script gets the date when the budget is used at constant emissions, the net zero date of a straight line path that stays within the budget, the yearly cut it needs, and the warming that the budget represents with the TCRE.
#1. Remaining carbon budget for 1.5 C, 50 percent chance, 130 GtCO2 from 1 January 2025, emissions 41.6 GtCO2/yr; -> "[B]" 130; -> "[E]" 41.6; #2. Constant emissions: budget gone after B/E years, converted to a date; -> "[years]" (math calc "[B]/[E]"); -> "[gone]" (date add "2025-01-01" "DAY" (math trunc (math calc "[years]*365.25"))); #3. Straight line to net zero within the budget: T = 2B/E; -> "[T]" (math calc "2*[B]/[E]"); -> "[nz]" (date add "2025-01-01" "DAY" (math trunc (math calc "[T]*365.25"))); #4. Warming from the TCRE, 0.45 C per 1000 GtCO2, and the yearly cut needed; concat "budget gone on " [gone] " at constant emissions, " (math trunc [years]) " years and " (math round (math calc (concat "12*" (math frac_part [years]))) 1) " months; linear path: net zero on " [nz] " in year " (date year [nz]) ", cut of " (math round (math calc "[E]/[T]") 2) " GtCO2 per year; warming of the budget " (math round (math calc "0.45*[B]/1000") 3) " C"
budget gone on 2028-02-16 at constant emissions, 3 years and 1.5 months; linear path: net zero on 2031-04-02 in year 2031, cut of 6.66 GtCO2 per year; warming of the budget 0.059 C
- Use an exponential decline of the emissions: the integral E/k gives the rate k needed.
- Repeat for the 2 C budget, about 1050 GtCO2 from 2025.
Seasonal decomposition of a monthly temperature
Split 4 years of monthly temperatures into trend, season and residual with an STL decomposition, then give the warming of the trend, the amplitude of the season and the strengths.
#1. Monthly mean temperature in C; -> "[t]" "[3.1, 4.0, 7.2, 10.5, 14.8, 18.1, 20.3, 19.9, 16.2, 11.8, 7.0, 4.0, 3.4, 4.5, 7.6, 10.9, 15.0, 18.6, 20.8, 20.2, 16.6, 12.1, 7.3, 4.4, 3.6, 4.6, 7.9, 11.3, 15.4, 18.8, 21.1, 20.6, 16.9, 12.4, 7.7, 4.6, 4.0, 5.0, 8.2, 11.5, 15.8, 19.3, 21.5, 21.0, 17.2, 12.8, 8.0, 5.1]"; json load "rx_stl" (ml ts stl [t] 12); -> "[s]" (json select "rx_stl" "/seasonal"); -> "[res]" (concat "trend from " (math round (json select "rx_stl" "/trend/[0]") 2) " to " (math round (json select "rx_stl" "/trend/[47]") 2) " C | seasonal amplitude " (math round (- (stat max [s]) (stat min [s])) 2) " C | trend strength " (math round (json select "rx_stl" "/trend_strength") 3) " | seasonal strength " (math round (json select "rx_stl" "/seasonal_strength") 3)); json unload "rx_stl"; [res]
trend from 11.26 to 12.59 C | seasonal amplitude 17.37 C | trend strength 0.988 | seasonal strength 1
ml ts decomposeis the classical decomposition with a moving average.- Test the trend of the deseasonalized series with
stat kendall(Mann-Kendall).
Temperature between sparse stations
Interpolate the mean temperature along a mountain slope from 9 stations with a Gaussian process, with a 95% interval that widens where there is no station and above the highest one.
#1. Altitude in m, mean temperature in C; -> "[X]" "[[0], [150], [400], [700], [900], [1300], [1600], [2100], [2400]]"; -> "[y]" "[26.32, 25.91, 24.7, 22.89, 22.18, 18.87, 16.96, 12.38, 10.37]"; json load "rx_m" (ml train "rx_gp" "gaussian_process" [X] [y] "{\"kernel\": \"matern52\"}"); json load "rx_p" (ml model predict_interval "rx_gp" "[[300], [1100], [1850], [3000]]" 0.95); -> "[res]" (concat "length scale " (math round (json select "rx_m" "/length_scale") 2) " sd | "); json load "rx_alt" "[300, 1100, 1850, 3000]"; for (-> "[i]" 0) (< [i] 4) (++ "[i]") { -> "[p]" (concat "/[" [i] "]"); -> "[res]" (concat [res] (json select "rx_alt" [p]) " m: " (math round (json select "rx_p" (concat [p] "/prediction")) 1) " C [" (math round (json select "rx_p" (concat [p] "/lower")) 1) ", " (math round (json select "rx_p" (concat [p] "/upper")) 1) "] | "); }; ml model delete "rx_gp"; json unload "rx_m"; json unload "rx_p"; json unload "rx_alt"; [res]
length scale 5.88 sd | 300 m: 25.2 C [24.6, 25.7] | 1100 m: 20.5 C [20, 21.1] | 1850 m: 14.6 C [14, 15.3] | 3000 m: 6.4 C [4.4, 8.4] |
- The length scale is in standard deviations of the altitude: the correlation between two stations falls beyond it.
- Add the latitude and the distance to the sea as columns of X: the kernel works in N dimensions.
When are the hot days a regime?
From the list of days above 32 C and of rainy days in one year, find the time intervals where the hot days come back at least every 3 days: the hot season, without fixing it in advance.
#1. Day of the year, event; -> "[days]" "[[1, \"HOT\"], [2, \"RAIN\"], [4, \"RAIN\"], [5, \"HOT\"], [5, \"RAIN\"], [8, \"RAIN\"], [10, \"RAIN\"], [11, \"RAIN\"], [12, \"RAIN\"], [13, \"RAIN\"], [14, \"RAIN\"], [16, \"RAIN\"], [17, \"RAIN\"], [20, \"RAIN\"], [22, \"RAIN\"], [25, \"RAIN\"], [26, \"RAIN\"], [28, \"RAIN\"], [29, \"RAIN\"], [31, \"RAIN\"], [33, \"RAIN\"], [36, \"RAIN\"], [37, \"RAIN\"], [38, \"HOT\"], [39, \"RAIN\"], [45, \"RAIN\"], [46, \"RAIN\"], [49, \"RAIN\"], [51, \"RAIN\"], [52, \"RAIN\"], [55, \"RAIN\"], [56, \"RAIN\"], [58, \"RAIN\"], [59, \"RAIN\"], [65, \"RAIN\"], [68, \"RAIN\"], [72, \"RAIN\"], [87, \"RAIN\"], [104, \"RAIN\"], [127, \"RAIN\"], [135, \"RAIN\"], [148, \"HOT\"], [149, \"RAIN\"], [150, \"HOT\"], [151, \"HOT\"], [152, \"HOT\"], [153, \"HOT\"], [154, \"HOT\"], [155, \"HOT\"], [156, \"HOT\"], [156, \"RAIN\"], [157, \"HOT\"], [158, \"HOT\"], [158, \"RAIN\"], [159, \"HOT\"], [160, \"HOT\"], [161, \"HOT\"], [162, \"HOT\"], [166, \"HOT\"], [167, \"HOT\"], [168, \"HOT\"], [169, \"HOT\"], [170, \"HOT\"], [171, \"HOT\"], [172, \"HOT\"], [173, \"HOT\"], [174, \"HOT\"], [175, \"HOT\"], [176, \"HOT\"], [177, \"HOT\"], [178, \"HOT\"], [179, \"HOT\"], [181, \"HOT\"], [182, \"HOT\"], [183, \"HOT\"], [184, \"HOT\"], [185, \"HOT\"], [186, \"HOT\"], [187, \"HOT\"], [188, \"HOT\"], [189, \"HOT\"], [190, \"HOT\"], [191, \"RAIN\"], [192, \"HOT\"], [193, \"HOT\"], [194, \"HOT\"], [195, \"HOT\"], [197, \"HOT\"], [198, \"HOT\"], [199, \"HOT\"], [199, \"RAIN\"], [201, \"HOT\"], [202, \"HOT\"], [203, \"HOT\"], [204, \"HOT\"], [205, \"HOT\"], [206, \"HOT\"], [207, \"HOT\"], [208, \"HOT\"], [209, \"HOT\"], [210, \"HOT\"], [211, \"HOT\"], [213, \"HOT\"], [214, \"HOT\"], [215, \"HOT\"], [216, \"HOT\"], [217, \"HOT\"], [218, \"HOT\"], [219, \"HOT\"], [221, \"HOT\"], [223, \"HOT\"], [224, \"HOT\"], [226, \"HOT\"], [227, \"HOT\"], [228, \"HOT\"], [230, \"HOT\"], [231, \"HOT\"], [232, \"HOT\"], [233, \"HOT\"], [234, \"HOT\"], [235, \"HOT\"], [236, \"HOT\"], [237, \"HOT\"], [238, \"HOT\"], [238, \"RAIN\"], [239, \"HOT\"], [239, \"RAIN\"], [240, \"HOT\"], [241, \"HOT\"], [258, \"RAIN\"], [264, \"RAIN\"], [265, \"RAIN\"], [283, \"HOT\"], [285, \"HOT\"], [296, \"RAIN\"], [300, \"RAIN\"], [301, \"RAIN\"], [303, \"RAIN\"], [304, \"RAIN\"], [306, \"RAIN\"], [307, \"RAIN\"], [308, \"RAIN\"], [310, \"RAIN\"], [313, \"RAIN\"], [315, \"RAIN\"], [321, \"RAIN\"], [324, \"HOT\"], [324, \"RAIN\"], [326, \"RAIN\"], [328, \"RAIN\"], [329, \"RAIN\"], [330, \"RAIN\"], [332, \"RAIN\"], [334, \"HOT\"], [334, \"RAIN\"], [335, \"RAIN\"], [337, \"RAIN\"], [338, \"RAIN\"], [339, \"HOT\"], [339, \"RAIN\"], [340, \"RAIN\"], [341, \"RAIN\"], [343, \"RAIN\"], [344, \"RAIN\"], [345, \"RAIN\"], [347, \"HOT\"], [347, \"RAIN\"], [348, \"RAIN\"], [351, \"RAIN\"], [353, \"HOT\"], [355, \"HOT\"], [355, \"RAIN\"], [357, \"RAIN\"], [358, \"RAIN\"], [359, \"RAIN\"], [360, \"RAIN\"], [361, \"RAIN\"], [362, \"RAIN\"], [365, \"RAIN\"]]"; #2. Back at least every 3 days, 5 days of delay tolerated, at least 20 days; json load "rx_l" (ml assoc local_periodic [days] 3 20 5); -> "[res]" ""; for (-> "[i]" 0) (< [i] (json select "rx_l" "/count")) (++ "[i]") { -> "[p]" (concat "/itemsets/[" [i] "]"); -> "[res]" (concat [res] (json select "rx_l" (concat [p] "/items/[0]")) ": days " (json select "rx_l" (concat [p] "/intervals/[0]/[0]")) " to " (json select "rx_l" (concat [p] "/intervals/[0]/[1]")) " (intervals: " (json count "rx_l" (concat [p] "/intervals")) ") | "); }; json unload "rx_l"; [res]
RAIN: days 2 to 72 (intervals: 2) | HOT: days 148 to 241 (intervals: 1) |
- Compare the intervals year after year to measure the lengthening of the hot season.
ml assoc periodicchecks a regularity over the whole period instead.
Non linear effects on the temperature
Model the mean temperature of 80 stations against the altitude and the latitude with a generalized additive model: the altitude effect is almost linear (lapse rate), the latitude effect is curved; each term gets its own smoothness by GCV.
#1. Altitude in m, latitude, mean temperature in C; -> "[X]" "[[436, -23.25], [2077, -24.22], [1053, -24.0], [927, -22.95], [2484, -23.16], [779, -20.48], [123, -20.44], [1367, -24.61], [184, -24.51], [814, -23.9], [2096, -22.67], [1983, -22.24], [2778, -24.26], [818, -20.37], [2995, -22.35], [2511, -21.91], [1553, -24.89], [1087, -20.4], [2917, -21.24], [35, -21.42], [2154, -22.99], [1103, -23.76], [2219, -22.19], [1420, -22.31], [155, -23.2], [2967, -24.13], [1689, -22.65], [850, -23.68], [2218, -23.79], [708, -24.46], [1769, -22.52], [15, -23.04], [2124, -23.45], [1128, -22.3], [2430, -22.48], [2706, -23.35], [803, -24.24], [1586, -20.32], [1127, -21.98], [1608, -24.3], [1431, -21.87], [205, -21.4], [1393, -21.42], [1175, -23.46], [274, -20.24], [2614, -23.57], [2955, -22.67], [599, -24.69], [1190, -23.32], [675, -22.72], [944, -22.47], [1417, -23.19], [1587, -20.65], [665, -24.1], [1080, -23.98], [386, -24.71], [174, -20.37], [1013, -22.59], [2306, -20.93], [2090, -23.89], [514, -23.41], [1855, -20.88], [981, -22.79], [1627, -23.76], [2564, -21.32], [490, -20.53], [707, -22.07], [2467, -24.56], [1682, -20.06], [579, -23.66], [661, -22.98], [2607, -24.48], [330, -21.96], [1114, -21.7], [809, -24.39], [980, -24.09], [1381, -24.82], [2031, -22.27], [2910, -22.86], [1414, -22.77]]"; -> "[y]" "[26.67, 14.58, 21.83, 23.42, 13.42, 21.17, 25.47, 18.73, 26.3, 23.34, 15.81, 16.08, 9.94, 21.9, 9.55, 11.82, 16.54, 19.11, 8.72, 27.74, 15.3, 21.67, 14.39, 19.29, 28.09, 8.67, 18.59, 23.88, 14.49, 22.73, 17.93, 28.47, 15.62, 21.49, 13.29, 12.23, 22.51, 15.66, 21.15, 16.91, 18.65, 25.59, 17.75, 20.82, 24.57, 12.18, 10.15, 22.9, 22.04, 25.27, 23.28, 19.69, 15.91, 23.51, 21.56, 24.45, 25.46, 22.69, 12.11, 15.97, 25.78, 13.81, 22.87, 18.26, 10.49, 23.28, 24.38, 10.81, 16.08, 24.86, 25.28, 10.91, 25.99, 20.41, 22.5, 21.6, 17.57, 15.58, 10.84, 20.08]"; json load "rx_g" (stat gam [X] [y]); -> "[res]" (concat "R2 " (math round (json select "rx_g" "/r2") 3) " | altitude edf " (math round (json select "rx_g" "/terms/[0]/edf") 1) ", effect from " (math round (json select "rx_g" "/terms/[0]/effect/[0]/[1]") 2) " to " (math round (json select "rx_g" "/terms/[0]/effect/[10]/[1]") 2) " C | latitude edf " (math round (json select "rx_g" "/terms/[1]/edf") 1)); json unload "rx_g"; [res]
R2 0.996 | altitude edf 1, effect from 8.86 to -10.26 C | latitude edf 5
- edf = 1 means a straight line, more means a curve.
- The effect of each term is given at 11 points: plot it to read the shape.
Shifts in a temperature record
Find the years where the mean annual temperature of a station shifts (PELT, MBIC penalty), with the mean of each period, to separate the abrupt changes from a trend.
#1. Mean annual temperature from 1946 to 2025; -> "[t]" "[13.94, 13.54, 14.5, 13.97, 14.33, 14.88, 14.44, 13.91, 13.72, 14.19, 13.58, 14.24, 14.03, 13.66, 13.76, 13.92, 14.27, 14.29, 14.37, 14.64, 14.23, 14.38, 13.93, 14.38, 13.99, 14.58, 14.33, 14.52, 14.55, 14.08, 14.83, 14.94, 14.86, 14.45, 14.5, 14.77, 14.56, 14.36, 14.6, 14.81, 14.84, 14.01, 15.01, 14.77, 15.43, 15.32, 15.02, 14.44, 14.56, 14.71, 14.59, 14.53, 14.75, 14.6, 14.92, 15.06, 15.4, 15.32, 15.43, 14.94, 15.69, 15.53, 15.18, 15.27, 15.69, 15.64, 15.08, 15.15, 15.29, 15.3, 15.73, 15.29, 15.26, 15.17, 15.31, 15.43, 15.26, 15.85, 15.28, 15.35]"; json load "rx_c" (ml ts changepoints [t]); -> "[res]" ""; for (-> "[i]" 0) (< [i] (json count "rx_c" "/segments")) (++ "[i]") { -> "[p]" (concat "/segments/[" [i] "]"); -> "[res]" (concat [res] (+ 1946 (json select "rx_c" (concat [p] "/start"))) "-" (+ 1946 (json select "rx_c" (concat [p] "/end"))) ": " (math round (json select "rx_c" (concat [p] "/mean")) 2) " C | "); }; json unload "rx_c"; [res]
1946-1975: 14.17 C | 1976-2000: 14.73 C | 2001-2025: 15.36 C |
- {"cost": "meanvar"} also detects the changes of variability.
- Check a station change (instrument, site) before concluding to a climate shift.
Temperature between weather stations
Ten stations measure the mean temperature of an island: ordinary kriging predicts the temperature at two sites without a station, with a standard error that grows far from the stations; inverse distance weighting gives a quick comparison.
#1. Stations: latitude, longitude, mean temperature in C; -> "[st]" "[[-20.88, 55.45, 26.1], [-21.0, 55.27, 25.4], [-21.33, 55.47, 24.8], [-21.13, 55.55, 17.2], [-20.95, 55.65, 25.6], [-21.26, 55.33, 23.9], [-21.07, 55.36, 20.1], [-21.2, 55.62, 22.4], [-21.38, 55.62, 24.2], [-20.92, 55.33, 25.9]]"; -> "[sites]" "[[-21.05, 55.40], [-21.25, 55.55]]"; json load "rx_k" (geo kriging [st] [sites]); json load "rx_i" (geo idw [st] [sites]); -> "[res]" (concat "site 1: kriging " (math round (json select "rx_k" "/predictions/[0]/prediction") 1) " C +/- " (math round (json select "rx_k" "/predictions/[0]/sd") 1) ", IDW " (math round (json select "rx_i" "/[0]") 1) " | site 2: kriging " (math round (json select "rx_k" "/predictions/[1]/prediction") 1) " C +/- " (math round (json select "rx_k" "/predictions/[1]/sd") 1) ", IDW " (math round (json select "rx_i" "/[1]") 1) " | variogram range " (math round (json select "rx_k" "/variogram/range_km") 0) " km"); json unload "rx_k"; json unload "rx_i"; [res]
site 1: kriging 20.5 C +/- 1.9, IDW 21.3 | site 2: kriging 22.1 C +/- 2.2, IDW 22.5 | variogram range 75 km
- With few stations the variogram is uncertain: give it with {"model": ..., "nugget": ..., "sill": ..., "range_km": ...} when it is known.
- The altitude explains most of the temperature on an island: regress on the altitude first, then krige the residuals.
