Example #1
0
def bobs_erode_test( driver_port_name='LEM',
                     cfg_prefix=None, cfg_directory=None,
                     time_interp_method='Linear'):

    #-------------------------------------------------------
    # (2/6/13) Since the framework runs the clock now, do
    # we still need to specify a "driver_port" ??
    # Might still be necessary for use in CSDMS framework.
    #-------------------------------------------------------
    f = emeli.framework()
    examples_dir = emeli.paths['examples']
    ## examples_dir = f.paths['examples']   
    
    #--------------------
    # Default arguments
    #--------------------
    if (cfg_prefix is None):
        cfg_prefix = 'Erode_Test_LCP'
    if (cfg_directory is None):
        cfg_directory = os.getenv("HOME") + '/Erode_Tests/Bob_LCP/'
        ## cfg_directory = '~/Erode_Tests/Bob_LCP/'  # (doesn't work)
           
    #------------------------------
    # Run the full TopoFlow model
    #------------------------------
    f.run_model( driver_port_name=driver_port_name,
                 cfg_prefix=cfg_prefix,
                 cfg_directory=cfg_directory,
                 time_interp_method=time_interp_method )
Example #2
0
def topoflow_test( driver_port_name='hydro_model',
                   cfg_prefix=None, cfg_directory=None,
                   time_interp_method='Linear'):

    #-----------------------------------------------------
    # Note: The "driver_port_name" defaults to using a
    #       component of "hydro_model" type as the driver.
    #       The component of this type specified in the
    #       provider_file will be the driver component.
    #
    #       Any other component in the provider_file can
    #       also be used as the driver.  Examples are:
    #          meteorology
    #          channels
    #          snow
    #          satzone
    #          evap
    #          infil
    #          diversions
    #          ice
    #-----------------------------------------------------

    #-------------------------------------------------------
    # (2/6/13) Since the framework runs the clock now, do
    # we still need to specify a "driver_port" ??
    # Might still be necessary for use in CSDMS framework.
    #-------------------------------------------------------
    f = emeli.framework()
    examples_dir = emeli.paths['examples']
    ## examples_dir = f.paths['examples']
    
    #--------------------
    # Default arguments
    #--------------------
    if (cfg_prefix is None):
        cfg_prefix = 'June_20_67'
    if (cfg_directory is None):
        cfg_directory = examples_dir + 'Treynor_Iowa/'
    
    #------------------------------
    # Run the full TopoFlow model
    #------------------------------
    f.run_model( driver_port_name=driver_port_name,
                 cfg_prefix=cfg_prefix,
                 cfg_directory=cfg_directory,
                 time_interp_method=time_interp_method )
Example #3
0
def erode_test( cfg_prefix=None, cfg_directory=None,
                time_interp_method='Linear'):
         
    f = emeli.framework()
    driver_port_name = 'LEM'
    examples_dir = emeli.paths['examples']
    ## examples_dir = f.paths['examples']

    #--------------------
    # Default arguments
    #--------------------
    if (cfg_prefix is None):
        cfg_prefix = 'Test'
    if (cfg_directory is None):
        cfg_directory = examples_dir + 'Erode_Test/'

    #----------------------
    # Run the Erode model
    #----------------------   
    f.run_model( driver_port_name=driver_port_name,
                 cfg_prefix=cfg_prefix,
                 cfg_directory=cfg_directory,
                 time_interp_method=time_interp_method )
Example #4
0
def framework_test2():

    f = emeli.framework()
    examples_dir = emeli.paths['examples']
    ## examples_dir = f.paths['examples']    
    ## driver_port_name = 'hydro_model'  # (TopoFlow Driver test)

    f.read_repository( SILENT=False )

    #-----------------------------------------
    # Set the working directory for test run
    #-----------------------------------------
    f.cfg_directory = examples_dir + 'Treynor_Iowa/'
    f.cfg_prefix = 'June_20_67'  # (needed by initialize())
        
    print 'Components in repository:'
    for comp_name in f.repo_list:
        print '   ' + comp_name
    print ' '
 
    #-----------------------------------------------------
    # Set self.comp_set_list and self.provider_list
    # from info in the provider file.
    #-----------------------------------------------------
    filename = (f.cfg_prefix + '_providers.txt')
    f.provider_file = (f.cfg_directory + filename)
    f.read_provider_file()
    
    #--------------------------------------------
    # Instantiate a complete set of components.
    #--------------------------------------------
    # Now the instantiate() method only allows
    # one component of each "type" (port_name).
    #--------------------------------------------    
    for comp_name in f.comp_set_list:
        f.instantiate( comp_name, SILENT=False )

    #---------------------------------------------
    # Try to automatically connect every user to
    # a corresponding provider in the comp_set.
    #---------------------------------------------------
    # Provider components are initialized in the order
    # of provider_list and then set references in each
    # component that uses one or more of their vars.
    #---------------------------------------------------
    OK = f.initialize_and_connect_comp_set( REPORT=True )
    if not(OK):
        return
    
    #------------------------------------------------
    # Call update() for each provider, in order.
    # Don't worry about reconciling time steps yet.
    #------------------------------------------------
    print ' '
    # f.update_all()  # (not ordered)

##    for k in xrange(10):
##        for port_name in f.provider_list:
##            print 'Calling update() for port_name =', port_name
##            if (port_name != 'hydro_model'):
##                bmi = f.comp_set[ port_name ]
##                bmi.update( -1.0 )
            
    #----------------------------------------------
    # Call the driver component's "update" method
    #----------------------------------------------
##    print ' '
##    print "Calling driver's update() method..."
##    f.update( 'hydro_model' )
    
    #----------------
    # Final message
    #----------------
    print 'Finished with framework_test2.'
    print ' '
Example #5
0
def framework_test1():

    f = emeli.framework()
    examples_dir = emeli.paths['examples']
    ## examples_dir = f.paths['examples']
    ## driver_port_name = 'hydro_model'  # (TopoFlow Driver test)

    #-----------------------------------------
    # Set the working directory for test run
    #-----------------------------------------
    f.cfg_directory = examples_dir + 'Treynor_Iowa/'
    f.cfg_prefix = 'June_20_67'
    
    f.read_repository( SILENT=False )  
    print 'Components in repository:'
    for comp_name in f.repo_list:
        print '   ' + comp_name
    print ' '

    tf_comp_info = f.comp_info[ 'topoflow_driver' ]  
    print 'Checking some info for "topoflow_driver":'
    print '    comp_name  =', tf_comp_info.comp_name
    print '    model_name =', tf_comp_info.model_name
    print '    uses_ports =', tf_comp_info.uses_ports
    print ' '

    #--------------------------------------------
    # Instantiate a complete set of components.
    #--------------------------------------------
    # Now the instantiate() method only allows
    # one component of each "type" (port_name).
    #--------------------------------------------
    comp_list = ['tf_meteorology', 
                 'tf_channels_kin_wave',
                 'tf_infil_green_ampt',
                 'tf_evap_priestley_taylor',
                 'tf_snow_degree_day',
                 'tf_ice_gc2d',
                 'tf_satzone_darcy_layers',
                 'tf_diversions_fraction_method',
                 'topoflow_driver' ]
    for comp_name in comp_list:
        f.instantiate( comp_name, SILENT=False )
    print ' '
    print 'ALL_PYTHON =', f.ALL_PYTHON
    print ' '

    #------------------------------------------
    # Check if all uses ports have a provider
    #------------------------------------------
    COMPLETE = f.comp_set_complete( SILENT=False, REPORT=True )
    
    #------------------------------------------------------
    # Try to instantiate another with port_name == snow.
    # It should issue an error message.
    # Also, Treynor_Iowa doesn't have this CFG file yet.
    #------------------------------------------------------
    f.instantiate( 'tf_snow_energy_balance', SILENT=False )

    #------------------------------------------------
    # Remove existing snow component and try again.
    #------------------------------------------------
    f.remove( 'tf_snow_degree_day', SILENT=False )
    f.instantiate( 'tf_snow_energy_balance', SILENT=False )
    
    #-----------------------------------
    # Instantiate all components and
    # store instances in self.comp_set.
    #-----------------------------------
##    skip_list = ['tf_data_his', 'erode_d8_global',
##                 'erode_d8_local', 'd8_global', 'dem_smoother']
##    for comp_name in f.repo_list:
##        if (comp_name not in skip_list):
##            f.instantiate( comp_name )
##            print 'Instantiated component named:', comp_name
##    print ' '
    #-------------------------------------------------------------
##    try:
##        for comp_name in f.repo_list:
##            f.instantiate( comp_name )
##            print 'Instantiated component named:', comp_name
##    except:
##        print 'ERROR: Could not instantiate component.'
##    print ' '
 
    #-----------------------------
    # Initialize some components
    #-------------------------------------------------------------
    # (3/15/12) The TopoFlow components currently call a method:
    # "initialize_required_components()" that in turn calls:
    # "initialize_ports()", inherited from CSDMS_base.py.
    # But this won't be done with the new approach.
    #-------------------------------------------------------------
    ## cfg_file = None
    ## f.initialize( 'meteorology', cfg_file )
    f.initialize( 'meteorology' )
    print 'Initialized component of type: meteorology.'
    ## f.initialize( 'snow', cfg_file)
    f.initialize( 'snow' )
    print 'Initialized component of type: snow.'   
    print ' '

    #--------------------------------------------
    # Copy references from Meteorology to Snow.
    #--------------------------------------------
    print 'Copying references from Meteorology to Snow component...'
    provider_name = 'meteorology'
    user_name     = 'snow'
    var_name_list = ['atmosphere_bottom_air__temperature',
                     'land_surface__temperature',
                     'land_surface_net-total-energy__energy_flux',
                     'water-liquid__mass-per-volume_density' ]

    for long_var_name in var_name_list:
        f.connect( provider_name, user_name,
                   long_var_name )
    
    #--------------------------------------------
    # Copy references from Snow to Meteorology.
    #--------------------------------------------
    print 'Copying references from Snow to Meteorology component...'
    provider_name = 'snow'
    user_name     = 'meteorology'
    var_name_list = [ 'snowpack__depth',
                      'snowpack__liquid-equivalent_depth',
                      'snowpack__melt_volume_flux',
                      'snowpack__z_mean_of_mass-per-volume_density']
    for long_var_name in var_name_list:
        f.connect( provider_name, user_name,
                   long_var_name )

    #---------------------------------------
    # Check whether the references worked.
    #---------------------------------------
    snow_comp = f.comp_set['snow']
    met_comp  = f.comp_set['meteorology']
    print ' '
    print 'From meteorology, snow got: density of water =', \
          snow_comp.rho_H2O
          ### snow_comp.met_vars.rho_H2O
    print 'From snow, meteorology got: density of snow  =', \
          met_comp.rho_snow
          ### met_comp.snow_vars.rho_snow
    
    #----------------
    # Final message
    #----------------
    print 'Finished with framework_test1.'
    print ' '