Skip to content

Commit 19b23d2

Browse files
committedOct 15, 2024·
Exposed sigma for LSC class for backward compatibility.
1 parent 1576f61 commit 19b23d2

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed
 

‎pyschism/mesh/vgrid.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,35 @@ def is3D(self):
108108

109109
class LSC2(Vgrid):
110110

111-
def __init__(self, hsm, nv, h_c, theta_b, theta_f):
111+
def __init__(self, hsm, nv, h_c, theta_b, theta_f, sigma):
112112
self.hsm = np.array(hsm)
113113
self.nv = np.array(nv)
114114
self.h_c = h_c
115115
self.theta_b = theta_b
116116
self.theta_f = theta_f
117117
self.m_grid = None
118118
self._znd = None
119-
self._snd = None
120119
self._nlayer = None
120+
self.sigma = sigma # expose sigma for backward compatibility
121+
self._snd = self.sigma
122+
123+
@classmethod
124+
def from_sigma(cls, sigma):
125+
'''
126+
Initialize the LSC2 class using the sigma values for backward compatibility
127+
128+
sigma: np.ndarray of shape (n, m), where
129+
n: number of horizontal nodes
130+
m: number of vertical layers
131+
'''
132+
hsm = None # placeholder value
133+
nv = sigma.shape[1] # number of vertical layers
134+
h_c = None # placeholder value
135+
theta_b = None # placeholder value
136+
theta_f = None # placeholder value
137+
138+
# Return an instance of the class using the computed values
139+
return cls(hsm=hsm, nv=nv, h_c=h_c, theta_b=theta_b, theta_f=theta_f, sigma=sigma)
121140

122141
def __str__(self):
123142
f = [
@@ -298,7 +317,7 @@ def open(cls, path):
298317

299318
sline = np.array(lines[2].split()).astype('float')
300319
if sline.min() < 0:
301-
#old version
320+
# old version
302321
kbp = np.array([int(i.split()[1])-1 for i in lines[2:]])
303322
sigma = -np.ones((len(kbp), nvrt))
304323

@@ -307,15 +326,15 @@ def open(cls, path):
307326
line.strip().split()[2:]).astype('float')
308327

309328
else:
310-
#new version
329+
# new version
311330
sline = sline.astype('int')
312331
kbp = sline-1
313332
sigma = np.array([line.split()[1:] for line in lines[3:]]).T.astype('float')
314-
#replace -9. with -1.
315-
fpm = sigma<-1
333+
# replace -9. with -1.
334+
fpm = sigma < -1
316335
sigma[fpm] = -1
317336

318-
return cls(sigma)
337+
return cls.from_sigma(sigma)
319338

320339
@property
321340
def nvrt(self):

0 commit comments

Comments
 (0)
Please sign in to comment.