Skip to content

Commit

Permalink
Merge pull request #409 from xylar/fix_string_length_for_moc_regions
Browse files Browse the repository at this point in the history
Make make sure all strings in MOC files have 64 char
  • Loading branch information
xylar authored Apr 6, 2021
2 parents 25756f2 + a677dd2 commit ac85e45
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion conda_package/mpas_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (0, 5, 0)
__version_info__ = (0, 5, 1)
__version__ = '.'.join(str(vi) for vi in __version_info__)
15 changes: 12 additions & 3 deletions conda_package/mpas_tools/ocean/moc.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,13 @@ def _add_transects_to_moc(mesh, mocMask, southernBoundaryEdges,
mocMask['transectVertexGlobalIDs'] = \
(('nTransects', 'maxVerticesInTransect'), transectVertexGlobalIDs)

mocMask['transectNames'] = mocMask.regionNames.rename(
{'nRegions': 'nTransects'})

if 'nRegionsInGroup' not in mocMask:
nRegions = mocMask.sizes['nRegions']
nRegionGroups = 2
nRegionsInGroup = nRegions*numpy.ones(nRegionGroups, dtype=int)
regionsInGroup = numpy.zeros((nRegionGroups, nRegions), dtype=int)
regionGroupNames = ['MOCBasinRegionsGroup', 'all']
regionNames = mocMask.regionNames.values
nChar = 64
for index in range(nRegionGroups):
regionsInGroup[index, :] = numpy.arange(1, nRegions+1)
Expand All @@ -315,6 +313,17 @@ def _add_transects_to_moc(mesh, mocMask, southernBoundaryEdges,
for index in range(nRegionGroups):
mocMask['regionGroupNames'][index] = regionGroupNames[index]

# we need to make sure the region names use the same string length
mocMask['regionNames'] = \
(('nRegions',), numpy.zeros((nRegions,),
dtype='|S{}'.format(nChar)))

for index in range(nRegions):
mocMask['regionNames'][index] = regionNames[index]

mocMask['transectNames'] = mocMask.regionNames.rename(
{'nRegions': 'nTransects'})

mocMask['nTransectsInGroup'] = mocMask.nRegionsInGroup.rename(
{'nRegionGroups': 'nTransectGroups'})

Expand Down
2 changes: 1 addition & 1 deletion conda_package/recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% set name = "mpas_tools" %}
{% set version = "0.5.0" %}
{% set version = "0.5.1" %}

package:
name: {{ name|lower }}
Expand Down

0 comments on commit ac85e45

Please sign in to comment.