Skip to content

Commit

Permalink
Merge pull request #114 from geoscixyz/tdem_loop_app_bugfix
Browse files Browse the repository at this point in the history
fix bugs in tdem loop app
  • Loading branch information
sgkang authored Jul 25, 2018
2 parents 995e997 + 1224f37 commit d96f286
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 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.28
current_version = 0.0.29
files = em_examples/__init__.py setup.py

68 changes: 45 additions & 23 deletions em_examples/TDEMHorizontalLoopCylWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ def getData(self):
self.dBzdt = (-Pfz*self.mesh.edgeCurl*self.f[src, "e", :]).flatten()

def plotField(
self, Field='B', view="vec", scale="linear", itime=0, Geometry=True, Scenario=None
self, Field='B', view="vec", scale="linear", itime=0, Geometry=True, Scenario=None,
Fixed=False, vmin=None, vmax=None
):
# Printout for null cases
if (Field == "B") & (view == "y"):
Expand All @@ -282,7 +283,11 @@ def plotField(
elif Scenario == 'Layer':
model2D, mapping2D = self.getCoreModel('Layer')

out = self.mesh2D.plotImage(np.log10(mapping2D * model2D), ax=ax)
if Fixed:
clim=(np.log10(vmin), np.log10(vmax))
else:
clim=None
out = self.mesh2D.plotImage(np.log10(mapping2D * model2D), ax=ax, clim=clim)
cb = plt.colorbar(
out[0], ax=ax, format="$10^{%.1f}$"
)
Expand Down Expand Up @@ -342,19 +347,31 @@ def plotField(
else:
return

out = Utils.plot2Ddata(
self.mesh2D.gridCC, val, vec=vec, ax=ax,
contourOpts={"cmap": "viridis"},
ncontour=200, scale=scale
)
if Fixed:
if scale == "log":
vmin, vmax = (np.log10(vmin), np.log10(vmax))
out=ax.scatter(np.zeros(3)-1000, np.zeros(3), c=np.linspace(vmin, vmax, 3))
Utils.plot2Ddata(
self.mesh2D.gridCC, val, vec=vec, ax=ax,
contourOpts={"cmap": "viridis", "vmin":vmin, "vmax":vmax},
ncontour=200, scale=scale
)

else:
out = Utils.plot2Ddata(
self.mesh2D.gridCC, val, vec=vec, ax=ax,
contourOpts={"cmap": "viridis"},
ncontour=200, scale=scale
)[0]

if scale == "linear":
cb = plt.colorbar(
out[0], ax=ax,
out, ax=ax,
format="%.2e"
)
elif scale == "log":
cb = plt.colorbar(
out[0], ax=ax,
out, ax=ax,
format="$10^{%.1f}$"
)
else:
Expand Down Expand Up @@ -387,6 +404,8 @@ def plotField(
ax.set_ylabel("Depth (m)")
title = title + "\nt = " + '{:.2e}'.format(self.prb.times[itime]*1e3) + " ms"
ax.set_title(title)
ax.set_xlim(-190, 190)
ax.set_ylim(-190, 190)
plt.show()

######################################################
Expand All @@ -400,7 +419,7 @@ def foo(
Update, Field, AmpDir, Component,
Sigma0, Sigma1, Sigma2, Sigma3,
Sus, h1, h2, Scale,
rxOffset, z, radius, itime, Geometry=True
rxOffset, z, radius, itime, Geometry=True, Fixed=False, vmin=None, vmax=None
):

if AmpDir == "Direction (B or dBdt)":
Expand All @@ -412,21 +431,19 @@ def foo(
self.srcLoc = np.array([0., 0., z])
self.rxLoc = np.array([[rxOffset, 0., z]])
self.radius = radius
if Update == "True":
if Update:
dpred = self.simulate(
self.srcLoc, self.rxLoc, self.time, self.radius
)
self.getFields(itime)
self.getFields(itime)
return self.plotField(
Field=Field, view=Component, scale=Scale,
Geometry=Geometry, itime=itime, Scenario='Layer'
Geometry=Geometry, itime=itime, Scenario='Layer', Fixed=Fixed, vmin=vmin, vmax=vmax
)

out = widgetify(
foo,
Update=widgets.ToggleButtons(
options=["True", "False"], value="True"
),
Update=widgets.widget_bool.Checkbox(value=True, description="Update"),
Field=widgets.ToggleButtons(
options=["E", "B", "dBdt", "J", "Model"], value=fieldvalue
),
Expand Down Expand Up @@ -484,6 +501,10 @@ def foo(
min=2., max=50., step=2., value=2., continuous_update=False,
description='Tx radius (m)'
),
Fixed=widgets.widget_bool.Checkbox(value=False, description="Fixed"),
vmin=FloatText(value=None, description='vmin'),
vmax=FloatText(value=None, description='vmax')

)
return out

Expand Down Expand Up @@ -587,7 +608,7 @@ def foo(
Update, Field, AmpDir, Component,
Sigma0, Sigmab, Sigma1, Sigma2,
Sus, d1, h, d2, R, Scale,
rxOffset, z, radius, itime, Geometry=True
rxOffset, z, radius, itime, Geometry=True, Fixed=False, vmin=None, vmax=None
):

if AmpDir == "Direction (B or dBdt)":
Expand All @@ -598,21 +619,19 @@ def foo(
self.srcLoc = np.array([0., 0., z])
self.rxLoc = np.array([[rxOffset, 0., z]])
self.radius = radius
if Update == "True":
if Update:
dpred = self.simulate(
self.srcLoc, self.rxLoc, self.time, self.radius
)
self.getFields(itime)
self.getFields(itime)
return self.plotField(
Field=Field, view=Component, scale=Scale,
Geometry=Geometry, itime=itime, Scenario='Sphere'
Geometry=Geometry, itime=itime, Scenario='Sphere', Fixed=Fixed, vmin=vmin, vmax=vmax
)

out = widgetify(
foo,
Update=widgets.ToggleButtons(
options=["True", "False"], value="True"
),
Update=widgets.widget_bool.Checkbox(value=True, description="Update"),
Field=widgets.ToggleButtons(
options=["E", "B", "dBdt", "J", "Model"], value=fieldvalue
),
Expand Down Expand Up @@ -678,6 +697,9 @@ def foo(
min=1, max=70, step=1, value=1,
continuous_update=False, description='Time index'
),
Fixed=widgets.widget_bool.Checkbox(value=False, description="Fixed"),
vmin=FloatText(value=None, description='vmin'),
vmax=FloatText(value=None, description='vmax')
)
return out

Expand Down
2 changes: 1 addition & 1 deletion em_examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from matplotlib import rcParams
rcParams['font.size'] = 16

__version__ = '0.0.28'
__version__ = '0.0.29'
__author__ = 'GeoScixyz developers'
__license__ = 'MIT'
__copyright__ = 'Copyright 2017 GeoScixyz developers'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

setup(
name = 'em_examples',
version = '0.0.28',
version = '0.0.29',
packages = find_packages(),
install_requires = [
'future',
Expand Down

0 comments on commit d96f286

Please sign in to comment.