Skip to content

Instantly share code, notes, and snippets.

@jkone27
Created February 11, 2024 00:54
Show Gist options
  • Save jkone27/a3db44cc5174426fdce85044154bd938 to your computer and use it in GitHub Desktop.
Save jkone27/a3db44cc5174426fdce85044154bd938 to your computer and use it in GitHub Desktop.
Ocean Heating 2023 to 2023
//open FSharp.Data.UnitSystems.SI
[<Measure>]
type g
[<Measure>]
type kg
[<Measure>]
type m
[<Measure>]
type km
[<Measure>]
type cm
[<Measure>]
type Celsius
[<Measure>]
type Fahrenheit
// Volume, liters.
[<Measure>]
type L
// Energy, Joules.
[<Measure>]
type J
[<Measure>]
type MJ
[<Measure>]
type kgCO2e // CO2 equivalent (kilograms)
module Conv =
// Conversion factor from cubic kilometers to liters:
let km3_to_liter = 1.0e15<L / km^3>
// Define a function to convert meters to kilometers
let meters_to_km = 0.001<km / m>
// On average, a mature tree is estimated to absorb around 22 kg of CO2 per year.
let toTreeEquiv = 1. / 22.<kgCO2e>
// Define constants
let ocean_thermal_capacity = 4.18<J / (g * Celsius)> // Specific heat capacity of water
let heat_of_an_atomic_bomb = 4.18e15<J> // Energy released by one kiloton atomic bomb
let ocean_volume_estimate = 1.386e9<km^3> // Volume of the oceans in cubic kilometers
let ocean_volume_liters = ocean_volume_estimate * Conv.km3_to_liter
// let C2F (temp: float<Celsius>) =
// 9.0<Fahrenheit> / 5.0<Celsius> * temp + 32.0<Fahrenheit>
// let F2C (temp: float<Fahrenheit>) =
// 5.0<Celsius> / 9.0<Fahrenheit> * (temp - 32.0<Fahrenheit>)
let dtC2F (dtC: float<Celsius>) : float<Fahrenheit> = dtC * 9.0<Fahrenheit> / 5.0<Celsius> // Multiply by 9/5 and convert units
let dtF2C (dtF: float<Fahrenheit>) : float<Celsius> = dtF * 5.0<Celsius> / 9.0<Fahrenheit>
// Ocean temperature in Celsius in 2024
// let ocean_temperature_F = 69.9<Fahrenheit>
// let ocean_temperature_C = F2C ocean_temperature_F
// Estimate ocean mass
let ocean_density = 1.025<kg / L> // Average density of seawater
let ocean_mass_estimate: float<kg> = ocean_volume_liters * ocean_density
// Calculate radius of the Earth (assuming spherical approximation)
let earth_radius = 6371.0<km> // Average radius of Earth
// Calculate radius of the ocean sphere (assuming same average radius)
let ocean_sphere_radius = earth_radius
// Calculate volume of the entire ocean sphere
let ocean_sphere_volume: float<km^3> =
4.0 / 3.0
* System.Math.PI
* ocean_sphere_radius
* ocean_sphere_radius
* ocean_sphere_radius
// Calculate volume of a concentric sphere with radius reduced by 2 meters
let smaller_sphere_radius = ocean_sphere_radius - 2.0<m> * Conv.meters_to_km // Convert depth to meters
let smaller_sphere_volume: float<km^3> =
4.0 / 3.0
* System.Math.PI
* smaller_sphere_radius
* smaller_sphere_radius
* smaller_sphere_radius
// Calculate the volume of the 2-meter
// surface layer (difference of spheres)
let top_2m_volume: float<km^3> = ocean_sphere_volume - smaller_sphere_volume
// Convert volume to liters for density calculation
let top_2m_volume_liters: float<L> = top_2m_volume * Conv.km3_to_liter
// Calculate density * volume in kg/km^3
let top_2m_density_volume: float<kg / km^3> =
ocean_density * top_2m_volume_liters / top_2m_volume // Cancel out km^3
// Calculate mass of top 2 meters in kg
let ocean_2m_surface_mass_estimate: float<kg> =
top_2m_density_volume * top_2m_volume
// Delta temperature of the top 2 meters of
//ocean surface due to human-induced climate change
let delta_t_ocean_2m_surface_temperature_F = 1.0<Fahrenheit>
let delta_t_ocean_2m_surface_temperature_C =
delta_t_ocean_2m_surface_temperature_F |> dtF2C
// Compute the heat equivalent to raise the temperature
// of the top 2 meters of ocean surface by 1 degree Farenheit
// https://www.nytimes.com/2024/02/07/climate/2024-hottest-january-data.html
let heat_equivalent_2m_dt: float<J> =
ocean_2m_surface_mass_estimate // kg
* 1000.0<g / kg> // Conversion factor (grams per kilogram)
* ocean_thermal_capacity // J / (g * Celsius)
* delta_t_ocean_2m_surface_temperature_C // Celsius
// Compute the number of atomic bombs needed to produce the same amount of heat
let heat_in_atomic_bombs = heat_equivalent_2m_dt / heat_of_an_atomic_bomb
let jtoCo2 (joules: float<J>) : float<kgCO2e> =
// Average emission factor for all fossil fuels (kg CO2e / MJ)
let avg_emission_factor: float<kgCO2e / MJ> = 0.225<kgCO2e / MJ>
// Convert joules to megajoules
let mj = joules / 1.0e6<J / MJ>
// Calculate CO2 equivalent
mj * avg_emission_factor
let heatInCo2e = heat_equivalent_2m_dt |> jtoCo2
let trees = heatInCo2e * Conv.toTreeEquiv
let canadianWildFire2023TreesBurned = 460000000.
let nrOfCanadian2023Wildfires = trees / canadianWildFire2023TreesBurned
let million = 1000000000.
$"""
The number of atomic bombs
needed to heat the ocean global 2m surface temperature
by %.4f{delta_t_ocean_2m_surface_temperature_C} Celsius
is {(int64) (heatInCo2e / million)} million kg CO2 equivalent
or {(int64) (trees / million)} million trees (CO2 absorbed in 1 year)
or {(int) nrOfCanadian2023Wildfires} canadian 2023 wildfires equivalent
or {(int) heat_in_atomic_bombs} atomic bombs from 2023 to 2024!!!
"""
|> printfn "%s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment