Exemplo n.º 1
0
#
# 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/>.
"""
Package :mod:`openquake.hazardlib.gsim` contains base and specific
implementations of ground shaking intensity models. See
:mod:`openquake.hazardlib.gsim.base`.
"""
from openquake.baselib.general import import_all
from openquake.hazardlib.gsim.base import registry

import_all('openquake.hazardlib.gsim')


def get_available_gsims():
    '''
    Return an ordered dictionary with the available GSIM classes, keyed
    by class name.
    '''
    return dict(sorted(registry.items()))
Exemplo n.º 2
0
        array = dstore[ekey[0]].value
    except AttributeError:
        # this happens if the key correspond to a HDF5 group
        return []  # write a custom exporter in this case
    if len(array.shape) == 1:  # vector
        array = array.reshape((len(array), 1))
    return [write_csv(dstore.export_path(name), array)]


def dispatch_on_colon(ekey, dstore):
    """
    If the datastore key contains a colon, i.e. it is of the form
    dskey:spec, then call `export(('<dskey>:', fmt), dstore, spec)`.

    :param ekey:
        export key of the form (k0, ext) with k0 of the form <dskey>:<spec>
    :param dstore:
        datastore instance

    This function is called only for ekey not present in the datastore.
    """
    if ':' not in ekey[0]:
        raise MissingExporter(ekey)
    dkey, spec = ekey[0].split(':', 1)
    return export((dkey + ':', ekey[1]), dstore, spec)


export = CallableDict(keymissing=dispatch_on_colon)

import_all('openquake.commonlib.export')
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2014-2017 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/>.

import os
from openquake.baselib.general import import_all

# make sure the `base,calculators` dictionary is populated
import_all('openquake.calculators')

# import the development packages if any
extras = os.environ.get('OQ_IMPORT_PATH', '')
for extra_pkg in extras.split(':'):
    if extra_pkg:
        import_all(extra_pkg)
Exemplo n.º 4
0
    >>> keyfunc(('agg_loss_table', 'csv'))
    ('agg_loss_table', 'csv')
    >>> keyfunc(('agg_loss_table/1', 'csv'))
    ('agg_loss_table', 'csv')
    >>> keyfunc(('agg_loss_table/1/0', 'csv'))
    ('agg_loss_table', 'csv')
    """
    fullname, ext = ekey
    return (fullname.split('/', 1)[0], ext)


export = CallableDict(keyfunc)

export.from_db = False  # overridden when exporting from db

import_all('openquake.calculators.export')


@export.add(('input_zip', 'zip'))
def export_input_zip(ekey, dstore):
    """
    Export the data in the `input_zip` dataset as a .zip file
    """
    dest = dstore.export_path('input.zip')
    nbytes = dstore.get_attr('input_zip', 'nbytes')
    zbytes = dstore['input_zip'].value
    # when reading input_zip some terminating null bytes are truncated (for
    # unknown reasons) therefore they must be restored
    zbytes += b'\x00' * (nbytes - len(zbytes))
    open(dest, 'wb').write(zbytes)
    return [dest]
Exemplo n.º 5
0
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright (C) 2014-2019 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/>.

import os
from openquake.baselib.general import import_all

# make sure the `base,calculators` dictionary is populated
import_all('openquake.calculators')

# import the development packages if any
extras = os.environ.get('OQ_IMPORT_PATH', '')
for extra_pkg in extras.split(':'):
    if extra_pkg:
        import_all(extra_pkg)
Exemplo n.º 6
0
# Copyright (c) 2010-2015, 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 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/>.
"""This package contains Hazard and Risk calculator classes."""

from openquake.baselib.general import CallableDict, import_all

# an ordered dictionary of calculator classes
calculators = CallableDict(lambda job: job.get_param('calculation_mode'))

import_all('openquake.engine.calculators')
Exemplo n.º 7
0
# Copyright (c) 2010-2015, 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 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/>.


"""This package contains Hazard and Risk calculator classes."""

from openquake.baselib.general import CallableDict, import_all

# an ordered dictionary of calculator classes
calculators = CallableDict(lambda job: job.get_param("calculation_mode"))

import openquake.engine.utils.tasks  # monkey patch commonlib.parallel

import_all("openquake.engine.calculators")
Exemplo n.º 8
0
# 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/>.

"""
Package :mod:`openquake.hazardlib.gsim` contains base and specific
implementations of ground shaking intensity models. See
:mod:`openquake.hazardlib.gsim.base`.
"""
from openquake.baselib.general import import_all
from openquake.hazardlib.gsim.base import registry

import_all('openquake.hazardlib.gsim')


def get_available_gsims():
    '''
    Return an ordered dictionary with the available GSIM classes, keyed
    by class name.
    '''
    return dict(sorted(registry.items()))
Exemplo n.º 9
0
# Copyright (c) 2010-2015, 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 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/>.


"""This package contains Hazard and Risk calculator classes."""

from openquake.baselib.general import CallableDict, import_all

# an ordered dictionary of calculator classes
calculators = CallableDict(lambda job: job.get_param('calculation_mode'))

import_all('openquake.engine.calculators')
Exemplo n.º 10
0
    name = ekey[0] + '.csv'
    try:
        array = dstore[ekey[0]].value
    except AttributeError:
        # this happens if the key correspond to a HDF5 group
        return []  # write a custom exporter in this case
    if len(array.shape) == 1:  # vector
        array = array.reshape((len(array), 1))
    return [write_csv(dstore.export_path(name), array)]


def keyfunc(ekey):
    """
    Extract the name before the colons:

    >>> keyfunc(('agg_loss_table', 'csv'))
    ('agg_loss_table', 'csv')
    >>> keyfunc(('agg_loss_table:1', 'csv'))
    ('agg_loss_table', 'csv')
    >>> keyfunc(('agg_loss_table:1:0', 'csv'))
    ('agg_loss_table', 'csv')
    """
    fullname, ext = ekey
    return (fullname.split(':', 1)[0], ext)

export = CallableDict(keyfunc)

export.from_db = False  # overridden when exporting from db

import_all('openquake.calculators.export')