Skip to content

Commit

Permalink
CLN: Replace OrderedDict instances with dict
Browse files Browse the repository at this point in the history
  • Loading branch information
abastola0 authored Nov 29, 2023
1 parent 81d71ae commit 19a7988
Show file tree
Hide file tree
Showing 25 changed files with 90 additions and 122 deletions.
7 changes: 3 additions & 4 deletions bin/xtgls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pathlib

# import yaml
from collections import OrderedDict
from struct import unpack

VALIDEXT = [".xtgregsurf", ".xtgregcube", ".xtgcpgeom"]
Expand All @@ -25,7 +24,7 @@ def extract_meta_regsurf(fil):
with open(fil, "rb") as fhandle:
fhandle.seek(pos)
jmeta = fhandle.read().decode()
meta = json.loads(jmeta, object_pairs_hook=OrderedDict)
meta = json.loads(jmeta, object_pairs_hook=dict)
return meta


Expand All @@ -44,7 +43,7 @@ def extract_meta_regcube(fil):
with open(fil, "rb") as fhandle:
fhandle.seek(pos)
jmeta = fhandle.read().decode()
meta = json.loads(jmeta, object_pairs_hook=OrderedDict)
meta = json.loads(jmeta, object_pairs_hook=dict)

return meta

Expand All @@ -70,7 +69,7 @@ def extract_meta_cpgeom(fil):
with open(fil, "rb") as fhandle:
fhandle.seek(pos)
jmeta = fhandle.read().decode()
meta = json.loads(jmeta, object_pairs_hook=OrderedDict)
meta = json.loads(jmeta, object_pairs_hook=dict)

return meta

Expand Down
4 changes: 2 additions & 2 deletions src/xtgeo/cube/_cube_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from __future__ import annotations

import json
from collections import OrderedDict, defaultdict
from collections import defaultdict
from copy import deepcopy
from struct import unpack
from warnings import warn
Expand Down Expand Up @@ -596,7 +596,7 @@ def import_xtgregcube(mfile, values=True):
fhandle.seek(pos)
jmeta = fhandle.read().decode()

meta = json.loads(jmeta, object_pairs_hook=OrderedDict)
meta = json.loads(jmeta, object_pairs_hook=dict)
req = meta["_required_"]

reqattrs = xtgeo.MetaDataRegularCube.REQUIRED
Expand Down
5 changes: 2 additions & 3 deletions src/xtgeo/grid3d/_grid_etc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

from collections import OrderedDict
from copy import deepcopy
from math import atan2, degrees

Expand Down Expand Up @@ -350,7 +349,7 @@ def get_ijk_from_points(
jarr -= 1
karr -= 1

proplist = OrderedDict()
proplist = dict()
if includepoints:
proplist["X_UTME"] = points.dataframe[points.xname].values
proplist["Y_UTME"] = points.dataframe[points.yname].values
Expand Down Expand Up @@ -1066,7 +1065,7 @@ def crop(self, spec, props=None): # pylint: disable=too-many-locals
self._nlay = nnlay

if isinstance(self.subgrids, dict):
newsub = OrderedDict()
newsub = dict()
# easier to work with numpies than lists
newarr = np.array(range(1, oldnlay + 1))
newarr[newarr < kc1] = 0
Expand Down
19 changes: 9 additions & 10 deletions src/xtgeo/grid3d/_grid_import_xtgcpgeom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Private module, Grid Import private functions for xtgeo based formats."""

import json
from collections import OrderedDict
from struct import unpack

import h5py
Expand All @@ -21,16 +20,16 @@ def convert_subgrids(sdict):
The simplified dictionary is on the form
{"name1": 3, "name2": 5}
Note that the input must be an OrderedDict!
Note that the input must be an dict!
"""
if sdict is None:
return None

if not isinstance(sdict, OrderedDict):
raise ValueError("Input sdict is not an OrderedDict")
if not isinstance(sdict, dict):
raise ValueError("Input sdict is not an dict")

newsub = OrderedDict()
newsub = dict()

inn1 = 1
for name, nsub in sdict.items():
Expand Down Expand Up @@ -124,7 +123,7 @@ def import_xtgcpgeom(
fhandle.seek(pos)
jmeta = fhandle.read().decode()

meta = json.loads(jmeta, object_pairs_hook=OrderedDict)
meta = json.loads(jmeta, object_pairs_hook=dict)

handle_metadata(result, meta, ncol, nrow, nlay)
return result
Expand All @@ -143,7 +142,7 @@ def import_hdf5_cpgeom(mfile, ijkrange=None, zerobased=False):
logger.info("Provider is %s", provider)

jmeta = grp.attrs["metadata"]
meta = json.loads(jmeta, object_pairs_hook=OrderedDict)
meta = json.loads(jmeta, object_pairs_hook=dict)

req = meta["_required_"]
ncol = req["ncol"]
Expand Down Expand Up @@ -187,10 +186,10 @@ def filter_subgrids_partial(subgrids, k1, k2, nlay, zerobased):
... 12,
... True
... )
OrderedDict([('subgrid2', 1), ('subgrid3', 1)])
dict([('subgrid2', 1), ('subgrid3', 1)])
Args:
subgrids: The OrderedDict of subgrids.
subgrids: The dict of subgrids.
k1: Start of subgrid layers (can be "min" to mean 0 or 1 dependent on zerobased)
k2: End of subgrid layers (cna be "max" to mean nlay or nlay -1
dependent on zerobased.
Expand All @@ -213,7 +212,7 @@ def filter_subgrids_partial(subgrids, k1, k2, nlay, zerobased):
k1 -= 1
k2 -= 1

partial_subgrid = OrderedDict()
partial_subgrid = dict()
start = 0
for key, value in subgrids.items():
end = value + start
Expand Down
9 changes: 4 additions & 5 deletions src/xtgeo/grid3d/_grid_refine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Private module for refinement of a grid."""
from __future__ import annotations

from collections import OrderedDict
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -30,7 +29,7 @@ def refine_vertically(
"""
self._xtgformat1()

rfactord = OrderedDict()
rfactord = dict()

# case 1 rfactor as scalar value.
if isinstance(rfactor, int):
Expand All @@ -40,12 +39,12 @@ def refine_vertically(
rfactord[i + 1] = rfactor
else:
rfactord[0] = rfactor
subgrids = OrderedDict()
subgrids = dict()
subgrids[1] = self.nlay

# case 2 rfactor is a dict
else:
rfactord = OrderedDict(sorted(rfactor.items())) # redefined to ordered
rfactord = dict(sorted(rfactor.items())) # redefined to ordered
# 2a: zoneprop is present
if zoneprop is not None:
oldsubgrids = None
Expand Down Expand Up @@ -76,7 +75,7 @@ def refine_vertically(
self.set_subgrids(subgrids)

# Now, based on dict, give a value per subgrid for key, val in rfactor
newsubgrids = OrderedDict()
newsubgrids = dict()
newnlay = 0
for (_x, rfi), (snam, sran) in zip(rfactord.items(), subgrids.items()):
newsubgrids[snam] = sran * rfi
Expand Down
5 changes: 2 additions & 3 deletions src/xtgeo/grid3d/_grid_roxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Roxar API functions for XTGeo Grid Geometry."""
import os
import tempfile
from collections import OrderedDict

import numpy as np

Expand Down Expand Up @@ -188,7 +187,7 @@ def _convert_to_xtgeo_grid_v1(rox, roxgrid, corners, gname): # pragma: no cover
# subgrids
if len(indexer.zonation) > 1:
logger.debug("Zonation length (N subzones) is %s", len(indexer.zonation))
subz = OrderedDict()
subz = dict()
for inum, zrange in indexer.zonation.items():
logger.debug("inum: %s, zrange: %s", inum, zrange)
zname = roxgrid.zone_names[inum]
Expand Down Expand Up @@ -278,7 +277,7 @@ def _convert_to_xtgeo_grid_v2(roxgrid, gname):
# subgrids
if len(indexer.zonation) > 1:
logger.debug("Zonation length (N subzones) is %s", len(indexer.zonation))
subz = OrderedDict()
subz = dict()
for inum, zrange in indexer.zonation.items():
logger.debug("inum: %s, zrange: %s", inum, zrange)
zname = roxgrid.zone_names[inum]
Expand Down
2 changes: 1 addition & 1 deletion src/xtgeo/grid3d/_gridprop_import_roff.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def import_roff(
)
name = None

result: dict[str, Any]= dict()
result: dict[str, Any] = dict()
roff_param = RoffParameter.from_file(pfile._file, name)
result["codes"] = roff_param.xtgeo_codes()
result["name"] = roff_param.name
Expand Down
3 changes: 1 addition & 2 deletions src/xtgeo/grid3d/_gridprop_import_xtgcpprop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""GridProperty import function of xtgcpprop format."""

import json
from collections import OrderedDict
from struct import unpack

import numpy as np
Expand Down Expand Up @@ -58,7 +57,7 @@ def import_xtgcpprop(mfile, ijrange=None, zerobased=False):
fhandle.seek(pos)
jmeta = fhandle.read().decode()

meta = json.loads(jmeta, object_pairs_hook=OrderedDict)
meta = json.loads(jmeta, object_pairs_hook=dict)
req = meta["_required_"]

reqattrs = xtgeo.MetaDataCPProperty.REQUIRED
Expand Down
6 changes: 3 additions & 3 deletions src/xtgeo/grid3d/_roff_grid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import pathlib
from collections import OrderedDict, defaultdict
from collections import defaultdict
from collections.abc import MutableMapping, Sequence
from dataclasses import dataclass
from typing import IO, TYPE_CHECKING, Any
Expand Down Expand Up @@ -284,14 +284,14 @@ def xtgeo_zcorn(self) -> np.ndarray:
else:
raise ValueError(f"Unknown error {retval} occurred")

def xtgeo_subgrids(self) -> OrderedDict[str, range] | None:
def xtgeo_subgrids(self) -> dict[str, range] | None:
"""
Returns:
The z values for nodes in the format of xtgeo.Grid.zcornsv
"""
if self.subgrids is None:
return None
result = OrderedDict()
result = dict()
next_ind = 1
for i, current in enumerate(self.subgrids):
result[f"subgrid_{i}"] = range(next_ind, current + next_ind)
Expand Down
Loading

0 comments on commit 19a7988

Please sign in to comment.