Skip to content

Commit

Permalink
Merge pull request #6 from simpeg/feat/em
Browse files Browse the repository at this point in the history
Feat/em
  • Loading branch information
lheagy authored Apr 2, 2018
2 parents b5bfce4 + 613767c commit 549d5b0
Show file tree
Hide file tree
Showing 28 changed files with 1,869 additions and 236 deletions.
4 changes: 4 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[bumpversion]
current_version = 0.0.1
files = setup.py geoana/__init__.py docs/conf.py

7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- 3.4
- 3.6
- 2.7

sudo: false
Expand All @@ -11,9 +11,8 @@ env:
install:
- pip install --upgrade pip;
- pip install -r requirements.txt
- pip install sphinx_rtd_theme
- git clone https://github.com/3ptscience/vectormath;
- export PYTHONPATH=$PWD/geoana:$PWD/vectormath:$PYTHONPATH
- pip install -r requirements_dev.txt
- cd geoana; python setup.py install; cd ..

# Run test
script:
Expand Down
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
PACKAGE_NAME=geoana

.PHONY: install coverage lint graphs tests docs clean deploy

install:
python setup.py install

coverage:
nosetests --logging-level=INFO --with-coverage --cover-package=geoana --cover-html
open cover/index.html

lint:
pylint $(PACKAGE_NAME)

lint-html:
pylint --output-format=html $(PACKAGE_NAME) > pylint.html

graphs:
pyreverse -my -A -o pdf -p geoana geoana/**.py geoana/**/**.py

tests:
nosetests --logging-level=INFO

docs:
cd docs;make html

clean_pyc:
find . -name "*.pyc" | xargs -I {} rm -v "{}"

clean: clean_pyc
cd docs;make clean

deploy:
python setup.py sdist upload
13 changes: 5 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.. _index:
.. _geoana:

geoana
======

.. image:: https://readthedocs.org/projects/geoana/badge/?version=latest
:target: http://geoana.readthedocs.io/en/latest/?badge=latest
:target: https://geoana.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

.. image:: https://img.shields.io/github/license/simpeg/geoana.svg
Expand All @@ -13,15 +13,12 @@ geoana

.. image:: https://travis-ci.org/simpeg/geoana.svg?branch=master
:target: https://travis-ci.org/simpeg/geoana
:alt: travis status

.. image:: https://www.quantifiedcode.com/api/v1/project/cb381a23f09245bd855f86eac295d8ec/badge.svg
:target: https://www.quantifiedcode.com/app/project/cb381a23f09245bd855f86eac295d8ec
:alt: Code issues
:alt: Travis status

.. image:: https://api.codacy.com/project/badge/Grade/2e32cd28f4424dc1800f1590a64c244f
:target: https://www.codacy.com/app/lindseyheagy/geoana?utm_source=github.com&utm_medium=referral&utm_content=simpeg/geoana&utm_campaign=Badge_Grade
:alt: codacy status

Interactive geoscience (mostly) analytic functions.

Interactive geoscience (mostly) analytic functions in geophysics.

45 changes: 45 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# AppVeyor.com is a Continuous Integration service to build and run tests under Windows

build: off

environment:
matrix:
- PYTHON: 2.7
MINICONDA: C:\Miniconda
PYTHON_ARCH: 32

- PYTHON: 3.5
MINICONDA: C:\Miniconda3
PYTHON_ARCH: 32

- PYTHON: 3.6
MINICONDA: C:\Miniconda3
PYTHON_ARCH: 32

- PYTHON: 2.7
MINICONDA: C:\Miniconda
PYTHON_ARCH: 64

- PYTHON: 3.5
MINICONDA: C:\Miniconda3
PYTHON_ARCH: 64

- PYTHON: 3.6
MINICONDA: C:\Miniconda3
PYTHON_ARCH: 64

init:
- "ECHO %PYTHON% %MINICONDA%"

install:
- "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%"
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a
- "conda create -q -n test-environment python=%PYTHON% numpy scipy matplotlib cython jupyter ipython pillow wheel"
- activate test-environment
- pip install -r requirements_dev.txt
- python setup.py install

test_script:
- nosetests tests -v -s
25 changes: 25 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]


linkcheck_ignore = [
'https://readthedocs.org/projects/geoana/badge/?version=latest'
]

linkcheck_retries = 3
linkcheck_timeout = 500

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
Expand Down Expand Up @@ -299,3 +307,20 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}


def supress_nonlocal_image_warn():
import sphinx.environment
sphinx.environment.BuildEnvironment.warn_node = (
_supress_nonlocal_image_warn
)


def _supress_nonlocal_image_warn(self, msg, node, **kwargs):
from docutils.utils import get_source_line

if not msg.startswith('nonlocal image URI found:'):
self._warnfunc(msg, '{0!s}:{1!s}'.format(*get_source_line(node)))

supress_nonlocal_image_warn()

8 changes: 8 additions & 0 deletions docs/content/earthquake.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _earthquake:

Earthquake
==========

.. autoclass:: geoana.earthquake
:members:
:undoc-members:
8 changes: 8 additions & 0 deletions docs/content/em.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. _em:

Electromagnetics
================

.. autoclass:: geoana.em
:members:
:undoc-members:
15 changes: 5 additions & 10 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
.. _index:


.. include:: ../README.rst

Contents:

**Contents:**

.. toctree::
:maxdepth: 2



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
content/earthquake
content/em

2 changes: 2 additions & 0 deletions examples/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Examples
********
2 changes: 2 additions & 0 deletions examples/em/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Electromagnetics
****************
113 changes: 113 additions & 0 deletions examples/em/fdem_ElectricDipoleWholeSpace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""
Electric Dipole in a Whole Space: Frequency Domain
==================================================
In this example, we plot electric and magnetic flux density due to an electric
dipole in a whole space. Note that you can also examine the current density
and magnetic field.
We can vary the conductivity, magnetic permeability and dielectric permittivity
of the wholespace, the frequency of the source and whether or not the
quasistatic assumption is imposed.
"""

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from scipy.constants import mu_0, epsilon_0

from geoana import utils, spatial
from geoana.em import fdem

# define frequencies that we want to look at
frequencies = np.logspace(0, 4, 3)

# Build the electric dipole object
edipole = fdem.ElectricDipoleWholeSpace(
sigma=1., # conductivity of 1 S/m
mu=mu_0, # permeability of free space (this is the default)
epsilon=epsilon_0, # permittivity of free space (this is the default)
location=np.r_[0., 0., 0.], # location of the dipole
orientation='Z', # vertical dipole (can also be a unit-vector)
quasistatic=False # don't use the quasistatic assumption
)

# construct a grid where we want to plot electric fields
x = np.linspace(-50, 50, 100)
z = np.linspace(-50, 50, 100)
xyz = utils.ndgrid([x, np.r_[0], z])


# plot amplitude
def plot_amplitude(ax, v):
v = spatial.vector_magnitude(v)
plt.colorbar(
ax.pcolormesh(
x, z, v.reshape(len(x), len(z), order='F'), norm=LogNorm()
), ax=ax
)
ax.axis('square')
ax.set_xlabel('x (m)')
ax.set_ylabel('z (m)')


# plot streamlines
def plot_streamlines(ax, v):
vx = v[:, 0].reshape(len(x), len(z), order='F')
vz = v[:, 2].reshape(len(x), len(z), order='F')
ax.streamplot(x, z, vx.T, vz.T, color='k')


# create fig, ax for electric fields and magnetic flux
fig_e, ax_e = plt.subplots(
2, len(frequencies), figsize=(5*len(frequencies), 7)
)
fig_b, ax_b = plt.subplots(
2, len(frequencies), figsize=(5*len(frequencies), 7)
)

# loop over frequencies and plot
for i, frequency in enumerate(frequencies):

# set the frequency of the dipole
edipole.frequency = frequency

# evaluate the electric field and magnetic flux density
electric_field = edipole.electric_field(xyz)
magnetic_flux_density = edipole.magnetic_flux_density(xyz)

# plot amplitude of electric field
for ax, reim in zip(ax_e[:, i], ['real', 'imag']):
# grab real or imag component
e_plot = getattr(electric_field, reim)

# plot both amplitude and streamlines
plot_amplitude(ax, e_plot)
plot_streamlines(ax, e_plot)

# set the title
ax.set_title(
'E {} at {:1.1e} Hz'.format(reim, frequency)
)

# plot the amplitude of the magnetic field (note the magnetic field is into
# and out of the page in this geometry, so we don't plot vectors)
for ax, reim in zip(ax_b[:, i], ['real', 'imag']):
# grab real or imag component
b_plot = getattr(magnetic_flux_density, reim)

# plot amplitude
plot_amplitude(ax, b_plot)

# set the title
ax.set_title(
'B {} at {:1.1e} Hz'.format(reim, frequency)
)

# format so text doesn't overlap
fig_e.tight_layout()
fig_b.tight_layout()
plt.show()


8 changes: 8 additions & 0 deletions geoana/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
from . import earthquake
from . import em
from . import utils

__version__ = '0.0.1'
__author__ = 'SimPEG developers'
__license__ = 'MIT'
__copyright__ = 'Copyright 2017 SimPEG developers'

16 changes: 14 additions & 2 deletions geoana/earthquake/oksar.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
import matplotlib.pyplot as plt


class EarthquakeInterferogram(properties.UidModel):
class EarthquakeInterferogram(properties.HasProperties):
title = properties.String(
'name of the earthquake',
required=True
)

description = properties.String(
'description of the event',
required=False
)

location = properties.Vector2(
'interferogram location (bottom N, left E)',
required=True
Expand Down Expand Up @@ -229,6 +239,8 @@ def get_LOS_vector(self, locations):
calculate beta - the angle at earth center between reference point
and satellite nadir
"""
if not isinstance(locations, list):
locations = [locations]

utmZone = self.location_UTM_zone
refPoint = vmath.Vector3(self.ref.x, self.ref.y, 0)
Expand Down Expand Up @@ -283,7 +295,7 @@ def get_LOS_vector(self, locations):
los_y = -np.sin(satAzimuth * DEG2RAD) * np.cos(satIncidence * DEG2RAD)
los_z = np.sin(satIncidence * DEG2RAD)

return vmath.Vector3(los_x, los_y, los_z)
return vmath.Vector3Array([los_x, los_y, los_z])

@staticmethod
def _ang_to_gc(x, y, origx, origy, satAzimuth):
Expand Down
1 change: 1 addition & 0 deletions geoana/em/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import static
from . import fdem
from . import tdem
Loading

0 comments on commit 549d5b0

Please sign in to comment.