Skip to content

Commit 8e9d204

Browse files
authored
Merge pull request #34 from liamtoney/pass-rij
Allow users to directly pass an `rij` array to `ltsva()`
2 parents 5a52703 + 69f9b67 commit 8e9d204

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

lts_array/classes/lts_data_class.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ def __init__(self, window_length, window_overlap, alpha):
1717
self.window_overlap = window_overlap
1818
self.alpha = alpha
1919

20-
def build_data_arrays(self, st, latlist, lonlist, remove_elements=None):
20+
def build_data_arrays(self, st, latlist, lonlist, remove_elements=None, rij=None):
2121
""" Collect basic data from stream file. Project lat/lon into r_ij coordinates.
2222
23+
Alternatively, if ``rij`` is provided, ``latlist`` and ``lonlist`` are not used
24+
and the provided Cartesion coordinates ``rij`` are used instead.
25+
2326
Args:
2427
st (stream): An obspy stream object.
2528
latlist (list): A list of latitude points.
2629
lonlist (list): A list of longitude points.
2730
remove_elements (list): A list of elements to remove before processing. Python numbering is used, so "[0]" removes the first element.
31+
rij (array or None): A NumPy array with the first row corresponding to
32+
cartesian "X" - coordinates and the second row corresponding to
33+
cartesian "Y" - coordinates, in units of km. If this is provided then
34+
``latlist`` and ``lonlist`` are ignored.
2835
"""
2936
# Check that all traces have the same length
3037
if len(set([len(tr) for tr in st])) != 1:
@@ -35,8 +42,14 @@ def build_data_arrays(self, st, latlist, lonlist, remove_elements=None):
3542
remove_elements = np.sort(remove_elements)
3643
for jj in range(0, len(remove_elements)):
3744
st.remove(st[remove_elements[jj]])
38-
latlist.remove(latlist[remove_elements[jj]])
39-
lonlist.remove(lonlist[remove_elements[jj]])
45+
if rij is None:
46+
latlist.remove(latlist[remove_elements[jj]])
47+
lonlist.remove(lonlist[remove_elements[jj]])
48+
else:
49+
_x, _y = [list(_) for _ in rij]
50+
_x.remove(_x[remove_elements[jj]])
51+
_y.remove(_y[remove_elements[jj]])
52+
rij = np.array([_x, _y])
4053
remove_elements -= 1
4154

4255
# Save the station name
@@ -69,7 +82,11 @@ def build_data_arrays(self, st, latlist, lonlist, remove_elements=None):
6982
for ii, tr in enumerate(st):
7083
self.data[:, ii] = tr.data
7184
# Set the array coordinates
72-
self.rij = self.getrij(latlist, lonlist)
85+
if rij is None:
86+
self.rij = self.getrij(latlist, lonlist)
87+
else:
88+
print('Ignoring `lat_list` and `lon_list` since `rij` array was provided!')
89+
self.rij = rij
7390
# Make sure the least squares problem is well-posed
7491
# rij must have at least 3 elements
7592
if np.shape(self.rij)[1] < 3:
@@ -92,10 +109,9 @@ def getrij(self, latlist, lonlist):
92109
93110
Returns:
94111
(array):
95-
``rij``: A numpy array with the first row corresponding to
112+
``rij``: A NumPy array with the first row corresponding to
96113
cartesian "X" - coordinates and the second row
97-
corresponding to cartesian "Y" - coordinates.
98-
114+
corresponding to cartesian "Y" - coordinates, in units of km.
99115
"""
100116

101117
# Check that the lat-lon arrays are the same size.

lts_array/ltsva.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
warnings.simplefilter(action='ignore', category=FutureWarning)
77

88

9-
def ltsva(st, lat_list, lon_list, window_length, window_overlap, alpha=1.0, plot_array_coordinates=False, remove_elements=None):
9+
def ltsva(st, lat_list, lon_list, window_length, window_overlap, alpha=1.0, plot_array_coordinates=False, remove_elements=None, rij=None):
1010
r""" Process infrasound or seismic array data with least trimmed squares (LTS).
1111
1212
Args:
@@ -19,6 +19,10 @@ def ltsva(st, lat_list, lon_list, window_length, window_overlap, alpha=1.0, plot
1919
Choose 1.0 for ordinary least squares (default).
2020
plot_array_coordinates (bool): Plot array coordinates? Defaults to False.
2121
remove_elements (list): (Optional) Remove element number(s) from ``st``, ``lat_list``, and ``lon_list`` before processing. Here numbering refers to the Python index (e.g. [0] = remove 1st element in stream).
22+
rij (array or None): A NumPy array with the first row corresponding to cartesian
23+
"X" - coordinates and the second row corresponding to cartesian "Y" -
24+
coordinates, in units of km. If this is provided then ``lat_list`` and
25+
``lon_list`` are ignored.
2226
2327
Returns:
2428
(tuple):
@@ -36,7 +40,7 @@ def ltsva(st, lat_list, lon_list, window_length, window_overlap, alpha=1.0, plot
3640

3741
# Build data object
3842
data = DataBin(window_length, window_overlap, alpha)
39-
data.build_data_arrays(st, lat_list, lon_list, remove_elements)
43+
data.build_data_arrays(st, lat_list, lon_list, remove_elements, rij)
4044

4145
# Plot array coordinates as a check
4246
if plot_array_coordinates:

0 commit comments

Comments
 (0)