---
title: "Recomputing photon counts and native Cloudy shells"
description: "Recompute ionized volumes and hydrogen-line luminosities in Python, then test what shell and atomic refinement change in Cloudy."
canonical_url: "https://sandboxphysics.com/stories/ionized-nebulae/photon-counting-and-a-native-cloudy-grid/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/ionized-nebulae/photon-counting-and-a-native-cloudy-grid/"
last_modified: "2026-11-22"
---

[Hot stars, ionized nebulae and hydrogen light](https://sandboxphysics.com/stories/ionized-nebulae/)

Ionized nebulae · L4

# Recomputing photon counts and native Cloudy shells

Sandbox Physics · 2026-11-22

How much does the ionized volume change when Cloudy follows the edge of the nebula shell by shell? First compute the ideal sphere from photon counting. Then use the same volume calculation on Cloudy’s saved shells and see how changes in atomic and spatial resolution affect the line luminosities.

## Before you begin

Read L1–L3. The analytic and saved-shell calculations use only Python’s standard library; they were checked with Python 3.12.12. Optional figures use NumPy 2.4.4 and Matplotlib 3.10.8, which are not bundled. The single-run commands take local saved files. The companion grid replay requires Python 3.10 or later.

## Open the photon-counting exercises

Download the photon-counting exercises, compare the listed SHA-256 and extract the archive. Start with the ideal-sphere script and use the figures to check its output.

The generic shell exercise takes two files from an existing Cloudy model, first.rad and first.emis. If you have no saved model, start with the ideal-sphere exercise below.

Reading: Independent photon-counting and saved-shell scientific materials · Cloudy C25.00 fixed source commit fb07fa7142af77846af521753622453fb551bef7

## Recalculate the ideal sphere in a fresh directory

Run the commands below from the extracted material directory. It creates a results folder, recomputes physical scales and the full ideal on/off history, checks independent time stepping and projection, and writes summary.json and ideal-history.csv.

Inputs are $Q=10^{49}\,\mathrm{s^{-1}}$, $n_{\rm H}=100\,\mathrm{cm^{-3}}$ and prescribed $\alpha_{\rm B}=2.60\times10^{-13}\,\mathrm{cm^3\,s^{-1}}$. Expect $R_{\rm S}\simeq3.14989\,\mathrm{pc}$ and $t_{\rm rec}\simeq1218.77\,\mathrm{yr}$. These are calculations with a teaching coefficient, not a new atomic-code evaluation.

Inspect coarse\_failure\_retained. Step $0.01$ produces relative ion-count error about $0.003833$ at half a recombination time, exceeding the registered example gate $0.002$. Meanwhile, the maximum photon-count residual over its history remains below $10^{-12}$. Step $0.005$ reduces the error to about $0.001922$, with further improvement after another halving. The coarse failure remains in the output.

```
python science/recompute.py --output results/ideal
python science/validate_reader.py --output results/self-check
```

Reading: Independent photon-counting and saved-shell scientific materials

## Check that power and projection count the same gas

One recombination time after switch-off, an initially ionized parcel has $x=0.5$ and fixed-coefficient line emission $0.25$ of its switch-off value. An independent fourth-order Runge–Kutta integration agrees with the reciprocal solution to an absolute difference of about $4.86\times10^{-10}$ in this test.

The projection\_refinement output integrates a uniform sphere’s sightline intensity with annular area weights and recovers its volume luminosity. At 256 radial bins the relative difference is approximately 0.00649%. This checks geometry and integration, not complete atomic physics.

If the optional plotting dependencies are present, the next command regenerates three synthetic figures. They read the newly calculated ideal history or the same analytic geometry. No webpage screenshot or independent decorative emission map is used.

![Own ideal ion-count radius and fixed-yield line-power history through source-off](https://sandboxphysics.com/_astro/history.DGynM32s.svg)

Independent fixed-gas ideal reference. Shading marks source-off; radius and line light are calculated from the same particle history. This is not a native Cloudy time series. [Open the full figure](https://sandboxphysics.com/_astro/history.DGynM32s.svg)

```
python science/plot_references.py --results results/ideal --output results/figures
```

Reading: Independent photon-counting and saved-shell scientific materials

## Inspect the native model’s physical identity

The reference source is Cloudy C25.00 commit fb07fa7142af77846af521753622453fb551bef7. The parameter-grid middle node has $Q=10^{49}\,\mathrm{s^{-1}}$ and $n_{\rm H}=100\,\mathrm{cm^{-3}}$; the second worked example has $Q=10^{48}\,\mathrm{s^{-1}}$ and $n_{\rm H}=30\,\mathrm{cm^{-3}}$. They use prescribed-temperature hydrogen, a 40000 K blackbody, a small inner radius, and explicit OTS, atomic-basis and stopping choices.

These native models and the ideal teaching sphere differ physically. Native results retain radial ionization structure and a more complete atomic system. The teaching reference assumes a fully ionized thin-front interior and prescribed coefficients. Match composition, temperature, geometry, spectrum, atomic configuration and equilibrium versus time dependence before interpreting a difference.

The first.rad columns are zone number, radius, depth and thickness in centimetres. The first.emis columns are matching depth and four energy emissivities: ordinary H1 blue/red lines and separately saved native CaB blue/red diagnostics. The two CaB columns use Cloudy’s Case B diagnostic for the same pair of wavelengths.

Reading: Cloudy C25.00 fixed source commit fb07fa7142af77846af521753622453fb551bef7 · Independent photon-counting and saved-shell scientific materials

## Integrate the saved emission shell by shell

Point the three commands at directories already containing the base, atomic-control and spatial-control native files respectively. Missing input fails explicitly. The code checks names, zone order, overlapping printed depth intervals and positive geometry, computes each actual shell volume, multiplies by energy emissivity and adds the results. It writes a new output file only.

For midpoint radius $r$ and thickness $\Delta r$, use $4\pi(r^2\Delta r+\Delta r^3/12)$. This is the difference of outer and inner sphere volumes expressed as a positive polynomial. Each shell retains its finite thickness.

Radius and thickness have different saved precision. The program derives intervals from each actual numeric token, uses positive directed Decimal arithmetic and records file bytes and SHA values. The output checks the volume integral. The native receipt records the charge balance check and incident-source diagnostics separately.

```
python science/inspect_native.py --model-dir /your/local/base --output results/native-base.json
python science/inspect_native.py --model-dir /your/local/atomic --output results/native-atomic.json
python science/inspect_native.py --model-dir /your/local/space --output results/native-space.json
```

Reading: Independent photon-counting and saved-shell scientific materials

## Compare atomic and spatial controls separately

Each completed node has three native results. The base resolves atomic principal shells through 40 and adds 25 collapsed shells, with highest principal quantum number 65 and maximum relative gas-shell thickness 0.005. The atomic control resolves through 50 plus 15 collapsed shells, retaining highest 65. The spatial control retains the atomic basis and halves maximum gas-shell thickness to 0.0025.

After integrating the three files, compare the base with each refined result separately. Subtract the refined power from the base power and divide by the refined power. The script carries the whole rounding interval through this calculation for each line. An interval entirely inside the limit passes. An interval entirely outside fails, and one crossing the limit is UNDETERMINED.

The noncentral node’s base ordinary red-line power is approximately $1.36525\times10^{36}\,\mathrm{erg\,s^{-1}}$. The middle node gives about $1.36102\times10^{37}\,\mathrm{erg\,s^{-1}}$, while its CaB red-line diagnostic is $1.36574\times10^{37}\,\mathrm{erg\,s^{-1}}$. Preserve these distinct atomic outputs; no normalization was adjusted to force the analytic value.

These two worked examples pass the original $\pm0.002$ relative four-line gate on each of the two axes. Each pair measures what happens when one setting changes. Testing both at once would require another native run with both settings refined.

```
python science/compare_axes.py results/native-base.json results/native-atomic.json --output results/atomic-axis.json
python science/compare_axes.py results/native-base.json results/native-space.json --output results/space-axis.json
```

Reading: Independent photon-counting and saved-shell scientific materials · Cloudy C25.00 fixed source commit fb07fa7142af77846af521753622453fb551bef7

## Compare the whole Cloudy grid with photon counting

Use the fixed Cloudy grid ZIP in the download panel. Check its SHA-256, extract it to a fresh directory and run the command below from that directory. It checks the file identities, then reads the radius, emissivity and hydrogen-state files from the 27 runs.

Open models → Q49-nH100 → base in the new JSON. The sum of hydrogen ion fraction times shell volume gives a sphere of equal ionized volume, with a radius of 3.178 parsecs. Photon counting with the fixed teaching coefficient gives 3.150 parsecs. The radius changes by less than one percent and the volume is 2.68 percent larger, because volume grows with the cube of radius. Try changing the node to Q48-nH30 and compare relativeVolumeDifference.

Then open lineRefinements. Each of the 18 entries changes only the atomic basis or only the shell thickness. Its four energy-line intervals pass only when each entire interval is within 0.2 percent. These checks bound the observed changes for the two separate refinements. The replay starts from the saved shells. The native solver records hold the separate charge balance checks.

The first Q49-nH100 base run stopped while opening a hydrogen atomic-data file and saved no shells. Restoring the pinned data let the same input deck complete. A missing or damaged shell file in your copy also stops the replay, so keep both the original archive and the new JSON.

```
python -B science/compare_native_grid.py --bundle . --out results/cloudy-shell-comparison.json
```

Reading: Fixed Cloudy C25 grid and saved-shell replay · Cloudy C25.00 fixed source commit fb07fa7142af77846af521753622453fb551bef7

## Exercises and explained answers

1. The coarse step conserves photons near machine precision but misses the example’s ion-count accuracy gate. Should the failed item be deleted or the conservation test altered?

   Read the explanation

   Neither. Conservation and accuracy test different properties. Retain the coarse result, its independent analytic comparison and the prospectively refined calculations. A passing count does not guarantee sufficient accuracy in the requested observable.

2. A point relative difference is inside the gate but its full print interval crosses it. Separately, two individual refinement axes pass. Do these establish a passing interval and a joint error at the same level?

   Read the explanation

   The first case is undetermined: a point does not remove print uncertainty. Two passing individual axes do not determine the error under simultaneous refinement. Report their separate scopes and perform a joint comparison if that claim is needed.

## Try the prediction

### [Follow one cloud from ions to hydrogen light](https://sandboxphysics.com/labs/stromgren-ionization-front/)

1. Choose a fixed preset and record source supply, density and displayed time before distinguishing the transient from a native equilibrium reference.
2. Export one shell record and use the previous chapter’s formulas to check volume power and projection.
3. The public Python supplies independent ideal references and saved-native integration. Read the Lab effective model and the more complete native atom as separate calculations.

## Standalone scientific materials

[Download the photon-counting exercises](https://sandboxphysics.com/stories/ionized-nebulae/materials/ionized-nebulae-science-v1.zip) · [Original setup and two-node snapshot](https://sandboxphysics.com/stories/ionized-nebulae/materials/README.md)

The exercises use the Python standard library to compute ideal references. The generic shell integrator accepts saved Cloudy runs that you supply.

[Download the fixed Cloudy grid](https://sandboxphysics.com/stories/ionized-nebulae/materials/ionized-nebulae-native-grid-v1.zip) · [Run the shell comparison](https://sandboxphysics.com/stories/ionized-nebulae/photon-counting-and-a-native-cloudy-grid/#native-grid-replay)

The archive includes our input decks and saved radius, emissivity and hydrogen-state files.

Files, sizes and SHA-256

- [ionized-nebulae-science-v1.zip](https://sandboxphysics.com/stories/ionized-nebulae/materials/ionized-nebulae-science-v1.zip) (158729 B)
  `f7b837cf0b7c77fa48a10638662cd9947d90584004ec524fb067658ff7cc28f8`
- [README.md](https://sandboxphysics.com/stories/ionized-nebulae/materials/README.md) (5577 B)
  `fc23b2d31067ac760053196c88ed973e7bfd03b97f93132ecb5d63fe1236e3f0`
- [analytic\_cloud.py](https://sandboxphysics.com/stories/ionized-nebulae/materials/analytic_cloud.py) (3658 B)
  `5444f2922161a17dc199d64e9e1b9683fb08bf9698fdf2f38a312c8e5e189e60`
- [compare\_axes.py](https://sandboxphysics.com/stories/ionized-nebulae/materials/compare_axes.py) (1778 B)
  `e890390eb0e1a0569ee7218d098ad99490ccedbccc225ad7f3ad78dbadd21942`
- [inspect\_native.py](https://sandboxphysics.com/stories/ionized-nebulae/materials/inspect_native.py) (4217 B)
  `4c538371f5219fcf27c7b39b975cb61db3f79cc678cd4266356ff46dc61c3d48`
- [plot\_references.py](https://sandboxphysics.com/stories/ionized-nebulae/materials/plot_references.py) (4119 B)
  `8e568d459488e56d4e0ff290c5827d2828b97eaa6d7b9d90122ef155cf39ffda`
- [recompute.py](https://sandboxphysics.com/stories/ionized-nebulae/materials/recompute.py) (2966 B)
  `379cdb01474a0e3e25409408c71fac4b02e4ee6e422ce0fe683599d6197cd4cf`
- [validate\_reader.py](https://sandboxphysics.com/stories/ionized-nebulae/materials/validate_reader.py) (3251 B)
  `1c7eb089404606771a12f98cd679f35ef1b7c6eeb9a62a80bf415efd7e1305a1`
- [ionized-nebulae-native-grid-v1.zip](https://sandboxphysics.com/stories/ionized-nebulae/materials/ionized-nebulae-native-grid-v1.zip) (3256527 B)
  `efbc462e2d2a9ab4608255d48ec8355537e2fee731595c87f2781c98494eb417`

[Previous: Adding hydrogen-line light along a sightline](https://sandboxphysics.com/stories/ionized-nebulae/from-ions-to-a-line-image/) [Next: Reading a galaxy's line ratios through escaping photons](https://sandboxphysics.com/stories/ionized-nebulae/when-ionizing-light-leaves-its-nebula/)

## Sources and calculation scope

1. [Cloudy C25.00 fixed source commit fb07fa7142af77846af521753622453fb551bef7](https://gitlab.nublado.org/cloudy/cloudy/-/tree/fb07fa7142af77846af521753622453fb551bef7)

   The native equilibrium runs pin this Cloudy release. They use uniform hydrogen at fixed temperature, a prescribed stellar spectrum and an on-the-spot treatment of recombination radiation. The teaching calculation prescribes its own constant recombination coefficient.

2. [Independent photon-counting and saved-shell scientific materials](https://sandboxphysics.com/stories/ionized-nebulae/materials/ionized-nebulae-science-v1.zip)

   MIT-licensed Python recomputes ideal scales, growth, local recombination, projection and synthetic filtering. The generic shell integrator reads radius and emissivity files from locally saved runs.

3. [Fixed Cloudy C25 grid and saved-shell replay](https://sandboxphysics.com/stories/ionized-nebulae/materials/ionized-nebulae-native-grid-v1.zip)

   Includes our input decks and first.rad, first.emis and first.ovr saves. Its Python script replays the shell integrals and independent line comparisons. The archive records the original native receipt identities. Cloudy itself, its atomic data and full charge arrays are separate inputs for a native solve.

## Keep reading

Hot stars and ionized nebulae · Reading path

### From photon counts to hydrogen light and evidence

1. [Article **How far can a hot star ionize a cloud?**](https://sandboxphysics.com/stories/ionized-nebulae/why-a-nebula-has-an-edge/)
2. [Article **Counting photons to find an ionized sphere**](https://sandboxphysics.com/stories/ionized-nebulae/counting-photons-in-a-sphere/)
3. [Article **How a hydrogen cloud fades after its star switches off**](https://sandboxphysics.com/stories/ionized-nebulae/when-the-source-switches-off/)
4. [Article **Adding hydrogen-line light along a sightline**](https://sandboxphysics.com/stories/ionized-nebulae/from-ions-to-a-line-image/)
5. [You are here **Recomputing photon counts and native Cloudy shells**](https://sandboxphysics.com/stories/ionized-nebulae/photon-counting-and-a-native-cloudy-grid/)
6. [Article **Reading a galaxy's line ratios through escaping photons**](https://sandboxphysics.com/stories/ionized-nebulae/when-ionizing-light-leaves-its-nebula/)
