def main(argv):
    """
    Process the original hazard curves. The required input information is
    described in the header of the `process_maps` function.
    """
    p = sap.Script(process_maps)
    #
    # Logging
    logging.basicConfig(format='%(asctime)s %(message)s', level=logging.ERROR)
    #
    # Settings
    p.arg(name='contacts_shp', help='Name of shapefile with contacts')
    p.arg(name='outpath', help='Output folder')
    p.arg(name='datafolder', help='Folder with the mosaic repository')
    p.arg(name='sidx_fname', help='Rtree spatial index file with ref. grid')
    p.arg(name='boundaries_shp', help='Name of shapefile with boundaries')
    p.arg(name='imt_str', help='String with the intensity measure type')
    p.arg(name='inland_shp', help='Name of shapefile with inland territories')
    p.opt(name='models_list', help='List of models to be processed')
    #
    # Processing
    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 2
0
 def test_ok(self):
     p = sap.Script(f)
     p.arg('a', 'first argument')
     p.opt('b', 'second argument')
     p.flg('c', 'third argument')
     p.opt('d', 'fourth argument')
     self.assertEqual(
         ['1', '2', False, '3'], p.callfunc('1 -b=2 -d=3'.split()))
Ejemplo n.º 3
0
def main(argv):

    p = sap.Script(parse)
    p.arg(name='json_fname', help='Name of the .json filename')
    p.opt(name='output_path', help='Output path')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 4
0
def main(argv):

    p = sap.Script(filter_gcmt)
    p.arg(name='ndf_fname', help='Name of the file with .ndk format')
    p.arg(name='limits', help='A list with: lomin, lomax, lamin, lamax')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 5
0
def main(argv):
    """
    """
    p = sap.Script(check)
    p.arg(name='fname', help='TR hdf5 filename')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 6
0
def runner(argv):

    p = sap.Script(complex_fault_src_from_edges)
    p.arg(name='edges_folder', help='Name of the folder containing the edges')
    p.arg(name='out_nrml', help='Name of the output file')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 7
0
def main(argv):
    p = sap.Script(create)
    p.arg(name='label', help='TR label')
    p.arg(name='rupture_hdf5_fname', help='hdf5 file with the ruptures')
    p.arg(name='output_folder', help='Name of the output folder')
    p.arg(name='investigation_t', help='Investigation time')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 8
0
def main(argv):

    p = sap.Script(calculate_ruptures)
    p.arg(name='ini_fname', help='.ini filename')
    p.flg(name='only_plt', help='Only plotting')
    p.opt(name='ref_fdr', help='Reference folder for paths')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 9
0
def main(argv):
    """
    This is the controlling script that can be used to subdivide an
    earthquake catalogue into many subsets, each one describing the seismicity
    generated by a specific tectonic region.

    The code supports the following classification criteria:
        - shallow crust
        - subduction (interface and inslab)

    The parameters required to complete the classification are specified in a
    .ini file (see https://en.wikipedia.org/wiki/INI_file for an explanation
    of the format) containing at least two sections.

    The first section - defined `general` - specifies global parameters such as
    the path to the catalogue filename (note that this one must follow the
    .hmtk format), the path to the .hdf5 file where the results will be stored,
    the folder where to store the files containing the computed distances
    between the subduction surfaces and the events included in the catalogue.
    A very important parameter in this section is the `priority` parameter.

    The second (and the following sections) specify the parameters and the
    data required to create tectonically uniform families of earthquakes.

    The selection of crustal earthquakes requires a set of points (described in
    terms of longitude, latitude and depth) describing the bottom surface of
    the crust. Ideally, this set of points should be homogenously distributed
    over a regular grid.

    The selection of subduction interface earthquakes is perfomed by selecting
    the ones located at less than a thershold distance [in km] from
    surface describing the top of the subducted slab - interface part.
    The threshold distance is defined in the `.ini` configuration file.

    The selection of subduction inslab earthquakes is perfomed in a manner
    similar to the one used for subduction interface seismicity.

    """
    p = sap.Script(classify)
    #
    # set arguments
    msg = 'Path to the configuration fname - typically a .ini file for tr'
    p.arg(name='ini_fname', help=msg)
    msg = 'Flag defining if the calculation of distances'
    p.flg(name='compute_distances', help=msg)
    msg = 'Root folder (path are relative to this in the .ini file)'
    p.opt(name='rf', help=msg)
    #
    # check command line arguments and run the code
    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 10
0
    def test_long_argument(self):
        # test the replacement '_' -> '-' in variable names
        p = sap.Script(lambda a_long_argument: None)
        p.opt('a_long_argument', 'a long argument')
        self.assertEqual(p.help(), '''\
usage: %s [-h] [-a A_LONG_ARGUMENT]

optional arguments:
  -h, --help            show this help message and exit
  -a A_LONG_ARGUMENT, --a-long-argument A_LONG_ARGUMENT
                        a long argument
''' % p.parentparser.prog)
Ejemplo n.º 11
0
def main(argv):
    """
    """
    p = sap.Script(change)
    p.arg(name='cat_pickle_filename', help='pickled catalogue')
    p.arg(name='treg', help='TR hdf5 filename')
    msg = 'list of events to change. format <eventID>,<target class>'
    p.arg(name='eqlist', help=msg)

    if len(argv) < 3:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 12
0
def main(argv):
    """ """

    p = sap.Script(check_catalogue)
    msg = 'Name of a .h5 file containing the homogenised catalogue'
    p.arg(name='catalogue_fname', help=msg)
    p.arg(name='settings_fname', help='.toml file with the model settings')
    p.arg(name='out_folder', help='path of the output folder')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 13
0
    def test_no_help(self):
        p = sap.Script(f, help=None)
        p.arg('a', 'first argument')
        p.opt('b', 'second argument')
        self.assertEqual(p.help(), '''\
usage: %s [-b B] a

positional arguments:
  a            first argument

optional arguments:
  -b B, --b B  second argument
''' % p.parentparser.prog)
        # missing argparse specification for 'c'
        with self.assertRaises(NameError):
            p.check_arguments()
Ejemplo n.º 14
0
def main(argv):
    """
    Creates a hazard map from a set of hazard curves
    """
    p = sap.Script(create_map)
    #
    # Settings
    p.arg(name='path_in', help='Name of the file with input .json files')
    p.arg(name='prefix', help='Prefix for selecting files')
    p.arg(name='fname_out', help='Name output csv file')
    p.arg(name='path_out', help='Path to the output folder')
    p.arg(name='imt_str', help='String describing the IMT')
    p.opt(name='pex', help='Probability of exceedance')
    msg = 'Intensity measure level used for building the maps'
    p.opt(name='iml', help=msg)
    #
    # Processing
    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 15
0
    def test_group(self):
        p = sap.Script(f)
        p.arg('a', 'first argument')
        p.opt('b', 'second argument')
        p.group('other arguments')
        p.flg('c', 'third argument')
        p.opt('d', 'fourth argument')
        self.assertEqual(p.help(), '''\
usage: %s [-h] [-b B] [-c] [-d 1] a

positional arguments:
  a            first argument

optional arguments:
  -h, --help   show this help message and exit
  -b B, --b B  second argument

other arguments:
  -c, --c      third argument
  -d 1, --d 1  fourth argument
''' % p.parentparser.prog)
Ejemplo n.º 16
0
def main(argv):
    """
    Command line interface of the tool
    """

    p = sap.Script(build_fault_model)
    p.opt(name='cfg_file',
          help='Parameter configuration file (.ini)',
          abbrev='-cfg',
          metavar='\'*.ini\'')
    p.opt(name='geojson_file',
          help='Fault database in geojson format',
          abbrev='-geo',
          metavar='\'*.geojson\'')
    p.opt(name='xml_output',
          help='Output xml containing the fault model',
          abbrev='-xml',
          metavar='\'*.xml\'')
    p.opt(name='black_list',
          help='List of fault IDs NOT to be processed [id1,id2]',
          type=ast.literal_eval,
          abbrev='-h')
    p.opt(name='select_list',
          help='List of selected fault IDs to be processed [id1,id2]',
          type=ast.literal_eval,
          abbrev='-h')
    p.opt(name='project_name', help='Name of the current project', abbrev='-h')
    p.opt(name='width_method',
          help='Method to compute the fault width',
          abbrev='-h')
    p.opt(name='oqt_source',
          help='Switch between hazardlib and oq-mbt source formats',
          abbrev='-h')

    if len(argv) < 1:
        print(p.help())
    else:
        p.callfunc()
Ejemplo n.º 17
0
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2017-2018 GEM Foundation
#
# OpenQuake is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenQuake is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with OpenQuake. If not, see <http://www.gnu.org/licenses/>.
from openquake.baselib import sap
from openquake.engine.engine import zip

zip = sap.Script(zip)
zip.arg('job_ini', 'path to a job.ini file')
zip.arg('archive_zip', 'path to a non-existing .zip file')
zip.opt('risk_ini', 'optional .ini file for risk')
Ejemplo n.º 18
0
 def test_NameError(self):
     p = sap.Script(f)
     p.arg('a', 'first argument')
     with self.assertRaises(NameError):
         p.flg('c', 'third argument')