Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize numpy imports with as np #1776

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions armi/bookkeeping/db/compareDB3.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

from tabulate import tabulate
import h5py
import numpy
import numpy as np

from armi import runLog
from armi.bookkeeping.db import database3
Expand Down Expand Up @@ -329,7 +329,7 @@ def _diffSpecialData(
diffResults.addStructureDiffs(nDiffs)

if not keysMatch:
diffResults.addDiff(name, name, numpy.inf, numpy.inf, numpy.inf)
diffResults.addDiff(name, name, np.inf, np.inf, np.inf)
return

if srcData.attrs.get("dict", False):
Expand All @@ -341,7 +341,7 @@ def _diffSpecialData(
for k, srcAttr in srcData.attrs.items():
refAttr = refData.attrs[k]

if isinstance(srcAttr, numpy.ndarray) and isinstance(refAttr, numpy.ndarray):
if isinstance(srcAttr, np.ndarray) and isinstance(refAttr, np.ndarray):
srcFlat = srcAttr.flatten()
refFlat = refAttr.flatten()
if len(srcFlat) != len(refFlat):
Expand Down Expand Up @@ -374,12 +374,10 @@ def _diffSpecialData(

diff = []
for dSrc, dRef in zip(src.tolist(), ref.tolist()):
if isinstance(dSrc, numpy.ndarray) and isinstance(dRef, numpy.ndarray):
if isinstance(dSrc, np.ndarray) and isinstance(dRef, np.ndarray):
if dSrc.shape != dRef.shape:
out.writeln("Shapes did not match for {}".format(refData))
diffResults.addDiff(
compName, paramName, numpy.inf, numpy.inf, numpy.inf
)
diffResults.addDiff(compName, paramName, np.inf, np.inf, np.inf)
return

# make sure not to try to compare empty arrays. Numpy is mediocre at
Expand All @@ -395,7 +393,7 @@ def _diffSpecialData(

if (dSrc is None) ^ (dRef is None):
out.writeln("Mismatched Nones for {} in {}".format(paramName, compName))
diff.append([numpy.inf])
diff.append([np.inf])
continue

if dSrc is None:
Expand All @@ -410,12 +408,12 @@ def _diffSpecialData(
if dSrc == dRef:
diff.append([0.0])
else:
diff.append([numpy.inf])
diff.append([np.inf])

if diff:
try:
diff = [numpy.array(d).flatten() for d in diff]
diff = numpy.concatenate(diff)
diff = [np.array(d).flatten() for d in diff]
diff = np.concatenate(diff)
except ValueError as e:
out.writeln(
"Failed to concatenate diff data for {} in {}: {}".format(
Expand All @@ -424,10 +422,10 @@ def _diffSpecialData(
)
out.writeln("Because: {}".format(e))
return
absDiff = numpy.abs(diff)
mean = numpy.nanmean(diff)
absMax = numpy.nanmax(absDiff)
absMean = numpy.nanmean(absDiff)
absDiff = np.abs(diff)
mean = np.nanmean(diff)
absMax = np.nanmax(absDiff)
absMean = np.nanmean(absDiff)

diffResults.addDiff(compName, paramName, absMean, mean, absMax)

Expand All @@ -448,21 +446,21 @@ def _diffSimpleData(ref: h5py.Dataset, src: h5py.Dataset, diffResults: DiffResul
runLog.error("Failed to compare {} in {}".format(paramName, compName))
runLog.error("source: {}".format(src))
runLog.error("reference: {}".format(ref))
diff = numpy.array([numpy.inf])
diff = np.array([np.inf])
except ValueError:
runLog.error("Failed to compare {} in {}".format(paramName, compName))
runLog.error("source: {}".format(src))
runLog.error("reference: {}".format(ref))
diff = numpy.array([numpy.inf])
diff = np.array([np.inf])

if 0 in diff.shape:
# Empty list, no diff
return

absDiff = numpy.abs(diff)
mean = numpy.nanmean(diff)
absMax = numpy.nanmax(absDiff)
absMean = numpy.nanmean(absDiff)
absDiff = np.abs(diff)
mean = np.nanmean(diff)
absMax = np.nanmax(absDiff)
absMean = np.nanmean(absDiff)

diffResults.addDiff(compName, paramName, absMean, mean, absMax)

Expand Down Expand Up @@ -501,9 +499,7 @@ def _compareComponentData(
paramName, refSpecial, srcSpecial
)
)
diffResults.addDiff(
refGroup.name, paramName, numpy.inf, numpy.inf, numpy.inf
)
diffResults.addDiff(refGroup.name, paramName, np.inf, np.inf, np.inf)
continue

if srcSpecial or refSpecial:
Expand Down
Loading
Loading