asp = 'NS'

    # modify weather 'up','down','avg'
    # runs average weather
#    wStations = ['BRW', 'LDP', 'Treeline', 'SCR', 'LW']
#    for w in wStations:
#        mpiGO_(weatherstation=w, T='avg', P='avg')

    weatherstation = 'Treeline'
    Temp = 'avg'
    Precip = 'avg'
    iteration = 1
    # Read the DEM
    (grid, elevation) = read_esri_ascii('topoDEM_{}_d100x.asc'.format(asp))
    # Representative grid    
    grid1 = rmg(5,4,5)

    # reads in the inputs
    InputFile = 'CA_veginputs_{}_{}T_{}P.txt'.format(weatherstation, Temp, Precip)
    data = txt_data_dict(InputFile)  # Create dictionary that holds the inputs

    PD_D, PD_W, Rad, Rad_PET, PET_Tree_W, PET_Shrub_W, PET_Grass_W, \
                        PET_Tree_D, PET_Shrub_D, PET_Grass_D, SM, VEG, \
                        vegca = Initialize_(data, grid, grid1, elevation)

    storms = EstimateStormsPerYear_(data)
    n = n_years * storms   # Number of storms the model will be run for

    # creates empty arrays to store data
    P, Tb, Tr, Time, CumWaterStress, VegType, VegTypeN, VegTypeE, VegTypeS, \
                        VegTypeW, PET_, Rad_Factor, EP30, PET_threshold = \
Exemple #2
0
print(name_simulation)
try:
    os.chdir(sim)
except:
    os.mkdir(sim)

## Creating folders to categorize and store plots
sim_R = sim + 'Elev/'
sim_V = sim + 'Veg/'
sim_Rnorm = sim + 'norm_Elev/'
ensure_dir(sim_R)
ensure_dir(sim_V)
ensure_dir(sim_Rnorm)

## Initialize grid
grid = rmg((1000, 1000), 2.5)  # Grid creation
# Create State Variable - R
R = np.ones(grid.number_of_cells)
#R = np.random.random(grid.number_of_cells) * 2 + \
#        (-2)*np.ones(grid.number_of_cells, dtype=float)
print('R_sum() - Initial = ', R.sum())
# Create State Variable - V
V = compose_veg_grid(grid,
                     percent_bare=0.3,
                     percent_grass=0.3,
                     percent_shrub=0.4)  # Organization is random

## Inputs
n_years = 300  # number of years to run model
plot_interval = 50  # interval at which plots are generated
# Fire Inputs
           m, n = line.split(':')
           line = f.next()
           e = line[:].strip()
           if e[0].isdigit():
               if e.find('.') != -1:
                   data1[m.strip()] = float(line[:].strip())
               else:
                   data1[m.strip()] = int(line[:].strip())
           else:
               data1[m.strip()] = line[:].strip()
    f.close()
    return data1.copy()


## Initialize domain
grid1 = rmg(100,100,5.) # Grid for Cellular Automaton modeling of plant types
grid1['node']['Elevation'] = 1700. * np.ones(grid1.number_of_nodes)
grid = rmg(5,4,5)  # Representative grid for Ecohydrology of each plant type
grid['node']['Elevation'] = 1700. * np.ones(grid.number_of_nodes)

## Initialize random plant type field
grid1['cell']['VegetationType'] = np.random.choice([0,1,2,3,4,5],grid1.number_of_cells)
## Plant types are defined as following:
# GRASS = 0; SHRUB = 1; TREE = 2; BARE = 3;
# SHRUBSEEDLING = 4; TREESEEDLING = 5

## Assign plant type for representative ecohydrologic simulations
grid['cell']['VegetationType'] = np.arange(0,6)

## Create input dictionary from text file
InputFile = 'Inputs_Vegetation_CA.txt'
This tutorial is on:
landlab/tutorials/ecohydrology/cellular_automaton_vegetation_flat_surface.ipynb

Creating a (.py) version of the same.

@author: Sai Nudurupati & Erkan Istanbulluoglu
"""

import time
import numpy as np
from landlab import RasterModelGrid as rmg
from Ecohyd_functions_flat import (txt_data_dict, Initialize_, Empty_arrays,
                                   Create_PET_lookup, Save_, Plot_)

grid1 = rmg((100, 100), spacing=(5., 5.))
grid = rmg((5, 4), spacing=(5., 5.))

InputFile = 'Inputs_Vegetation_CA_flat.txt'
data = txt_data_dict(InputFile)  # Create dictionary that holds the inputs

PD_D, PD_W, Rad, PET_Tree, PET_Shrub, PET_Grass, SM, VEG, vegca = Initialize_(
            data, grid, grid1)

n_years = 1200      # Approx number of years for model to run
# Calculate approximate number of storms per year
fraction_wet = (data['doy__end_of_monsoon']-data['doy__start_of_monsoon'])/365.
fraction_dry = 1 - fraction_wet
no_of_storms_wet = (8760 * (fraction_wet)/(data['mean_interstorm_wet'] +
                    data['mean_storm_wet']))
no_of_storms_dry = (8760 * (fraction_dry)/(data['mean_interstorm_dry'] +
landlab/tutorials/ecohydrology/cellular_automaton_vegetation_DEM.ipynb

Creating a (.py) version of the same.

@author: Sai Nudurupati & Erkan Istanbulluoglu
"""

import time
import numpy as np
from landlab.io import read_esri_ascii
from landlab import RasterModelGrid as rmg
from Ecohyd_functions_DEM import (txt_data_dict, Initialize_, Empty_arrays,
                                  Create_PET_lookup, Save_, Plot_)

(grid, elevation) = read_esri_ascii('DEM_10m.asc')  # Read the DEM
grid1 = rmg((5, 4), spacing=(5., 5.))  # Representative grid

InputFile = 'Inputs_Vegetation_CA.txt'
data = txt_data_dict(InputFile)  # Creates dictionary that holds the inputs

PD_D, PD_W, Rad, Rad_PET, PET_Tree, PET_Shrub, PET_Grass, SM, VEG, vegca = (
    Initialize_(data, grid, grid1, elevation))

n_years = 50  # Approx number of years for model to run
# Calculate approximate number of storms per year
fraction_wet = (data['doy__end_of_monsoon'] -
                data['doy__start_of_monsoon']) / 365.
fraction_dry = 1 - fraction_wet
no_of_storms_wet = (8760 * (fraction_wet) /
                    (data['mean_interstorm_wet'] + data['mean_storm_wet']))
no_of_storms_dry = (8760 * (fraction_dry) /
Exemple #6
0
def run_ecohydrology_model(grid,
                           input_data,
                           input_file,
                           synthetic_storms=True,
                           number_of_storms=None,
                           number_of_years=None,
                           first_julian_day_of_observations=0,
                           pet_method='Cosine',
                           save_files=False,
                           sim_name='Trial'):
    # Create data object by reading in the input_file
    data = load_params(input_file)
    # Create a grid that can hold enough cells to represent all individual
    # vegetation types
    grid_veg = rmg((5, 4), spacing=(5., 5.))
    if pet_method == 'Cosine':
        (precip_dry, precip_wet, radiation, pet_tree, pet_shrub, pet_grass,
         soil_moisture, vegetation,
         vegca) = initialize_components(data,
                                        grid_veg,
                                        grid,
                                        pet_method='Cosine')
    elif pet_method == 'PriestleyTaylor':
        (precip_dry, precip_wet, radiation, pet_met, soil_moisture, vegetation,
         vegca) = initialize_components(data,
                                        grid_veg,
                                        grid,
                                        pet_method='PriestleyTaylor')

    if number_of_years != None:
        # Calculate approximate number of storms per year
        fraction_wet = (
            (data['doy__end_of_monsoon'] - data['doy__start_of_monsoon']) /
            365.)
        fraction_dry = (1 - fraction_wet)
        number_of_storms_wet = (
            8760 * (fraction_wet) /
            (data['mean_interstorm_wet'] + data['mean_storm_wet']))
        number_of_storms_dry = (
            8760 * (fraction_dry) /
            (data['mean_interstorm_dry'] + data['mean_storm_dry']))
        number_of_storms = int(number_of_years *
                               (number_of_storms_wet + number_of_storms_dry))

    (precip, inter_storm_dt, storm_dt, Time, VegType, pet_arr, Rad_Factor,
     Rad_Factor_met, EP30, EP30_met,
     pet_threshold) = create_empty_arrays(number_of_storms,
                                          grid_veg,
                                          grid,
                                          pet_method=pet_method)

    if pet_method == 'Cosine':
        (pet_arr, EP30) = create_pet_lookup(grid_veg,
                                            radiation=radiation,
                                            Rad_Factor=Rad_Factor,
                                            EP30=EP30,
                                            pet_tree=pet_tree,
                                            pet_shrub=pet_shrub,
                                            pet_grass=pet_grass,
                                            pet_arr=pet_arr)
    if pet_method == 'PriestleyTaylor':
        (pet_arr, EP30_met) = create_pet_lookup(
            grid_veg,
            radiation=radiation,
            Rad_Factor_met=Rad_Factor_met,
            number_of_storms=number_of_storms,
            pet_met=pet_met,
            Tmax_met=input_data['Tmax_met'],
            Tmin_met=input_data['Tmin_met'],
            EP30_met=EP30_met,
            first_day=first_julian_day_of_observations,
            pet_method=pet_method,
            pet_arr=pet_arr)

    # declaring few variables that will be used in the storm loop
    current_time = first_julian_day_of_observations / 365.25  # Initial time
    time_check = 0.  # Buffer to store current_time at previous storm
    yrs = 0  # Keep track of number of years passed
    water_stress = 0.  # Buffer for Water Stress
    Tg = 0  # Growing season in days

    # # Run storm Loop
    for i in range(0, number_of_storms):
        # Update objects

        # Calculate Day of Year (DOY)
        julian = np.int(
            np.floor((current_time - np.floor(current_time)) * 365.))
        if synthetic_storms:
            # Generate seasonal storms
            # for Dry season
            if julian < data['doy__start_of_monsoon'] or julian > data[
                    'doy__end_of_monsoon']:
                precip_dry.update()
                precip[i] = precip_dry.storm_depth
                storm_dt[i] = precip_dry.storm_duration
                inter_storm_dt[i] = precip_dry.interstorm_duration
            # Wet Season - Jul to Sep - NA Monsoon
            else:
                precip_wet.update()
                precip[i] = precip_wet.storm_depth
                storm_dt[i] = precip_wet.storm_duration
                inter_storm_dt[i] = precip_wet.interstorm_duration
        else:
            precip[i] = input_data['precip_met'][i]
            storm_dt[i] = 0.
            inter_storm_dt[i] = 24.

        # Spatially distribute PET and its 30-day-mean (analogous to degree day)
        if pet_method == 'Cosine':
            grid_veg.at_cell['surface__potential_evapotranspiration_rate'] = (
                pet_arr[julian])
            grid_veg.at_cell[
                'surface__potential_evapotranspiration_30day_mean'] = (
                    EP30[julian])
            grid_veg.at_cell[
                'surface__potential_evapotranspiration_rate__grass'] = (
                    np.full(grid_veg.number_of_cells, pet_arr[julian, 0]))
        elif pet_method == 'PriestleyTaylor':
            grid_veg.at_cell['surface__potential_evapotranspiration_rate'] = (
                pet_arr[i])
            grid_veg.at_cell[
                'surface__potential_evapotranspiration_30day_mean'] = (
                    EP30_met[i])
            grid_veg.at_cell[
                'surface__potential_evapotranspiration_rate__grass'] = (
                    np.full(grid_veg.number_of_cells, pet_arr[i, 0]))

        # Assign spatial rainfall data
        grid_veg.at_cell['rainfall__daily_depth'] = (np.full(
            grid_veg.number_of_cells, precip[i]))

        # Update soil moisture component
        current_time = soil_moisture.update(current_time,
                                            Tr=storm_dt[i],
                                            Tb=inter_storm_dt[i])

        # Decide whether its growing season or not
        if pet_method == 'Cosine':
            if julian != 364:
                if EP30[julian + 1, 0] > EP30[julian, 0]:
                    pet_threshold = 1
                    # 1 corresponds to ETThresholdup (begin growing season)
                    if EP30[julian, 0] > vegetation._ETthresholdup:
                        growing_season = True
                    else:
                        growing_season = False
                else:
                    pet_threshold = 0
                    # 0 corresponds to ETThresholddown (end growing season)
                    if EP30[julian, 0] > vegetation._ETthresholddown:
                        growing_season = True
                    else:
                        growing_season = False
        elif pet_method == 'PriestleyTaylor':
            if i != number_of_storms - 1:
                if EP30_met[i + 1, 0] > EP30_met[i, 0]:
                    pet_threshold = 1
                    # 1 corresponds to ETThresholdup (begin growing season)
                    if EP30_met[i, 0] > vegetation._ETthresholdup:
                        growing_season = True
                    else:
                        growing_season = False
                else:
                    pet_threshold = 0
                    # 0 corresponds to ETThresholddown (end growing season)
                    if EP30_met[i, 0] > vegetation._ETthresholddown:
                        growing_season = True
                    else:
                        growing_season = False

        # Update vegetation component
        vegetation.update(PETThreshold_switch=pet_threshold,
                          Tb=inter_storm_dt[i],
                          Tr=storm_dt[i])

        if growing_season:
            # Update yearly cumulative water stress data
            Tg += (storm_dt[i] + inter_storm_dt[i]
                   ) / 24.  # Incrementing growing season storm count
            water_stress += ((grid_veg.at_cell['vegetation__water_stress']) *
                             inter_storm_dt[i] / 24.)

        # Record time (optional)
        Time[i] = current_time

        # Update spatial PFTs with Cellular Automata rules
        if (current_time - time_check) >= 1.:
            if yrs % 100 == 0:
                print('Elapsed time = ', yrs, ' years')
            VegType[yrs] = grid.at_cell['vegetation__plant_functional_type']
            WS_ = np.choose(VegType[yrs], water_stress)
            grid.at_cell['vegetation__cumulative_water_stress'] = WS_ / Tg
            vegca.update()
            time_check = np.floor(current_time)
            water_stress = 0
            yrs += 1
            Tg = 0

    VegType[yrs] = grid.at_cell['vegetation__plant_functional_type']
    if save_files:
        save_data(sim_name, inter_storm_dt, storm_dt, precip, VegType, yrs, 0,
                  Time)
    if pet_method == 'Cosine':
        returns_debug = [
            grid_veg, precip_dry, precip_wet, radiation, pet_tree, pet_shrub,
            pet_grass, soil_moisture, vegetation, vegca
        ]

    elif pet_method == 'PriestleyTaylor':
        returns_debug = [
            grid_veg, precip_dry, precip_wet, radiation, pet_met,
            soil_moisture, vegetation, vegca
        ]
    return (VegType, yrs - 1, returns_debug)
               data1[m.strip()] = line[:].strip()
    f.close()
    return data1.copy()


## Point to the input DEM
_DEFAULT_INPUT_FILE_1 = os.path.join(os.path.dirname(__file__),
                                 'DEM_10m.asc')

InputFile = 'Inputs_Vegetation_CA.txt'
data = txt_data_dict( InputFile ) # Create dictionary that holds the inputs

## Importing Grid and Elevations from DEM
(grid1,elevation) = read_esri_ascii(_DEFAULT_INPUT_FILE_1)
grid1['node']['Elevation'] = elevation
grid = rmg(5,4,5)
grid['node']['Elevation'] = 1700. * np.ones(grid.number_of_nodes)
grid1['cell']['VegetationType'] = np.random.randint(0,4,grid1.number_of_cells)
# Age of the plants is randomnly generated by the constructor of vegca
# component. Seedlings of shrubs and trees are determined by their age
# within the constructor as well. Hence the random vegetation type
# field is called for types GRASS, SHRUB, TREE and BARE only. -SN 10Mar15

grid['cell']['VegetationType'] = np.arange(0,6)

# Create radiation, soil moisture and Vegetation objects
PD_D = PrecipitationDistribution(mean_storm = data['mean_storm_dry'],  \
                    mean_interstorm = data['mean_interstorm_dry'],
                    mean_storm_depth = data['mean_storm_depth_dry'])
PD_W = PrecipitationDistribution(mean_storm = data['mean_storm_wet'],  \
                    mean_interstorm = data['mean_interstorm_wet'],
                                 'DEM_10m.asc')
## Point to the input elevation file
_DEFAULT_INPUT_FILE_2 = os.path.join(os.path.dirname(__file__),
                                 'elevation_NS.npy')

InputFile = 'Inputs_Vegetation_CA.txt'
data = txt_data_dict( InputFile ) # Create dictionary that holds the inputs

USE_DEM = 1    # Make this 0 to use a custom grid
if USE_DEM == 1:
    ## Importing Grid and Elevations from DEM
    (grid,elevation) = read_esri_ascii(_DEFAULT_INPUT_FILE_1)
    grid['node']['Elevation'] = elevation
else:
    ## Use an open book like grid - custom grid
    grid = rmg(53,67,10.)
    elev = np.load(_DEFAULT_INPUT_FILE_2)
    grid['node']['Elevation'] = elev
grid['cell']['VegetationType'] = np.random.randint(0,4,grid.number_of_cells)
# Age of the plants is randomnly generated by the constructor of vegca
# component. Seedlings of shrubs and trees are determined by their age
# within the constructor as well. Hence the random vegetation type
# field is called for types GRASS, SHRUB, TREE and BARE only. -SN 10Mar15

# Dummy grid for PET
grid1 = rmg(5,4,5)
grid1['node']['Elevation'] = 1700. * np.ones(grid1.number_of_nodes)
grid1['cell']['VegetationType'] = np.arange(0,6)
# Create radiation, soil moisture and Vegetation objects
PD_D = PrecipitationDistribution(mean_storm = data['mean_storm_dry'],  \
                    mean_interstorm = data['mean_interstorm_dry'],
Exemple #9
0
            else:
                data1[m.strip()] = line[:].strip()
    f.close()
    return data1.copy()


## Point to the input DEM
_DEFAULT_INPUT_FILE_1 = os.path.join(os.path.dirname(__file__), 'DEM_10m.asc')

InputFile = 'Inputs_Vegetation_CA.txt'
data = txt_data_dict(InputFile)  # Create dictionary that holds the inputs

## Importing Grid and Elevations from DEM
(grid1, elevation) = read_esri_ascii(_DEFAULT_INPUT_FILE_1)
grid1['node']['Elevation'] = elevation
grid = rmg(5, 4, 5)
grid['node']['Elevation'] = 1700. * np.ones(grid.number_of_nodes)
grid1['cell']['VegetationType'] = np.random.randint(0, 4,
                                                    grid1.number_of_cells)
# Age of the plants is randomnly generated by the constructor of vegca
# component. Seedlings of shrubs and trees are determined by their age
# within the constructor as well. Hence the random vegetation type
# field is called for types GRASS, SHRUB, TREE and BARE only. -SN 10Mar15

grid['cell']['VegetationType'] = np.arange(0, 6)

# Create radiation, soil moisture and Vegetation objects
PD_D = PrecipitationDistribution(mean_storm = data['mean_storm_dry'],  \
                    mean_interstorm = data['mean_interstorm_dry'],
                    mean_storm_depth = data['mean_storm_depth_dry'])
PD_W = PrecipitationDistribution(mean_storm = data['mean_storm_wet'],  \
Exemple #10
0
This tutorial is on:
landlab/tutorials/ecohydrology/cellular_automaton_vegetation_flat_surface.ipynb

Creating a (.py) version of the same.

@author: Sai Nudurupati & Erkan Istanbulluoglu
"""

import time
import numpy as np
from landlab import RasterModelGrid as rmg
from Ecohyd_functions_flat import (txt_data_dict, Initialize_, Empty_arrays,
                                   Create_PET_lookup, Save_, Plot_)

grid1 = rmg((100, 100), spacing=(5., 5.))
grid = rmg((5, 4), spacing=(5., 5.))

InputFile = 'Inputs_Vegetation_CA.txt'
data = txt_data_dict(InputFile)  # Create dictionary that holds the inputs

PD_D, PD_W, Rad, PET_Tree, PET_Shrub, PET_Grass, SM, VEG, vegca = Initialize_(
    data, grid, grid1)

n_years = 1200  # Approx number of years for model to run
# Calculate approximate number of storms per year
fraction_wet = (data['doy__end_of_monsoon'] -
                data['doy__start_of_monsoon']) / 365.
fraction_dry = 1 - fraction_wet
no_of_storms_wet = (8760 * (fraction_wet) /
                    (data['mean_interstorm_wet'] + data['mean_storm_wet']))
import matplotlib as mpl
import matplotlib.pyplot as plt

## Point to the input DEM
_DEFAULT_INPUT_FILE_1 = os.path.join(os.path.dirname(__file__), 'DEM_10m.asc')
## Point to the input elevation file
_DEFAULT_INPUT_FILE_2 = os.path.join(os.path.dirname(__file__),
                                     'elevation_NS.npy')
USE_DEM = 1  # Make this 0 to use a custom grid
if USE_DEM == 1:
    ## Importing Grid and Elevations from DEM
    (grid, elevation) = read_esri_ascii(_DEFAULT_INPUT_FILE_1)
    grid['node']['Elevation'] = elevation
else:
    ## Use an open book like grid - custom grid
    grid = rmg(53, 67, 10.)
    elev = np.load(_DEFAULT_INPUT_FILE_2)
    grid['node']['Elevation'] = elev

sim = 'long_DEM_'
CumWaterStress = np.load(sim + 'CumWaterStress.npy')
P = np.load(sim + 'P.npy')
Tb = np.load(sim + 'Tb.npy')
Tr = np.load(sim + 'Tr.npy')
yrs = np.load(sim + 'Years.npy')
VegType = np.load(sim + 'VegType.npy')

n = P.shape[0]  # Number of iterations
Time = np.empty(n)
Time[0] = 0
for x in range(1, n):
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

## Point to the input DEM
_DEFAULT_INPUT_FILE_1 = os.path.join(os.path.dirname(__file__), "DEM_10m.asc")
## Point to the input elevation file
_DEFAULT_INPUT_FILE_2 = os.path.join(os.path.dirname(__file__), "elevation_NS.npy")
USE_DEM = 1  # Make this 0 to use a custom grid
if USE_DEM == 1:
    ## Importing Grid and Elevations from DEM
    (grid, elevation) = read_esri_ascii(_DEFAULT_INPUT_FILE_1)
    grid["node"]["Elevation"] = elevation
else:
    ## Use an open book like grid - custom grid
    grid = rmg(53, 67, 10.0)
    elev = np.load(_DEFAULT_INPUT_FILE_2)
    grid["node"]["Elevation"] = elev

sim = "long_DEM_"
CumWaterStress = np.load(sim + "CumWaterStress.npy")
P = np.load(sim + "P.npy")
Tb = np.load(sim + "Tb.npy")
Tr = np.load(sim + "Tr.npy")
yrs = np.load(sim + "Years.npy")
VegType = np.load(sim + "VegType.npy")

n = P.shape[0]  # Number of iterations
Time = np.empty(n)
Time[0] = 0
for x in range(1, n):
landlab/tutorials/ecohydrology/cellular_automaton_vegetation_DEM.ipynb

Creating a (.py) version of the same.

@author: Sai Nudurupati & Erkan Istanbulluoglu
"""

import time
import numpy as np
from landlab.io import read_esri_ascii
from landlab import RasterModelGrid as rmg
from Ecohyd_functions_DEM import (txt_data_dict, Initialize_, Empty_arrays,
                                  Create_PET_lookup, Save_, Plot_)

(grid, elevation) = read_esri_ascii('DEM_10m.asc')    # Read the DEM
grid1 = rmg((5, 4), spacing=(5., 5.))                 # Representative grid

InputFile = 'Inputs_Vegetation_CA_DEM.txt'
data = txt_data_dict(InputFile)  # Creates dictionary that holds the inputs

PD_D, PD_W, Rad, Rad_PET, PET_Tree, PET_Shrub, PET_Grass, SM, VEG, vegca = (
                Initialize_(data, grid, grid1, elevation))

n_years = 50       # Approx number of years for model to run
# Calculate approximate number of storms per year
fraction_wet = (data['doy__end_of_monsoon']-data['doy__start_of_monsoon'])/365.
fraction_dry = 1 - fraction_wet
no_of_storms_wet = (8760 * (fraction_wet)/(data['mean_interstorm_wet'] +
                    data['mean_storm_wet']))
no_of_storms_dry = (8760 * (fraction_dry)/(data['mean_interstorm_dry'] +
                    data['mean_storm_dry']))
            m, n = line.split(':')
            line = f.next()
            e = line[:].strip()
            if e[0].isdigit():
                if e.find('.') != -1:
                    data1[m.strip()] = float(line[:].strip())
                else:
                    data1[m.strip()] = int(line[:].strip())
            else:
                data1[m.strip()] = line[:].strip()
    f.close()
    return data1.copy()


## Initialize domain
grid1 = rmg(100, 100,
            5.)  # Grid for Cellular Automaton modeling of plant types
grid1['node']['Elevation'] = 1700. * np.ones(grid1.number_of_nodes)
grid = rmg(5, 4, 5)  # Representative grid for Ecohydrology of each plant type
grid['node']['Elevation'] = 1700. * np.ones(grid.number_of_nodes)

## Initialize random plant type field
grid1['cell']['VegetationType'] = np.random.choice([0, 1, 2, 3, 4, 5],
                                                   grid1.number_of_cells)
## Plant types are defined as following:
# GRASS = 0; SHRUB = 1; TREE = 2; BARE = 3;
# SHRUBSEEDLING = 4; TREESEEDLING = 5

## Assign plant type for representative ecohydrologic simulations
grid['cell']['VegetationType'] = np.arange(0, 6)

## Create input dictionary from text file
from landlab.plot import imshow_grid
from landlab.plot import channel_profile as prf
from landlab.components.uniform_precip import PrecipitationDistribution
from matplotlib.pyplot import loglog
import matplotlib as mpl

#construct a 2D numerical model on a raster grid
#erosional degradation of a karst sinkhole
#randomly generate rain onto the grid
#evolves from downhole vertical movement of aqueous carbonate rock and hole radially widens
#downhole vert movement and hole widening proportional water input (w carbonic acid) * transport coefficient
#should make a 3d conical shape

######## model the sinkhole development in plan view and cross section ##################################

mg = rmg((40, 40),
         1.0)  #master grid with 40 rows, 40 columns, grid spacing of 1m

z = mg.add_zeros('node', 'Plan view topography')  #call function add zeros

# make plan view sinkhole trace by equation of a circle line (x-h)**2 + (y-k)**2 = r**2
# h,k represents the coordinates of the center of the circle. r is radius
r = 5  #[m]
h = 20
k = 20
sinkhole_trace_y_upper = (((r**2) - (
    (mg.x_of_node - h)**2))**0.5) + k  # half circle upper eq
sinkhole_trace_y_lower = (-1 * (((r**2) - (
    (mg.x_of_node - h)**2))**0.5)) + k  # half circle lower eq

# outside of the sinkhole trace, the ground is moving up relative to the sinkhole
sinkdown_nodes1 = np.where(mg.y_of_node < sinkhole_trace_y_upper)
Exemple #16
0
_DEFAULT_INPUT_FILE_1 = os.path.join(os.path.dirname(__file__), 'DEM_10m.asc')
## Point to the input elevation file
_DEFAULT_INPUT_FILE_2 = os.path.join(os.path.dirname(__file__),
                                     'elevation_NS.npy')

InputFile = 'Inputs_Vegetation_CA.txt'
data = txt_data_dict(InputFile)  # Create dictionary that holds the inputs

USE_DEM = 1  # Make this 0 to use a custom grid
if USE_DEM == 1:
    ## Importing Grid and Elevations from DEM
    (grid, elevation) = read_esri_ascii(_DEFAULT_INPUT_FILE_1)
    grid['node']['Elevation'] = elevation
else:
    ## Use an open book like grid - custom grid
    grid = rmg(53, 67, 10.)
    elev = np.load(_DEFAULT_INPUT_FILE_2)
    grid['node']['Elevation'] = elev
grid['cell']['VegetationType'] = np.random.randint(0, 4, grid.number_of_cells)
# Age of the plants is randomnly generated by the constructor of vegca
# component. Seedlings of shrubs and trees are determined by their age
# within the constructor as well. Hence the random vegetation type
# field is called for types GRASS, SHRUB, TREE and BARE only. -SN 10Mar15

# Dummy grid for PET
grid1 = rmg(5, 4, 5)
grid1['node']['Elevation'] = 1700. * np.ones(grid1.number_of_nodes)
grid1['cell']['VegetationType'] = np.arange(0, 6)
# Create radiation, soil moisture and Vegetation objects
PD_D = PrecipitationDistribution(mean_storm = data['mean_storm_dry'],  \
                    mean_interstorm = data['mean_interstorm_dry'],