Skip to content

Commit 4cd1812

Browse files
authored
Merge pull request #243 from agilescientific/develop
release v0.5.3
2 parents 306e4b2 + 82b60fa commit 4cd1812

File tree

7 files changed

+56
-23
lines changed

7 files changed

+56
-23
lines changed
-5.1 KB
Loading

tests/test_plots.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
https://pypi.python.org/pypi/pytest-mpl/0.3
1111
"""
12+
import matplotlib.pyplot as plt
1213
import pytest
1314

1415
from welly import Well
@@ -114,7 +115,8 @@ def test_synthetic_plot():
114115
test_params = {'dt': 0.004}
115116
s = Synthetic(data, params=test_params)
116117

117-
fig = s.plot().get_figure()
118+
fig, ax = plt.subplots(figsize=(2, 10))
119+
s.plot(ax)
118120

119121
return fig
120122

@@ -127,7 +129,8 @@ def test_well_synthetic_plot():
127129
w = Well.from_las(FNAME)
128130
w.make_synthetic()
129131

130-
fig = w.data['Synthetic'].plot().get_figure()
132+
fig, ax = plt.subplots(figsize=(2, 10))
133+
w.data['Synthetic'].plot(ax)
131134

132135
return fig
133136

tests/test_synthetic.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf 8 -*-
22
"""
3-
Define a suite a tests for the Curve module.
3+
Define a suite a tests for the Synthetic class.
44
"""
55
import numpy as np
66

@@ -17,3 +17,18 @@ def test_synthetic():
1717

1818
assert s.dt == 0.004
1919
assert s.name == 'Synthetic'
20+
21+
22+
def test_synthetic_as_curve():
23+
"""
24+
Test synthetic to curve.
25+
"""
26+
data = np.array([4, 2, 0, -4, -2, 1, 3, 6, 3, 1, -2, -5, -1, 0])
27+
params = {'dt': 0.004}
28+
s = Synthetic(data, params=params)
29+
30+
crv = s.as_curve(0, 500, 0.1, mnemonic="SYNTH_CRV")
31+
32+
assert crv.index[0] == 0
33+
assert round((crv.index[1]-crv.index[0]),2) == 0.1
34+
assert crv.mnemonic == 'SYNTH_CRV'

welly/location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def trajectory(self, datum=None, elev=True, points=1000, **kwargs):
338338
339339
Returns:
340340
ndarray. An array with shape (`points` x 3) representing the well
341-
trajectory. Columns are (x, y, z).
341+
trajectory. Columns are (x, y, z).
342342
"""
343343
pos = self.position.copy()
344344

welly/synthetic.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,22 @@ def basis(self):
5555
precision_adj = self.dt / 100
5656
return np.arange(self.start, self.stop - precision_adj, self.dt)
5757

58-
def as_curve(self, data):
58+
def as_curve(self, depth_start=0., depth_stop=99999., depth_step=0.1524, mnemonic="SYN"):
5959
"""
6060
Get the synthetic as a Curve, in depth. Facilitates plotting along-
6161
side other curve data.
6262
"""
63-
params = {'mnemonic': 'SYN'}
63+
if depth_stop <= 0.:
64+
depth_stop = 99999.
6465

65-
return Curve(data, **params)
66+
new_crv = None
67+
if depth_stop > depth_start:
68+
depth_basis = np.arange(depth_start, depth_stop+depth_step, depth_step)
69+
data = np.interp(depth_basis, self.basis, self)
70+
71+
new_crv = Curve(data, mnemonic=mnemonic, index=depth_basis)
72+
73+
return new_crv
6674

6775
def plot(self, ax=None, **kwargs):
6876
"""
@@ -93,5 +101,5 @@ def plot(self, ax=None, **kwargs):
93101

94102
if return_ax:
95103
return ax
96-
97-
return fig
104+
else:
105+
return None

welly/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def bbox(points):
8484

8585
def aspect(points):
8686
"""
87-
Aspect like 2:1 is twice as wide as high.
87+
Aspect like 2:1 is shape like |___ (twice as wide as high).
8888
8989
This function returns the WIDTH per unit height.
9090
"""
@@ -542,16 +542,16 @@ def ricker(f, length, dt):
542542
A Ricker wavelet.
543543
544544
Args:
545-
f (float): frequency in Haz, e.g. 25 Hz.
545+
f (float): frequency in Hz, e.g. 25 Hz.
546546
length (float): Length in s, e.g. 0.128.
547547
dt (float): sample interval in s, e.g. 0.001.
548548
549549
Returns:
550550
tuple. time basis, amplitude values.
551551
"""
552-
t = np.linspace(-int(length / 2), int((length - dt) / 2), int(length / dt))
553-
y = (1. - 2. * (np.pi ** 2) * (f ** 2) * (t ** 2)) * np.exp(-(np.pi ** 2) * (f ** 2) * (t ** 2))
554-
return t, y
552+
time = np.arange(-length/2, length/2, dt)
553+
amp = (1. - 2.*(np.pi**2)*(f**2)*(time**2))*np.exp(-(np.pi**2)*(f**2)*(time**2))
554+
return time, amp
555555

556556

557557
def hex_to_rgb(hexx):

welly/well.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -935,27 +935,33 @@ def is_complete(self, keys=None, alias=None):
935935
def alias_has_multiple(self, mnemonic, alias):
936936
return 1 < len([a for a in alias[mnemonic] if a in self.data])
937937

938-
def make_synthetic(self, srd=0, v_repl_seismic=2000, v_repl_log=2000, f=50,
938+
def make_synthetic(self,
939+
srd=0,
940+
sonic_mnemonic="DT",
941+
density_mnemonic="RHOB",
942+
v_repl_seismic=2000,
943+
v_repl_log=2000,
944+
f=50,
939945
dt=0.001):
940946
"""
941947
Early hack. Use with extreme caution.
942948
943949
Hands-free. There'll be a more granualr version in synthetic.py.
944950
945-
Assumes DT is in µs/m and RHOB is kg/m3.
951+
Assumes Sonic is in µs/m and Density is kg/m3.
946952
947953
There is no handling yet for TVD.
948954
949955
The datum handling is probably sketchy.
950956
"""
951957
kb = getattr(self.location, 'kb', None) or 0
952-
data0 = self.data['DT'].start
958+
data0 = self.data[sonic_mnemonic].start
953959
log_start_time = ((srd - kb) / v_repl_seismic) + (data0 / v_repl_log)
954960

955961
# Basic log values.
956-
dt_log = self.data['DT'].despike() # assume µs/m
957-
rho_log = self.data['RHOB'].despike() # assume kg/m3
958-
if not np.allclose(dt_log.df.index, rho_log.df.index):
962+
dt_log = self.data[sonic_mnemonic].despike() # assume µs/m
963+
rho_log = self.data[density_mnemonic].despike() # assume kg/m3
964+
if not np.allclose(dt_log.basis, rho_log.basis):
959965
rho_log = rho_log.to_basis_like(dt_log)
960966
Z = (1e6 / dt_log.df.values) * rho_log.df.values
961967

@@ -977,12 +983,13 @@ def make_synthetic(self, srd=0, v_repl_seismic=2000, v_repl_log=2000, f=50,
977983

978984
# Convolve.
979985
_, ricker = utils.ricker(f=f, length=0.128, dt=dt)
980-
synth = np.convolve(ricker, rc_t, mode='same')
986+
synth = np.convolve(rc_t, ricker, mode='same')
981987

982-
params = {'dt': dt, 'z start': dt_log.start, 'z stop': dt_log.stop}
988+
params = {'dt': dt,
989+
'start': dt_log.start,
990+
}
983991

984992
self.data['Synthetic'] = Synthetic(synth, basis=t_reg, params=params)
985-
986993
return None
987994

988995
def qc_curve_group(self, tests, keys=None, alias=None):

0 commit comments

Comments
 (0)