Skip to content

Commit

Permalink
Merge pull request #2 from cmeessen/dev
Browse files Browse the repository at this point in the history
Merge current version of dev to master
  • Loading branch information
cmeessen authored Jul 25, 2019
2 parents ec368da + 28dbf48 commit 3ddf24f
Show file tree
Hide file tree
Showing 88 changed files with 7,449 additions and 2,032 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
velocityconversion_cmeessen.egg-info
.vscode
docs/sphinx/build
Examples/VsSL2013_*.dat
33 changes: 18 additions & 15 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@ 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]
### Added
- Version number is defined within `VelocityConversion/__init__.py` and is being
read when building the documentation.
- 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.

### Changed
- Enhanced the documentation.

## [1.1.0] - 2019-07-16
### Added
- Python 3 support.
- Support for usage of VelocityConversion as a Python module.
- This CHANGELOG.
- Function `DefaultMineralogy()`.
- Added encoding, copyright and license disclaimers.
- Added option `-dT` to manually adjust the temperature stepping.
- Added option `-scaleV` to apply a scaling factor to the input velocities.
- Added warning if velocities are in km/s instead of m/s.
- Added LoadArray().
- Added tests with unittest.

### Changed
- The function `CalcPT()` was improved. Instead of manually performing the
Expand All @@ -17,21 +35,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
more performant.
- Updated README.md.
- Migrated from pep8 to pycodestyle.

## [unreleased] - 2017-11-15
### Added
- Added encoding, copyright and license disclaimers.

## [unreleased] - 2017-10-26
### Added
- Added option `-dT` to manually adjust the temperature stepping.

## [unreleased] - 2017-10-05
### Added
- Added option `-scaleV` to apply a scaling factor to the input velocities.
- Added warning if velocities are in km/s instead of m/s.

### Changed
- Fixed a bug in clearing depth values beyond the stored AK135 values.

## [1.0.1] - 2017-06-22
Expand Down
2 changes: 1 addition & 1 deletion Examples/RunAsModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
to DataRaw, for example:
>> SomeArray = np.zeros([10,4])
>> MC.DataRaw = SomeArray
>> MC.LoadArray(SomeArray)
"""

# Set Velocity type
Expand Down
5 changes: 4 additions & 1 deletion Examples/VelocityConversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
set -e

python ../VelocityConversion/__init__.py $@
# Get the directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

python $DIR/../VelocityConversion/__init__.py $@
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ help:
pycodestyle:
pycodestyle --show-source --show-pep8 --ignore=W503,E226,E241 VelocityConversion/__init__.py

docs:
cd docs/sphinx && make html

20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ repository:
git clone https://github.com/cmeessen/VelocityConversion.git
```

To check whether everything is working run the tests

```bash
python test.py
```

If the output looks like this, everything is working fine:

```
test_vp_AlphaConst (__main__.TestVelocityConversion) ... ok
test_vs_AlphaConst (__main__.TestVelocityConversion) ... ok
test_vs_AlphaPT (__main__.TestVelocityConversion) ... ok
test_vs_AlphaT (__main__.TestVelocityConversion) ... ok
----------------------------------------------------------------------
Ran 4 tests in 1.633s
OK
```

### Usage as command line tool

In order to use the code as command line tool, add the `./Examples` directory
Expand Down
55 changes: 45 additions & 10 deletions VelocityConversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
from warnings import warn
import __main__

__version__ = '1.1.1-rc1'


class MantleConversion:
"""The conversion class
Expand Down Expand Up @@ -85,6 +87,7 @@ def __init__(self):
# Rock properties
self.Composition = None
self.XFe = None
self.SimpleRho = 3000. # Density kg/m3 for simple pressure computation

# Initialise mineral database
self.MinDB = self.LoadMineralProperties()
Expand Down Expand Up @@ -242,7 +245,7 @@ def AK135(self, depth, simple=False):
return Pressure
else:
self.SimpleP = True
return 3000.*self.g*np.absolute(depth)
return self.SimpleRho*self.g*np.absolute(depth)

def Alpha(self, P, T, Mineral, p=4.0):
"""Return the thermal expansion coefficient
Expand Down Expand Up @@ -574,6 +577,15 @@ def CalcVRho(self, z, T):

return TableVRho

def Convert(self):
"""A convenience function to start the converion.
Calls :meth:`~.FillTables` and :meth:`~.CalcPT`.
"""
self.FillTables()
self.CalcPT()

def DefaultMineralogy(self):
"""Assign a default mineralogy.
Expand Down Expand Up @@ -754,6 +766,35 @@ def LoadAlphaTables(self, FileIn='AlphaDB.csv'):
i_phase = self.Mineralogy['phase'][i]
self.AlphaPT[:, :, i] = np.reshape(AlphaTables[i_phase], (nP, nT))

def LoadArray(self, array):
"""Load a numpy array as input data
Load a numpy array of shape `[nrows, 4]`. The columns of the array
should be:
+---+---+-------+---------+
| X | Y | Z / m | V / m/s |
+---+---+-------+---------+
Parameters
----------
array : numpy.array
The data array.
"""
if array.shape[1] != 4:
msg = "Incorrect numbers of columns in input array."
raise ValueError(msg)
self.DataRaw = array
# Remove rows below maximum depth, defined by self.MaxDepth
DelRows = np.where(np.abs(self.DataRaw[:, 2]) >= np.abs(self.MaxDepth))
if len(DelRows[0]) > 0:
print("> Removing depth values beyond", self.MaxDepth, "m.")
self.DataRaw = np.delete(self.DataRaw, DelRows, axis=0)
self.Depths = np.unique(self.DataRaw[:, 2])
self.DataRaw[:, 3] *= self.scaleV
self.__check_vmin__()

def LoadMineralogy(self, FileIn=None):
"""
Import mineralogy of the mantle rock from an input file and perform
Expand Down Expand Up @@ -853,15 +894,7 @@ def LoadFile(self, filename=None):
self.__raise__(ValueError, "No input file defined!")
print("Loading input file:", self.FileIn)
print("> Velocity scale factor is", self.scaleV)
self.DataRaw = np.loadtxt(self.FileIn)
# Remove rows below maximum depth, defined by self.MaxDepth
DelRows = np.where(np.abs(self.DataRaw[:, 2]) >= np.abs(self.MaxDepth))
if len(DelRows[0]) > 0:
print("> Removing depth values beyond", self.MaxDepth, "m.")
self.DataRaw = np.delete(self.DataRaw, DelRows, axis=0)
self.Depths = np.unique(self.DataRaw[:, 2])
self.DataRaw[:, 3] *= self.scaleV
self.__check_vmin__()
self.LoadArray(np.loadtxt(self.FileIn))

def ReadArgs(self):
"""
Expand Down Expand Up @@ -940,6 +973,8 @@ def SaveFile(self, fileout=None):
Output_h += "XFe - " + str(self.XFe) + "\n"
if self.SimpleP:
Output_h += "Pressure calculation: Simplified\n"
Output_h += "Pressure calculation density: " + str(self.SimpleRho)
Output_h += " kg/m3\n"
else:
Output_h += "Pressure calculation: AK135\n"
Output_h += "Wave frequency (Omega) / Hz: " + str(self.f) + "\n"
Expand Down
Loading

0 comments on commit 3ddf24f

Please sign in to comment.