Skip to content

Commit

Permalink
Merge pull request #109 from geoscixyz/ref/light-plotting-cleanup
Browse files Browse the repository at this point in the history
Ref/light plotting cleanup
  • Loading branch information
lheagy authored Jul 20, 2018
2 parents b13552f + 31ce469 commit cb6d7ce
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[bumpversion]
current_version = 0.0.23
current_version = 0.0.24
files = em_examples/__init__.py setup.py

44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# em_examples

[![binder](https://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/geoscixyz/em-apps/master?filepath=index.ipynb)
[![azure](https://notebooks.azure.com/launch.png)](https://notebooks.azure.com/import/gh/geoscixyz/em-apps)
[![travis](https://travis-ci.org/geoscixyz/em_examples.svg?branch=master)](https://travis-ci.org/geoscixyz/em_examples)
[![pypi](https://img.shields.io/pypi/v/em_examples.svg)](https://pypi.python.org/pypi/SimPEG)

This is a repository of code used to power the notebooks and interactive examples for http://em.geosci.xyz. The associated notebooks are in the repository [em_apps](http://github.com/geoscixyz/em_apps).
The notebooks are available on
- [Binder](https://mybinder.org/v2/gh/geoscixyz/em-apps/master?filepath=index.ipynb)
- [Azure Notebooks](https://notebooks.azure.com/import/gh/geoscixyz/em-apps)

The examples are based on code available in [SimPEG](http://simpeg.xyz).

## Why

Interactive visualizations are a powerful way to interrogate mathematical equations. The goal of this repository is to be the home for code that can be plugged into jupyter notebooks so that we can play with the governing equations of geophysical electromagnetics.

## Scope

The repository contains the python code to run the ipython-widget style apps in http://github.com/geoscixyz/em-apps. These are mainly plotting code and some simple analytics. More complex numerical simulations depend on [SimPEG](http://simpeg.xyz)

Installing
----------

`em_examples` is on PyPi

```
pip install em_examples
```

For developers you can clone this repo from github:

```
git clone https://github.com/geoscixyz/em_examples.git
```

and install

```
python setup.py install
```


46 changes: 0 additions & 46 deletions README.rst

This file was deleted.

40 changes: 22 additions & 18 deletions em_examples/DCLayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm


from matplotlib import rcParams
rcParams['font.size'] = 16

from ipywidgets import (
IntSlider, FloatSlider, FloatText, ToggleButtons
)
Expand Down Expand Up @@ -191,8 +195,8 @@ def solve_2D_J(rho1, rho2, h, A, B):

def plot_layer_potentials(rho1, rho2, h, A, B, M, N, imgplt='Model'):

markersize = 6.
fontsize = 10.
markersize = 8.
fontsize = 16.
ylim = np.r_[-1., 1.]*rhomax/(5*2*np.pi)*1.5

fig, ax = plt.subplots(2, 1, figsize=(9, 7))
Expand Down Expand Up @@ -222,8 +226,8 @@ def plot_layer_potentials(rho1, rho2, h, A, B, M, N, imgplt='Model'):
ax[0].grid(which='both', linestyle='-', linewidth=0.5, color=[0.2, 0.2, 0.2], alpha=0.5)
ax[0].plot(A, 0, '+', markersize = 12, markeredgewidth = 3, color=[1., 0., 0])
ax[0].plot(B, 0, '_', markersize = 12, markeredgewidth = 3, color=[0., 0., 1.])
ax[0].set_ylabel('Potential, (V)', fontsize = 14)
ax[0].set_xlabel('x (m)', fontsize = 14)
ax[0].set_ylabel('Potential, (V)')
ax[0].set_xlabel('x (m)')
ax[0].set_xlim([x.min(), x.max()])
ax[0].set_ylim(ylim)

Expand All @@ -240,16 +244,16 @@ def plot_layer_potentials(rho1, rho2, h, A, B, M, N, imgplt='Model'):

props = dict(boxstyle='round', facecolor='grey', alpha=0.4)

ax[0].annotate('%2.1e'%(VM), xy=xytextM, xytext=xytextM, fontsize = 14)
ax[0].annotate('%2.1e'%(VN), xy=xytextN, xytext=xytextN, fontsize = 14)
ax[0].annotate('%2.1e'%(VM), xy=xytextM, xytext=xytextM)
ax[0].annotate('%2.1e'%(VN), xy=xytextN, xytext=xytextN)

# ax[0].plot(np.r_[M, N], np.ones(2)*VN, color='k')
# ax[0].plot(np.r_[M, M], np.r_[VM, VN], color='k')
# ax[0].annotate('%2.1e'%(VM-VN) , xy=(M, (VM+VN)/2), xytext=(M-9, (VM+VN)/2.), fontsize = 14)
# ax[0].annotate('%2.1e'%(VM-VN) , xy=(M, (VM+VN)/2), xytext=(M-9, (VM+VN)/2.))

props = dict(boxstyle='round', facecolor='grey', alpha=0.4)
ax[0].text(x.max()+1, ylim.max()-0.1*ylim.max(), '$\\rho_a$ = %2.2f'%(rho_a(VM, VN, A, B, M, N)),
verticalalignment='bottom', bbox=props, fontsize = 14)
verticalalignment='bottom', bbox=props)

if imgplt == 'Model':
model = rho2*np.ones(pltgrid.shape[0])
Expand All @@ -266,7 +270,7 @@ def plot_layer_potentials(rho1, rho2, h, A, B, M, N, imgplt='Model'):
# Vplt = Vplt.reshape(x.size, z.size, order='F')
# cb = ax[1].pcolor(xplt, zplt, Vplt)
# ax[1].contour(xplt, zplt, np.abs(Vplt), np.logspace(-2., 1., 10), colors='k', alpha=0.5)
# ax[1].set_ylabel('z (m)', fontsize=14)
# ax[1].set_ylabel('z (m)', fontsize=16)
# clim = ylim
# clabel = 'Potential (V)'

Expand All @@ -289,7 +293,7 @@ def plot_layer_potentials(rho1, rho2, h, A, B, M, N, imgplt='Model'):
cb = ax[1].pcolor(xplt, zplt, Vplt * fudgeFactor, cmap="viridis")
ax[1].plot([xplt.min(), xplt.max()], -h*np.r_[1., 1], color=[0.5, 0.5, 0.5], linewidth = 1.5 )
ax[1].contour(xplt, zplt, np.abs(Vplt), colors='k', alpha=0.5)
ax[1].set_ylabel('z (m)', fontsize=14)
ax[1].set_ylabel('z (m)', fontsize=16)
clim = np.r_[-15., 15.]
clabel = 'Potential (V)'

Expand Down Expand Up @@ -339,24 +343,24 @@ def plot_layer_potentials(rho1, rho2, h, A, B, M, N, imgplt='Model'):
cb = ax[1].pcolor(xplt, zplt, J, cmap="viridis", norm=LogNorm())
ax[1].plot([xplt.min(), xplt.max()], -h*np.r_[1., 1], color=[0.5, 0.5, 0.5], linewidth = 1.5 )
ax[1].streamplot(x, z, Jx.T, Jz.T, color = 'k', linewidth = 2*(np.log(J.T)-np.log(J).min())/(np.log(J).max() - np.log(J).min()) )
ax[1].set_ylabel('z (m)', fontsize=14)
ax[1].set_ylabel('z (m)', fontsize=16)

clim = np.r_[3e-5, 3e-2]
clabel = 'Current Density (A/m$^2$)'

ax[1].set_xlim([x.min(), x.max()])
ax[1].set_ylim([z.min(), 5.])
ax[1].set_ylabel('z (m)', fontsize=14)
ax[1].set_ylim([z.min(), 6.])
ax[1].set_ylabel('z (m)', fontsize=16)
cbar_ax = fig.add_axes([1., 0.08, 0.04, 0.4])
plt.colorbar(cb, cax=cbar_ax, label=clabel)
if 'clim' in locals():
cb.set_clim(clim)
ax[1].set_xlabel('x(m)', fontsize=14)
ax[1].set_xlabel('x(m)', fontsize=16)

xytextA1 = (A-0.5,2)
xytextB1 = (B-0.5,2)
xytextM1 = (M-0.5,2)
xytextN1 = (N-0.5,2)
xytextA1 = (A-0.75,2.5)
xytextB1 = (B-0.75,2.5)
xytextM1 = (M-0.75,2.5)
xytextN1 = (N-0.75,2.5)

ax[1].plot(A,1.,marker = 'v',color='red', markersize=markersize)
ax[1].plot(B,1.,marker = 'v',color='blue', markersize=markersize)
Expand Down
46 changes: 23 additions & 23 deletions em_examples/DCWidgetPlate2_5D.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
xmin = -40.
xmax = 40.
ymin = -40.
ymax = 5.
ymax = 8.
xylim = np.c_[[xmin,ymin],[xmax,ymax]]
indCC, meshcore = ExtractCoreMesh(xylim,mesh)
indx = (mesh.gridFx[:,0]>=xmin) & (mesh.gridFx[:,0]<=xmax) \
Expand Down Expand Up @@ -289,8 +289,8 @@ def calculateRhoA(survey,VM,VN,A,B,M,N):

def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):

labelsize = 12.
ticksize = 10.
labelsize = 16.
ticksize = 16.

sigplate = 1./rhoplate
sighalf = 1./rhohalf
Expand Down Expand Up @@ -349,15 +349,15 @@ def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):
if(survey == "Dipole-Pole" or survey == "Pole-Pole"):
ax[0].plot(M,VM,'o',color='k')

xytextM = (M+0.5,np.max([np.min([VM,ylim.max()]),ylim.min()])+0.5)
xytextM = (M+0.5,np.max([np.min([VM,ylim.max()]),ylim.min()])+10)
ax[0].annotate('%2.1e'%(VM), xy=xytextM, xytext=xytextM,fontsize = labelsize)

else:
ax[0].plot(M,VM,'o',color='k')
ax[0].plot(N,VN,'o',color='k')

xytextM = (M+0.5,np.max([np.min([VM,ylim.max()]),ylim.min()])+0.5)
xytextN = (N+0.5,np.max([np.min([VN,ylim.max()]),ylim.min()])+0.5)
xytextM = (M+0.5,np.max([np.min([VM,ylim.max()]),ylim.min()])+10)
xytextN = (N+0.5,np.max([np.min([VN,ylim.max()]),ylim.min()])+10)
ax[0].annotate('%2.1e'%(VM), xy=xytextM, xytext=xytextM,fontsize = labelsize)
ax[0].annotate('%2.1e'%(VN), xy=xytextN, xytext=xytextN,fontsize = labelsize)

Expand Down Expand Up @@ -598,11 +598,11 @@ def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):
ax[1].plot(qPosAvgLoc[0],qPosAvgLoc[1], marker = '.', color='black', markersize= labelsize)
ax[1].plot(qNegAvgLoc[0],qNegAvgLoc[1], marker = '.', color='black', markersize= labelsize)
if(qPosAvgLoc[0] > qNegAvgLoc[0]):
xytext_qPos = (qPosAvgLoc[0] + 1., qPosAvgLoc[1] - 0.5)
xytext_qNeg = (qNegAvgLoc[0] - 15., qNegAvgLoc[1] - 0.5)
xytext_qPos = (qPosAvgLoc[0] + 1., qPosAvgLoc[1] - 1)
xytext_qNeg = (qNegAvgLoc[0] - 15., qNegAvgLoc[1] - 1)
else:
xytext_qPos = (qPosAvgLoc[0] - 15., qPosAvgLoc[1] - 0.5)
xytext_qNeg = (qNegAvgLoc[0] + 1., qNegAvgLoc[1] - 0.5)
xytext_qPos = (qPosAvgLoc[0] - 15., qPosAvgLoc[1] - 1)
xytext_qNeg = (qNegAvgLoc[0] + 1., qNegAvgLoc[1] - 1)
ax[1].annotate('+Q = %2.1e'%(qPosSum), xy=xytext_qPos, xytext=xytext_qPos ,fontsize = labelsize)
ax[1].annotate('-Q = %2.1e'%(qNegSum), xy=xytext_qNeg, xytext=xytext_qNeg ,fontsize = labelsize)

Expand All @@ -617,10 +617,10 @@ def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):
ax[1].plot(M,1.,marker = '^',color='yellow',markersize= labelsize)
ax[1].plot(N,1.,marker = '^',color='green',markersize= labelsize)

xytextA1 = (A-0.5,2.)
xytextB1 = (B-0.5,2.)
xytextM1 = (M-0.5,2.)
xytextN1 = (N-0.5,2.)
xytextA1 = (A-0.5,3)
xytextB1 = (B-0.5,3)
xytextM1 = (M-0.5,3)
xytextN1 = (N-0.5,3)
ax[1].annotate('A', xy=xytextA1, xytext=xytextA1,fontsize = labelsize)
ax[1].annotate('B', xy=xytextB1, xytext=xytextB1,fontsize = labelsize)
ax[1].annotate('M', xy=xytextM1, xytext=xytextM1,fontsize = labelsize)
Expand All @@ -630,9 +630,9 @@ def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):
ax[1].plot(M,1.,marker = '^',color='yellow',markersize= labelsize)
ax[1].plot(N,1.,marker = '^',color='green',markersize= labelsize)

xytextA1 = (A-0.5,2.)
xytextM1 = (M-0.5,2.)
xytextN1 = (N-0.5,2.)
xytextA1 = (A-0.5,3)
xytextM1 = (M-0.5,3)
xytextN1 = (N-0.5,3)
ax[1].annotate('A', xy=xytextA1, xytext=xytextA1,fontsize = labelsize)
ax[1].annotate('M', xy=xytextM1, xytext=xytextM1,fontsize = labelsize)
ax[1].annotate('N', xy=xytextN1, xytext=xytextN1,fontsize = labelsize)
Expand All @@ -641,18 +641,18 @@ def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):
ax[1].plot(B,1.,marker = 'v',color='blue',markersize= labelsize)
ax[1].plot(M,1.,marker = '^',color='yellow',markersize= labelsize)

xytextA1 = (A-0.5,2.)
xytextB1 = (B-0.5,2.)
xytextM1 = (M-0.5,2.)
xytextA1 = (A-0.5,3)
xytextB1 = (B-0.5,3)
xytextM1 = (M-0.5,3)
ax[1].annotate('A', xy=xytextA1, xytext=xytextA1,fontsize = labelsize)
ax[1].annotate('B', xy=xytextB1, xytext=xytextB1,fontsize = labelsize)
ax[1].annotate('M', xy=xytextM1, xytext=xytextM1,fontsize = labelsize)
elif(survey == "Pole-Pole"):
ax[1].plot(A,1.,marker = 'v',color='red',markersize= labelsize)
ax[1].plot(M,1.,marker = '^',color='yellow',markersize= labelsize)

xytextA1 = (A-0.5,2.)
xytextM1 = (M-0.5,2.)
xytextA1 = (A-0.5,3)
xytextM1 = (M-0.5,3)
ax[1].annotate('A', xy=xytextA1, xytext=xytextA1,fontsize = labelsize)
ax[1].annotate('M', xy=xytextM1, xytext=xytextM1,fontsize = labelsize)

Expand Down Expand Up @@ -683,7 +683,7 @@ def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):
cb.set_label(label, fontsize=labelsize)

ax[1].set_xlim([-40.,40.])
ax[1].set_ylim([-40.,5.])
ax[1].set_ylim([-40.,8.])
# ax[1].set_aspect('equal')
plt.show()
# return fig, ax
Expand Down
Loading

0 comments on commit cb6d7ce

Please sign in to comment.