Exemple #1
0
 def setUp(self):
     #
     # set logging settings
     fname = './testcomputedoubletruncatedmfd.log'
     logging.basicConfig(filename=fname, level=logging.DEBUG)
     #
     # clear directory
     folder = os.path.join(BASE_DATA_PATH, './../../tmp/project_test')
     delete_and_create_project_dir(folder)
     #
     # set environment variable
     self.prj_path = os.path.join(BASE_DATA_PATH,
                                  './../../tmp/project_test/test.oqmbtp')
     os.environ["OQMBT_PROJECT"] = self.prj_path
     #
     # create the project
     path = './../data/project.ini'
     inifile = os.path.join(BASE_DATA_PATH, path)
     project_create([inifile, os.path.dirname(self.prj_path)])
     #
     # add to the model the name of the shapefile - the path is relative to
     # the position of the project file
     oqtkp = OQtProject.load_from_file(self.prj_path)
     model_id = 'model01'
     oqtkp.active_model_id = model_id
     model = oqtkp.models[model_id]
     path = './../../data/wf01/shapefiles/test_faults.shp'
     model.faults_shp_filename = path
     oqtkp.models[model_id] = model
     oqtkp.save()
Exemple #2
0
def project_create(argv):
    """
    This creates a new `oqmbt` project

    :parameter argv:
        A list. The first argument contains the path to the folder where the
        project will be created. The second parameter is the folder (this
        overrides the `directory` parameter in the `project` section of the
        .ini file
    """
    ini_filename = argv[0]
    print('Reading project information from: \n{:s}'.format(ini_filename))
    assert os.path.exists(ini_filename)
    #
    # reading the .ini file
    config = ConfigParser(dict_type=AttrDict)
    config.read(ini_filename)
    #
    # set project dir and name
    if len(argv) > 1:
        project_dir = argv[1]
        config._sections.project.directory = project_dir
    else:
        project_dir = os.path.abspath(config._sections.project.directory)
    project_name = config._sections.project.name
    #
    # info
    print('Project directory : {:s}'.format((project_dir)))
    print('Project name      : {:s}'.format((project_name)))
    #
    # create a clean project directory
    delete_and_create_project_dir(project_dir)
    #
    # create the project
    prj = OQtProject(project_name, project_dir)
    # MN: 'project_filename' assigned but never used
    project_filename = os.path.join(project_dir, prj._get_filename())
    #
    # create default files
    create_default_files(prj, project_dir)
    #
    # add standard subfolders
    add_subfolders(project_dir)
    #
    # load information for the various models
    for key in config._sections.keys():
        #
        # search for sections containing model information
        if re.search('^model', key):
            model = load_model_info(config, key)
            prj.add_model(model)
    #
    # save the project
    prj.save()
 def setUp(self):
     #
     #
     fname = './testcomputedoubletruncatedGRfromseismicity.log'
     logging.basicConfig(filename=fname, level=logging.DEBUG)
     #
     # clear directory
     folder = os.path.join(self.BASE_DATA_PATH, './../../tmp/project_test')
     delete_and_create_project_dir(folder)
     #
     # set environment variable
     self.prj_path = os.path.join(self.BASE_DATA_PATH,
                                  './../../tmp/project_test/test.oqmbtp')
     os.environ["OQMBT_PROJECT"] = self.prj_path
     #
     # create the project
     path = './../data/project.ini'
     inifile = os.path.join(self.BASE_DATA_PATH, path)
     project_create([inifile, os.path.dirname(self.prj_path)])
     #
     # add to the model the name of the shapefile - the path is relative to
     # the position of the project file
     oqtkp = OQtProject.load_from_file(self.prj_path)
     model_id = 'model01'
     oqtkp.active_model_id = model_id
     model = oqtkp.models[model_id]
     #
     # set the shapefile with the geometry of area sources
     path = './../../notebooks/data/shapefiles/area_sources.shp'
     model.area_shapefile_filename = path
     #
     # set the catalogue name
     path = './../../notebooks/data/catalogue.csv'
     model.catalogue_csv_filename = path
     #
     # saving the project
     oqtkp.models[model_id] = model
     oqtkp.save()
Exemple #4
0
    def setUp(self):
        #
        #
        fname = './wf01.log'
        # logging.basicConfig(filename=fname, level=logging.DEBUG)
        logging.basicConfig(filename=fname, level=logging.WARN)
        #
        # clear directory where the project will be created
        folder = os.path.join(self.BASE_DATA_PATH, '..', 'tmp', 'project_test')
        delete_and_create_project_dir(folder)
        #
        # set environment variable
        self.prj_path = os.path.join(folder, 'test.oqmbtp')
        os.environ["OQMBT_PROJECT"] = self.prj_path
        #
        # create the project
        inifile = os.path.join(self.BASE_DATA_PATH, '..', 'data', 'wf01',
                               'project.ini')
        project_create([inifile, os.path.dirname(self.prj_path)])
        #
        # load the project just created
        oqtkp = OQtProject.load_from_file(self.prj_path)
        model_id = 'model01'
        oqtkp.active_model_id = model_id
        model = oqtkp.models[model_id]
        #
        # set the shapefile with the geometry of area sources [relative path
        # with origin the project folder]
        model.area_shapefile_filename = os.path.join('.', '..', '..', 'data',
                                                     'wf01', 'shapefiles',
                                                     'test_area.shp')
        #
        # set the shapefile with the geometry of fault sources [relative path
        # with origin the project folder]
        model.faults_shp_filename = os.path.join('.', '..', '..', 'data',
                                                 'wf01', 'shapefiles',
                                                 'test_faults.shp')
        #
        # set the shapefile withe the faults
        path = './../../data/wf01/shapefile/test_faults.csv'
        model.catalogue_csv_filename = path
        #
        # set the catalogue name
        path = './../../data/wf01/catalogue.csv'
        model.catalogue_csv_filename = path

        # required by imfd_double_truncated_from_slip_rate_SRC.ipynb
        model.default_bgr = 1.0

        model.strain_pickle_spatial_index_filename = (
            './../../data/wf01/strain/sample_average_strain')
        model.strain_rate_model_hdf5_filename = (
            './../../data/wf01/strain/sample_average_strain.hdf5')

        # required by compute_mo_from_strain.ipynb
        model.shear_modulus = 3.2e10

        # required by compute_mo_from_strain.ipynb
        model.coup_coef = 0.8

        # required by compute_mo_from_strain.ipynb
        model.coup_thick = 15.0

        # required by compute_mo_from_strain.ipynb
        model.strain_cell_dx = 0.250
        model.strain_cell_dy = 0.200

        # required by set_mfd_tapered_GR.ipynb
        model.m_min = 5.0

        # required by set_mfd_tapered_GR.ipynb
        model.bin_width = 0.1

        model.faults_lower_threshold_magnitude = 6.5
        model.msr = 'WC1994'
        #
        # create the hypo files - the folder hypo_depths is created by the
        # 'project_create' script
        folder = os.path.dirname(self.prj_path)
        for i in [1, 2, 3]:
            fname = 'hypo_depths-model01-{:d}.csv'.format(i)
            path = os.path.join(folder, 'hypo_depths', fname)
            f = open(path, 'w')
            f.write('depth,weight\n')
            f.write('10,0.6\n')
            f.write('20,0.4\n')
            f.close()
        model.hypo_dist_filename = 'model01_hypo_dist.hdf5'
        #
        # create the focal mechanism files
        for i in [1, 2, 3]:
            fname = 'focal_mechs-model01-{:d}.csv'.format(i)
            path = os.path.join(folder, 'focal_mechs', fname)
            f = open(path, 'w')
            f.write('strike,dip,rake,weight\n')
            f.write('0.00,90.00,0.00,1.00\n')
            f.close()
        model.nodal_plane_dist_filename = 'model01_focal_mech_dist.hdf5'
        #
        # saving the project
        oqtkp.models[model_id] = model
        oqtkp.save()