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

Data source fix #841

Merged
merged 6 commits into from May 9, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 15 additions & 14 deletions pyne/origen22.py
Expand Up @@ -1457,8 +1457,7 @@ def _compute_xslib(nuc, key, lib, xscache):
elif field == 'title':
continue
data[key] = _xslib_computers[field](nuc, xscache)



def xslibs(nucs=NUCS, xscache=None, nlb=(201, 202, 203), verbose=False):
"""Generates a TAPE9 dictionary of cross section & fission product yield data
for a set of nuclides.
Expand Down Expand Up @@ -1491,7 +1490,6 @@ def xslibs(nucs=NUCS, xscache=None, nlb=(201, 202, 203), verbose=False):
else:
xscache['E_g'] = [old_group_struct[0], old_group_struct[-1]]
nucs = sorted(nucs)

# setup tape9
t9 = {nlb[0]: {'_type': 'xsfpy', '_subtype': 'activation_products',
'title': 'PyNE Cross Section Data for Activation Products'},
Expand All @@ -1509,18 +1507,22 @@ def xslibs(nucs=NUCS, xscache=None, nlb=(201, 202, 203), verbose=False):
t9[nlb[1]][field] = {}
for field in FISSION_PRODUCT_FIELDS:
t9[nlb[2]][field] = {}

# fill with data
for nuc in nucs:
if verbose:
print('computing {0}'.format(nucname.name(nuc)))
key = nucname.zzaaam(nuc)
if nuc in ACTIVATION_PRODUCT_NUCS:
_compute_xslib(nuc, key, t9[nlb[0]], xscache)
if nuc in ACTINIDE_AND_DAUGHTER_NUCS:
_compute_xslib(nuc, key, t9[nlb[1]], xscache)
if nuc in FISSION_PRODUCT_NUCS:
_compute_xslib(nuc, key, t9[nlb[2]], xscache)
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try blocks should be a couple of lines at most, and ideally should only be 1 line This is too all-encompassing. I think you should have three try-except blocks, one in each of the conditionals.

if verbose:
print('computing {0}'.format(nucname.name(nuc)))
key = nucname.zzaaam(nuc)
if nuc in ACTIVATION_PRODUCT_NUCS:
_compute_xslib(nuc, key, t9[nlb[0]], xscache)
if nuc in ACTINIDE_AND_DAUGHTER_NUCS:
_compute_xslib(nuc, key, t9[nlb[1]], xscache)
if nuc in FISSION_PRODUCT_NUCS:
_compute_xslib(nuc, key, t9[nlb[2]], xscache)
except KeyError:
if verbose:
print('Key Error with ', key, ' in a computing cross sections')
continue
xscache['E_g'] = old_group_struct
xscache['phi_g'] = old_flux
return t9
Expand Down Expand Up @@ -1575,7 +1577,6 @@ def make_tape9(nucs, xscache=None, nlb=(201, 202, 203)):
# build decay decks
decay_file = StringIO(decay_tape9.decay_tape9)
decay = parse_tape9(decay_file)

if xscache is None:
xscache = cache.XSCache()
nucs = {nucname.id(nuc) for nuc in nucs}
Expand Down
10 changes: 6 additions & 4 deletions pyne/xs/cache.py
Expand Up @@ -74,7 +74,7 @@ def __init__(self, group_struct=None,
ds = ds(dst_group_struct=group_struct)
if ds.exists:
self.data_sources.append(ds)
self._cache['E_g'] = _valid_group_struct(group_struct)
self._cache['E_g'] = _valid_group_struct(group_struct)
self._cache['phi_g'] = None

#
Expand Down Expand Up @@ -114,7 +114,9 @@ def __getitem__(self, key):
xsdata = ds.discretize(**kw)
if xsdata is not None:
self._cache[key] = xsdata
break
break
else:
raise KeyError
# Return the value requested
return self._cache[key]

Expand All @@ -126,11 +128,11 @@ def __setitem__(self, key, value):
value = _valid_group_struct(value)
cache_value = self._cache['E_g']
if _same_arr_or_none(value, cache_value):
return
return
self.clear()
self._cache['phi_g'] = None
for ds in self.data_sources:
ds.dst_group_struct = value
ds.dst_group_struct = value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a 3-space indent? Shouldn't it be 4-space?

elif (key == 'phi_g'):
value = value if value is None else np.asarray(value, dtype='f8')
cache_value = self._cache['phi_g']
Expand Down