Build a glacier debris cover albedo feedback experiment: mapping, energy balance, and…
- User
Build a glacier debris cover albedo feedback experiment: mapping, energy balance, and melt.
Assistant
Build a glacier debris cover albedo feedback experiment: mapping, energy balance, and melt.
The user wants a simulation of glacier debris cover albedo feedback. This is a fascinating glaciological phenomenon. Let me break down what needs to be modeled:
Debris Cover Effects on Glaciers:
Albedo Feedback:
Energy Balance Components:
Melt Calculation:
Feedback Loop:
2D Map View:
Energy Balance Panel:
Melt Rate Visualization:
Interactive Controls:
Feedback Visualization:
Let me create a comprehensive simulation with matplotlib visualization:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import Rectangle
import matplotlib.gridspec as gridspec
I'll create:
Let me write this comprehensively: This is a fascinating glaciological problem! I'll build a comprehensive simulation of the debris cover albedo feedback, which involves the counterintuitive Østrem curve effect - where thin debris accelerates melt (low albedo) but thick debris insulates and suppresses it.
Østrem Curve Effect - The counterintuitive relationship where:
Complete Energy Balance:
Feedback Mechanisms:
Run the code to explore how debris cover creates complex melt patterns on glaciers!
"""
Glacier Debris Cover Albedo Feedback Experiment
================================================
Models the complex interaction between debris thickness, albedo,
energy balance, and ice melt on glacier surfaces.
Key Physics:
- Østrem Curve: Thin debris (<2cm) enhances melt, thick debris suppresses it
- Albedo feedback: Lower albedo → more energy absorption → more melt
- Energy balance: Shortwave, longwave, sensible, latent heat fluxes
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
from matplotlib.colors import LinearSegmentedColormap, Normalize
from matplotlib.patches import FancyBboxPatch, FancyArrowPatch
from matplotlib.collections import LineCollection
import matplotlib.gridspec as gridspec
from mpl_toolkits.axes_grid1 import make_axes_locatable
import warnings
warnings.filterwarnings('ignore')
# Physical constants
STEFAN_BOLTZMANN = 5.67e-8 # W m^-2 K^-4
LATENT_HEAT_FUSION = 334000 # J kg^-1
LATENT_HEAT_VAPORIZATION = 2.501e6 # J kg^-1
ICE_DENSITY = 900 # kg m^-3
WATER_DENSITY = 1000 # kg m^-3
AIR_DENSITY = 1.225 # kg m^-3
SPECIFIC_HEAT_AIR = 1005 # J kg^-1 K^-1
VON_KARMAN = 0.4
GRAVITY = 9.81 # m s^-2
class GlacierDebrisModel:
"""
Energy balance model for debris-covered glaciers
incorporating albedo feedback and the Østrem curve effect
"""
def __init__(self, nx=60, ny=40, dx=10.0):
"""
Initialize the glacier debris model
Parameters:
-----------
nx, ny : int
Grid dimensions
dx : float
Grid spacing in meters
"""
self.nx = nx
self.ny = ny
self.dx = dx
# Initialize spatial fields
self.debris_thickness = np.zeros((ny, nx)) # meters
self.ice_elevation = np.zeros((ny, nx)) # meters
self.cumulative_melt = np.zeros((ny, nx)) # meters water equivalent
# Create glacier geometry
self._init_glacier_geometry()
# Climate parameters
self.air_temp = 5.0 # °C
self.wind_speed = 3.0 # m/s
self.solar_radiation = 800.0 # W/m²
self.cloud_cover = 0.3 # fraction
self.humidity = 0.7 # relative humidity
# Debris properties
self.debris_albedo_min = 0.10 # Fresh dark debris
self.debris_albedo_max = 0.30 # Weathered/ dusty debris
self.ice_albedo = 0.35 # Clean ice
self.debris_thermal_conductivity = 0.94 # W m^-1 K^-1
self.debris_density = 1800 # kg m^-3
self.critical_thickness = 0.02 # meters - Østrem curve critical point
# Time tracking
self.time = 0 # hours
self.dt = 1.0 # time step in hours
def _init_glacier_geometry(self):
"""Create realistic glacier surface geometry"""
x = np.linspace(0, self.nx * self.dx, self.nx)
y = np.linspace(0, self.ny * self.dx, self.ny)
X, Y = np.meshgrid(x, y)
# Base glacier elevation (higher at top, lower at terminus)
self.ice_elevation = 3000 - 0.05 * Y + 20 * np.sin(X / 200)
# Initialize debris distribution
# More debris near terminus and margins
terminus_factor = np.exp(-((Y - self.ny * self.dx) / (self.ny * self.dx * 0.3))**2)
margin_factor = np.exp(-((X - self.nx * self.dx / 2) / (self.nx * self.dx * 0.3))**2)
margin_factor = 1 - 0.5 * margin_factor # More debris at margins
# Random spatial variation
np.random.seed(42)
noise = np.random.randn(self.ny, self.nx) * 0.01
smooth_noise = self._smooth_field(noise, iterations=3)
self.debris_thickness = 0.05 * terminus_factor * margin_factor + 0.02
self.debris_thickness = np.clip(self.debris_thickness + smooth_noise * 0.01, 0, 0.5)
# Create glacier mask (debris only on glacier)
self.glacier_mask = self.debris_thickness > 0.001
def _smooth_field(self, field, iterations=1):
"""Apply smoothing to a field"""
result = field.copy()
for _ in range(iterations):
result = np.array([
[np.mean(result[max(0,i-1):min(self.ny,i+2), max(0,j-1):min(self.nx,j+2)])
for j in range(self.nx)] for i in range(self.ny)])
return result
def calculate_albedo(self, debris_thickness):
"""
Calculate surface albedo based on debris thickness
Uses exponential transition from ice albedo to debris albedo
"""
# Characteristic length scale for albedo transition
albedo_length = 0.005 # 5mm
# Weight between ice and debris albedo
weight = 1 - np.exp(-debris_thickness / albedo_length)
# Debris albedo can vary with thickness (thin=dark, thick can have light dust)
debris_alb = self.debris_albedo_min + (self.debris_albedo_max - self.debris_albedo_min) * \
(1 - np.exp(-debris_thickness / 0.05))
albedo = self.ice_albedo * (1 - weight) + debris_alb * weight
return albedo
def oestrem_factor(self, debris_thickness):
"""
Calculate the Østrem curve factor
Returns a multiplier on melt rate:
- debris < critical: factor > 1 (enhanced melt)
- debris > critical: factor < 1 (suppressed melt)
Based on empirical relationships from glacier studies
"""
h = debris_thickness
h_crit = self.critical_thickness
# Enhanced melt for thin debris (albedo effect dominates)
# Suppressed melt for thick debris (insulation effect dominates)
# Peak enhancement around 1-2 cm
# Semi-empirical formula based on field observations
if np.isscalar(h):
if h < 0.001: # Essentially clean ice
return 1.0
else:
# Combination of enhancement and suppression
enhancement = 1 + 1.5 * (h / h_crit) * np.exp(-h / h_crit)
insulation = np.exp(-h / (3 * h_crit))
return enhancement * insulation
else:
result = np.ones_like(h)
mask = h >= 0.001
h_masked = h[mask]
enhancement = 1 + 1.5 * (h_masked / h_crit) * np.exp(-h_masked / h_crit)
insulation = np.exp(-h_masked / (3 * h_crit))
result[mask] = enhancement * insulation
return result
def calculate_energy_balance(self, albedo, debris_thickness, surface_temp=273.15):
"""
Calculate full energy balance at the surface
Returns individual components and net energy
"""
T_air = self.air_temp + 273.15 # Convert to Kelvin
T_surf = surface_temp
# 1. Shortwave radiation
S_in = self.solar_radiation
S_net = S_in * (1 - albedo)
# 2. Longwave radiation
# Incoming from atmosphere (cloudy sky)
emissivity_sky = 0.7 + 0.2 * self.cloud_cover
L_in = emissivity_sky * STEFAN_BOLTZMANN * T_air**4
# Outgoing from surface
emissivity_surf = 0.95 # Debris/ice emissivity
L_out = emissivity_surf * STEFAN_BOLTZMANN * T_surf**4
L_net = L_in - L_out
# 3. Sensible heat flux (bulk aerodynamic method)
# Roughness length for debris
z0 = 0.001 + 0.01 * debris_thickness # increases with debris
z = 2.0 # measurement height
# Turbulent exchange coefficient
C_h = VON_KARMAN**2 / (np.log(z / z0))**2
Q_H = AIR_DENSITY * SPECIFIC_HEAT_AIR * C_h * self.wind_speed * (T_air - T_surf)
# 4. Latent heat flux
# Saturation vapor pressure (Tetens formula)
e_sat_surf = 611 * np.exp(17.27 * (T_surf - 273.15) / (T_surf - 35.85))
e_sat_air = 611 * np.exp(17.27 * self.air_temp / (self.air_temp + 237.3))
e_air = self.humidity * e_sat_air
# Latent heat flux (evaporation/sublimation)
Q_E = 0.622 * AIR_DENSITY * LATENT_HEAT_VAPORIZATION / 101325 * \
C_h * self.wind_speed * (e_air - e_sat_surf) / AIR_DENSITY
# 5. Ground/heat conduction through debris
# Heat flux into the ice depends on debris thickness
if np.isscalar(debris_thickness):
if debris_thickness > 0.001:
# Temperature gradient through debris
T_debris_surf = T_surf
G = self.debris_thermal_conductivity * (T_debris_surf - 273.15) / debris_thickness
else:
G = 0
else:
G = np.zeros_like(debris_thickness)
mask = debris_thickness > 0.001
G[mask] = self.debris_thermal_conductivity * (T_surf - 273.15) / debris_thickness[mask]
# Net energy available for melt
Q_melt = S_net + L_net + Q_H + Q_E - G
Q_melt = np.maximum(Q_melt, 0) # Can't have negative melt
return {
'SW_net': S_net,
'LW_net': L_net,
'Q_H': Q_H,
'Q_E': Q_E,
'G': G,
'Q_melt': Q_melt
}
def calculate_melt_rate(self, debris_thickness):
"""
Calculate melt rate in mm/hr for given debris thickness
Combines energy balance with Østrem curve effect
"""
albedo = self.calculate_albedo(debris_thickness)
energy = self.calculate_energy_balance(albedo, debris_thickness)
# Base melt rate from energy balance (m/s)
base_melt_rate = energy['Q_melt'] / (ICE_DENSITY * LATENT_HEAT_FUSION)
# Convert to mm/hr
base_melt_rate_mmhr = base_melt_rate * 1000 * 3600
# Apply Østrem factor
oestrem = self.oestrem_factor(debris_thickness)
melt_rate = base_melt_rate_mmhr * oestrem
return melt_rate
def step(self):
"""Advance simulation by one time step"""
# Calculate melt rate for entire grid
melt_rate = self.calculate_melt_rate(self.debris_thickness)
# Convert mm/hr to m per time step
melt_per_step = (melt_rate / 1000) * (self.dt / 1) # m
# Update cumulative melt
self.cumulative_melt += melt_per_step
# Update ice elevation
self.ice_elevation -= melt_per_step
# Debris concentration feedback
# As ice melts, debris accumulates (thickens) - negative feedback
# This is simplified - in reality debris can also be transported
if np.isscalar(self.debris_thickness):
if self.debris_thickness > 0.001 and melt_per_step > 0:
# Debris concentrates as ice melts
self.debris_thickness *= 1 + 0.01 * melt_per_step / 0.01
else:
mask = (self.debris_thickness > 0.001) & (melt_per_step > 0)
self.debris_thickness[mask] *= 1 + 0.01 * melt_per_step[mask] / 0.01
self.time += self.dt
return melt_rate
class GlacierVisualization:
"""Interactive visualization for the glacier debris feedback experiment"""
def __init__(self):
self.model = GlacierDebrisModel()
self.running = False
self.setup_figure()
self.update_plots()
def setup_figure(self):
"""Create the figure with all subplots and controls"""
self.fig = plt.figure(figsize=(16, 10))
self.fig.patch.set_facecolor('#1a1a2e')
# Create grid layout
gs = gridspec.GridSpec(3, 4, figure=self.fig,
height_ratios=[1.2, 1, 0.8],
width_ratios=[1, 1, 1, 0.3],
hspace=0.3, wspace=0.3)
# Main glacier map
self.ax_map = self.fig.add_subplot(gs[0, 0:2])
self.ax_map.set_facecolor('#16213e')
# Albedo map
self.ax_albedo = self.fig.add_subplot(gs[0, 2])
self.ax_albedo.set_facecolor('#16213e')
# Østrem curve
self.ax_oestrem = self.fig.add_subplot(gs[1, 0])
self.ax_oestrem.set_facecolor('#16213e')
# Energy balance
self.ax_energy = self.fig.add_subplot(gs[1, 1])
self.ax_energy.set_facecolor('#16213e')
# Melt rate map
self.ax_melt = self.fig.add_subplot(gs[1, 2])
self.ax_melt.set_facecolor('#16213e')
# Time series
self.ax_ts = self.fig.add_subplot(gs[2, 0:3])
self.ax_ts.set_facecolor('#16213e')
# Info panel
self.ax_info = self.fig.add_subplot(gs[0:2, 3])
self.ax_info.set_facecolor('#16213e')
self.ax_info.axis('off')
# Control panel area
self.ax_controls = self.fig.add_subplot(gs[2, 3])
self.ax_controls.axis('off')
# Custom colormaps
self.debris_cmap = self._create_debris_cmap()
self.melt_cmap = self._create_melt_cmap()
# Initialize time series storage
self.time_history = [0]
self.melt_history = [0]
self.albedo_history = [np.mean(self.model.calculate_albedo(self.model.debris_thickness))]
# Create sliders
self._create_sliders()
# Create buttons
self._create_buttons()
def _create_debris_cmap(self):
"""Create custom colormap for debris thickness"""
colors = ['#e8f4f8', '#a8d5e5', '#7fc8a9', '#5d9c59',
'#8b7355', '#6b4423', '#3d2914']
return LinearSegmentedColormap.from_list('debris', colors, N=256)
def _create_melt_cmap(self):
"""Create custom colormap for melt rate"""
colors = ['#0d1b2a', '#1b263b', '#415a77', '#778da9',
'#e0e1dd', '#ffd166', '#ef476f']
return LinearSegmentedColormap.from_list('melt', colors, N=256)
def _create_sliders(self):
"""Create interactive sliders for model parameters"""
slider_color = '#4a4e69'
# Temperature slider
ax_temp = plt.axes([0.78, 0.38, 0.15, 0.02], facecolor=slider_color)
self.slider_temp = Slider(ax_temp, 'Air Temp (°C)', -5, 20,
valinit=self.model.air_temp, color='#e63946')
self.slider_temp.on_changed(self._update_params)
# Solar radiation slider
ax_solar = plt.axes([0.78, 0.34, 0.15, 0.02], facecolor=slider_color)
self.slider_solar = Slider(ax_solar, 'Solar (W/m²)', 100, 1200,
valinit=self.model.solar_radiation, color='#f4a261')
self.slider_solar.on_changed(self._update_params)
# Wind speed slider
ax_wind = plt.axes([0.78, 0.30, 0.15, 0.02], facecolor=slider_color)
self.slider_wind = Slider(ax_wind, 'Wind (m/s)', 0.5, 15,
valinit=self.model.wind_speed, color='#2a9d8f')
self.slider_wind.on_changed(self._update_params)
# Cloud cover slider
ax_cloud = plt.axes([0.78, 0.26, 0.15, 0.02], facecolor=slider_color)
self.slider_cloud = Slider(ax_cloud, 'Clouds', 0, 1,
valinit=self.model.cloud_cover, color='#457b9d')
self.slider_cloud.on_changed(self._update_params)
# Debris input slider
ax_debris = plt.axes([0.78, 0.22, 0.15, 0.02], facecolor=slider_color)
self.slider_debris = Slider(ax_debris, 'Debris Input', 0.5, 3.0,
valinit=1.0, color='#6b4423')
self.slider_debris.on_changed(self._update_params)
# Style slider labels
for slider in [self.slider_temp, self.slider_solar, self.slider_wind,
self.slider_cloud, self.slider_debris]:
slider.label.set_color('white')
slider.valtext.set_color('white')
def _create_buttons(self):
"""Create control buttons"""
# Run/Pause button
ax_run = plt.axes([0.78, 0.14, 0.08, 0.04])
self.btn_run = Button(ax_run, 'Run', color='#2a9d8f', hovercolor='#40c9b0')
self.btn_run.on_clicked(self._toggle_run)
self.btn_run.label.set_color('white')
# Reset button
ax_reset = plt.axes([0.87, 0.14, 0.08, 0.04])
self.btn_reset = Button(ax_reset, 'Reset', color='#e63946', hovercolor='#ff6b6b')
self.btn_reset.on_clicked(self._reset)
self.btn_reset.label.set_color('white')
# Step button
ax_step = plt.axes([0.78, 0.08, 0.08, 0.04])
self.btn_step = Button(ax_step, 'Step', color='#457b9d', hovercolor='#5a9fc7')
self.btn_step.on_clicked(self._step)
self.btn_step.label.set_color('white')
# Add debris event button
ax_event = plt.axes([0.87, 0.08, 0.08, 0.04])
self.btn_event = Button(ax_event, 'Rockfall', color='#6b4423', hovercolor='#8b5a2b')
self.btn_event.on_clicked(self._add_debris_event)
self.btn_event.label.set_color('white')
def _update_params(self, val):
"""Update model parameters from sliders"""
self.model.air_temp = self.slider_temp.val
self.model.solar_radiation = self.slider_solar.val
self.model.wind_speed = self.slider_wind.val
self.model.cloud_cover = self.slider_cloud.val
self.update_plots()
def _toggle_run(self, event):
"""Toggle simulation running state"""
self.running = not self.running
self.btn_run.label.set_text('Pause' if self.running else 'Run')
def _reset(self, event):
"""Reset simulation to initial state"""
self.running = False
self.btn_run.label.set_text('Run')
self.model = GlacierDebrisModel()
self.model.air_temp = self.slider_temp.val
self.model.solar_radiation = self.slider_solar.val
self.model.wind_speed = self.slider_wind.val
self.model.cloud_cover = self.slider_cloud.val
self.time_history = [0]
self.melt_history = [0]
self.albedo_history = [np.mean(self.model.calculate_albedo(self.model.debris_thickness))]
self.update_plots()
def _step(self, event):
"""Advance simulation by one step"""
self._run_step()
def _add_debris_event(self, event):
"""Simulate a rockfall event adding debris"""
# Add debris in a random location
cx, cy = np.random.randint(10, self.model.nx-10), np.random.randint(10, self.model.ny-10)
x = np.linspace(0, self.model.nx, self.model.nx)
y = np.linspace(0, self.model.ny, self.model.ny)
X, Y = np.meshgrid(x, y)
# Gaussian debris addition
debris_add = 0.1 * np.exp(-((X - cx)**2 + (Y - cy)**2) / 50)
self.model.debris_thickness += debris_add * self.slider_debris.val
self.model.debris_thickness = np.clip(self.model.debris_thickness, 0, 0.5)
self.update_plots()
def _run_step(self):
"""Execute one simulation step"""
melt_rate = self.model.step()
# Update history
self.time_history.append(self.model.time)
self.melt_history.append(np.mean(melt_rate[self.model.glacier_mask]))
self.albedo_history.append(np.mean(self.model.calculate_albedo(
self.model.debris_thickness[self.model.glacier_mask])))
self.update_plots()
def update_plots(self):
"""Update all visualization plots"""
self._draw_glacier_map()
self._draw_albedo_map()
self._draw_oestrem_curve()
self._draw_energy_balance()
self._draw_melt_map()
self._draw_time_series()
self._draw_info_panel()
self.fig.canvas.draw_idle()
def _draw_glacier_map(self):
"""Draw debris thickness map"""
self.ax_map.clear()
self.ax_map.set_facecolor('#16213e')
im = self.ax_map.imshow(self.model.debris_thickness * 100, # Convert to cm
cmap=self.debris_cmap, aspect='auto',
extent=[0, self.model.nx * self.model.dx,
0, self.model.ny * self.model.dx])
# Add contours for ice elevation
x = np.linspace(0, self.model.nx * self.model.dx, self.model.nx)
y = np.linspace(0, self.model.ny * self.model.dx, self.model.ny)
X, Y = np.meshgrid(x, y)
contours = self.ax_map.contour(X, Y, self.model.ice_elevation,
levels=10, colors='white',
alpha=0.3, linewidths=0.5)
self.ax_map.set_xlabel('Distance (m)', color='white')
self.ax_map.set_ylabel('Distance (m)', color='white')
self.ax_map.set_title('Debris Thickness & Ice Topography', color='white', fontsize=12)
self.ax_map.tick_params(colors='white')
# Colorbar
divider = make_axes_locatable(self.ax_map)
cax = divider.append_axes("right", size="3%", pad=0.05)
cbar = plt.colorbar(im, cax=cax)
cbar.set_label('Debris (cm)', color='white')
cbar.ax.yaxis.set_tick_params(color='white')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='white')
def _draw_albedo_map(self):
"""Draw surface albedo distribution"""
self.ax_albedo.clear()
self.ax_albedo.set_facecolor('#16213e')
albedo = self.model.calculate_albedo(self.model.debris_thickness)
im = self.ax_albedo.imshow(albedo, cmap='coolwarm_r', aspect='auto',
vmin=0.1, vmax=0.4,
extent=[0, self.model.nx * self.model.dx,
0, self.model.ny * self.model.dx])
self.ax_albedo.set_xlabel('Distance (m)', color='white')
self.ax_albedo.set_ylabel('Distance (m)', color='white')
self.ax_albedo.set_title('Surface Albedo', color='white', fontsize=12)
self.ax_albedo.tick_params(colors='white')
divider = make_axes_locatable(self.ax_albedo)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbar = plt.colorbar(im, cax=cax)
cbar.set_label('α', color='white')
cbar.ax.yaxis.set_tick_params(color='white')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='white')
def _draw_oestrem_curve(self):
"""Draw the Østrem curve showing melt factor vs debris thickness"""
self.ax_oestrem.clear()
self.ax_oestrem.set_facecolor('#16213e')
# Calculate curve
h = np.linspace(0, 0.15, 200) # 0 to 15 cm
oestrem = self.model.oestrem_factor(h)
# Plot curve
self.ax_oestrem.fill_between(h * 100, 1, oestrem, where=oestrem > 1,
color='#e63946', alpha=0.3, label='Enhanced melt')
self.ax_oestrem.fill_between(h * 100, 1, oestrem, where=oestrem <= 1,
color='#2a9d8f', alpha=0.3, label='Suppressed melt')
self.ax_oestrem.plot(h * 100, oestrem, 'w-', linewidth=2)
# Mark current mean debris thickness
mean_debris = np.mean(self.model.debris_thickness[self.model.glacier_mask])
mean_oestrem = self.model.oestrem_factor(mean_debris)
self.ax_oestrem.scatter([mean_debris * 100], [mean_oestrem],
c='#f4a261', s=100, zorder=5, edgecolor='white')
# Critical thickness line
self.ax_oestrem.axvline(x=self.model.critical_thickness * 100,
color='#f4a261', linestyle='--', alpha=0.7)
self.ax_oestrem.axhline(y=1, color='white', linestyle='-', alpha=0.3)
self.ax_oestrem.set_xlim(0, 15)
self.ax_oestrem.set_ylim(0, 2.5)
self.ax_oestrem.set_xlabel('Debris Thickness (cm)', color='white')
self.ax_oestrem.set_ylabel('Melt Factor', color='white')
self.ax_oestrem.set_title('Østrem Curve', color='white', fontsize=12)
self.ax_oestrem.tick_params(colors='white')
self.ax_oestrem.legend(loc='upper right', fontsize=8,
facecolor='#16213e', edgecolor='white',
labelcolor='white')
# Annotations
self.ax_oestrem.annotate('Thin debris:\nlow albedo,\nfast melt',
xy=(1, 2.0), fontsize=8, color='#e63946',
ha='center')
self.ax_oestrem.annotate('Thick debris:\ninsulation,\nslow melt',
xy=(10, 0.5), fontsize=8, color='#2a9d8f',
ha='center')
def _draw_energy_balance(self):
"""Draw energy balance components"""
self.ax_energy.clear()
self.ax_energy.set_facecolor('#16213e')
# Get energy components for mean debris thickness
mean_debris = np.mean(self.model.debris_thickness[self.model.glacier_mask])
albedo = self.model.calculate_albedo(mean_debris)
energy = self.model.calculate_energy_balance(albedo, mean_debris)
# Bar chart of energy components
components = ['SW↓', 'LW↓', 'H+', 'E-', 'Q_melt']
values = [energy['SW_net'], energy['LW_net'],
energy['Q_H'], -energy['Q_E'], energy['Q_melt']]
colors = ['#f4a261', '#457b9d', '#e63946', '#2a9d8f', '#9b5de5']
bars = self.ax_energy.bar(components, values, color=colors,
edgecolor='white', linewidth=1)
# Add value labels
for bar, val in zip(bars, values):
height = bar.get_height()
self.ax_energy.annotate(f'{val:.0f}',
xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 3), textcoords="offset points",
ha='center', va='bottom', color='white', fontsize=9)
self.ax_energy.axhline(y=0, color='white', linestyle='-', alpha=0.3)
self.ax_energy.set_ylabel('Energy Flux (W/m²)', color='white')
self.ax_energy.set_title(f'Energy Balance (α={albedo:.2f})', color='white', fontsize=12)
self.ax_energy.tick_params(colors='white')
self.ax_energy.set_ylim(min(min(values) - 50, -100), max(max(values) + 50, 300))
def _draw_melt_map(self):
"""Draw spatial distribution of melt rate"""
self.ax_melt.clear()
self.ax_melt.set_facecolor('#16213e')
melt_rate = self.model.calculate_melt_rate(self.model.debris_thickness)
im = self.ax_melt.imshow(melt_rate, cmap=self.melt_cmap, aspect='auto',
vmin=0, vmax=np.percentile(melt_rate, 98),
extent=[0, self.model.nx * self.model.dx,
0, self.model.ny * self.model.dx])
self.ax_melt.set_xlabel('Distance (m)', color='white')
self.ax_melt.set_ylabel('Distance (m)', color='white')
self.ax_melt.set_title('Melt Rate (mm/hr)', color='white', fontsize=12)
self.ax_melt.tick_params(colors='white')
divider = make_axes_locatable(self.ax_melt)
cax = divider.append_axes("right", size="5%", pad=0.05)
cbar = plt.colorbar(im, cax=cax)
cbar.set_label('mm/hr', color='white')
cbar.ax.yaxis.set_tick_params(color='white')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='white')
def _draw_time_series(self):
"""Draw time series of melt and albedo"""
self.ax_ts.clear()
self.ax_ts.set_facecolor('#16213e')
time_arr = np.array(self.time_history)
melt_arr = np.array(self.melt_history)
albedo_arr = np.array(self.albedo_history)
# Plot melt rate
color1 = '#e63946'
self.ax_ts.plot(time_arr, melt_arr, color=color1, linewidth=2, label='Mean Melt Rate')
self.ax_ts.set_xlabel('Time (hours)', color='white')
self.ax_ts.set_ylabel('Melt Rate (mm/hr)', color=color1)
self.ax_ts.tick_params(axis='y', labelcolor=color1)
self.ax_ts.tick_params(axis='x', colors='white')
# Secondary axis for albedo
ax2 = self.ax_ts.twinx()
color2 = '#457b9d'
ax2.plot(time_arr, albedo_arr, color=color2, linewidth=2, linestyle='--', label='Mean Albedo')
ax2.set_ylabel('Mean Albedo', color=color2)
ax2.tick_params(axis='y', labelcolor=color2)
ax2.set_ylim(0.1, 0.45)
self.ax_ts.set_title('Temporal Evolution: Albedo Feedback', color='white', fontsize=12)
# Combined legend
lines1, labels1 = self.ax_ts.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
self.ax_ts.legend(lines1 + lines2, labels1 + labels2, loc='upper left',
facecolor='#16213e', edgecolor='white', labelcolor='white')
# Grid
self.ax_ts.grid(True, alpha=0.2, color='white')
# Show cumulative melt
total_melt = np.sum(self.model.cumulative_melt[self.model.glacier_mask])
self.ax_ts.text(0.98, 0.95, f'Total Melt: {total_melt:.2f} m w.e.',
transform=self.ax_ts.transAxes, color='white',
fontsize=10, ha='right', va='top',
bbox=dict(boxstyle='round', facecolor='#0d1b2a', alpha=0.8))
def _draw_info_panel(self):
"""Draw information panel with model status"""
self.ax_info.clear()
self.ax_info.set_facecolor('#16213e')
self.ax_info.axis('off')
# Title
self.ax_info.text(0.5, 0.98, 'MODEL STATUS', transform=self.ax_info.transAxes,
color='#f4a261', fontsize=11, fontweight='bold',
ha='center', va='top')
# Calculate statistics
mean_debris = np.mean(self.model.debris_thickness[self.model.glacier_mask]) * 100
mean_albedo = np.mean(self.model.calculate_albedo(self.model.debris_thickness[self.model.glacier_mask]))
mean_melt = np.mean(self.model.calculate_melt_rate(self.model.debris_thickness[self.model.glacier_mask]))
mean_oestrem = self.model.oestrem_factor(mean_debris / 100)
total_melt = np.sum(self.model.cumulative_melt[self.model.glacier_mask])
# Status text
info_text = f"""
Time: {self.model.time:.1f} hrs
━━━ Statistics ━━━
Mean Debris: {mean_debris:.1f} cm
Mean Albedo: {mean_albedo:.3f}
Melt Factor: {mean_oestrem:.2f}×
Mean Melt: {mean_melt:.1f} mm/hr
━━━ Cumulative ━━━
Total Melt: {total_melt:.3f} m w.e.
Ice Loss: {total_melt * ICE_DENSITY / WATER_DENSITY:.3f} m
━━━ Feedback Loop ━━━
Lower albedo →
More absorption →
Higher melt rate
"""
self.ax_info.text(0.1, 0.85, info_text, transform=self.ax_info.transAxes,
color='white', fontsize=9, fontfamily='monospace',
va='top', ha='left')
# Draw feedback diagram
self._draw_feedback_diagram()
def _draw_feedback_diagram(self):
"""Draw small feedback loop diagram"""
# Circle positions
cx, cy = 0.5, 0.15
radius = 0.08
# Draw nodes
nodes = [
(0.25, 0.18, 'Debris'),
(0.5, 0.05, 'Low α'),
(0.75, 0.18, 'Melt↑'),
]
for x, y, label in nodes:
circle = plt.Circle((x, y), 0.05, transform=self.ax_info.transAxes,
facecolor='#2a9d8f', edgecolor='white', linewidth=1)
self.ax_info.add_patch(circle)
self.ax_info.text(x, y, label, transform=self.ax_info.transAxes,
color='white', fontsize=8, ha='center', va='center')
# Arrows
arrow_style = dict(arrowstyle='->', color='#f4a261', lw=1.5,
connectionstyle='arc3,rad=0.2')
# Draw arrows manually using annotation
self.ax_info.annotate('', xy=(0.45, 0.08), xytext=(0.30, 0.15),
arrowprops=dict(arrowstyle='->', color='#f4a261', lw=1.5),
transform=self.ax_info.transAxes)
self.ax_info.annotate('', xy=(0.70, 0.15), xytext=(0.55, 0.08),
arrowprops=dict(arrowstyle='->', color='#f4a261', lw=1.5),
transform=self.ax_info.transAxes)
self.ax_info.annotate('', xy=(0.30, 0.22), xytext=(0.70, 0.22),
arrowprops=dict(arrowstyle='->', color='#e63946', lw=1.5,
connectionstyle='arc3,rad=-0.3'),
transform=self.ax_info.transAxes)
self.ax_info.text(0.5, 0.28, 'Feedback', transform=self.ax_info.transAxes,
color='#e63946', fontsize=8, ha='center')
def run(self):
"""Start the interactive simulation"""
# Animation timer
self.timer = self.fig.canvas.new_timer(interval=200)
self.timer.add_callback(self._animate)
self.timer.start()
plt.suptitle('Glacier Debris Cover Albedo Feedback Experiment',
color='white', fontsize=14, fontweight='bold', y=0.98)
plt.show()
def _animate(self):
"""Animation callback"""
if self.running:
self._run_step()
def main():
"""Main function to run the glacier debris feedback experiment"""
print("=" * 60)
print(" GLACIER DEBRIS COVER ALBEDO FEEDBACK EXPERIMENT")
print("=" * 60)
print("""
This simulation demonstrates the complex feedback between
supraglacial debris cover and ice melt rates.
Key Concepts:
━━━━━━━━━━━━
• Østrem Curve: Thin debris enhances melt (low albedo),
thick debris suppresses melt (insulation)
• Albedo Feedback: Dark debris absorbs more solar radiation,
increasing energy available for melt
• Debris Evolution: As ice melts, debris concentrates and
thickens, creating a negative feedback
Controls:
━━━━━━━━━
• Run/Pause: Start/stop the simulation
• Step: Advance by one time step
• Reset: Return to initial conditions
• Rockfall: Add a debris deposit event
• Sliders: Adjust climate parameters
Watch how the system evolves and how the feedback loop
affects melt patterns across the glacier surface!
""")
viz = GlacierVisualization()
viz.run()
if __name__ == "__main__":
main()