Skip to content

Commit 78843b7

Browse files
committed
fix glossary generator
1 parent 85d3305 commit 78843b7

4 files changed

Lines changed: 42 additions & 216 deletions

File tree

cfspopcon/variables.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,8 @@ n_points_for_confined_region_profiles:
10781078
- calc_1D_plasma_profiles
10791079
n_sep_ratio:
10801080
default_units: dimensionless
1081-
description: Ratio of separatrix density to pedestal density.
1081+
description:
1082+
- Ratio of separatrix density to pedestal density.
10821083
set_by: []
10831084
used_by:
10841085
- calc_peaked_profiles
@@ -1378,7 +1379,8 @@ peak_pressure:
13781379
used_by: []
13791380
pedestal_width:
13801381
default_units: dimensionless
1381-
description: Width of the edge pedestal in normalized rho space.
1382+
description:
1383+
- Width of the edge pedestal in normalized rho space.
13821384
set_by: []
13831385
used_by:
13841386
- calc_peaked_profiles
@@ -1626,7 +1628,8 @@ reference_ne_tau:
16261628
- calc_edge_impurity_concentration
16271629
required_H98:
16281630
default_units: dimensionless
1629-
description: Required H98 factor to maintain power balance with a specified P_aux.
1631+
description:
1632+
- Required H98 factor to maintain power balance with a specified P_aux.
16301633
set_by:
16311634
- solve_energy_confinement_scaling_for_input_power
16321635
- calc_power_balance_from_input_P_aux
@@ -1883,7 +1886,8 @@ sustainment_power_in_ion_channel:
18831886
used_by: []
18841887
t_sep:
18851888
default_units: kiloelectron_volt
1886-
description: Electron temperature at the separatrix.
1889+
description:
1890+
- Electron temperature at the separatrix.
18871891
set_by: []
18881892
used_by:
18891893
- calc_peaked_profiles

docs/doc_sources/physics_glossary.rst

Lines changed: 4 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -300,54 +300,7 @@ Physics Glossary
300300
The number of points to use for the confined region profiles.
301301

302302
n_sep_ratio
303-
R
304-
a
305-
t
306-
i
307-
o
308-
309-
o
310-
f
311-
312-
s
313-
e
314-
p
315-
a
316-
r
317-
a
318-
t
319-
r
320-
i
321-
x
322-
323-
d
324-
e
325-
n
326-
s
327-
i
328-
t
329-
y
330-
331-
t
332-
o
333-
334-
p
335-
e
336-
d
337-
e
338-
s
339-
t
340-
a
341-
l
342-
343-
d
344-
e
345-
n
346-
s
347-
i
348-
t
349-
y
350-
.
303+
Ratio of separatrix density to pedestal density.
351304

352305
neoclassical_loop_resistivity
353306
Plasma loop neoclassical resistivity.
@@ -446,57 +399,7 @@ Physics Glossary
446399
Peak total pressure in the core.
447400

448401
pedestal_width
449-
W
450-
i
451-
d
452-
t
453-
h
454-
455-
o
456-
f
457-
458-
t
459-
h
460-
e
461-
462-
e
463-
d
464-
g
465-
e
466-
467-
p
468-
e
469-
d
470-
e
471-
s
472-
t
473-
a
474-
l
475-
476-
i
477-
n
478-
479-
n
480-
o
481-
r
482-
m
483-
a
484-
l
485-
i
486-
z
487-
e
488-
d
489-
490-
r
491-
h
492-
o
493-
494-
s
495-
p
496-
a
497-
c
498-
e
499-
.
402+
Width of the edge pedestal in normalized rho space.
500403

501404
plasma_current
502405
Current carried by the plasma :math:`I_p`.
@@ -568,75 +471,7 @@ Physics Glossary
568471
A constant :math:`n_e\tau` (upstream electron density times impurity residence time) used when evaluating the :math:`L_Z` impurity radiation curve.
569472

570473
required_H98
571-
R
572-
e
573-
q
574-
u
575-
i
576-
r
577-
e
578-
d
579-
580-
H
581-
9
582-
8
583-
584-
f
585-
a
586-
c
587-
t
588-
o
589-
r
590-
591-
t
592-
o
593-
594-
m
595-
a
596-
i
597-
n
598-
t
599-
a
600-
i
601-
n
602-
603-
p
604-
o
605-
w
606-
e
607-
r
608-
609-
b
610-
a
611-
l
612-
a
613-
n
614-
c
615-
e
616-
617-
w
618-
i
619-
t
620-
h
621-
622-
a
623-
624-
s
625-
p
626-
e
627-
c
628-
i
629-
f
630-
i
631-
e
632-
d
633-
634-
P
635-
_
636-
a
637-
u
638-
x
639-
.
474+
Required H98 factor to maintain power balance with a specified P_aux.
640475

641476
resistive_flux
642477
Usually this is the magnetic flux induced by the resistance of the plasma. However, given that POPCON calculates this with the empirical :math:`C_E`, it may also hold information about flux induced coupling with the wall. :math:`\psi_{res} = C_E\mu_0R_0I_p`.
@@ -711,45 +546,7 @@ Physics Glossary
711546
The power in the ion channel required to maintain the ion temperature gradient at the separatrix.
712547

713548
t_sep
714-
E
715-
l
716-
e
717-
c
718-
t
719-
r
720-
o
721-
n
722-
723-
t
724-
e
725-
m
726-
p
727-
e
728-
r
729-
a
730-
t
731-
u
732-
r
733-
e
734-
735-
a
736-
t
737-
738-
t
739-
h
740-
e
741-
742-
s
743-
e
744-
p
745-
a
746-
r
747-
a
748-
t
749-
r
750-
i
751-
x
752-
.
549+
Electron temperature at the separatrix.
753550

754551
target_angle_of_incidence
755552
Angle of incidence between magnetic field vector and surface normal vector at divertor target.

tests/test_helpers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33
import xarray as xr
4+
from utils.variable_consistency_checker import VariableConsistencyChecker
45

56
from cfspopcon import named_options
67
from cfspopcon.formulas.impurities.impurity_array_helpers import (
@@ -65,3 +66,9 @@ def test_impurity_array_helpers():
6566

6667
assert np.isclose(ds["array2"].sel(dim_species=AtomicSpecies.Helium).isel(a=0, b=1).item(), 0.1)
6768
assert np.isclose(ds["array2"].sel(dim_species=AtomicSpecies.Tungsten).isel(a=1, b=1).item(), 0.4)
69+
70+
71+
def test_variable_consistency_checker_normalize_description():
72+
assert VariableConsistencyChecker.normalize_description("single line") == ["single line"]
73+
assert VariableConsistencyChecker.normalize_description("first line\nsecond line") == ["first line", "second line"]
74+
assert VariableConsistencyChecker.normalize_description(["first line", "second line"]) == ["first line", "second line"]

tests/utils/variable_consistency_checker.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def read_physics_glossary(self) -> tuple[dict[str, list[str]], set[str]]:
3939

4040
# Define patterns for identifying blank lines, keys and descriptions.
4141
pattern_for_key = re.compile(r"^\s{2}\S+\s*$")
42-
pattern_for_description = re.compile(r"^\s{4}\S.+")
43-
pattern_for_blank = re.compile(r"^\s*$")
42+
pattern_for_description = re.compile(r"^\s{4}.*$")
43+
pattern_for_blank = re.compile(r"^$")
4444

4545
# Store the results in a dictionary
4646
glossary: dict[str, list[str]] = dict()
@@ -98,6 +98,24 @@ def read_variables_dict(self) -> tuple[dict[str, dict[str, Any]], set[str]]:
9898

9999
return variables_dict, set(variables_dict.keys())
100100

101+
@staticmethod
102+
def normalize_description(description: str | list[str]) -> list[str]:
103+
"""Normalize a variable description into a list of glossary lines.
104+
105+
``variables.yaml`` historically contains a mix of plain strings and
106+
explicit line lists. The glossary writer expects a list, so string
107+
descriptions must be wrapped as single entries rather than iterated
108+
character-by-character.
109+
"""
110+
if isinstance(description, str):
111+
return description.splitlines() or [description]
112+
113+
normalized_description: list[str] = []
114+
for line in description:
115+
normalized_description.extend(line.splitlines() or [line])
116+
117+
return normalized_description
118+
101119
def run(self, apply_changes: bool = True) -> None: # noqa: PLR0912, PLR0915
102120
"""Check the files and, if apply_changes = True, modify the files in place."""
103121
success = True
@@ -153,7 +171,7 @@ def run(self, apply_changes: bool = True) -> None: # noqa: PLR0912, PLR0915
153171
default_units = self.variables_dict[key]["default_units"]
154172
if default_units is not None:
155173
default_units = str(Quantity(1.0, default_units).units)
156-
description = self.variables_dict[key]["description"]
174+
description = self.normalize_description(self.variables_dict[key]["description"])
157175
if key not in self.glossary:
158176
print(f"Adding description for '{key}'.{linebreak}New: '{description}'.{linebreak}")
159177
elif not (description == self.glossary[key]):
@@ -204,8 +222,8 @@ def run(self, apply_changes: bool = True) -> None: # noqa: PLR0912, PLR0915
204222
for line in description:
205223
glossary_text += [f" {line}"]
206224

207-
with as_file(files("cfspopcon").parents[0] / "docs" / "doc_sources" / "physics_glossary.rst") as filepath: # type:ignore[attr-defined]
208-
filepath.write_text("\n".join(glossary_text))
225+
with as_file(files("cfspopcon").parents[0] / "docs" / "doc_sources" / "physics_glossary.rst") as filepath: # type:ignore[attr-defined]
226+
filepath.write_text("\n".join(glossary_text))
209227

210228
exit(0) if success else exit(1)
211229

0 commit comments

Comments
 (0)