示例#1
0
def test_progress_to_equilibrium():
    """Test progressing a collection of glaciers to equilibrium."""
    mb = MassBalance(ela=3000, gradient=8)
    bed = GlacierBed(top=3700, bottom=1500, width=600)
    glacier1 = Glacier(bed=bed, mass_balance=mb)
    glacier2 = Glacier(bed=bed, mass_balance=mb)
    collection = GlacierCollection([glacier1, glacier2])

    # Since the glaciers in the collection have the same attributes, they should
    # reach the same equilibrium state.

    collection.progress_to_equilibrium()
    assert collection.glaciers[0].age == collection.glaciers[1].age
示例#2
0
def test_glacier_constructor():
    """The glacier consructor is fairly simple, we only check that exceptions are raised."""

    with pytest.raises(Exception) as e_info:
        fake_bed = ["hello"]
        Glacier(bed=fake_bed, mass_balance=real_mb)
    with pytest.raises(Exception) as e_info:
        fake_mb = 21654
        Glacier(bed=real_bed, mass_balance=fake_mb)

    # Initial glacier height should match bed height.
    glacier = Glacier(bed=real_bed, mass_balance=real_mb)
    assert_equal(glacier.surface_h, real_bed.bed_h)
示例#3
0
def test_copy():
    """Is copy really producing a copy?"""
    glacier = Glacier(bed=real_bed, mass_balance=real_mb)

    glacier_copy = glacier.copy()

    assert glacier != glacier_copy
    assert isinstance(glacier_copy, Glacier)

    # Change attribute of the copy and make sure that it is only changed of the copy.
    # Should be the same value here.
    assert glacier_copy.ela == glacier.ela
    glacier_copy.mass_balance.ela = 3200
    # But not any longer.
    assert glacier_copy.ela != glacier.ela
示例#4
0
def test_progress_to_year():
    """Test progressing the collection to a specified year"""
    mb = MassBalance(ela=3000, gradient=8)
    bed = GlacierBed(top=3700, bottom=1500, width=600)
    glacier1 = Glacier(bed=bed, mass_balance=mb)
    glacier2 = Glacier(bed=bed, mass_balance=mb)
    collection = GlacierCollection([glacier1, glacier2])
    collection = GlacierCollection([glacier1, glacier2])
    # Essntially all glaciers in the collection should be of the same age.

    year = 100
    collection.progress_to_year(year)

    # Check the ages.
    assert collection.glaciers[0].age == year
    assert collection.glaciers[1].age == year

    # Empty collection should raise.
    collection = GlacierCollection()
    with pytest.raises(Exception) as e_info:
        collection.progress_to_year(year)
示例#5
0
def test_progress_to_year():
    """Test the method progress_to_year."""
    glacier = Glacier(bed=real_bed, mass_balance=real_mb)

    # Progress the glacier.
    year = 50
    glacier.progress_to_year(year)

    # This will progress the glacier normally and relies on
    # oggm.FluxBasedModel for run and store.
    assert glacier.age == year
    # Length of history will be 1 longer since we include the 0 year.
    assert len(glacier.history.time) == year + 1
    assert glacier.history.time.isel(time=-1) == year
    # State history appending should work as well.
    assert len(glacier.state_history.time) == year + 1

    # Progress a bit further, checks that appending to history works as intended.
    year = 60
    glacier.progress_to_year(year)
    assert glacier.age == year
    # Length of history will be 1 longer since we include the 0 year.
    assert len(glacier.history.time) == year + 1
    assert glacier.history.time.isel(time=-1) == year
    assert len(glacier.state_history.time) == year + 1
示例#6
0
def test_add_random_climate():
    """Test parts of the random climate."""
    glacier = Glacier(bed=real_bed, mass_balance=real_mb)

    glacier.progress_to_year(100)
    assert len(glacier.mass_balance.temp_bias_series.bias) == 101

    # Add a random climate.
    glacier.add_random_climate(duration=200, temperature_range=(-2.0, 2.0))
    # Should now be of the length 301
    assert len(glacier.mass_balance.temp_bias_series.bias) == 301
    glacier.progress_to_year(300)
    # Should still be of the length 301
    assert len(glacier.mass_balance.temp_bias_series.bias) == 301
示例#7
0
def test_progress_to_equilibrium():
    """Should be possible to combine progress_to_year and progress_to_equilibrium"""
    glacier = Glacier(bed=real_bed, mass_balance=real_mb)
    glacier.progress_to_year(100)
    glacier.progress_to_equilibrium()

    # We don't really now what the eq state is. But at least some checks on the data.
    assert len(glacier.history.time) == len(glacier.state_history.time)
示例#8
0
def test_add_temperature_bias():
    """Test to make sure that the entire temperature bias mechanism works as intended."""
    glacier = Glacier(bed=real_bed, mass_balance=real_mb)
    # Add a temperature bias
    duration = 10
    bias = 2.0
    glacier.add_temperature_bias(bias=2.0, duration=duration)
    # Progress the glacier a few years.
    year = 2
    glacier.progress_to_year(year)
    # Check the current temperature bias.
    assert glacier.mass_balance.temp_bias == bias / duration * year

    # Progress a bit further
    year = 10
    glacier.progress_to_year(year)
    # We should have reached the final temp bias now.
    assert glacier.mass_balance.temp_bias == bias
    # This should've also have update the ELA, check against the original ELA.
    assert glacier.ela == real_mb.ela + 150 * 2
    assert glacier.age == 10
    # Progress even further, bias should not continue to evolve
    glacier.progress_to_year(20)
    assert glacier.mass_balance.temp_bias == bias
    assert glacier.ela == real_mb.ela + 150 * 2
    # If we then set a new bias this should start to evolve again.
    new_bias = -1.0
    new_duration = 10
    glacier.add_temperature_bias(bias=new_bias, duration=new_duration)
    # Progress
    year = 25
    glacier.progress_to_year(year)
    # What should the bias be now?
    # We should be going from the previous bias towards the new bias.
    assert glacier.mass_balance.temp_bias == bias + (
        (new_bias - bias) / new_duration * 5)

    # Progress further
    year = 35
    glacier.progress_to_year(year)
    assert glacier.mass_balance.temp_bias == new_bias
    assert glacier.ela == real_mb.ela + 150 * new_bias
示例#9
0
from oggm_edu import GlacierBed, Glacier, MassBalance, GlacierCollection
import pytest

mb = MassBalance(ela=3000, gradient=8)
bed = GlacierBed(top=3700, bottom=1500, width=600)
glacier1 = Glacier(bed=bed, mass_balance=mb)
glacier2 = Glacier(bed=bed, mass_balance=mb)
bed_new = GlacierBed(top=3700, bottom=2500, width=300, slopes=45)
glacier3 = Glacier(bed=bed_new, mass_balance=mb)

# We need a global collection for testing the plots, for some efficiency.
collection = GlacierCollection()
collection.fill(glacier1, 2)
collection.change_attributes(attributes_to_change={"gradient": [10, 15]})
year = 200
collection.progress_to_year(year)


def test_constructor():
    """Can we initialise a collection from a list directly?"""
    collection = GlacierCollection([glacier1, glacier2])

    # Should have length 2.
    assert len(collection.glaciers) == 2


def test_check_collection():
    """Check if the glaciers in the collection are the same."""

    # Check collection should be true since glaciers have the same beds.
    collection = GlacierCollection([glacier1, glacier2])