Ejemplo n.º 1
0
def test_initiate(model="septoria_exchanging_rings"):
    """ Check if 'initiate' from 'protocol.py' deposits dispersal units on the MTG.

    Generate a wheat MTG and distribute dispersal units randomly on leaf elements.
    Check that all the stock of DU is distributed in properties of leaf elements.

    Parameters
    ----------
    model: model
        One version of the model of septoria lesion among:
        'septoria_exchanging_rings', 'septoria_with_rings', 'septoria_continuous'
    """
    # Generate a wheat MTG
    g = adel_one_leaf_element()
    set_properties(g,
                   label='LeafElement',
                   area=5.,
                   green_area=5.,
                   position_senescence=None)

    # Generate a stock of septoria dispersal units and distribute it on g
    nb_initial_dus = 100
    distribute_dispersal_units(g,
                               nb_dus=nb_initial_dus,
                               disease_model=model,
                               initiation_model=RandomInoculation(),
                               label='LeafElement')

    # Check that all the DUs that were in the stock are now instantiated
    # on leaf elements :
    dispersal_units = g.property('dispersal_units')
    nb_dus_on_leaves = sum(len(dus) for dus in dispersal_units.itervalues())
    assert nb_dus_on_leaves == nb_initial_dus
Ejemplo n.º 2
0
def test_infect(model="septoria_exchanging_rings"):
    """ Check if 'infect' from 'protocol.py' leads to infection by dispersal units
        on the MTG.

    Generate a wheat MTG and distribute dispersal units randomly on leaf elements.
    Run a short loop to compute infection. Check that all the stock of DU caused
    appearance of a lesion on leaf elements.

    Parameters
    ----------
    model: model
        One version of the model of septoria lesion among:
        'septoria_exchanging_rings', 'septoria_with_rings', 'septoria_continuous'
    """
    # Generate a wheat MTG
    g = adel_one_leaf_element()
    set_properties(g,
                   label='LeafElement',
                   area=5.,
                   green_area=5.,
                   healthy_area=5.,
                   position_senescence=None)

    # Generate a stock of septoria dispersal units and distribute it on g
    nb_dus = 100
    distribute_dispersal_units(g,
                               nb_dus=nb_dus,
                               disease_model=model,
                               initiation_model=RandomInoculation(),
                               label='LeafElement')

    # Loop of simulation
    septo_timing = TimeControl(delay=1, steps=10)
    timer = TimeControler(disease=septo_timing)
    for t in timer:
        # Offer good conditions for at least 10h
        set_properties(g, label='LeafElement', wetness=True, temp=20.)

        # Infect
        infect(g, t['disease'].dt, label='LeafElement')

    # Check that all the DUs that were in the stock are now lesions on leaf elements
    lesions = g.property('lesions')
    nb_lesions_on_leaves = sum(len(l) for l in lesions.itervalues())
    assert nb_lesions_on_leaves == nb_dus
Ejemplo n.º 3
0
def test_update(senescence_threshold=330., sen_day=500., model="septoria_exchanging_rings", **kwds):
    """ 
    """
    from alinea.alep.wheat import adel_one_leaf_element
    
    # Read weather and adapt it to septoria (add wetness)
    meteo_path = shared_data(alinea.septo3d, 'meteo00-01.txt')
    weather = Weather(data_file=meteo_path)
    weather.check(varnames=['wetness'], models={'wetness':wetness_rapilly})
    seq = pandas.date_range(start = "2000-10-01 01:00:00",
                            end = "2000-12-31 01:00:00", 
                            freq='H')
    
    # Generate a wheat MTG
    g = adel_one_leaf_element()
    set_properties(g, label = 'LeafElement', 
                   area=5., green_area=5., healthy_area=5., position_senescence=1,
                   wetness=True, temp=22., rain_intensity=0., relative_humidity=90.)
    
    # Generate one lesion of septoria and distribute it on g
    # septoria = new_septoria(senescence_threshold=senescence_threshold)
    septoria = plugin_septoria(model)
    Lesion = septoria.lesion(**kwds)
    leaf = g.node(10)
    leaf.lesions = [Lesion(nb_spores=1, position=[0.5, 0])]
    
    # Call model of growth control
    growth_controler = NoPriorityGrowthControl()
    sen_model = WheatSeptoriaPositionedSenescence(g, label='LeafElement')
    
    #Temp
    emitter = SeptoriaRainEmission(domain_area=0.0004)
    transporter = Septo3DSplash(reference_surface=0.0004)
    
    # Loop of simulation
    every_h = time_filter(seq, delay=1)
    every_rain = rain_filter(seq, weather)
    septo_timing = IterWithDelays(*time_control(seq, every_h, weather.data))
    rain_timing = IterWithDelays(*time_control(seq, every_rain, weather.data))
    surface = []
    surface_alive = []
    surface_empty = []
    nb_dus = []
    stock_spores = []
    for i,controls in enumerate(zip(septo_timing, rain_timing)):
        septo_eval, rain_eval = controls
        
        if i==sen_day:
            set_properties(g, label = 'LeafElement', position_senescence=0) 
        if rain_eval:
            set_properties(g,label = 'LeafElement',
                           rain_intensity = rain_eval.value.rain.mean(),
                           rain_duration = len(rain_eval.value.rain) if rain_eval.value.rain.sum() > 0 else 0.)
            
        # Update healthy area
        sen_model.find_senescent_lesions(g, label = 'LeafElement')
        update_healthy_area(g, label = 'LeafElement')
    
        # Update
        update(g, septo_eval.dt, growth_controler, senescence_model=sen_model, label='LeafElement')
        
        if rain_eval:
            g, nb = disperse(g, emitter, transporter, "septoria", label='LeafElement')
        else:
            nb=0.
        nb_dus.append(nb)
        
        # Check that the lesion is in the right status and has the right surface
        lesion = g.property('lesions')
        if lesion:
            assert sum(len(l) for l in lesion.itervalues()) == 1
            l = lesion.values()[0][0]
            surface.append(l.surface)
            surface_alive.append(l.surface_alive)
            surface_empty.append(l.surface_empty)
            stock_spores.append(l.stock_spores)
            # if i==299:
                # import pdb
                # pdb.set_trace()
            l.compute_all_surfaces()
            f = l.fungus
            print('lesion surface: %f' % round(l.surface, 6))
            
    return g, surface, surface_alive, surface_empty, nb_dus, stock_spores
Ejemplo n.º 4
0
def test_senescence(status='CHLOROTIC', model="septoria_exchanging_rings"):
    """ Check if 'senescence' from 'protocol.py' compute the effects of
    senescence on the lesions of the MTG

    Generate a wheat MTG and distribute 2 DUs with know position on leaf elements.
    Make them grow into lesions until chosen status, then stop updating them.

    Set senescence on first lesion. Check that the activity of this lesion is reduced
    by senescence comparatively to the other lesion, but not the stock of spores.

    Parameters
    ----------
    status: str: 'CHLOROTIC' or 'SPORULATING'
        Status of the lesion when touched by senescence.
    model: model
        One version of the model of septoria lesion among:
        'septoria_exchanging_rings', 'septoria_with_rings', 'septoria_continuous'
    """
    # Generate a wheat MTG
    g = adel_one_leaf_element()
    set_properties(g,
                   label='LeafElement',
                   area=5.,
                   green_area=5.,
                   healthy_area=5.,
                   position_senescence=None)

    # Generate a stock of septoria dispersal units and distribute it on g
    distribute_lesions(g,
                       nb_lesions=2,
                       disease_model=model,
                       initiation_model=RandomInoculation(),
                       label='LeafElement')

    # create a flat list of lesions and fix their position
    lesions = g.property('lesions')
    les = sum(lesions.values(), [])
    les[0].position = [0.3, 0]
    les[1].position = [0.7, 0]
    # Call a models growth control and senescence
    controler = NoPriorityGrowthControl()
    senescence_model = WheatSeptoriaPositionedSenescence(g)

    # Test if lesion is CHLOROTIC when senescence occur
    if status == "CHLOROTIC":
        if model != "septoria_exchanging_rings":
            dt = 300
            set_properties(g,
                           label='LeafElement',
                           wetness=True,
                           temp=22.,
                           rain_intensity=0.)
            # Simulation to obtain a lesion in chosen status
            update(g,
                   dt=dt,
                   growth_control_model=controler,
                   senescence_model=senescence_model)
        else:
            dt = 1
            nb_steps = 300
            for i in range(0, nb_steps, dt):
                # Simulation to obtain a lesion in chosen status
                set_properties(g,
                               label='LeafElement',
                               wetness=True,
                               temp=22.,
                               rain_intensity=0.)
                update(g,
                       dt=dt,
                       growth_control_model=controler,
                       senescence_model=senescence_model)

        # 1. Compare lesions before senescence
        # Compute variables of interest
        l = g.property('lesions')
        l = sum(l.values(), [])
        lesion1 = l[0]
        lesion1.compute_all_surfaces()
        lesion2 = l[1]
        lesion2.compute_all_surfaces()
        # Compare the two lesions
        assert lesion1.status == lesion2.status == 1
        assert lesion1.surface_alive == lesion2.surface_alive
        assert lesion1.surface_dead == lesion2.surface_dead == 0.

        # 2. Set senescence, update lesion so they know they
        #    are on a senescent tissue and compare lesions
        set_properties(g, label='LeafElement', position_senescence=0.6)
        update(g,
               dt=0.,
               growth_control_model=controler,
               senescence_model=senescence_model)

        # Compute variables of interest
        l = g.property('lesions')
        l = sum(l.values(), [])
        lesion1 = l[0]
        lesion1.compute_all_surfaces()
        lesion2 = l[1]
        lesion2.compute_all_surfaces()
        # Compare the two lesions
        assert lesion2.growth_is_active == False
        assert lesion2.is_active == False
        assert lesion1.surface_alive > lesion2.surface_alive
        assert lesion2.surface_alive == 0.
        assert lesion1.surface_dead == 0.
        assert lesion2.surface_dead > 0.
        assert lesion2.surface == lesion2.surface_dead

    # Test if lesion is SPORULATING when senescence occur
    elif status == "SPORULATING":
        if model != "septoria_exchanging_rings":
            dt = 400
            set_properties(g,
                           label='LeafElement',
                           wetness=True,
                           temp=22.,
                           rain_intensity=0.)
            # Simulation to obtain a lesion in chosen status
            update(g,
                   dt=dt,
                   growth_control_model=controler,
                   senescence_model=senescence_model)
        else:
            dt = 1
            nb_steps = 400
            for i in range(0, nb_steps, dt):
                # Simulation to obtain a lesion in chosen status
                set_properties(g,
                               label='LeafElement',
                               wetness=True,
                               temp=22.,
                               rain_intensity=0.)
                update(g,
                       dt=dt,
                       growth_control_model=controler,
                       senescence_model=senescence_model)

        # 1. Compare lesions before senescence
        # Compute variables of interest
        l = g.property('lesions')
        l = sum(l.values(), [])
        lesion1 = l[0]
        lesion1.compute_all_surfaces()
        lesion2 = l[1]
        lesion2.compute_all_surfaces()
        # Compare the two lesions
        assert lesion1.status == lesion2.status == 3
        assert lesion1.surface_alive == lesion2.surface_alive
        assert lesion1.surface_dead == lesion2.surface_dead == 0.
        assert lesion1.stock_spores == lesion2.stock_spores > 0.

        # 2. Set senescence, update lesion so they know they
        #    are on a senescent tissue and compare lesions
        set_properties(g, label='LeafElement', position_senescence=0.6)
        update(g,
               dt=0.,
               growth_control_model=controler,
               senescence_model=senescence_model)

        # Compute variables of interest
        l = g.property('lesions')
        l = sum(l.values(), [])
        lesion1 = l[0]
        lesion1.compute_all_surfaces()
        lesion2 = l[1]
        lesion2.compute_all_surfaces()
        # Compare the two lesions
        assert lesion2.growth_is_active == False
        assert lesion2.is_active == True
        assert lesion1.surface_alive > lesion2.surface_alive
        assert lesion2.surface_alive > 0.
        assert lesion1.surface_dead == 0.
        assert lesion2.surface_dead > 0.
        assert lesion2.surface > lesion2.surface_dead
        assert lesion1.stock_spores == lesion2.stock_spores > 0.


# if __name__ == '__main__':
# g=test_growth_control()
Ejemplo n.º 5
0
def test_update(model="septoria_exchanging_rings"):
    """ Check if 'update' from 'protocol.py' provokes the growth of a lesion
        instantiated on the MTG.

    Generate a wheat MTG and deposit 1 lesion on a leaf element. Run a loop
    to compute update and growth. Check that all the stages of a lesion of
    septoria have been reached eventually. Check that the lesion size does
    not exceed Smax.

    Parameters
    ----------
    model: model
        One version of the model of septoria lesion among:
        'septoria_exchanging_rings', 'septoria_with_rings', 'septoria_continuous'
    """
    # Generate a wheat MTG
    g = adel_one_leaf_element()
    set_properties(g,
                   label='LeafElement',
                   area=5.,
                   green_area=5.,
                   healthy_area=5.,
                   position_senescence=None)

    # Generate a stock of septoria dispersal units and distribute it on g
    distribute_lesions(g,
                       nb_lesions=1,
                       disease_model=model,
                       initiation_model=RandomInoculation(),
                       label='LeafElement')

    # Call model of growth control
    controler = NoPriorityGrowthControl()

    # Loop of simulation
    septo_timing = TimeControl(delay=1, steps=1000)
    timer = TimeControler(disease=septo_timing)
    for t in timer:
        # print(timer.numiter)
        # After infection, the lesion 'age_dday' will be added 1 DD by time step
        # Note : base temperature for septoria = -2 degrees celsius
        set_properties(g,
                       label='LeafElement',
                       wetness=True,
                       temp=22.,
                       rain_intensity=0.)

        # Update
        update(g,
               t['disease'].dt,
               controler,
               senescence_model=None,
               label='LeafElement')

        # Check that the lesion is in the right status and has the right surface
        lesion = g.property('lesions')
        if lesion:
            assert sum(len(l) for l in lesion.itervalues()) == 1
            l = lesion.values()[0][0]
            assert l.age_dday == timer.numiter
            f = l.fungus
            print('lesion surface: %f' % round(l.surface, 6))
            if l.age_dday < 220.:
                assert l.status == 0
                assert round(l.surface, 6) < round(f.Smin, 6)
            if 220. <= l.age_dday < 330.:
                assert l.status == 1
                assert round(f.Smin, 6) <= round(l.surface, 6)
                assert round(l.surface, 6) < round(
                    f.Smin + f.growth_rate * f.degree_days_to_necrosis, 6)
            elif 330. <= l.age_dday < 350.:
                assert l.status == 2
                assert round(
                    f.Smin + f.growth_rate * f.degree_days_to_necrosis,
                    6) <= round(l.surface, 6)
                assert round(l.surface, 6) < round(
                    f.Smin + f.growth_rate *
                    (f.degree_days_to_necrosis + f.degree_days_to_sporulation),
                    6)
            elif l.age_dday >= 350.:
                assert l.status == 3
                assert round(
                    f.Smin + f.growth_rate * f.degree_days_to_sporulation,
                    6) <= round(l.surface, 6)
                assert round(l.surface, 6) <= round(l.fungus.Smax, 6)
Ejemplo n.º 6
0
def test_update(senescence_threshold=330.,
                sen_day=500.,
                model="septoria_exchanging_rings",
                **kwds):
    """ 
    """
    from alinea.alep.wheat import adel_one_leaf_element

    # Read weather and adapt it to septoria (add wetness)
    meteo_path = shared_data(alinea.septo3d, 'meteo00-01.txt')
    weather = Weather(data_file=meteo_path)
    weather.check(varnames=['wetness'], models={'wetness': wetness_rapilly})
    seq = pandas.date_range(start="2000-10-01 01:00:00",
                            end="2000-12-31 01:00:00",
                            freq='H')

    # Generate a wheat MTG
    g = adel_one_leaf_element()
    set_properties(g,
                   label='LeafElement',
                   area=5.,
                   green_area=5.,
                   healthy_area=5.,
                   position_senescence=1,
                   wetness=True,
                   temp=22.,
                   rain_intensity=0.,
                   relative_humidity=90.)

    # Generate one lesion of septoria and distribute it on g
    # septoria = new_septoria(senescence_threshold=senescence_threshold)
    septoria = plugin_septoria(model)
    Lesion = septoria.lesion(**kwds)
    leaf = g.node(10)
    leaf.lesions = [Lesion(nb_spores=1, position=[0.5, 0])]

    # Call model of growth control
    growth_controler = NoPriorityGrowthControl()
    sen_model = WheatSeptoriaPositionedSenescence(g, label='LeafElement')

    #Temp
    emitter = SeptoriaRainEmission(domain_area=0.0004)
    transporter = Septo3DSplash(reference_surface=0.0004)

    # Loop of simulation
    every_h = time_filter(seq, delay=1)
    every_rain = rain_filter(seq, weather)
    septo_timing = IterWithDelays(*time_control(seq, every_h, weather.data))
    rain_timing = IterWithDelays(*time_control(seq, every_rain, weather.data))
    surface = []
    surface_alive = []
    surface_empty = []
    nb_dus = []
    stock_spores = []
    for i, controls in enumerate(zip(septo_timing, rain_timing)):
        septo_eval, rain_eval = controls

        if i == sen_day:
            set_properties(g, label='LeafElement', position_senescence=0)
        if rain_eval:
            set_properties(g,
                           label='LeafElement',
                           rain_intensity=rain_eval.value.rain.mean(),
                           rain_duration=len(rain_eval.value.rain)
                           if rain_eval.value.rain.sum() > 0 else 0.)

        # Update healthy area
        sen_model.find_senescent_lesions(g, label='LeafElement')
        update_healthy_area(g, label='LeafElement')

        # Update
        update(g,
               septo_eval.dt,
               growth_controler,
               senescence_model=sen_model,
               label='LeafElement')

        if rain_eval:
            g, nb = disperse(g,
                             emitter,
                             transporter,
                             "septoria",
                             label='LeafElement')
        else:
            nb = 0.
        nb_dus.append(nb)

        # Check that the lesion is in the right status and has the right surface
        lesion = g.property('lesions')
        if lesion:
            assert sum(len(l) for l in lesion.itervalues()) == 1
            l = lesion.values()[0][0]
            surface.append(l.surface)
            surface_alive.append(l.surface_alive)
            surface_empty.append(l.surface_empty)
            stock_spores.append(l.stock_spores)
            # if i==299:
            # import pdb
            # pdb.set_trace()
            l.compute_all_surfaces()
            f = l.fungus
            print('lesion surface: %f' % round(l.surface, 6))

    return g, surface, surface_alive, surface_empty, nb_dus, stock_spores