def demo_run(verbose=True, plot_dir=eqrm_filesystem.demo_plot_path,
             run_names=plot_demo_run_names):
    if verbose:
        print 'STARTING'

    plot_dir = os.path.join(plot_dir)  # Why do this?
    current_dir = os.path.abspath(os.getcwd())
    print "current_dir", current_dir
    os.chdir(plot_dir)
    if verbose:
        print 'Parameter file names = ', run_names

    for run in run_names:
        run = os.path.join(plot_dir, run)
        # loop over all the input parameter files
        #(i.e. loop over different simulations)

        if verbose:
            print '============================\n============================'
            print 'Doing ', run

        # run the EQRM with the next input parameter file
        analysis.main(run)

        if verbose:
            print 'FINISH'
    os.chdir(current_dir)
Exemple #2
0
def demo_run(verbose=True,
             plot_dir=eqrm_filesystem.demo_plot_path,
             run_names=plot_demo_run_names):
    if verbose:
        print 'STARTING'

    plot_dir = os.path.join(plot_dir)  # Why do this?
    current_dir = os.path.abspath(os.getcwd())
    print "current_dir", current_dir
    os.chdir(plot_dir)
    if verbose:
        print 'Parameter file names = ', run_names

    for run in run_names:
        run = os.path.join(plot_dir, run)
        # loop over all the input parameter files
        #(i.e. loop over different simulations)

        if verbose:
            print '============================\n============================'
            print 'Doing ', run

        # run the EQRM with the next input parameter file
        analysis.main(run)

        if verbose:
            print 'FINISH'
    os.chdir(current_dir)
Exemple #3
0
def run_scenarios(dir, file_start='plot_', extension='.py'):
    """
    Run all of the python files starting with [file_start] in a directory,.
    """

    # Make the current dir the dir this file is in.
    #known_dir, tail = os.path.split(__file__)
    # if known_dir == '':
    #  known_dir = '.'
    known_dir = os.path.abspath(dir)
    current_dir = os.getcwd()
    os.chdir(known_dir)
    plot_files = os.listdir(known_dir)
    plot_files = [x for x in plot_files if x.endswith(extension)]
    plot_files = [x for x in plot_files if 0 == string.find(x, file_start)]
    for plot_file in plot_files:
        eqrm_flags = parse_in_parameters.create_parameter_data(plot_file)
        plot_output_dir = os.path.join(eqrm_flags['output_dir'])
        files = os.listdir(plot_output_dir)
        demo_files = [x for x in files if x[-3:] == 'txt']
        # print "len(demo_files)", len(demo_files)
        if len(demo_files) <= 4:  # 4 is the magic number
            # Assume the plot data has not been created.
            # Run the plot scenario
            analysis.main(os.path.join(plot_file))
    os.chdir(current_dir)
def run_scenarios(dir, file_start='plot_', extension='.py'):
    """
    Run all of the python files starting with [file_start] in a directory,.
    """

    # Make the current dir the dir this file is in.
    #known_dir, tail = os.path.split(__file__)
    # if known_dir == '':
      #  known_dir = '.'
    known_dir = os.path.abspath(dir)
    current_dir = os.getcwd()
    os.chdir(known_dir)
    plot_files = os.listdir(known_dir)
    plot_files = [x for x in plot_files if x.endswith(extension)]
    plot_files = [x for x in plot_files if 0 == string.find(x, file_start)]
    for plot_file in plot_files:
        eqrm_flags = parse_in_parameters.create_parameter_data(plot_file)
        plot_output_dir = os.path.join(eqrm_flags['output_dir'])
        files = os.listdir(plot_output_dir)
        demo_files = [x for x in files if x[-3:] == 'txt']
        # print "len(demo_files)", len(demo_files)
        if len(demo_files) <= 4:  # 4 is the magic number
            # Assume the plot data has not been created.
            # Run the plot scenario
            analysis.main(os.path.join(plot_file))
    os.chdir(current_dir)
Exemple #5
0
    def run_trial(self, run_profile=False, use_determ_seed=True):
        """

        """

        if run_profile:
            self.run_trial_profile(run_profile=run_profile,
                                   use_determ_seed=use_determ_seed)
            memory_used = None
            time_taken_sec = None
        else:
            #Initial time and memory
            t0 = time.time()

            #m0 = None on windows
            m0 = mem_usage()

            # The main call
            main(self.scenario_name, use_determ_seed)

            time_taken_sec = (time.time() - t0)
            m1 = mem_usage()
            if m0 is None or m1 is None:
                memory_used = None
            else:
                memory_used = (m1 - m0)
        return time_taken_sec, memory_used, self.version
Exemple #6
0
def create_demo_data():
    """
    Create the demo data if it is not already there.
    """

    # Make the current dir the dir this file is in.
    known_dir, tail = os.path.split(__file__)
    if known_dir == '':
        known_dir = '.'
    known_dir = os.path.abspath(known_dir)
    os.chdir(known_dir)
    files = os.listdir(known_dir)
    plot_files = [x for x in files if x[-2:] == 'py']
    #plot_files = [x for x in plot_files if x[:12] == 'little_plot_']
    plot_files = [x for x in plot_files if x[:5] == 'plot_']
    print "plot_files", plot_files
    for plot_file in plot_files:
        THE_PARAM_T = parse_in_parameters.create_parameter_data(plot_file)
        plot_output_dir = os.path.join(THE_PARAM_T['output_dir'])
        files = os.listdir(plot_output_dir)
        demo_files = [x for x in files if x[-3:] == 'txt']
        print "len(demo_files)", len(demo_files)
        if len(demo_files) <= 4:  # 4 is the magic number
            # Assume the plot data has not been created.
            # Run the plot scenario
            analysis.main(os.path.join(plot_file))
Exemple #7
0
def create_demo_data():
    """
    Create the demo data if it is not already there.
    """
    
    # Make the current dir the dir this file is in.
    known_dir, tail = os.path.split(__file__)
    if known_dir == '':
        known_dir = '.'
    known_dir = os.path.abspath(known_dir)
    os.chdir(known_dir)
    files = os.listdir(known_dir)
    plot_files = [x for x in files if x[-2:] == 'py']
    #plot_files = [x for x in plot_files if x[:12] == 'little_plot_']
    plot_files = [x for x in plot_files if x[:5] == 'plot_']
    print "plot_files", plot_files
    for plot_file in plot_files:
        THE_PARAM_T = parse_in_parameters.create_parameter_data(plot_file)
        plot_output_dir = os.path.join(THE_PARAM_T['output_dir'])
        files = os.listdir(plot_output_dir)
        demo_files = [x for x in files if x[-3:] == 'txt']
        print "len(demo_files)", len(demo_files)
        if len(demo_files) <= 4: # 4 is the magic number
            # Assume the plot data has not been created.
            # Run the plot scenario
            analysis.main(os.path.join(plot_file))
Exemple #8
0
    def run_trial(self, run_profile=False, use_determ_seed=True):
        """

        """

        if run_profile:          
            self.run_trial_profile(run_profile=run_profile,
                              use_determ_seed=use_determ_seed)
            memory_used = None
            time_taken_sec = None
        else:
            #Initial time and memory
            t0 = time.time()
            
            #m0 = None on windows
            m0 = mem_usage()

            # The main call
            main(self.scenario_name,use_determ_seed)
            
            time_taken_sec = (time.time()-t0)
            m1 = mem_usage()
            if m0 is None or m1 is None:
                memory_used = None
            else:
                memory_used = (m1 - m0)
        return time_taken_sec, memory_used, self.version
Exemple #9
0
def run_scenarios(scenario_dir=SCENARIO_DIR, current_string=CURRENT_STRING,
                  extension='.py', files=None):
    """
    Run all of the the scenario's in the scenario_dir.

    parameters:
      scenario_dir: The path to the directory of scenarios
      current_string: Used in the timing file name
      extension: The last three characters of the scenario files.
      Bad hack to represent the file extension of the scenarios.
      Currently .py or par.

    Write timings and svn info to a file.
    """
    timings = {}
    delimiter = ','
    ofile = 'imp_test_performance.asc'
    fd = open(ofile, 'a')
    fd.write("version" + delimiter +
             "last_check_in_date" + delimiter +
             "modification_status" + delimiter +
             "scenario_file" + delimiter +
             "scenario_time" + "\n")
    files = par_files(scenario_dir, extension=extension, files=files)
    output_dirs = []
    for file in files:
        pull_path = join(scenario_dir, file)
        eqrm_flags = parse_in_parameters.create_parameter_data(pull_path)
        output_dirs.append(join(eqrm_flags['output_dir']))
        print "Running scenario", file
        # Initial time and memory
        t0 = time.clock()

        # Run the scenario
        analysis.main(pull_path, parallel_finalise=False)

        # Run post-processing (if needed)
        if eqrm_flags['save_motion']:
            postprocessing.generate_motion_csv(eqrm_flags['output_dir'],
                                               eqrm_flags['site_tag'],
                                               soil_amp=False)
            if eqrm_flags['use_amplification']:
                postprocessing.generate_motion_csv(eqrm_flags['output_dir'],
                                                   eqrm_flags['site_tag'],
                                                   soil_amp=True)

        root, ext = splitext(file)
        time_taken_sec = (time.clock() - t0)
        timings[root] = time_taken_sec
        version, date, modified = get_version()
        fd.write(str(version) + delimiter +
                 str(date) + delimiter +
                 str(modified) + delimiter +
                 str(file) + delimiter +
                 str(time_taken_sec) + "\n")
    fd.close()
    timings = Scenario_times(timings, current_string=current_string)
    return timings, output_dirs
Exemple #10
0
def run_analysis(setdata=None):

    try:
        # import main (i.e. this is basically eqrm_analysis.py)
        from eqrm_code import analysis
    except:
        raise ImportError(
            'Please edit the PYTHONPATH ' + \
            'environmental variable to point to the python_eqrm directory.')

    if setdata is not None:
        # run the EQRM with the next input parameter file
        analysis.main(setdata, reset_seed, compress_output)
Exemple #11
0
def run_analysis(setdata=None):
    
    try:
        # import main (i.e. this is basically eqrm_analysis.py)
        from eqrm_code import analysis
    except:
        raise ImportError(
            'Please edit the PYTHONPATH ' + \
            'environmental variable to point to the python_eqrm directory.')
    
    if setdata is not None:
        # run the EQRM with the next input parameter file
        analysis.main(setdata,reset_seed,compress_output)
Exemple #12
0
def run_analysis(setdata=None):
    print 'STARTING PERFORMANCE TEST'

    print 'Setdata file name = ',setdata

    if setdata is not None:
        # loop over all the input parameter files
        #(i.e. loop over different simulations)
        print '============================\n============================'
        print 'Doing ', setdata
        
        # run the EQRM with the next input parameter file
        analysis.main(setdata,reset_seed,compress_output)
        
        print 'FINISH'
    
    print 'FINISH PERFORMANCE TEST'
Exemple #13
0
def demo_run():
    print "STARTING"
    try:
        # import main (i.e. this is basically eqrm_analysis.py)
        from eqrm_code import analysis
    except:
        raise ImportError(
            "Please edit the PYTHONPATH " + "environmental variable to point to the python_eqrm directory."
        )

    # list of input parameter files to use in the batch run
    run_names = [
        # probabilistic hazard, very few events (1 attenuation model)
        "setdata_ProbHaz.py",
        # scenario ground motion (1 attenuation model)
        "setdata_ScenGM.py",
        # scenario loss simulation (1 attenuation model)
        "setdata_ScenRisk.py",
        # sceario loss simulation
        # (multiple attenuation models - not collapsed)
        "setdata_ScenRisk2.py",
        # probabilistic hazard (1 attenuation model)
        "setdata_ProbHaz.py",
        # probablistic risk (1 attenuation model)
        "setdata_ProbRisk.py",
    ]

    print "Parameter file names = ", run_names

    for run in run_names:
        # loop over all the input parameter files
        # (i.e. loop over different simulations)
        print "============================\n============================"
        print "Doing ", run
        # run the EQRM with the next input parameter file
        analysis.main(run, True, compress_output)
        print "FINISH"
Exemple #14
0
def demo_run():
    print 'STARTING'
    try:
        # import main (i.e. this is basically eqrm_analysis.py)
        from eqrm_code import analysis
    except:
        raise ImportError(
            'Please edit the PYTHONPATH ' + \
            'environmental variable to point to the python_eqrm directory.')

    # list of input parameter files to use in the batch run
    run_names = [
        # probabilistic hazard, very few events (1 attenuation model)
        'setdata_ProbHaz.py',
        # scenario ground motion (1 attenuation model)
        'setdata_ScenGM.py',
        # scenario loss simulation (1 attenuation model)
        'setdata_ScenRisk.py',
        # sceario loss simulation
        #(multiple attenuation models - not collapsed)
        'setdata_ScenRisk2.py',
        # probabilistic hazard (1 attenuation model)
        'setdata_ProbHaz.py',
        # probablistic risk (1 attenuation model)
        'setdata_ProbRisk.py',
    ]

    print 'Parameter file names = ', run_names

    for run in run_names:
        # loop over all the input parameter files
        #(i.e. loop over different simulations)
        print '============================\n============================'
        print 'Doing ', run
        # run the EQRM with the next input parameter file
        analysis.main(run, True, compress_output)
        print 'FINISH'
atten_smooth_spectral_acceleration = False
atten_log_sigma_eq_weight = 0

# Amplification
use_amplification = False
amp_variability_method = 2
amp_min_factor = 0.6
amp_max_factor = 10000

event_set_handler = 'save'

# Buildings

# Capacity Spectrum Method

# Loss

# Save
save_hazard_map = True
save_total_financial_loss = False
save_building_loss = False
save_contents_loss = False
save_motion = False
save_prob_structural_damage = None

# If this file is executed the simulation will start
# Delete all variables that are not EQRM parameters variables. 
if __name__ == '__main__':
    from eqrm_code.analysis import main
    main(locals() )
Exemple #16
0
atten_smooth_spectral_acceleration = None
atten_log_sigma_eq_weight = 0

# Amplification
use_amplification = True
amp_variability_method = None
amp_min_factor = 0.6
amp_max_factor = 10000

# Buildings

# Capacity Spectrum Method

# Loss

# Save
save_hazard_map = False
save_total_financial_loss = False
save_building_loss = False
save_contents_loss = False
save_motion = True
save_prob_structural_damage = None

file_array = False

# If this file is executed the simulation will start.
# Delete all variables that are not EQRM attributes variables.
if __name__ == '__main__':
    from eqrm_code.analysis import main
    main(locals())
Exemple #17
0
    if len(argv) > 2:
        f = argv[1]  # note argv[0] will be 'main.py'
        use_determ_seed = argv[2]
        if use_determ_seed is 'y':
            print 'RESETTING RANDOM SEED'
            use_determ_seed = True
        elif use_determ_seed is 'n':
            print 'NOT RESETTING RANDOM SEED'
            use_determ_seed = False
        else:
            raise ValueError('Input seed parameter must be y or n')
        compress_output = False
        if len(argv) > 3:
            compress_output = argv[3]
            if compress_output is 'y':
                print 'Compressing output'
                compress_output = True
            elif compress_output is 'n':
                print 'Not compressing output'
                compress_output = False
        main(f, use_determ_seed, compress_output=compress_output)
    else:
        assert len(argv) == 1
        import profile
        profile.run("main('setdata.txt',True)", 'fooprof')
        import pstats
        p = pstats.Stats('fooprof')
        p.sort_stats('cumulative').print_stats(10)
        p.sort_stats('cumulative').strip_dirs().print_callees(
            'distribution_function')
Exemple #18
0
sdp.loss_min_pga = None
sdp.loss_regional_cost_index_multiplier = None
sdp.loss_aus_contents = None

# Save
sdp.save_hazard_map = True
sdp.save_total_financial_loss = False
sdp.save_building_loss = False
sdp.save_contents_loss = False
sdp.save_motion = False
sdp.save_prob_structural_damage = None

# General
sdp.site_tag = "nat" 
sdp.return_periods = [50, 475]
sdp.use_site_indexes = True #False
sdp.site_indexes = [1]
sdp.site_db_tag = "" 
sdp.input_dir = join(sdp.eqrm_data_home(), 'test_national',
                      'EQRM_input')
sdp.output_dir = join(sdp.eqrm_data_home(), 'test_national',
                      'EQRM_output','benchmark','events_'+ \
                  str(sum(sdp.prob_number_of_events_in_zones)) + '_' + \
                  'sites_1_' + \
                  sdp.get_time_user())

# If this file is executed the simulation will start
if __name__ == '__main__':
    from eqrm_code.analysis import main
    main(sdp)