Skip to content

Commit

Permalink
refactor: replace OrderedDict with dict
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Aug 19, 2021
1 parent 63ce93d commit b6c1a30
Show file tree
Hide file tree
Showing 31 changed files with 128 additions and 175 deletions.
3 changes: 1 addition & 2 deletions examples/scripts/flopy_swi2_ex2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import sys
import collections

import numpy as np

Expand Down Expand Up @@ -48,7 +47,7 @@ def run():
if cleanFiles:
print("cleaning all files")
print("excluding *.py files")
file_dict = collections.OrderedDict()
file_dict = {}
file_dict[0] = os.listdir(dirs[0])
file_dict[1] = os.listdir(dirs[1])
file_dict[-1] = os.listdir(workspace)
Expand Down
3 changes: 1 addition & 2 deletions examples/scripts/flopy_swi2_ex5.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import sys
import math
import collections

import numpy as np

Expand Down Expand Up @@ -49,7 +48,7 @@ def run(silent=False):
if cleanFiles:
print("cleaning all files")
print("excluding *.py files")
file_dict = collections.OrderedDict()
file_dict = {}
file_dict[0] = os.listdir(dirs[0])
file_dict[1] = os.listdir(dirs[1])
file_dict[-1] = os.listdir(workspace)
Expand Down
5 changes: 2 additions & 3 deletions flopy/export/shapefile_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np
import os
import warnings
from collections import OrderedDict

from ..datbase import DataType, DataInterface
from ..utils import Util3d
Expand Down Expand Up @@ -989,10 +988,10 @@ def to_dict(self):
"""
returns dict with EPSG code integer key, and WKT CRS text
"""
data = OrderedDict()
data = {}
if os.path.exists(self.location):
with open(self.location, "r") as f:
loaded_data = json.load(f, object_pairs_hook=OrderedDict)
loaded_data = json.load(f)
# convert JSON key from str to EPSG integer
for key, value in loaded_data.items():
try:
Expand Down
5 changes: 2 additions & 3 deletions flopy/mf6/data/mfdataarray.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys, inspect, copy, os
import numpy as np
from collections import OrderedDict
from ..data.mfstructure import DatumType
from .mfdatastorage import DataStorage, DataStructureType, DataStorageType
from ...utils.datautil import MultiList, DatumUtil
Expand Down Expand Up @@ -1712,7 +1711,7 @@ def set_data(self, data, multiplier=None, layer=None, key=None):
if `data` is a dictionary.
"""

if isinstance(data, dict) or isinstance(data, OrderedDict):
if isinstance(data, dict):
# each item in the dictionary is a list for one stress period
# the dictionary key is the stress period the list is for
del_keys = []
Expand Down Expand Up @@ -1815,7 +1814,7 @@ def _new_storage(
set_layers, base_storage, stress_period
)
else:
return OrderedDict()
return {}

def _set_storage_obj(self, storage):
self._data_storage[self._current_key] = storage
Expand Down
5 changes: 2 additions & 3 deletions flopy/mf6/data/mfdatalist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import OrderedDict
import math
import sys
import os
Expand Down Expand Up @@ -1671,7 +1670,7 @@ def set_data(self, data, key=None, autofill=False):
Automatically correct data.
"""
self._cache_model_grid = True
if isinstance(data, dict) or isinstance(data, OrderedDict):
if isinstance(data, dict):
if "filename" not in data:
# each item in the dictionary is a list for one stress period
# the dictionary key is the stress period the list is for
Expand Down Expand Up @@ -1815,7 +1814,7 @@ def update_record(self, record, key_index, key=0):
super().update_record(record, key_index)

def _new_storage(self, stress_period=0):
return OrderedDict()
return {}

def _get_storage_obj(self):
if (
Expand Down
5 changes: 2 additions & 3 deletions flopy/mf6/data/mfdatascalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import numpy as np
from ..data.mfstructure import DatumType
from ..data import mfdata
from collections import OrderedDict
from ..mfbase import ExtFileAction, MFDataException
from ...datbase import DataType
from .mfdatautil import convert_data, to_string
Expand Down Expand Up @@ -820,7 +819,7 @@ def set_data(self, data, key=None):
if `data` is a dictionary.
"""
if isinstance(data, dict) or isinstance(data, OrderedDict):
if isinstance(data, dict):
# each item in the dictionary is a list for one stress period
# the dictionary key is the stress period the list is for
for key, list_item in data.items():
Expand Down Expand Up @@ -902,7 +901,7 @@ def load(
)

def _new_storage(self, stress_period=0):
return OrderedDict()
return {}

def _get_storage_obj(self):
if (
Expand Down
5 changes: 2 additions & 3 deletions flopy/mf6/data/mfdatastorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import inspect
from shutil import copyfile
from collections import OrderedDict
from enum import Enum
import numpy as np
from ..mfbase import MFDataException, VerbosityLevel
Expand Down Expand Up @@ -205,7 +204,7 @@ class DataStorage:
is the data layered
pre_data_comments : string
any comments before the start of the data
comments : OrderedDict
comments : dict
any comments mixed in with the data, dictionary keys are data lines
post_data_comments : string
any comments after the end of the data
Expand Down Expand Up @@ -331,7 +330,7 @@ def __init__(

# initialize comments
self.pre_data_comments = None
self.comments = OrderedDict()
self.comments = {}

def __repr__(self):
return self.get_data_str(True)
Expand Down
33 changes: 16 additions & 17 deletions flopy/mf6/data/mfstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import keyword
from enum import Enum
from textwrap import TextWrapper
from collections import OrderedDict
import numpy as np
from ..mfbase import PackageContainer, StructException

Expand Down Expand Up @@ -228,7 +227,7 @@ def multi_package_support(self):
return self.package.package_abbr in self.multi_package

def get_block_structure_dict(self, path, common, model_file):
block_dict = OrderedDict()
block_dict = {}
dataset_items_in_block = {}
self.dataset_items_needed_dict = {}
keystring_items_needed_dict = {}
Expand Down Expand Up @@ -497,7 +496,7 @@ def multi_package_support(self):
return base_file in self.multi_package

def dict_by_name(self):
name_dict = OrderedDict()
name_dict = {}
name = None
dfn_fp = open(self._file_path, "r")
for line in dfn_fp:
Expand All @@ -512,7 +511,7 @@ def dict_by_name(self):

def get_block_structure_dict(self, path, common, model_file):
self.dfn_list = []
block_dict = OrderedDict()
block_dict = {}
dataset_items_in_block = {}
self.dataset_items_needed_dict = {}
keystring_items_needed_dict = {}
Expand Down Expand Up @@ -1430,9 +1429,9 @@ def __init__(self, data_item, model_data, package_type, dfn_list):
self.parameter_name = data_item.parameter_name
self.one_per_pkg = data_item.one_per_pkg

# self.data_item_structures_dict = OrderedDict()
# self.data_item_structures_dict = {}
self.data_item_structures = []
self.expected_data_items = OrderedDict()
self.expected_data_items = {}
self.shape = data_item.shape
if (
self.type == DatumType.recarray
Expand Down Expand Up @@ -1941,7 +1940,7 @@ class MFBlockStructure:
(<model>, <package>, <block>)
model_block : bool
true if this block is part of a model
data_structures : OrderedDict
data_structures : dict
dictionary of data items in this block, with the data item name as
the key
block_header_structure : list
Expand Down Expand Up @@ -1982,7 +1981,7 @@ class MFBlockStructure:

def __init__(self, name, path, model_block):
# initialize
self.data_structures = OrderedDict()
self.data_structures = {}
self.block_header_structure = []
self.name = name
self.path = path + (self.name,)
Expand Down Expand Up @@ -2130,7 +2129,7 @@ class MFModelStructure:
simulation structure validity
name_file_struct_obj : MFInputFileStructure
describes the structure of the simulation name file
package_struct_objs : OrderedDict
package_struct_objs : dict
describes the structure of the simulation packages
model_type : string
dictionary containing simulation package structure
Expand Down Expand Up @@ -2161,7 +2160,7 @@ def __init__(self, model_type, utl_struct_objs):
# add name file structure
self.model_type = model_type
self.name_file_struct_obj = None
self.package_struct_objs = OrderedDict()
self.package_struct_objs = {}
self.utl_struct_objs = utl_struct_objs

def add_namefile(self, dfn_file, common):
Expand Down Expand Up @@ -2217,13 +2216,13 @@ class MFSimulationStructure:
----------
name_file_struct_obj : MFInputFileStructure
describes the structure of the simulation name file
package_struct_objs : OrderedDict
package_struct_objs : dict
describes the structure of the simulation packages
model_struct_objs : OrderedDict
model_struct_objs : dict
describes the structure of the supported model types
utl_struct_objs : OrderedDict
utl_struct_objs : dict
describes the structure of the supported utility packages
common : OrderedDict
common : dict
common file information
model_type : string
placeholder
Expand Down Expand Up @@ -2265,9 +2264,9 @@ class MFSimulationStructure:
def __init__(self):
# initialize
self.name_file_struct_obj = None
self.package_struct_objs = OrderedDict()
self.utl_struct_objs = OrderedDict()
self.model_struct_objs = OrderedDict()
self.package_struct_objs = {}
self.utl_struct_objs = {}
self.model_struct_objs = {}
self.common = None
self.model_type = ""

Expand Down
7 changes: 3 additions & 4 deletions flopy/mf6/mfbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import importlib
import inspect, sys, traceback
import os, copy
from collections import OrderedDict
from collections.abc import Iterable
from shutil import copyfile
from enum import Enum
Expand Down Expand Up @@ -221,7 +220,7 @@ class MFFileMgmt:
Attributes
----------
model_relative_path : OrderedDict
model_relative_path : dict
Dictionary of relative paths to each model folder
"""
Expand All @@ -235,10 +234,10 @@ def __init__(self, path, mfsim=None):
self.existing_file_dict = {}
# keys:filenames,vals:instance name

self.model_relative_path = OrderedDict()
self.model_relative_path = {}

self._last_loaded_sim_path = None
self._last_loaded_model_relative_path = OrderedDict()
self._last_loaded_model_relative_path = {}

def copy_files(self, copy_relative_only=True):
"""Copy files external to updated path.
Expand Down
2 changes: 1 addition & 1 deletion flopy/mf6/mfmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MFModel(PackageContainer, ModelInterface):
Name of the model
exe_name : str
Model executable name
packages : OrderedDict(MFPackage)
packages : dict of MFPackage
Dictionary of model packages
"""
Expand Down
7 changes: 3 additions & 4 deletions flopy/mf6/mfpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import inspect
import datetime
import numpy as np
from collections import OrderedDict

from .mfbase import PackageContainer, ExtFileAction, PackageContainerType
from .mfbase import (
Expand Down Expand Up @@ -347,7 +346,7 @@ def __init__(
]
self.structure = structure
self.path = path
self.datasets = OrderedDict()
self.datasets = {}
self.datasets_keyword = {}
# initially disable if optional
self.enabled = structure.number_non_optional_data() > 0
Expand Down Expand Up @@ -1475,7 +1474,7 @@ class MFPackage(PackageContainer, PackageInterface):
Attributes
----------
blocks : OrderedDict
blocks : dict
Dictionary of blocks contained in this package by block name
path : tuple
Data dictionary path to this package
Expand Down Expand Up @@ -1530,7 +1529,7 @@ def __init__(
self.parent = model_or_sim
self._simulation_data = model_or_sim.simulation_data
self.parent_file = parent_file
self.blocks = OrderedDict()
self.blocks = {}
self.container_type = []
self.loading_package = loading_package
if pname is not None:
Expand Down
14 changes: 7 additions & 7 deletions flopy/mf6/modflow/mfsimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class MFSimulationData:
Numbers less than this threshold are written in scientific notation
mfpath : MFFileMgmt
File path location information for the simulation
model_dimensions : OrderedDict
model_dimensions : dict
Dictionary containing discretization information for each model
mfdata : SimulationDict
Custom dictionary containing all model data for the simulation
Expand Down Expand Up @@ -254,14 +254,14 @@ def __init__(self, path, mfsim):

# --- ease of use variables to make working with modflow input and
# output data easier --- model dimension class for each model
self.model_dimensions = collections.OrderedDict()
self.model_dimensions = {}

# --- model data ---
self.mfdata = SimulationDict(self.mfpath)

# --- temporary variables ---
# other external files referenced
self.referenced_files = collections.OrderedDict()
self.referenced_files = {}

@property
def max_columns_of_data(self):
Expand Down Expand Up @@ -402,13 +402,13 @@ def __init__(

self.version = version
self.exe_name = exe_name
self._models = collections.OrderedDict()
self._models = {}
self._tdis_file = None
self._exchange_files = collections.OrderedDict()
self._ims_files = collections.OrderedDict()
self._exchange_files = {}
self._ims_files = {}
self._ghost_node_files = {}
self._mover_files = {}
self._other_files = collections.OrderedDict()
self._other_files = {}
self.structure = fpdata.sim_struct
self.model_type = None

Expand Down
Loading

0 comments on commit b6c1a30

Please sign in to comment.