From 3b192ab6d55b483c54915a944d49461e8ef1fe27 Mon Sep 17 00:00:00 2001 From: uxcpa Date: Thu, 20 Oct 2022 12:03:58 +0200 Subject: [PATCH] Changes to allow distinguishing metastable isotopes in plot (see issue #45) examples/outputplotting/plotnuclideheat.py - plotting all isotopes of one element with get_all_isotopes as before, here Sc - plotting one specific ZAI with new get_all_isotopes_states, here Sc45m - plotting all isotopes and states of an element with new get_all_isotopes_states, here Sc pypact/analysis/__init__.py - import new get_all_isotopes_states() pypact/analysis/propertyplotter.py - NuclideDataEntry class(): added self.state, IndexError handling if get_all_isotopes() is used instead of of get_all_isotopes_states() - plotproperty(): also distinguish by state, labels pypact/library/nuclidelib.py - new function get_all_isotopes_states(): multiplying by STATE_MAPPINGS --- examples/outputplotting/plotnuclideheat.py | 16 +++++++++++++--- pypact/analysis/__init__.py | 1 + pypact/analysis/propertyplotter.py | 15 ++++++++++----- pypact/library/nuclidelib.py | 11 +++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/examples/outputplotting/plotnuclideheat.py b/examples/outputplotting/plotnuclideheat.py index 3b4d37c..55cff66 100644 --- a/examples/outputplotting/plotnuclideheat.py +++ b/examples/outputplotting/plotnuclideheat.py @@ -3,13 +3,23 @@ import os import pypact as pp import pypact.analysis as ppa +from pypact.library.nuclidelib import get_zai filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..', 'reference', 'test127.out') -tz = ppa.TimeZone.COOL -properties = ['heat', 'grams', 'ingestion'] -isotopes = [ ppa.NuclideDataEntry(i) for i in ppa.get_all_isotopes() if ppa.find_z(i[0]) <= 10] +tz = ppa.TimeZone.BOTH +properties = ['heat', 'grams', 'inhalation'] + +# plot all isotopes of a specific element regardless of state, here Sc +#isotopes = [ ppa.NuclideDataEntry(i) for i in ppa.get_all_isotopes() if ppa.find_z(i[0]) == 21] + +# plot specific isotope with specific state, here Sc45m +#isotopes = [ ppa.NuclideDataEntry(i) for i in ppa.get_all_isotopes_states() if get_zai(i[0]+str(i[1])+str(i[2])) == 210451 ] + +# plot all isotopes and states of an element, here Sc +isotopes = [ ppa.NuclideDataEntry(i) for i in ppa.get_all_isotopes_states() if ppa.find_z(i[0]) == 21 ] + plt = ppa.LinePlotAdapter() diff --git a/pypact/analysis/__init__.py b/pypact/analysis/__init__.py index 9134b29..ac73cde 100644 --- a/pypact/analysis/__init__.py +++ b/pypact/analysis/__init__.py @@ -11,3 +11,4 @@ from pypact.library.nuclidelib import find_element from pypact.library.nuclidelib import find_z from pypact.library.nuclidelib import get_all_isotopes +from pypact.library.nuclidelib import get_all_isotopes_states \ No newline at end of file diff --git a/pypact/analysis/propertyplotter.py b/pypact/analysis/propertyplotter.py index a21e0fb..6986cb8 100644 --- a/pypact/analysis/propertyplotter.py +++ b/pypact/analysis/propertyplotter.py @@ -7,16 +7,21 @@ class NuclideDataEntry(object): def __init__(self, nuclide): self.element = nuclide[0] self.isotope = nuclide[1] - + try: + self.state = nuclide[2] + except IndexError: + self.state = "" + self.reset() def reset(self): self.times = [] self.values = [] + def __str__(self): - return str.format("Isotope {0}-{1} values: {2}", - self.element, self.isotope, self.values) + return str.format("Isotope {0}-{1}-{2} values: {3}", + self.element, self.isotope, self.state, self.values) def plotproperty(output, @@ -40,7 +45,7 @@ def plotproperty(output, value = getattr(n, property) total += value for i in isotopes: - if n.element == i.element and n.isotope == i.isotope: + if n.element == i.element and n.isotope == i.isotope and n.state == i.state: i.times.append(t.irradiation_time + t.cooling_time) i.values.append(value) @@ -60,7 +65,7 @@ def plotproperty(output, f = plotter.lineplot(x=i.times, y=i.values, - datalabel=str.format('{0}-{1}', i.element, i.isotope), + datalabel=str.format('{0}-{1}{2}', i.element, i.isotope, i.state), xlabel="time [s]", ylabel=yaxislabel, logx=(timeperiod != TimeZone.IRRAD), diff --git a/pypact/library/nuclidelib.py b/pypact/library/nuclidelib.py index 047f6fa..65969f5 100644 --- a/pypact/library/nuclidelib.py +++ b/pypact/library/nuclidelib.py @@ -197,3 +197,14 @@ def get_all_isotopes(): all_list[count] = (n[ELEMENT_KEY], i) count += 1 return all_list + +def get_all_isotopes_states(): + all_list_2 = [('', 0,'')] * NUMBER_OF_ISOTOPES * len(STATE_MAPPINGS) + count = 0 + for n in NUCLIDE_DICTIONARY: + if ELEMENT_KEY in n and ISOTOPES_KEY in n: + for i in n[ISOTOPES_KEY]: + for k in STATE_MAPPINGS: + all_list_2[count] = (n[ELEMENT_KEY], i, STATE_MAPPINGS[k]) + count += 1 + return all_list_2 \ No newline at end of file