Skip to content

Commit

Permalink
Ensure consistent snake-case varibale names are used.
Browse files Browse the repository at this point in the history
    - Previously mixed camel-case and snake-case for variables
      names. Have tried to use consitent snake-case for all
      varibales, while keeping camel-case for classes.
  • Loading branch information
andrewdnolan committed Feb 1, 2024
1 parent 4b0f35a commit 7025f22
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
64 changes: 32 additions & 32 deletions compass/landice/tests/mismipplus/setup_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def run(self):
# read the resolution from the .cfg file at runtime
resolution = section.getfloat('resolution')
# read the gutter lenth from the .cfg file
gutterLength = section.getfloat('gutter_length')
# ensure that the requested `gutterLength` is valid. Otherwise set
# the value to zero, such that the default `gutterLength` of two
gutter_length = section.getfloat('gutter_length')
# ensure that the requested `gutter_length` is valid. Otherwise set
# the value to zero, such that the default `gutter_length` of two
# gridcells is used.
if (gutterLength < 2. * resolution) and (gutterLength != 0.):
gutterLength = 0.
if (gutter_length < 2. * resolution) and (gutter_length != 0.):
gutter_length = 0.

# check if the resolution has been changed since the `compass setup`
# command was run
Expand All @@ -96,10 +96,10 @@ def run(self):
f' setup` command in order to create a mesh at a'
f' resolution of {resolution:4.0f}m')

nx, ny, dc = calculateMeshParams(nominal_resolution=resolution,
Lx=Lx,
Ly=Ly,
gutterLength=gutterLength)
nx, ny, dc = calculate_mesh_params(nominal_resolution=resolution,
Lx=Lx,
Ly=Ly,
gutter_length=gutter_length)

ds_mesh = make_planar_hex_mesh(nx=nx, ny=ny, dc=dc,
nonperiodic_x=True,
Expand Down Expand Up @@ -137,10 +137,10 @@ def run(self):
filename='landice_grid.nc')


def calculateMeshParams(nominal_resolution,
Lx=640e3,
Ly=80e3,
gutterLength=0.0):
def calculate_mesh_params(nominal_resolution,
Lx=640e3,
Ly=80e3,
gutter_length=0.0):
"""
Calculate the appropriate parameters for use by `make_planar_hex_mesh`
from the desired nominal resolution (e.g. 8e3, 4e3, 2e3, 1e3...).
Expand All @@ -156,7 +156,7 @@ def calculateMeshParams(nominal_resolution,
Ly : float
Domain length in y direction [m]
gutterLength : float
gutter_length : float
Desired gutter length [m] on the eastern domain. Default value of 0.0
will ensure there are two extra cell for the gutter.
"""
Expand Down Expand Up @@ -208,7 +208,7 @@ def calculate_dc(Ly, ny):

return dc

def calculate_nx(Lx, dc, gutterLength):
def calculate_nx(Lx, dc, gutter_length):
"""
Caluculate the number of x gridcell, per the required `dc` with
considerations for the requested gutter length
Expand All @@ -221,12 +221,12 @@ def calculate_nx(Lx, dc, gutterLength):
dc : float
Edge length [m]
gutterLength: float
gutter_length: float
Desired gutter length [m] on the eastern domain. A value of 0.0
will result in two extra cell for the gutter.
"""

if gutterLength == 0.0:
if gutter_length == 0.0:
nx = np.ceil(Lx / dc)
# The modulo condition below ensures there is exactly one cell
# past the the desired domain length. So, when no gutter
Expand All @@ -235,7 +235,7 @@ def calculate_nx(Lx, dc, gutterLength):
nx += 1
else:
# amend the domain length to account for the gutter
Lx += gutterLength
Lx += gutter_length
nx = np.ceil(Lx / dc)

# Just rounding `nx` up to the nearest `int` doesn't gurantee that the
Expand All @@ -250,7 +250,7 @@ def calculate_nx(Lx, dc, gutterLength):

ny = calculate_ny(nominal_resolution, Ly)
dc = calculate_dc(Ly, ny)
nx = calculate_nx(Lx, dc, gutterLength)
nx = calculate_nx(Lx, dc, gutter_length)

# add two to `ny` to accomodate MISMIP+ specific culling requirments.
# This ensures, after the culling, that the cell center to cell center
Expand All @@ -273,10 +273,10 @@ def mark_cull_cells_for_MISMIP(ds_mesh):
# calculate the amplitude (i.e. `dy`) [m] of the dual mesh
dy = np.sqrt(3.) / 2. * dc
# Get the y position of the top row
yMax = ds_mesh.yCell.max()
y_max = ds_mesh.yCell.max()

# find the first interior row along the top of the domain
mask = np.isclose(ds_mesh.yCell, yMax - dy, rtol=0.02)
mask = np.isclose(ds_mesh.yCell, y_max - dy, rtol=0.02)

# add first interior row along northern boudnary to the cells to be culled
ds_mesh['cullCell'] = xr.where(mask, 1, ds_mesh.cullCell)
Expand All @@ -296,17 +296,17 @@ def center_trough(ds_mesh):
"""

# Get the center of y-axis (i.e. half distance)
yCenter = (ds_mesh.yCell.max() + ds_mesh.yCell.min()) / 2.
y_center = (ds_mesh.yCell.max() + ds_mesh.yCell.min()) / 2.

# Shift x-axis so that the x-origin is all the way to the left
xShift = -1.0 * ds_mesh.xCell.min()
x_shift = -1.0 * ds_mesh.xCell.min()
# Shift y-axis so that it's centered about the MISMIP+ bed trough
yShift = 4.e4 - yCenter
y_shift = 4.e4 - y_center

# Shift all spatial points by calculated shift
for loc in ['Cell', 'Edge', 'Vertex']:
ds_mesh[f'x{loc}'] = ds_mesh[f'x{loc}'] + xShift
ds_mesh[f'y{loc}'] = ds_mesh[f'y{loc}'] + yShift
ds_mesh[f'x{loc}'] = ds_mesh[f'x{loc}'] + x_shift
ds_mesh[f'y{loc}'] = ds_mesh[f'y{loc}'] + y_shift

##########################################################################
# WHL :
Expand Down Expand Up @@ -334,21 +334,21 @@ def center_trough(ds_mesh):
# get the distance between edges
de = 0.5 * dc * np.sin(np.pi / 3)
# find the min and max (i.e. N/S boundary) edges
yMin = ds_mesh.yEdge.min()
yMax = ds_mesh.yEdge.max()
y_min = ds_mesh.yEdge.min()
y_max = ds_mesh.yEdge.max()

# Boolean mask for edge indices on the N/S boundary of the mesh
mask = (np.isclose(ds_mesh.yEdge, yMin, rtol=0.01) |
np.isclose(ds_mesh.yEdge, yMax, rtol=0.01))
mask = (np.isclose(ds_mesh.yEdge, y_min, rtol=0.01) |
np.isclose(ds_mesh.yEdge, y_max, rtol=0.01))
# WHL: zero out the edges on the boundary
# (not necessary because velocity will also be zero)
ds_mesh['dvEdge'] = xr.where(mask, 0.0, ds_mesh.dvEdge)

# Boolean mask for the indexed of edges N/S of boundary cell centers,
# using a 2% relative threshold to account for accumulated roundoff
# from min calculation
mask = (np.isclose(ds_mesh.yEdge, yMin + de, rtol=0.02) |
np.isclose(ds_mesh.yEdge, yMax - de, rtol=0.02))
mask = (np.isclose(ds_mesh.yEdge, y_min + de, rtol=0.02) |
np.isclose(ds_mesh.yEdge, y_max - de, rtol=0.02))
# cut length in half for edges between boundary cells
ds_mesh['dvEdge'] = xr.where(mask, ds_mesh.dvEdge * 0.5, ds_mesh.dvEdge)

Expand Down
2 changes: 1 addition & 1 deletion compass/landice/tests/mismipplus/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def approx_cell_count(resolution, gutter_length):
resolution : float
The nominal resolution requested in the configuration file.
gutterLength: float
gutter_length: float
Desired gutter length [m] on the eastern domain.
Returns
Expand Down

0 comments on commit 7025f22

Please sign in to comment.