Skip to content

Commit

Permalink
Exposed sigma for LSC class for backward compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
feiye-vims committed Oct 15, 2024
1 parent 1576f61 commit 19b23d2
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions pyschism/mesh/vgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,35 @@ def is3D(self):

class LSC2(Vgrid):

def __init__(self, hsm, nv, h_c, theta_b, theta_f):
def __init__(self, hsm, nv, h_c, theta_b, theta_f, sigma):
self.hsm = np.array(hsm)
self.nv = np.array(nv)
self.h_c = h_c
self.theta_b = theta_b
self.theta_f = theta_f
self.m_grid = None
self._znd = None
self._snd = None
self._nlayer = None
self.sigma = sigma # expose sigma for backward compatibility
self._snd = self.sigma

@classmethod
def from_sigma(cls, sigma):
'''
Initialize the LSC2 class using the sigma values for backward compatibility
sigma: np.ndarray of shape (n, m), where
n: number of horizontal nodes
m: number of vertical layers
'''
hsm = None # placeholder value
nv = sigma.shape[1] # number of vertical layers
h_c = None # placeholder value
theta_b = None # placeholder value
theta_f = None # placeholder value

# Return an instance of the class using the computed values
return cls(hsm=hsm, nv=nv, h_c=h_c, theta_b=theta_b, theta_f=theta_f, sigma=sigma)

def __str__(self):
f = [
Expand Down Expand Up @@ -298,7 +317,7 @@ def open(cls, path):

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

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

else:
#new version
# new version
sline = sline.astype('int')
kbp = sline-1
sigma = np.array([line.split()[1:] for line in lines[3:]]).T.astype('float')
#replace -9. with -1.
fpm = sigma<-1
# replace -9. with -1.
fpm = sigma < -1
sigma[fpm] = -1

return cls(sigma)
return cls.from_sigma(sigma)

@property
def nvrt(self):
Expand Down

0 comments on commit 19b23d2

Please sign in to comment.