Skip to content

Commit 9c13f43

Browse files
committed
update to lengthAwareSegmentation for backwards compatibility
-factor can be either be a float or a list
1 parent 02222ff commit 9c13f43

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

moorpy/helpers.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,16 +1553,18 @@ def lines2subsystem(lines,points, ms,span=None,case=0):
15531553

15541554
return(ms)
15551555

1556-
def lengthAwareSegmentation(lineList, factor=[1,1], w_cutoff = 1000):
1556+
def lengthAwareSegmentation(lineList, factor=1, w_cutoff = 1000):
15571557
'''Function to segment a set of lines based on their lengths
15581558
to give appropriate segment lengths.
15591559
15601560
Parameters
15611561
----------
15621562
lineList : list
15631563
List of line objects to segment
1564-
factor : list
1565-
List of factors to multiply segment # by
1564+
factor : float or list
1565+
Factor(s) to multiply segment # by. If a single float is provided, it is applied to all lines.
1566+
If a list of two floats is provided, the first is applied to lines with wet weight less than w_cutoff,
1567+
and the second is applied to lines with wet weight greater than w_cutoff.
15661568
w_cutoff : float
15671569
apply factor [0] if linetype wet weight is less than w_cutoff, apply factor[1] if greater than w_cutoff
15681570
@@ -1573,10 +1575,16 @@ def lengthAwareSegmentation(lineList, factor=[1,1], w_cutoff = 1000):
15731575
'''
15741576
for line in lineList:
15751577
line.nNodes = int(np.ceil( np.sqrt(np.maximum(1, line.L-10))/2 ) + 1)
1576-
if line.type['w'] < w_cutoff:
1577-
line.nNodes = int(line.nNodes * factor[0])
1578+
if isinstance(factor, list):
1579+
if len(factor) != 2:
1580+
raise ValueError("If factor is a list, it must have two elements: [factor_for_lines_below_w_cutoff, factor_for_lines_above_w_cutoff]")
1581+
else:
1582+
if line.type['w'] < w_cutoff:
1583+
line.nNodes = int(line.nNodes * factor[0])
1584+
else:
1585+
line.nNodes = int(line.nNodes *factor[1])
15781586
else:
1579-
line.nNodes = int(line.nNodes *factor[1])
1587+
line.nNodes = int(line.nNodes * factor)
15801588
if line.nNodes == 1:
15811589
line.nNodes += 1 # minimum of 1 segment (two nodes)
15821590

0 commit comments

Comments
 (0)