Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nEdges float --> int in graph files #674

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions compass/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import xarray

import xarray as xr
from mpas_tools.logging import check_call

from compass.parallel import run_command


Expand Down Expand Up @@ -105,16 +106,16 @@ def make_graph_file(mesh_filename, graph_filename='graph.info',
weights
"""

with xarray.open_dataset(mesh_filename) as ds:
with xr.open_dataset(mesh_filename) as ds:

nCells = ds.sizes['nCells']

nEdgesOnCell = ds.nEdgesOnCell.values
cellsOnCell = ds.cellsOnCell.values - 1
if weight_field is not None:
if weight_field in ds:
raise ValueError('weight_field {} not found in {}'.format(
weight_field, mesh_filename))
raise ValueError(f'weight_field {weight_field} not found in '
f'{mesh_filename}')
weights = ds[weight_field].values
else:
weights = None
Expand All @@ -125,23 +126,23 @@ def make_graph_file(mesh_filename, graph_filename='graph.info',
if cellsOnCell[i][j] != -1:
nEdges = nEdges + 1

nEdges = nEdges/2
nEdges = nEdges // 2

with open(graph_filename, 'w+') as graph:
if weights is None:
graph.write('{} {}\n'.format(nCells, nEdges))
graph.write(f'{nCells} {nEdges}\n')

for i in range(nCells):
for j in range(0, nEdgesOnCell[i]):
if cellsOnCell[i][j] >= 0:
graph.write('{} '.format(cellsOnCell[i][j]+1))
graph.write(f'{cellsOnCell[i][j] + 1} ')
graph.write('\n')
else:
graph.write('{} {} 010\n'.format(nCells, nEdges))
graph.write(f'{nCells} {nEdges} 010\n')

for i in range(nCells):
graph.write('{} '.format(int(weights[i])))
graph.write(f'{int(weights[i])} ')
for j in range(0, nEdgesOnCell[i]):
if cellsOnCell[i][j] >= 0:
graph.write('{} '.format(cellsOnCell[i][j] + 1))
graph.write(f'{cellsOnCell[i][j] + 1} ')
graph.write('\n')