Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
klunk386 committed Aug 11, 2019
1 parent 923757c commit f1efa5d
Show file tree
Hide file tree
Showing 28 changed files with 614 additions and 116 deletions.
20 changes: 10 additions & 10 deletions README.md
@@ -1,34 +1,34 @@
<img alt="QuakeLab - Tools for Engineering Seismology" class="right" style="width: 60%" src="https://raw.githubusercontent.com/klunk386/QuakeLab/master/logo/quakelab.png" />
<img alt="ShakeLab - Tools for Engineering Seismology" class="right" style="width: 60%" src="https://raw.githubusercontent.com/klunk386/ShakeLab/master/logo/quakelab.png" />

[![AGPLv3](https://www.gnu.org/graphics/agplv3-88x31.png)](https://www.gnu.org/licenses/agpl.html)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/quakelab.svg)](https://pypi.python.org/pypi/openquake.engine)

# QuakeLab
# ShakeLab

QuakeLab is an opensource project with the goal of providing a set of free and opensource tools for seismologists dealing with most common enngineering problems
ShakeLab is an opensource project with the goal of providing a set of free and opensource tools for seismologists dealing with most common engineering problems.

### Installation

QuakeLab can be installed directly from the GitHub repository using pip:
ShakeLab can be installed directly from the GitHub repository using pip:

```console
sudo -H python3 -m pip install git+https://github.com/klunk386/QuakeLab.git
sudo -H python3 -m pip install git+https://github.com/klunk386/shakelab.git
```
To upgrade an existing installation:

```console
sudo -H python3 -m pip install --upgrade git+https://github.com/klunk386/QuakeLab.git
sudo -H python3 -m pip install --upgrade git+https://github.com/klunk386/shakelab.git
```

If you are a developer, you can simply install the cloned GIT repository with:

```console
sudo -H python3 -m pip install --upgrade --editable QuakeLab
sudo -H python3 -m pip install --upgrade --editable shakelab
```

### Dependencies

QuakeLab requires the following dependencies:
ShakeLab requires the following dependencies:

* [NumPy/Scipy](http://www.scipy.org/)
* [Matplotlib](http://matplotlib.org/)
Expand All @@ -38,12 +38,12 @@ QuakeLab requires the following dependencies:

Copyright (c) 2019 Valerio Poggi

QuakeLab 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.
ShakeLab 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.

You should have received a copy of the GNU Affero General Public License with this download. If not, see <http://www.gnu.org/licenses/>

### Disclaimer

QuakeLab 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.
ShakeLab 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.

The authors of the software assume no liability for use of the software.
41 changes: 0 additions & 41 deletions quakelab/signals/waveform.py

This file was deleted.

1 change: 0 additions & 1 deletion quakelab/utils/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions shakelab/__init__.py
@@ -0,0 +1 @@
name = "shakelab"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
69 changes: 69 additions & 0 deletions shakelab/modeling/gmpe/atkinson_2015.py
@@ -0,0 +1,69 @@
# ============================================================================
#
# Copyright (C) 2019 Valerio Poggi.
# This file is part of ShakeLab.
#
# ShakeLab 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.
#
# ShakeLab 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
# with this download. If not, see <http://www.gnu.org/licenses/>
#
# ============================================================================
"""
"""

import numpy as _np
from scipy.constants import g

from quakelab.modeling.gmpe.base import GMPE

class Atkinson2015(GMPE):
"""
Reference pubblication:
Atkinson, G. A. (2015) Ground-Motion Prediction Equation for
Small-to-Moderate Events at Short Hypocentral Distances,
with Application to Induced-Seismicity Hazards.
Bulletin of the Seismological Society of America. 105(2)
Distance: hypocentral
"""

COEFF_FILE = 'atkinson_2015.json'

def __init__(self):
super().__init__(self.COEFF_FILE)

def ground_motion(self, imt, mag, dist):

# Extract coefficients for the give intensity measure type
C = self.get_coefficients(imt)

# Compute mean
heff = _np.max([1., 10.**(-1.72+0.43*mag)])
mean = C['c0'] + C['c1']*mag + C['c2']*(mag**2.)
mean += C['c3']*_np.log10(_np.sqrt(dist**2. + heff**2.))

# Compute standard deviation
stdv = C['phi']

# Convert to natural log
mean *= _np.log(10.)
stdv *= _np.log(10.)

if not imt == 'PGV':
# Convert from cm/s2 to g
mean -= _np.log(100.*g)
else:
# Convert from cm/s to m/s
mean -= _np.log(100.)

return (mean, stdv)

67 changes: 67 additions & 0 deletions shakelab/modeling/gmpe/base.py
@@ -0,0 +1,67 @@
# ============================================================================
#
# Copyright (C) 2019 Valerio Poggi.
# This file is part of ShakeLab.
#
# ShakeLab 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.
#
# ShakeLab 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
# with this download. If not, see <http://www.gnu.org/licenses/>
#
# ============================================================================
"""
"""

import abc as _abc
import os as _os
import json as _json

class GMPE(metaclass=_abc.ABCMeta):
"""
Base class for ground motion prediction equation models (GMPEs).
"""

def __init__(self, json_file, version='default'):
self.import_coeff_from_json(json_file, version)

def import_coeff_from_json(self, json_file, version='default'):
"""
Loads the coefficient from a separate file in json format.
File has to be stored in the same directory of the GMPE class.
"""
full_path = _os.path.dirname(__file__)
path_file = _os.path.join(full_path, 'data', json_file)

self.coeff = {}
with open(path_file) as jf:
data = _json.load(jf)['coefficients'][version]
self.keys = data['keys']
for kp in data['type']:
self.coeff[kp] = [float(c) for c in data['type'][kp]]

def get_coefficients(self, imt):
"""
Extract coefficients corresponding to a given intensity
measure type.
"""
if imt in self.coeff:
return dict(zip(self.keys, self.coeff[imt]))
else:
print('Error: Not a valid intensity measure type')

@_abc.abstractmethod
def ground_motion(self, imt, magnitude, distance):
"""
"""
pass



10 changes: 10 additions & 0 deletions shakelab/modeling/gmpe/data/atkinson_2015.json
@@ -0,0 +1,10 @@
{"coefficients" :
{"default" :
{"keys" : ["c0", "c1", "c2", "c3", "phi", "tau", "sigma"],
"type" : {
"PGV" : ["-4.198", "1.818", "-0.1009", "-1.721", "0.28", "0.18", "0.33"],
"PGA" : ["-2.427", "1.877", "-0.1214", "-1.806", "0.29", "0.24", "0.37"]
}
}
}
}
File renamed without changes.
33 changes: 19 additions & 14 deletions quakelab/signals/io.py → shakelab/signals/io.py
@@ -1,14 +1,14 @@
# ============================================================================
#
# Copyright (C) 2019 Valerio Poggi.
# This file is part of QuakeLab.
# This file is part of ShakeLab.
#
# QuakeLab is free software: you can redistribute it and/or modify it
# ShakeLab 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.
#
# QuakeLab is distributed in the hope that it will be useful,
# ShakeLab 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.
Expand All @@ -21,32 +21,37 @@
"""

from quakelab.signals.iolib import sac
from quakelab.signals.waveform import Recording
from shakelab.signals.iolibs import sac
from shakelab.signals.waveform import Recording


def import_recording (files, use_path=None, file_type='sac', **kwargs):
def import_recording (file, use_path=None, file_type='sac', byte_order='le',
**kwargs):
"""
"""

# Initialise an empty trace
r = recording()
rec = Recording()

# Import recording from file
if file_type is 'sac':

s = sac.Sac()
s.Read(FileIn, byte_order='be')
if isinstance(file, list):
files = file
else:
files = [file]

key_map = {'dt': 'DELTA'}
r.data[0] = s.data[0]
for f in files:
s = sac.Sac()
s.read(f, byte_order=byte_order)

rec.dt = s.head['DELTA']
rec.channel.append(s.data[0])

if file_type is 'ascii':
print('ascii')



return r
return rec

def export_recording(file, use_path=None, file_type='sac', **kwargs):
print('export')

0 comments on commit f1efa5d

Please sign in to comment.