Skip to content

Commit

Permalink
Update example code to take advantage of pynucastro#702
Browse files Browse the repository at this point in the history
  • Loading branch information
yut23 committed Nov 29, 2023
1 parent 5022b75 commit 2532a21
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs/source/custom-rates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@
"metadata": {},
"outputs": [],
"source": [
"r_custom = MyRate(reactants=[pyna.Nucleus(\"n14\"), pyna.Nucleus(\"p\")],\n",
" products=[pyna.Nucleus(\"o15\")],\n",
"r_custom = MyRate(reactants=[\"n14\", \"p\"],\n",
" products=[\"o15\"],\n",
" r0=r0, T0=T0, nu=nu)"
]
},
Expand Down
4 changes: 2 additions & 2 deletions docs/source/neutrino-cooling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"outputs": [],
"source": [
"from pynucastro.neutrino_cooling import sneut5, NeutrinoCooling\n",
"from pynucastro import Composition, Nucleus"
"from pynucastro import Composition"
]
},
{
Expand Down Expand Up @@ -54,7 +54,7 @@
"source": [
"rho = 1.e8\n",
"T = 2.e9\n",
"c = Composition([Nucleus(\"p\"), Nucleus(\"a\"), Nucleus(\"fe56\")])\n",
"c = Composition([\"p\", \"a\", \"fe56\"])\n",
"c.set_equal()"
]
},
Expand Down
13 changes: 6 additions & 7 deletions docs/source/nse_table.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pynucastro as pyna\n",
"from pynucastro import Nucleus"
"import pynucastro as pyna"
]
},
{
Expand All @@ -43,11 +42,11 @@
"metadata": {},
"outputs": [],
"source": [
"nucs = [Nucleus(\"p\"), Nucleus(\"n\"), Nucleus(\"he4\"),\n",
" Nucleus(\"fe52\"), Nucleus(\"fe53\"), Nucleus(\"fe54\"),\n",
" Nucleus(\"fe55\"), Nucleus(\"fe56\"),\n",
" Nucleus(\"co54\"), Nucleus(\"co55\"), Nucleus(\"co56\"),\n",
" Nucleus(\"ni56\"), Nucleus(\"ni57\")]"
"nucs = [\"p\", \"n\", \"he4\",\n",
" \"fe52\", \"fe53\", \"fe54\",\n",
" \"fe55\", \"fe56\",\n",
" \"co54\", \"co55\", \"co56\",\n",
" \"ni56\", \"ni57\"]"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions docs/source/screening-examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
},
"outputs": [],
"source": [
"nuclei = [pyna.Nucleus(\"h1\"),\n",
" pyna.Nucleus(\"he4\"),\n",
" pyna.Nucleus(\"c12\"),\n",
" pyna.Nucleus(\"o16\"),\n",
" pyna.Nucleus(\"n14\"),\n",
" pyna.Nucleus(\"ca40\")]\n",
"nuclei = [\"h1\",\n",
" \"he4\",\n",
" \"c12\",\n",
" \"o16\",\n",
" \"n14\",\n",
" \"ca40\"]\n",
"\n",
"comp = pyna.Composition(nuclei)\n",
"comp.set_solar_like()\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/approx_rates.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
}
],
"source": [
"rc.remove_nuclei([pyna.Nucleus(\"al27\"), pyna.Nucleus(\"p31\")])"
"rc.remove_nuclei([\"al27\", \"p31\"])"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/pp-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"def to_composition(Y):\n",
" \"\"\"Convert an array of molar fractions to a Composition object.\"\"\"\n",
" from pynucastro import Composition, Nucleus\n",
" nuclei = [Nucleus.from_cache(name) for name in names]\n",
" nuclei = Nucleus.cast_list(names)\n",
" comp = Composition(nuclei)\n",
" for i, nuc in enumerate(nuclei):\n",
" comp.X[nuc] = Y[i] * A[i]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/pynet_approx_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"def to_composition(Y):\n",
" \"\"\"Convert an array of molar fractions to a Composition object.\"\"\"\n",
" from pynucastro import Composition, Nucleus\n",
" nuclei = [Nucleus.from_cache(name) for name in names]\n",
" nuclei = Nucleus.cast_list(names)\n",
" comp = Composition(nuclei)\n",
" for i, nuc in enumerate(nuclei):\n",
" comp.X[nuc] = Y[i] * A[i]\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/rp-process/network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"core_nuclei = [\"p\", \"d\", \"he3\", \"he4\", \"li7\", \"be7\", \"be8\", \"b8\", \"c12\",\n",
" \"n13\", \"n14\", \"n15\", \"o14\", \"o15\", \"o16\", \"o17\", \"o18\",\n",
" \"f17\", \"f18\", \"f19\", \"f20\", \"ne18\", \"ne19\", \"ne20\", \"ne21\"]\n",
"core_nuclei = list(map(Nucleus, core_nuclei))"
"core_nuclei = Nucleus.cast_list(core_nuclei)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/rp-process/rp_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
core_nuclei = ["p", "d", "he3", "he4", "li7", "be7", "be8", "b8", "c12",
"n13", "n14", "n15", "o14", "o15", "o16", "o17", "o18",
"f17", "f18", "f19", "f20", "ne18", "ne19", "ne20", "ne21"]
core_nuclei = list(map(Nucleus, core_nuclei))
core_nuclei = Nucleus.cast_list(core_nuclei)
core_lib = full_lib.linking_nuclei(core_nuclei)


Expand Down
2 changes: 1 addition & 1 deletion pynucastro/networks/python_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _write_network(self, outfile=None):
of.write("def to_composition(Y):\n")
of.write(f'{indent}''"""Convert an array of molar fractions to a Composition object."""\n')
of.write(f'{indent}'"from pynucastro import Composition, Nucleus\n")
of.write(f'{indent}'"nuclei = [Nucleus.from_cache(name) for name in names]\n")
of.write(f'{indent}'"nuclei = Nucleus.cast_list(names)\n")
of.write(f'{indent}'"comp = Composition(nuclei)\n")
of.write(f'{indent}'"for i, nuc in enumerate(nuclei):\n")
of.write(f'{indent*2}'"comp.X[nuc] = Y[i] * A[i]\n")
Expand Down
2 changes: 1 addition & 1 deletion pynucastro/networks/tests/_python_reference/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
def to_composition(Y):
"""Convert an array of molar fractions to a Composition object."""
from pynucastro import Composition, Nucleus
nuclei = [Nucleus.from_cache(name) for name in names]
nuclei = Nucleus.cast_list(names)
comp = Composition(nuclei)
for i, nuc in enumerate(nuclei):
comp.X[nuc] = Y[i] * A[i]
Expand Down

0 comments on commit 2532a21

Please sign in to comment.