Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream thickness #95

Merged
merged 17 commits into from
Dec 8, 2018
Merged

Stream thickness #95

merged 17 commits into from
Dec 8, 2018

Conversation

micmitch
Copy link
Contributor

Added stream_thickness keyword argument to plotSlice and _plotImage2D functions so that it is possible to scale the thickness of streamlines to reflect the amplitude of the vector field. This functionality was added in a manner similar to the stream_threshold keyword.

stream_thickness keyword currently takes a float which acts as a scaling factor for the streamline thickness. Bounds are hardwired to fix the thickness of the 10% largest and smallest vector amplitudes. Provides good results with the DC current density plots I've made but could probably be generalized in the future for more flexibility.

micmitch and others added 3 commits July 6, 2018 21:57
… functions so that it is possible to scale the thickness of streamlines to reflect the amplitude of the vector field. This functionality was added in a manner similar to the stream_threshold keyword.
@codecov
Copy link

codecov bot commented Jul 11, 2018

Codecov Report

Merging #95 into master will decrease coverage by 0.24%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #95      +/-   ##
==========================================
- Coverage   72.99%   72.75%   -0.25%     
==========================================
  Files          20       20              
  Lines        4503     4518      +15     
==========================================
  Hits         3287     3287              
- Misses       1216     1231      +15
Impacted Files Coverage Δ
discretize/View.py 18% <0%> (-0.37%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7bc916a...9cc77a1. Read the comment docs.

@lheagy
Copy link
Member

lheagy commented Aug 5, 2018

Thanks @micmitch: do you have a small example you could include in the discretize examples?

Copy link
Member

@lheagy lheagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @micmitch: this looks solid. There are two minor updates I have requested. See what you think and feel free to ping when you are happy with them.

vecAmp[highInds] = upperBound

# Normalize amplitudes 0-1
# norm_thickness = (np.log10(vecAmp) - np.log10(vecAmp.min())) / (np.log10(vecAmp.max()) - np.log10(vecAmp.min()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind cleaning out the commented-out line (523) if it is not needed? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -0,0 +1,83 @@
"""
Simple example to vary streamline thickness based on the vector amplitudes
Copy link
Member

@lheagy lheagy Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this @micmitch! Do you think we can shorten the title? (The whole title is included on the side-bar). What about

Plotting: Streamline thickness
==============================

A simple example to vary streamline thickness based on the vector amplitudes 

Author: `@micmitch <https://github.com/micmitch>`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@lheagy
Copy link
Member

lheagy commented Dec 6, 2018

@micmitch: would you mind adding a code snippet showing example usage (and perhaps an image from your new example) to the description of this pull request? I will use your notes as the release notes when the version is bumped (e.g. https://github.com/simpeg/discretize/releases/tag/0.3.5)

@micmitch
Copy link
Contributor Author

micmitch commented Dec 8, 2018

`

Plot secondary current densities for a pole transmitter in the ceiling of a tunnel with a conductive block 5 m above.

Set source Index

srcInd = 5
src = srcList_Combined[srcInd]

Set colorbar limits

clim = [5e-11, 4.0e-3]

Set surrent density plotting parameters

label = 'Current Density ($A/m^2$)'
pcolorOpts = {"cmap":"viridis"}
scale='linear'
cb=True

Get secondary current density values from fields object

uTotal = fields_total[src,'j']
uPrim = fields_primary[src,'j']
u = uTotal - uPrim

Set font sizes

labelsize = 30.
ticksize = 30.

Setup figure

fig = plt.figure()
ax = plt.subplot(111)
fig.set_figheight(30)
fig.set_figwidth(15)

Plot slice

dat = mesh.plotSlice(u, ax=ax, normal='X', ind=49, vType='F', view='vec', streamOpts={'color':'w', 'density':2.0}, gridOpts={"color":"k", "alpha":0.1}, grid=True, range_x=[-30, 30], range_y=[-20, 20], clim=[5e-11, 4.0e-3], stream_threshold=1e-8, stream_thickness=3)

Plot outline of conductive block above the tunnel

getBlkOutline(sigmaTrue_Block,mesh,sliceInd,normal=sliceNormal, ax=ax, lineWidth=3.0)

Plot electrode locations

ax.scatter(elecLocs[:,1],elecLocs[:,2], c='w', edgecolors='k', s=150)

Label Tx electrode

A = src.loc
ax.plot(A[1],A[2], marker = 'o',color='red', markersize=15)
yztextA1 = (A[1]-0.6,A[2] + 0.5)
ax.annotate('A', xy=yztextA1, xytext=yztextA1,fontsize = labelsize, color='w', weight='bold')

Add title and set layout

ax.set_title("N-S section at "+ "{0:.2f}".format(mesh.vectorCCx[sliceInd])+"m")
ax.set_xlim(ylim)
ax.set_ylim(zlim)

plt.gca().set_aspect('equal', adjustable='box')
plt.tight_layout()

Add colorbar

if scale == "log":
cbformat = "$10^{%1.1f}$"
elif scale == "linear":
cbformat = "%.1e"

if cb:
if clim is None:
cmin, cmax = dat[0].get_clim()
else:
cmin, cmax = clim[0],clim[1]

cb = add_colorbar(dat[0], format=cbformat, ax=ax, orientation="vertical",ticks = np.linspace(cmin, cmax, 5))

cb.ax.tick_params(labelsize=labelsize-4.0)
cb.set_label(label, fontsize=labelsize)
cb.set_clim([cmin, cmax])`

@micmitch
Copy link
Contributor Author

micmitch commented Dec 8, 2018

@micmitch
Copy link
Contributor Author

micmitch commented Dec 8, 2018

Is this what you had in mind?

@lheagy
Copy link
Member

lheagy commented Dec 8, 2018

The image looks great! I didn't mean for you to copy the whole example in, just a minimal part, but I can extract a subset

e.g.

mesh.plotSlice(
    u, ax=ax, normal='X', vType='F', view='vec', stream_threshold=1e-8, stream_thickness=3
)

@lheagy lheagy merged commit 82fa11c into master Dec 8, 2018
@lheagy lheagy deleted the StreamThickness branch December 8, 2018 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants