Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeessen committed Apr 17, 2021
2 parents 3ddf24f + 2374d5f commit cd09c1c
Show file tree
Hide file tree
Showing 65 changed files with 7,747 additions and 2,412 deletions.
17 changes: 13 additions & 4 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
## [1.1.1] - 2021-04-17
### Added
- Version number is defined within `VelocityConversion/__init__.py` and is being
read when building the documentation.
read when building the documentation and installing via `pip`.
- Added support for pipenv.
- The density for the simple pressure calculation can now be defined by
declaring the variable `SimpleRho`.
- Function `Convert()` for convenience when using VelocityConversion as a Python
module.
- Function `Convert()` for convenience when using VelocityConversion as a
Python module.
- Added `UnavailableMethodError` when user want to use pressure- and
temperature-dependent expansion coefficient (`-AlphaPT`), since this method
is currently buggy.

### Changed
- Enhanced the documentation.
- Use getter and setter for `UseAlpha` variable.

### Fixed
- Fixed a bug where the csv tables were not copied when using `pip install .`.
- Fixed an issue where pressure would not be computed with the simple method.

## [1.1.0] - 2019-07-16
### Added
Expand Down
22 changes: 22 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
numpy = "*"

[dev-packages]
flake8 = "*"
pydocstyle = "*"
ipython = "*"
pep8 = "*"
sphinx = "*"
sphinx-rtd-theme = "*"
doc8 = "*"
coverage = "*"
matplotlib = "*"
m2r2 = "*"

[requires]
python_version = "3.9"
686 changes: 686 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

48 changes: 37 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

[![DOI](https://zenodo.org/badge/87794116.svg)](https://zenodo.org/badge/latestdoi/87794116)

- [VelocityConversion](#VelocityConversion)
- [Introduction](#Introduction)
- [Recommended citation for VelocityConversion](#Recommended-citation-for-VelocityConversion)
- [Prerequisites](#Prerequisites)
- [How to get started](#How-to-get-started)
- [Usage as command line tool](#Usage-as-command-line-tool)
- [Usage as a Python module](#Usage-as-a-Python-module)
- [Modifying physical properties of the minerals](#Modifying-physical-properties-of-the-minerals)
- [References](#References)
- [Licence](#Licence)
- [VelocityConversion](#velocityconversion)
- [Introduction](#introduction)
- [Recommended citation for VelocityConversion](#recommended-citation-for-velocityconversion)
- [Prerequisites](#prerequisites)
- [How to get started](#how-to-get-started)
- [Usage as command line tool](#usage-as-command-line-tool)
- [Usage as a Python module](#usage-as-a-python-module)
- [Modifying physical properties of the minerals](#modifying-physical-properties-of-the-minerals)
- [References](#references)
- [Licence](#licence)

## Introduction

Expand Down Expand Up @@ -40,6 +40,19 @@ If you use this code, please consider citing it as
This code requires an installation of Python 3.x and numpy.
Building the documentation furthermore requires sphinx and m2r.

You can use [`pipenv`](https://pypi.org/project/pipenv/) to create an
environment:

```bash
pipenv install
```

ctivate the environment via

```bash
pipenv shell
```

## How to get started

The code can be used either as a command line tool or as a module within
Expand All @@ -50,6 +63,13 @@ repository:
git clone https://github.com/cmeessen/VelocityConversion.git
```

or, if you haven an [SSH key](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent)
associated to your account:

```bash
git clone [email protected]:cmeessen/VelocityConversion.git
```

To check whether everything is working run the tests

```bash
Expand All @@ -76,7 +96,7 @@ In order to use the code as command line tool, add the `./Examples` directory
to your `PATH`, e.g. in your bash profile:

```bash
export PATH=/path/to/VelocityConversion/Examples
export PATH=/path/to/VelocityConversion/Examples:$PATH
```

Alternatively you can move the bash script
Expand Down Expand Up @@ -147,6 +167,12 @@ For a more complete documentation on how to use `VelocityConversion` as a Python
module please visit the
[documentation](https://cmeessen.github.io/VelocityConversion/).

To uninstall `VelocityConversion`, run

```bash
pip uninstall velocityconversion-cmeessen
```

## Modifying physical properties of the minerals

The database that contains the physical properties of the individual mineral
Expand Down
61 changes: 30 additions & 31 deletions VelocityConversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@
# You should have received a copy of the GNU General Public License #
# along with VelocityConversion. If not, see <http://www.gnu.org/licenses/>. #
###############################################################################
"""
This code is a python implementation of the p- and s-wave velocity to density
conversion approach after Goes et al. (2000)
Recommended citation
====================
> Meeßen, Christian (2017): VelocityConversion. V. v1.0.1. GFZ Data Services.
> http://doi.org/10.5880/GFZ.6.1.2017.001
Contact
=======
For questions or suggestions please contact
| Christian Meeßen
| Section 4.5 Basin Modelling
| GFZ Potsdam
| [email protected]
"""

from __future__ import print_function, unicode_literals
import numpy as np
Expand All @@ -47,7 +27,12 @@
from warnings import warn
import __main__

__version__ = '1.1.1-rc1'
__version__ = '1.1.1'


class UnavailableMethodError(Exception):
"""Raise when trying to use AlphaPT"""
pass


class MantleConversion:
Expand All @@ -73,7 +58,7 @@ def __init__(self):
self.Verbose = False
self.SimpleP = False
self.NN = False
self.UseAlpha = 'Alpha'
self._UseAlpha = 'Alpha'
self.VelType = None
self.scaleV = 1.

Expand Down Expand Up @@ -204,6 +189,25 @@ def __check_mineralogy__(self):
self.Mineralogy = np.sort(self.Mineralogy, order='phase')
self.n_Phases = len(self.Mineralogy['phase'])

@property
def UseAlpha(self):
"""Property that defines how Alpha is computed"""
return self._UseAlpha

@UseAlpha.setter
def UseAlpha(self, mode):
valid_modes = {
'const': 'Alpha',
'T': 'AlphaT',
# 'PT': 'AlphaPT' # Deactivate due to unsolved issues
}
try:
self._UseAlpha = valid_modes[mode]
except KeyError:
raise UnavailableMethodError(
f"This method for computation of Alpha is not available: {mode}"
)

def AK135(self, depth, simple=False):
"""
Return Pressure at given depth based on AK135 model.
Expand Down Expand Up @@ -478,7 +482,7 @@ def CalcVRho(self, z, T):
Array contining V and Rho according for specified z and T
"""
# Calculate P
P = self.AK135(z)
P = self.AK135(z, self.SimpleP)
if self.Verbose:
print('> z='+str(z)+'km; P='+str(P)+'Pa')

Expand Down Expand Up @@ -913,9 +917,9 @@ def ReadArgs(self):
i = 2
while i < n_args:
if sys.argv[i] == '-AlphaT':
self.UseAlpha = 'AlphaT'
self.UseAlpha = 'T'
elif sys.argv[i] == '-AlphaPT':
self.UseAlpha = 'AlphaPT'
self.UseAlpha = 'PT'
elif sys.argv[i] == '-comp':
self.LoadMineralogy(sys.argv[i+1])
i += 1
Expand Down Expand Up @@ -1016,12 +1020,7 @@ def SetAlpha(self, mode):
mode : str
Valid modes are `const`, `T` and `PT`
"""
valid_modes = {
'const': 'Alpha',
'T': 'AlphaT',
'PT': 'AlphaPT'
}
self.UseAlpha = valid_modes[mode]
self.UseAlpha = mode

def SetMineralogy(self, assemblage):
"""Define the mineralogical assemblage
Expand Down
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: d81aaa56fef58c3b9148eedab21e9f9d
config: eff9231dd2a1754c818508a98793b04c
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified docs/_images/figure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 42 additions & 11 deletions docs/_sources/installation.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ Prerequisites
-------------

:mod:`VelocityConversion` requires Python 2.7 or 3, and a few modules.
I recommend to use Python 3 and `Anaconda <https://continuum.io>`_.
I recommend to use Python 3 and `Pipenv <https://github.com/pypa/pipenv>`_.

With Anaconda
~~~~~~~~~~~~~
With pipenv
~~~~~~~~~~~

Install the required modules with Anaconda:
The advantage of pipenv is, that all dependencies and their versions are
specified in the ``Pipfile.lock``. Pipenv will create an environment where all
necessary packages will be installed. To install dependencies with pipenv,
navigate to the project root folder, and run

.. code-block:: bash
conda install -c conda-forge numpy
pipenv install
To be able to build the documentation from source, further packages are
required:
To install other dependencies required to compile the documentation, run:

.. code-block:: bash
conda install -c conda-forge ipython sphinx m2r sphinx_rtd_theme
pipenv install --dev
Enter the environment in the terminal by running

.. code-block:: bash
pipenv shell
With pip
~~~~~~~~~
Expand All @@ -40,9 +48,24 @@ and to be able to compile the documentation:
pip install sphinx m2r sphinx_rtd_theme
With Anaconda
~~~~~~~~~~~~~

Install the required modules with Anaconda:

.. code-block:: bash
conda install -c conda-forge numpy
To be able to build the documentation from source, further packages are
required:

.. code-block:: bash
Installing
----------
conda install -c conda-forge ipython sphinx m2r sphinx_rtd_theme
Installation
------------

:mod:`VelocityConversion` can be used both as a command line tool and as a
Python module. In both cases, the first step is to create a clone or download
Expand All @@ -54,10 +77,18 @@ the repository.
and install it with

.. code-block::
.. code-block:: bash
pip install .
You can also use :mod:`VelocityConversion` without installing it. In this case,
you need to add the path of the ``./VelocityConversion`` folder to the system
path when importing the module:

.. code-block:: python
import sys
sys.path.append('../path/to/gitrepo')
Run tests
~~~~~~~~~~
Expand Down
Loading

0 comments on commit cd09c1c

Please sign in to comment.