From 47572f0ecbc024df1dfa57bcdff11175416f6f26 Mon Sep 17 00:00:00 2001 From: spaulins-usgs Date: Fri, 17 Jul 2020 12:44:46 -0700 Subject: [PATCH] fix(time series slowness): speeds up performance when a large number of time series are used by a single stress package (#943) --- flopy/mf6/data/mfdataarray.py | 7 ++++++- flopy/mf6/data/mfdatalist.py | 9 +++++++-- flopy/mf6/data/mfdatascalar.py | 5 +++++ flopy/mf6/data/mffileaccess.py | 2 ++ flopy/utils/datautil.py | 4 +++- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/flopy/mf6/data/mfdataarray.py b/flopy/mf6/data/mfdataarray.py index 5e02219394..0128bbc381 100644 --- a/flopy/mf6/data/mfdataarray.py +++ b/flopy/mf6/data/mfdataarray.py @@ -4,7 +4,7 @@ from ..data.mfstructure import DatumType from .mfdatastorage import DataStorage, DataStructureType, DataStorageType from ...utils.datautil import MultiList -from ..mfbase import ExtFileAction, MFDataException +from ..mfbase import ExtFileAction, MFDataException, VerbosityLevel from ..utils.mfenums import DiscretizationType from ...datbase import DataType from .mffileaccess import MFFileAccessArray @@ -435,6 +435,11 @@ def store_as_external_file(self, external_file_path, layer=None, continue try: # store layer's data in external file + if self._simulation_data.verbosity_level.value >= \ + VerbosityLevel.verbose.value: + print('Storing {} layer {} to external file {}..' + '.'.format(self.structure.name, current_layer[0]+1, + file_path)) factor = storage.layer_storage[current_layer].factor external_data = {'filename': file_path, 'data': self._get_data(current_layer, True), diff --git a/flopy/mf6/data/mfdatalist.py b/flopy/mf6/data/mfdatalist.py index a39a39c6b0..550724c0b7 100644 --- a/flopy/mf6/data/mfdatalist.py +++ b/flopy/mf6/data/mfdatalist.py @@ -6,7 +6,7 @@ import numpy as np from ..utils.mfenums import DiscretizationType from ..data import mfstructure, mfdata -from ..mfbase import MFDataException, ExtFileAction +from ..mfbase import MFDataException, ExtFileAction, VerbosityLevel from .mfstructure import DatumType from ...utils import datautil from ...datbase import DataListInterface, DataType @@ -246,8 +246,13 @@ def store_as_external_file(self, external_file_path, binary=False, data = self._get_data() # if not empty dataset if data is not None: + if self._simulation_data.verbosity_level.value >= \ + VerbosityLevel.verbose.value: + print('Storing {} to external file {}..' + '.'.format(self.structure.name, + external_file_path)) external_data = {'filename': external_file_path, - 'data': self._get_data(), + 'data': data, 'binary': binary} self._set_data(external_data) diff --git a/flopy/mf6/data/mfdatascalar.py b/flopy/mf6/data/mfdatascalar.py index e0f0efcc00..dae7ee3dac 100644 --- a/flopy/mf6/data/mfdatascalar.py +++ b/flopy/mf6/data/mfdatascalar.py @@ -328,6 +328,11 @@ def get_file_entry(self, values_only=False, one_based=False, if data_item.type == DatumType.keyword: if current_data is not None and current_data != \ False: + if isinstance(data[index], str) and \ + data[index] == '#': + # if data has been commented out, + # keep the comment + text_line.append(data[index]) text_line.append(data_item.name.upper()) else: try: diff --git a/flopy/mf6/data/mffileaccess.py b/flopy/mf6/data/mffileaccess.py index 7bb20ebb1d..2ec7415e08 100644 --- a/flopy/mf6/data/mffileaccess.py +++ b/flopy/mf6/data/mffileaccess.py @@ -832,6 +832,7 @@ def load_from_package(self, first_line, file_handle, storage, def read_list_data_from_file(self, file_handle, storage, current_key, current_line=None, data_line=None, store_internal=True): + self._data_dimensions.package_dim.locked = True data_rec = None data_loaded = [] self._temp_dict = {} @@ -1072,6 +1073,7 @@ def read_list_data_from_file(self, file_handle, storage, current_key, # store as rec array storage.store_internal(data_loaded, None, False, current_key) storage.data_dimensions.unlock() + self._data_dimensions.package_dim.locked = False if not store_internal: return data_rec else: diff --git a/flopy/utils/datautil.py b/flopy/utils/datautil.py index 5fd2ccbc0f..d3fa5f3f31 100644 --- a/flopy/utils/datautil.py +++ b/flopy/utils/datautil.py @@ -252,6 +252,7 @@ def split_data_line(line, external_file=False, delimiter_conf_length=15): # apart the most max_split_size = len(clean_line) max_split_type = None + max_split_list = clean_line for delimiter in PyListUtil.delimiter_list: comment_split = line.strip().split('#') alt_split = comment_split[0].strip().split(delimiter) @@ -268,9 +269,10 @@ def split_data_line(line, external_file=False, delimiter_conf_length=15): PyListUtil.delimiter_list[max_split_type]: max_split_size = len(alt_split) max_split_type = delimiter + max_split_list = alt_split if max_split_type is not None: - clean_line = line.strip().split(max_split_type) + clean_line = max_split_list if PyListUtil.line_num == 0: PyListUtil.delimiter_used = max_split_type elif PyListUtil.delimiter_used != max_split_type: