Skip to content

Commit 82fa11c

Browse files
authored
Merge pull request #95 from simpeg/StreamThickness
Stream thickness
2 parents 7bc916a + 9cc77a1 commit 82fa11c

File tree

6 files changed

+129
-9
lines changed

6 files changed

+129
-9
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[bumpversion]
2-
current_version = 0.3.6
2+
current_version = 0.3.7
33
files = setup.py discretize/__init__.py docs/conf.py
44

discretize/View.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ def plotSlice(
206206
range_x=None,
207207
range_y=None,
208208
sample_grid=None,
209-
stream_threshold=None
209+
stream_threshold=None,
210+
stream_thickness=None
210211
):
211212

212213
"""
@@ -249,7 +250,8 @@ def plotSlice(
249250
v, vType=vTypeI, normal=normal, ind=ind, grid=grid,
250251
view=view, ax=ax, clim=clim, showIt=False,
251252
pcolorOpts=pcolorOpts, streamOpts=streamOpts,
252-
gridOpts=gridOpts, stream_threshold=stream_threshold
253+
gridOpts=gridOpts, stream_threshold=stream_threshold,
254+
stream_thickness=stream_thickness
253255
)
254256
]
255257
return out
@@ -351,7 +353,9 @@ def doSlice(v):
351353
range_x=range_x,
352354
range_y=range_y,
353355
sample_grid=sample_grid,
354-
stream_threshold=stream_threshold
356+
stream_threshold=stream_threshold,
357+
stream_thickness=stream_thickness
358+
355359
)
356360

357361
ax.set_xlabel('y' if normal == 'X' else 'x')
@@ -368,7 +372,8 @@ def _plotImage2D(
368372
range_x=None,
369373
range_y=None,
370374
sample_grid=None,
371-
stream_threshold=None
375+
stream_threshold=None,
376+
stream_thickness=None
372377
):
373378

374379
if pcolorOpts is None:
@@ -494,6 +499,36 @@ def _plotImage2D(
494499
Ui = np.ma.masked_where(mask_me, Ui)
495500
Vi = np.ma.masked_where(mask_me, Vi)
496501

502+
503+
if stream_thickness is not None:
504+
scaleFact = np.copy(stream_thickness)
505+
506+
# Calculate vector amplitude
507+
vecAmp = np.sqrt(U**2 + V**2).T
508+
509+
# Form bounds to knockout the top and bottom 10%
510+
vecAmp_sort = np.sort(vecAmp.ravel())
511+
nVecAmp = vecAmp.size
512+
tenPercInd = int(np.ceil(0.1*nVecAmp))
513+
lowerBound = vecAmp_sort[tenPercInd]
514+
upperBound = vecAmp_sort[-tenPercInd]
515+
516+
lowInds = np.where(vecAmp < lowerBound)
517+
vecAmp[lowInds] = lowerBound
518+
519+
highInds = np.where(vecAmp > upperBound)
520+
vecAmp[highInds] = upperBound
521+
522+
# Normalize amplitudes 0-1
523+
norm_thickness = vecAmp/vecAmp.max()
524+
525+
# Scale by user defined thickness factor
526+
stream_thickness = scaleFact*norm_thickness
527+
528+
# Add linewidth to streamOpts
529+
streamOpts.update({'linewidth':stream_thickness})
530+
531+
497532
out += (
498533
ax.pcolormesh(
499534
x, y, np.sqrt(U**2+V**2).T, vmin=clim[0], vmax=clim[1],

discretize/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"""
2828
)
2929

30-
__version__ = '0.3.6'
30+
__version__ = '0.3.7'
3131
__author__ = 'SimPEG Team'
3232
__license__ = 'MIT'
3333
__copyright__ = '2013 - 2017, SimPEG Developers, http://simpeg.xyz'

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
# built documents.
6161
#
6262
# The short X.Y version.
63-
version = '0.3.6'
63+
version = '0.3.7'
6464
# The full version, including alpha/beta/rc tags.
65-
release = '0.3.6'
65+
release = '0.3.7'
6666

6767
# The language for content autogenerated by Sphinx. Refer to documentation
6868
# for a list of supported languages.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Plotting: Streamline thickness
3+
==============================
4+
5+
A simple example to vary streamline thickness based on the vector amplitudes
6+
7+
Author: `@micmitch <https://github.com/micmitch>`
8+
"""
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
12+
from discretize import TensorMesh
13+
14+
###############################################################################
15+
# Create mesh
16+
# -----------
17+
#
18+
# Minimum cell size in each direction
19+
dx = 1.
20+
dy = 1.
21+
dz = 1.
22+
23+
# Number of core cells in each direction
24+
nCoreX = 43.
25+
nCoreY = 43.
26+
nCoreZ = 43.
27+
28+
# Cell widths
29+
hx = [(dx,nCoreX)]
30+
hy = [(dy,nCoreY)]
31+
hz = [(dz,nCoreZ)]
32+
33+
# Desired Core mesh origin (Bottom SW corner)
34+
x0 = -21.5
35+
y0 = -21.5
36+
z0 = -21.5
37+
38+
mesh = TensorMesh([hx, hy, hz],[x0,y0,z0])
39+
print(mesh.nC)
40+
41+
###############################################################################
42+
# Define arbitrary function to plot
43+
# ---------------------------------
44+
#
45+
46+
X = mesh.gridCC[:,0]
47+
Y = mesh.gridCC[:,1]
48+
Z = mesh.gridCC[:,2]
49+
50+
U = -1 - X**2 + Y + Z
51+
V = 1 + X - Y**2 + Z
52+
W = 1 + X + Y - Z**2
53+
54+
###############################################################################
55+
# Plot streamlines
56+
# ----------------
57+
#
58+
# Create figure
59+
fig = plt.figure()
60+
ax = plt.subplot(111)
61+
fig.set_figheight(15)
62+
fig.set_figwidth(15)
63+
labelsize = 30.
64+
ticksize = 30.
65+
66+
# Create data vector
67+
dataVec = np.hstack([U,V,W])
68+
print(dataVec.shape)
69+
70+
# Set streamline plotting options
71+
streamOpts = {'color':'w', 'density':2.0}
72+
pcolorOpts = {"cmap":"viridis"}
73+
74+
dat = mesh.plotSlice(
75+
dataVec, ax=ax, normal='Z', ind=5, vType='CCv', view='vec',
76+
streamOpts=streamOpts, gridOpts={"color":"k", "alpha":0.1}, grid=True,
77+
clim=None, stream_thickness=3
78+
)
79+
80+
###############################################################################
81+
# Moving Forward
82+
# --------------
83+
#
84+
# If you have suggestions for improving this example, please create a
85+
# pull request on the example in discretize

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def configuration(parent_package='', top_path=None):
5656

5757
setup(
5858
name="discretize",
59-
version="0.3.6",
59+
version="0.3.7",
6060
install_requires=[
6161
'numpy>=1.7',
6262
'scipy>=0.13',

0 commit comments

Comments
 (0)