Skip to content

Commit

Permalink
feat(#862): Include message about zero based index variables in the d…
Browse files Browse the repository at this point in the history
…ocs.
  • Loading branch information
spaulins-usgs committed May 1, 2020
1 parent 8d8cb8e commit eb7b18a
Show file tree
Hide file tree
Showing 24 changed files with 5,768 additions and 5,520 deletions.
44 changes: 27 additions & 17 deletions flopy/mf6/data/mfdatalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,15 @@ def _set_data(self, data, autofill=False):
if iterable(data_check):
# verify data length
min_line_size = self.structure.get_min_record_entries()
for data_line in data_check:
if 0 < len(data_line) < min_line_size:
min_line_size = self.structure.get_min_record_entries()
message = 'Data line {} only has {} entries, minimum ' \
'number of entries is ' \
'{}.'.format(data_line, len(data_line),
min_line_size)
type_, value_, traceback_ = sys.exc_info()
raise MFDataException(
self.structure.get_model(),
self.structure.get_package(),
self.structure.path,
'storing data',
self.structure.name,
inspect.stack()[0][3],
type_, value_, traceback_, message,
self._simulation_data.debug)
if isinstance(data_check[0], np.record) or \
(iterable(data_check[0]) and not
isinstance(data_check[0], str)):
# data contains multiple records
for data_line in data_check:
self._check_line_size(data_line, min_line_size)
else:
# data is a single record
self._check_line_size(data_check, min_line_size)
# set data
self._resync()
try:
Expand All @@ -314,6 +306,24 @@ def _set_data(self, data, autofill=False):
traceback_, None,
self._simulation_data.debug, ex)

def _check_line_size(self, data_line, min_line_size):
if 0 < len(data_line) < min_line_size:
min_line_size = self.structure.get_min_record_entries()
message = 'Data line {} only has {} entries, ' \
'minimum number of entries is ' \
'{}.'.format(data_line, len(data_line),
min_line_size)
type_, value_, traceback_ = sys.exc_info()
raise MFDataException(
self.structure.get_model(),
self.structure.get_package(),
self.structure.path,
'storing data',
self.structure.name,
inspect.stack()[0][3],
type_, value_, traceback_, message,
self._simulation_data.debug)

def set_data(self, data, autofill=False):
self._set_data(data, autofill)

Expand Down
21 changes: 19 additions & 2 deletions flopy/mf6/data/mfstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
from ..mfbase import PackageContainer, StructException


numeric_index_text = 'This argument is an index variable, which means that ' \
'it should be treated as zero-based when working with ' \
'FloPy and Python. Flopy will automatically subtract ' \
'one when loading index variables and add one when ' \
'writing index variables.'


class DfnType(Enum):
common = 1
sim_name_file = 2
Expand Down Expand Up @@ -933,6 +940,10 @@ def get_type_string(self):
def get_description(self, line_size, initial_indent, level_indent):
item_desc = '* {} ({}) {}'.format(self.name, self.type_string,
self.description)
if self.numeric_index or self.is_cellid:
# append zero-based index text
item_desc = '{} {}'.format(item_desc,
numeric_index_text)
twr = TextWrapper(width=line_size, initial_indent=initial_indent,
drop_whitespace = True,
subsequent_indent=' {}'.format(initial_indent))
Expand All @@ -952,7 +963,6 @@ def get_doc_string(self, line_size, initial_indent, level_indent):
param_doc_string = '{}\n{}'.format(param_doc_string, description)
return param_doc_string


def get_keystring_desc(self, line_size, initial_indent, level_indent):
if self.type != DatumType.keystring:
raise StructException('Can not get keystring description for "{}" '
Expand Down Expand Up @@ -1518,8 +1528,14 @@ def get_description(self, line_size=79, initial_indent=' ',
elif datastr.display_item(index):
if len(description.strip()) > 0:
description = '{}\n'.format(description)
item_desc = item.description
if item.numeric_index or item.is_cellid:
# append zero-based index text
item_desc = '{} {}'.format(item_desc,
numeric_index_text)

item_desc = '* {} ({}) {}'.format(item.name, itype,
item.description)
item_desc)
twr = TextWrapper(width=line_size,
initial_indent=initial_indent,
subsequent_indent=' {}'.format(
Expand Down Expand Up @@ -1568,6 +1584,7 @@ def get_doc_string(self, line_size=79, initial_indent=' ',
level_indent)
var_name = self.python_name
type_name = self.get_type_string()

param_doc_string = '{} : {}'.format(var_name, type_name)
twr = TextWrapper(width=line_size, initial_indent=initial_indent,
subsequent_indent=' {}'.format(initial_indent))
Expand Down
Loading

0 comments on commit eb7b18a

Please sign in to comment.