Skip to content

Commit

Permalink
Merge pull request #161 from noaa-ocs-modeling/bugfix/meshplot
Browse files Browse the repository at this point in the history
Fix index vs ID core bug
  • Loading branch information
SorooshMani-NOAA authored Mar 2, 2023
2 parents 244ae8a + bbca5ae commit 811b1b9
Show file tree
Hide file tree
Showing 20 changed files with 275 additions and 196 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/quick_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
path: ${{ env.pythonLocation }}
key: test-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: install dependencies
run: pip install ".[testing]"
run: |
sudo apt install libhdf5-dev
sudo apt install libnetcdf-dev
pip install ".[testing]"
- name: run tests
run: pytest --numprocesses auto
24 changes: 22 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ jobs:
with:
path: ${{ env.pythonLocation }}
key: test-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: install dependencies
- name: install linux dependencies
run: |
sudo apt install libhdf5-dev
sudo apt install libnetcdf-dev
if: runner.os == 'Linux'
- name: install macos dependencies
run: |
brew install hdf5
brew install netcdf
if: runner.os == 'macOS'
- name: install repo
run: pip install ".[testing]"
- name: run tests
run: pytest --numprocesses auto
Expand All @@ -80,7 +90,17 @@ jobs:
with:
path: ${{ env.pythonLocation }}
key: test-${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}
- name: install dependencies
- name: install linux dependencies
run: |
sudo apt install libhdf5-dev
sudo apt install libnetcdf-dev
if: runner.os == 'Linux'
- name: install macos dependencies
run: |
brew install hdf5
brew install netcdf
if: runner.os == 'macOS'
- name: install repo
run: pip install ".[testing]"
- name: run tests with coverage
run: pytest --numprocesses auto --cov . --cov-report xml:coverage.xml
Expand Down
2 changes: 1 addition & 1 deletion adcircpy/fort15.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def get_tidal_forcing(self) -> str:
for index, row in self.mesh.boundaries.ocean.gdf.iterrows():
for constituent in self.mesh.forcings.tides.get_active_constituents():
f.append(fort15_line(constituent))
vertices = self.mesh.get_xy(crs='EPSG:4326').loc[row.indexes, :].values
vertices = self.mesh.get_xy(crs='EPSG:4326').iloc[row.indexes, :].values
amp, phase = self.mesh.forcings.tides.tidal_dataset(constituent, vertices)
f.extend(
fort15_line(f'{amp[i]:.8e} {phase[i]:.8e}')
Expand Down
32 changes: 29 additions & 3 deletions adcircpy/mesh/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,35 @@ def open(cls, file: Union[str, os.PathLike], crs: Union[str, CRS] = None):
@figure
def tricontourf(self, axes=None, show=True, figsize=None, cbar=False, **kwargs):
if len(self.triangles) > 0:
ax = axes.tricontourf(self.x, self.y, self.triangles, self.values, **kwargs)
values = self.values.values # this is a numpy array
if values.shape[1] > 1:
values = np.linalg.norm(values, ord=2, axis=1)
get_idx = self.nodes.index.get_loc
ax = axes.tricontourf(
self.x,
self.y,
[[get_idx(n_id) for n_id in tri] for tri in self.triangles.values],
values.squeeze(),
**kwargs,
)
if cbar is True:
plt.colorbar(ax)
return axes

@figure
def tripcolor(self, axes=None, show=True, figsize=None, **kwargs):
if len(self.triangles) > 0:
axes.tripcolor(self.x, self.y, self.triangles, self.values, **kwargs)
values = self.values.values # this is a numpy array
if values.shape[1] > 1:
values = np.linalg.norm(values, ord=2, axis=1)
get_idx = self.nodes.index.get_loc
axes.tripcolor(
self.x,
self.y,
[[get_idx(n_id) for n_id in tri] for tri in self.triangles.values],
values.squeeze(),
**kwargs,
)
return axes

@figure
Expand All @@ -478,7 +498,13 @@ def triplot(
if len(self.triangles) > 0:
kwargs.update({'linewidth': linewidth})
kwargs.update({'color': color})
axes.triplot(self.x, self.y, self.triangles, **kwargs)
get_idx = self.nodes.index.get_loc
axes.triplot(
self.x,
self.y,
[[get_idx(n_id) for n_id in tri] for tri in self.triangles.values],
**kwargs,
)
return axes

@figure
Expand Down
22 changes: 14 additions & 8 deletions adcircpy/mesh/fort14.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,31 @@ def ids(self):
@property
def indexes(self):
if not hasattr(self, '_indexes'):
self._indexes = [self._mesh.nodes.index[data['node_id']] for data in self._data]
return np.array(self._indexes)
self._indexes = [
[self._mesh.nodes.index.get_loc(int(node_id)) for node_id in data['node_id']]
for data in self._data.values()
]
return self._indexes

@property
def node_id(self):
if not hasattr(self, '_node_id'):
self._node_id = list()
for data in self._data:
for data in self._data.values():
self._node_id.append(data['node_id'])
return self._node_id

@property
def gdf(self):
if not hasattr(self, '_gdf'):
data = []
for i, boundary in enumerate(self._data):
for i, (bnd_id, boundary) in enumerate(self._data.items()):
data.append(
{
'geometry': LineString(
self._mesh.coords.loc[self.indexes[i], :].values
self._mesh.coords.iloc[self.indexes[i], :].values
),
'key': f'{boundary.get("ibtype")}:{id}',
'key': f'{boundary.get("ibtype")}:{bnd_id}',
'indexes': self.indexes[i],
**boundary,
}
Expand Down Expand Up @@ -141,7 +144,9 @@ def plot(
@property
def ocean(self):
if not hasattr(self, '_ocean'):
self._ocean = OceanBoundaries(self._mesh, self._data.get(None, {}))
self._ocean = OceanBoundaries(
self._mesh, {en: bdry for en, bdry in enumerate(self._data.get(None, []))}
)
return self._ocean

@property
Expand Down Expand Up @@ -182,11 +187,12 @@ def culvert(self):

def _aggregate_boundaries(self, endswith):
boundaries = {}

for ibtype, _boundaries in self._data.items():
if ibtype is None:
continue
if ibtype.endswith(endswith):
for bdata in list(_boundaries.values()):
for bdata in _boundaries:
boundaries.update({len(boundaries) + 1: {'ibtype': ibtype, **bdata,}})
return boundaries

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ requests = '*'
scipy = '*'
shapely = '*'
stormevents = '^1.4.0'
typepigeon = '<2' # newer versions require code update
utm = '*'
isort = { version = '*', optional = true }
oitnb = { version = '*', optional = true }
Expand Down
18 changes: 9 additions & 9 deletions tests/data/reference/example_3/fort.15.coldstart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
created on 2022-04-20 15:31 ! RUNDES - 32 CHARACTER ALPHANUMERIC RUN DESCRIPTION
created on 2023-02-23 16:47 ! RUNDES - 32 CHARACTER ALPHANUMERIC RUN DESCRIPTION
Shinacock Inlet Coarse Grid ! RUNID - 24 CHARACTER ALPANUMERIC RUN IDENTIFICATION
1 ! NFOVER - NONFATAL ERROR OVERRIDE OPTION
1 ! NABOUT - ABREVIATED OUTPUT OPTION PARAMETER
Expand Down Expand Up @@ -63,7 +63,6 @@ S2
K2
0.000145842 0.864095 256.729
Q1
1.17940985e-02 1.73069764e+02
1.13893401e-02 1.83698935e+02
1.21085823e-02 1.73352953e+02
1.20789492e-02 1.73360490e+02
Expand Down Expand Up @@ -138,8 +137,8 @@ Q1
1.17568855e-02 1.72204623e+02
1.17685268e-02 1.72637761e+02
1.17802916e-02 1.73069629e+02
1.17922348e-02 1.73499568e+02
O1
4.78577634e-02 1.95367552e+02
3.79374677e-02 1.78529759e+02
4.03967701e-02 1.78123913e+02
4.28200109e-02 1.77731749e+02
Expand Down Expand Up @@ -214,8 +213,8 @@ O1
4.81119864e-02 1.93069508e+02
4.80269313e-02 1.94273959e+02
4.79411731e-02 1.95473663e+02
4.78544025e-02 1.96666224e+02
P1
2.77636120e-02 1.97069071e+02
2.39791106e-02 2.20627560e+02
2.55117562e-02 2.13441513e+02
2.70220036e-02 2.06350152e+02
Expand Down Expand Up @@ -290,8 +289,8 @@ P1
2.83762520e-02 1.93784200e+02
2.80685313e-02 1.95423100e+02
2.77617353e-02 1.97057324e+02
2.74563430e-02 1.98684434e+02
K1
7.24141814e-02 1.79513779e+02
6.39327411e-02 1.75237072e+02
6.80804771e-02 1.74586196e+02
7.21663730e-02 1.73945369e+02
Expand Down Expand Up @@ -366,8 +365,8 @@ K1
7.34069773e-02 1.77609524e+02
7.28725542e-02 1.78581902e+02
7.23405409e-02 1.79551002e+02
7.18121397e-02 1.80515143e+02
N2
1.21859723e-01 2.04783594e+02
1.00892997e-01 2.72404213e+02
1.07287245e-01 2.84727230e+02
1.13581222e-01 2.96886645e+02
Expand Down Expand Up @@ -442,8 +441,8 @@ N2
1.20482261e-01 2.56015198e+02
1.21125964e-01 2.30890590e+02
1.21768816e-01 2.05827798e+02
1.22410314e-01 1.80859639e+02
M2
4.83605669e-01 2.20112655e+02
4.17823412e-01 3.11130902e+02
4.44913133e-01 3.18628023e+02
4.71558150e-01 3.26026894e+02
Expand Down Expand Up @@ -518,8 +517,8 @@ M2
4.77395433e-01 2.72630955e+02
4.80228035e-01 2.46897948e+02
4.83058572e-01 2.21227733e+02
4.85885604e-01 1.95653681e+02
S2
1.17248923e-01 2.27815587e+01
9.55332752e-02 5.27716328e+01
1.01727604e-01 4.33217911e+01
1.07823677e-01 3.39973551e+01
Expand Down Expand Up @@ -594,8 +593,8 @@ S2
1.14840665e-01 1.79486568e+01
1.15964353e-01 2.03622746e+01
1.17086597e-01 2.27689523e+01
1.18206537e-01 2.51650756e+01
K2
2.70764097e-02 2.04341770e+01
2.64366106e-02 3.18940471e+01
2.79369274e-02 2.11382069e+01
2.94414143e-02 1.03221912e+01
Expand Down Expand Up @@ -670,6 +669,7 @@ K2
2.68472571e-02 1.58475451e+01
2.69465780e-02 1.81354841e+01
2.70459553e-02 2.04169051e+01
2.71453977e-02 2.26884102e+01
110 ! ANGINN - INNER ANGLE THRESHOLD
0 0 0 0 ! NOUTE TOUTSE TOUTFE NSPOOLE - ELEV STATION OUTPUT INFO (UNIT 61)
0 ! NSTAE - TOTAL NUMBER OF ELEVATION RECORDING STATIONS
Expand Down
18 changes: 9 additions & 9 deletions tests/data/reference/example_3/fort.15.hotstart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
created on 2022-04-20 15:31 ! RUNDES - 32 CHARACTER ALPHANUMERIC RUN DESCRIPTION
created on 2023-02-23 16:47 ! RUNDES - 32 CHARACTER ALPHANUMERIC RUN DESCRIPTION
Shinacock Inlet Coarse Grid ! RUNID - 24 CHARACTER ALPANUMERIC RUN IDENTIFICATION
1 ! NFOVER - NONFATAL ERROR OVERRIDE OPTION
1 ! NABOUT - ABREVIATED OUTPUT OPTION PARAMETER
Expand Down Expand Up @@ -64,7 +64,6 @@ S2
K2
0.000145842 0.864095 256.729
Q1
1.17940985e-02 1.73069764e+02
1.13893401e-02 1.83698935e+02
1.21085823e-02 1.73352953e+02
1.20789492e-02 1.73360490e+02
Expand Down Expand Up @@ -139,8 +138,8 @@ Q1
1.17568855e-02 1.72204623e+02
1.17685268e-02 1.72637761e+02
1.17802916e-02 1.73069629e+02
1.17922348e-02 1.73499568e+02
O1
4.78577634e-02 1.95367552e+02
3.79374677e-02 1.78529759e+02
4.03967701e-02 1.78123913e+02
4.28200109e-02 1.77731749e+02
Expand Down Expand Up @@ -215,8 +214,8 @@ O1
4.81119864e-02 1.93069508e+02
4.80269313e-02 1.94273959e+02
4.79411731e-02 1.95473663e+02
4.78544025e-02 1.96666224e+02
P1
2.77636120e-02 1.97069071e+02
2.39791106e-02 2.20627560e+02
2.55117562e-02 2.13441513e+02
2.70220036e-02 2.06350152e+02
Expand Down Expand Up @@ -291,8 +290,8 @@ P1
2.83762520e-02 1.93784200e+02
2.80685313e-02 1.95423100e+02
2.77617353e-02 1.97057324e+02
2.74563430e-02 1.98684434e+02
K1
7.24141814e-02 1.79513779e+02
6.39327411e-02 1.75237072e+02
6.80804771e-02 1.74586196e+02
7.21663730e-02 1.73945369e+02
Expand Down Expand Up @@ -367,8 +366,8 @@ K1
7.34069773e-02 1.77609524e+02
7.28725542e-02 1.78581902e+02
7.23405409e-02 1.79551002e+02
7.18121397e-02 1.80515143e+02
N2
1.21859723e-01 2.04783594e+02
1.00892997e-01 2.72404213e+02
1.07287245e-01 2.84727230e+02
1.13581222e-01 2.96886645e+02
Expand Down Expand Up @@ -443,8 +442,8 @@ N2
1.20482261e-01 2.56015198e+02
1.21125964e-01 2.30890590e+02
1.21768816e-01 2.05827798e+02
1.22410314e-01 1.80859639e+02
M2
4.83605669e-01 2.20112655e+02
4.17823412e-01 3.11130902e+02
4.44913133e-01 3.18628023e+02
4.71558150e-01 3.26026894e+02
Expand Down Expand Up @@ -519,8 +518,8 @@ M2
4.77395433e-01 2.72630955e+02
4.80228035e-01 2.46897948e+02
4.83058572e-01 2.21227733e+02
4.85885604e-01 1.95653681e+02
S2
1.17248923e-01 2.27815587e+01
9.55332752e-02 5.27716328e+01
1.01727604e-01 4.33217911e+01
1.07823677e-01 3.39973551e+01
Expand Down Expand Up @@ -595,8 +594,8 @@ S2
1.14840665e-01 1.79486568e+01
1.15964353e-01 2.03622746e+01
1.17086597e-01 2.27689523e+01
1.18206537e-01 2.51650756e+01
K2
2.70764097e-02 2.04341770e+01
2.64366106e-02 3.18940471e+01
2.79369274e-02 2.11382069e+01
2.94414143e-02 1.03221912e+01
Expand Down Expand Up @@ -671,6 +670,7 @@ K2
2.68472571e-02 1.58475451e+01
2.69465780e-02 1.81354841e+01
2.70459553e-02 2.04169051e+01
2.71453977e-02 2.26884102e+01
110 ! ANGINN - INNER ANGLE THRESHOLD
0 0 0 0 ! NOUTE TOUTSE TOUTFE NSPOOLE - ELEV STATION OUTPUT INFO (UNIT 61)
0 ! NSTAE - TOTAL NUMBER OF ELEVATION RECORDING STATIONS
Expand Down
Loading

0 comments on commit 811b1b9

Please sign in to comment.