Skip to content

Commit 534afa2

Browse files
Second attempt at fixing mypy errors
1 parent e31309b commit 534afa2

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

imod/select/cross_sections.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,14 @@ def _cross_section(data, linecoords):
274274
else:
275275
ys[1:] += np.abs(dy_a).cumsum()
276276

277-
length = linecoords.size - 1
278-
279-
ixs = np.empty(length, dtype=np.int64)
280-
iys = np.empty(length, dtype=np.int64)
281-
sdxs = np.empty(length, dtype=np.float64)
282-
sdys = np.empty(length, dtype=np.float64)
283-
segments = np.empty(length, dtype=np.float64)
277+
ixs_ls = []
278+
iys_ls = []
279+
sdxs_ls = []
280+
sdys_ls = []
281+
segments_ls = []
284282

285283
bounding_box = _bounding_box(xmin, xmax, ymin, ymax)
286-
for idx, (start, end) in enumerate(zip(linecoords[:-1], linecoords[1:])):
284+
for start, end in zip(linecoords[:-1], linecoords[1:]):
287285
linestring = sg.LineString([start, end])
288286
if not linestring.length:
289287
continue
@@ -294,21 +292,28 @@ def _cross_section(data, linecoords):
294292
xs, ys, x0, x1, y0, y1, xmin, xmax, ymin, ymax
295293
)
296294
else: # append the linestring in full as nodata section
297-
i = -1
298-
j = -1
299-
sdx = -1
300-
sdy = -1
301-
segment_length = linestring.length
302-
303-
ixs[idx] = i
304-
iys[idx] = j
305-
sdxs[idx] = sdx
306-
sdys[idx] = sdy
307-
segments[idx] = segment_length
308-
309-
if np.all(ixs == -1):
295+
i = np.array([-1])
296+
j = np.array([-1])
297+
sdx = np.array([-1])
298+
sdy = np.array([-1])
299+
segment_length = np.array([linestring.length])
300+
301+
ixs_ls.append(i)
302+
iys_ls.append(j)
303+
sdxs_ls.append(sdx)
304+
sdys_ls.append(sdy)
305+
segments_ls.append(segment_length)
306+
307+
if len(ixs_ls) == 0:
310308
raise ValueError("Linestring does not intersect data")
311309

310+
# Concatenate into a single array
311+
ixs = np.concatenate(ixs_ls)
312+
iys = np.concatenate(iys_ls)
313+
sdxs = np.concatenate(sdxs_ls)
314+
sdys = np.concatenate(sdys_ls)
315+
segments = np.concatenate(segments_ls)
316+
312317
# Flip around indexes
313318
if x_decreasing:
314319
ixs = ncol - 1 - ixs

0 commit comments

Comments
 (0)