Skip to content

Commit

Permalink
Merge pull request #184 from bam241/clean_import
Browse files Browse the repository at this point in the history
removing Pyne import when not required
  • Loading branch information
gonuke committed Feb 13, 2024
2 parents c418d79 + 7182227 commit 4b7796c
Show file tree
Hide file tree
Showing 13 changed files with 1,824 additions and 1,835 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cymetric Change Log

**Changed**
* Converted test suite from nose to pytest (#188)
* Removed some unused imports, mainly pyne (#184)

v1.5.5
====================
Expand Down
1 change: 1 addition & 0 deletions cymetric/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np
import pandas as pd


from cymetric.evaluator import Evaluator, METRIC_REGISTRY


Expand Down
14 changes: 11 additions & 3 deletions cymetric/fco_metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""FCO metrics"""
import pandas as pd


try:
from pyne import data
import pyne.enrichment as enr
Expand Down Expand Up @@ -167,9 +169,15 @@ def fco_fuel_loading(mats, trans):
mass = mass.groupby(mass.index)['Mass'].sum()
mass = mass.reset_index()
# sum by years (12 time steps)
mass = pd.DataFrame(data={'Year': mass.TimeCreated.apply(lambda x: x // 12),
'FuelLoading': mass.Mass.apply(lambda x: x / 1000)},
columns=['Year', 'FuelLoading'])
mass = pd.DataFrame(
data={
'Year': mass.TimeCreated.apply(
lambda x: x // 12),
'FuelLoading': mass.Mass.apply(
lambda x: x / 1000)},
columns=[
'Year',
'FuelLoading'])
mass = mass.groupby('Year').sum()
rtn = mass.reset_index()
return rtn
Expand Down
4 changes: 0 additions & 4 deletions cymetric/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import warnings
import pandas as pd
import numpy as np

try:
from graphviz import Digraph
Expand All @@ -10,8 +8,6 @@

try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False
Expand Down
10 changes: 0 additions & 10 deletions cymetric/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@
"""
import warnings

import pandas as pd
import numpy as np

try:
from graphviz import Digraph
HAVE_GRAPHVIZ = True
except ImportError:
HAVE_GRAPHVIZ = False

try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False

from cymetric import tools
from cymetric.filters import transactions_nuc

Expand Down
4 changes: 2 additions & 2 deletions cymetric/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import numpy as np
import pandas as pd


try:
from pyne import data
import pyne.enrichment as enr
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False
Expand Down Expand Up @@ -284,7 +284,7 @@ def agents(entry, exit, decom, info):
mergeon = ['SimId', 'AgentId']
df = entry[['SimId', 'AgentId', 'Kind', 'Spec', 'Prototype', 'ParentId',
'Lifetime', 'EnterTime']]
df['ExitTime'] = [np.nan]*len(entry)
df['ExitTime'] = [np.nan] * len(entry)
if exit is not None:
exit.columns = ['SimId', 'AgentId', 'Exits']
df = tools.merge_and_fillna_col(df, exit[['SimId', 'AgentId',
Expand Down
6 changes: 3 additions & 3 deletions cymetric/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
else:
str_types = (str, unicode)

from cyclus import typesystem as ts
from cyclus.typesystem import NAMES, RANKS, IDS


Expand Down Expand Up @@ -40,8 +39,9 @@ def canon_shape(shape, dbtype):
s.append(i)
rank = RANKS[dbtype]
if len(s) != rank:
msg = ('the shape rank for the {0} type must be {1}, got {2} for a '
'shape of {3}.')
msg = (
'the shape rank for the {0} type must be {1}, got {2} for a '
'shape of {3}.')
raise ValueError(msg.format(NAMES[dbtype], rank, len(s), s))
rtn = tuple(s)
elif isinstance(shape, int):
Expand Down
22 changes: 8 additions & 14 deletions cymetric/timeseries.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import warnings

import pandas as pd
import numpy as np

try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
HAVE_PYNE = False

from cymetric import tools
from cymetric import filters

Expand Down Expand Up @@ -42,7 +31,12 @@ def transactions(evaler, senders=(), receivers=(), commodities=(), nucs=()):
return df


def transactions_activity(evaler, senders=(), receivers=(), commodities=(), nucs=()):
def transactions_activity(
evaler,
senders=(),
receivers=(),
commodities=(),
nucs=()):
"""
Shape the reduced transation Data Frame into a simple time serie. Applying nuclides selection when required.
Expand Down Expand Up @@ -86,8 +80,8 @@ def transactions_decayheat(
if len(nucs) != 0:
nucs = tools.format_nucs(nucs)

df = filters.transactions_decayheat(evaler, senders, receivers, commodities,
nucs)
df = filters.transactions_decayheat(
evaler, senders, receivers, commodities, nucs)

df = df[['Time', 'DecayHeat']].groupby(['Time']).sum()
df.reset_index(inplace=True)
Expand Down
9 changes: 4 additions & 5 deletions cymetric/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import sys
import warnings

import numpy as np
import pandas as pd


try:
from pyne import data
import pyne.enrichment as enr
from pyne import nucname
HAVE_PYNE = True
except ImportError:
Expand All @@ -26,8 +24,9 @@ def dbopen(fname):
"""Opens a Cyclus database."""
_, ext = os.path.splitext(fname)
if ext not in EXT_BACKENDS:
msg = ('The backend database type of {0!r} could not be determined from '
'extension {1!r}.')
msg = (
'The backend database type of {0!r} could not be determined from '
'extension {1!r}.')
raise ValueError(msg.format(fname, ext))
db = EXT_BACKENDS[ext](fname)
return db
Expand Down
Loading

0 comments on commit 4b7796c

Please sign in to comment.