Skip to content

Commit 487fbcc

Browse files
blaltermanclaude
andcommitted
feat(data): add Asplund 2009 photospheric reference abundances
Add reference photospheric elemental abundances from Asplund et al. (2009) for computing FIP bias and elemental fractionation factors in solar wind composition analysis. New module: solarwindpy.data.reference - ReferenceAbundances class with photospheric_abundance() method - Returns abundance ratios (e.g., Fe/O, Ne/O) with uncertainties - Data stored in asplund.csv, loaded via importlib.resources Reference: Asplund, M., Grevesse, N., Sauval, A. J., & Scott, P. (2009). The Chemical Composition of the Sun. Annual Review of Astronomy and Astrophysics, 47(1), 481-522. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 296ac07 commit 487fbcc

4 files changed

Lines changed: 223 additions & 1 deletion

File tree

solarwindpy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
spacecraft,
2121
alfvenic_turbulence,
2222
)
23-
from . import core, plotting, solar_activity, tools, fitfunctions
23+
from . import core, plotting, solar_activity, tools, fitfunctions, data
2424
from . import instabilities # noqa: F401
2525
from . import reproducibility
2626

@@ -43,6 +43,7 @@ def _configure_pandas() -> None:
4343

4444
__all__ = [
4545
"core",
46+
"data",
4647
"plasma",
4748
"ions",
4849
"tensor",

solarwindpy/data/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Solar wind reference data and constants."""
2+
3+
from .reference import ReferenceAbundances
4+
5+
__all__ = ["ReferenceAbundances"]
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""Reference photospheric abundances from Asplund et al. (2009).
2+
3+
Reference:
4+
Asplund, M., Grevesse, N., Sauval, A. J., & Scott, P. (2009).
5+
The Chemical Composition of the Sun.
6+
Annual Review of Astronomy and Astrophysics, 47(1), 481-522.
7+
https://doi.org/10.1146/annurev.astro.46.060407.145222
8+
"""
9+
10+
__all__ = ["ReferenceAbundances", "Abundance"]
11+
12+
import numpy as np
13+
import pandas as pd
14+
from collections import namedtuple
15+
from importlib import resources
16+
17+
Abundance = namedtuple("Abundance", "measurement,uncertainty")
18+
19+
20+
class ReferenceAbundances:
21+
"""Photospheric elemental abundances from Asplund et al. (2009).
22+
23+
Abundances are stored in 'dex' units:
24+
log(epsilon_X) = log(N_X/N_H) + 12
25+
26+
where N_X is the number density of element X and N_H is hydrogen.
27+
28+
Example
29+
-------
30+
>>> ref = ReferenceAbundances()
31+
>>> fe_o = ref.photospheric_abundance("Fe", "O")
32+
>>> print(f"Fe/O = {fe_o.measurement:.4f} +/- {fe_o.uncertainty:.4f}")
33+
Fe/O = 0.0646 +/- 0.0060
34+
"""
35+
36+
def __init__(self):
37+
self._load_data()
38+
39+
@property
40+
def data(self):
41+
"""Elemental abundances in dex units."""
42+
return self._data
43+
44+
def _load_data(self):
45+
"""Load Asplund 2009 data from package resources."""
46+
with resources.files(__package__).joinpath("asplund.csv").open() as f:
47+
data = pd.read_csv(
48+
f, skiprows=4, header=[0, 1], index_col=[0, 1]
49+
).astype(np.float64)
50+
self._data = data
51+
52+
def get_element(self, key, kind="Photosphere"):
53+
"""Get abundance measurements for an element.
54+
55+
Parameters
56+
----------
57+
key : str or int
58+
Element symbol (e.g., "Fe") or atomic number (e.g., 26)
59+
kind : str, optional
60+
"Photosphere" or "Meteorites" (default: "Photosphere")
61+
62+
Returns
63+
-------
64+
pd.Series
65+
Series with 'Ab' (abundance in dex) and 'Uncert' (uncertainty)
66+
"""
67+
if isinstance(key, str):
68+
level = "Symbol"
69+
elif isinstance(key, int):
70+
level = "Z"
71+
else:
72+
raise ValueError(f"Unrecognized key type ({type(key)})")
73+
74+
out = self.data.loc[:, kind].xs(key, axis=0, level=level)
75+
assert out.shape[0] == 1, f"Expected 1 row for {key}, got {out.shape[0]}"
76+
77+
return out.iloc[0]
78+
79+
@staticmethod
80+
def _convert_from_dex(case):
81+
"""Convert from dex to linear abundance ratio."""
82+
m = case.loc["Ab"]
83+
u = case.loc["Uncert"]
84+
85+
mm = 10.0 ** (m - 12.0)
86+
uu = mm * np.log(10) * u
87+
return mm, uu
88+
89+
def photospheric_abundance(self, top, bottom):
90+
"""Compute photospheric abundance ratio of two elements.
91+
92+
Parameters
93+
----------
94+
top : str or int
95+
Numerator element (symbol or Z)
96+
bottom : str or int
97+
Denominator element (symbol or Z), or "H" for hydrogen
98+
99+
Returns
100+
-------
101+
Abundance
102+
Named tuple with (measurement, uncertainty) for the ratio N_top/N_bottom
103+
104+
Example
105+
-------
106+
>>> ref = ReferenceAbundances()
107+
>>> ref.photospheric_abundance("Fe", "O")
108+
Abundance(measurement=0.0646, uncertainty=0.0060)
109+
"""
110+
top_data = self.get_element(top)
111+
tu = top_data.Uncert
112+
if np.isnan(tu):
113+
tu = 0
114+
115+
if bottom != "H":
116+
bottom_data = self.get_element(bottom)
117+
bu = bottom_data.Uncert
118+
if np.isnan(bu):
119+
bu = 0
120+
121+
rat = 10.0 ** (top_data.Ab - bottom_data.Ab)
122+
uncert = rat * np.log(10) * np.sqrt((tu ** 2) + (bu ** 2))
123+
else:
124+
rat, uncert = self._convert_from_dex(top_data)
125+
126+
return Abundance(rat, uncert)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
Chemical composition of the Sun from Table 1 in [1].
2+
3+
[1] Asplund, M., Grevesse, N., Sauval, A. J., & Scott, P. (2009). The Chemical Composition of the Sun. Annual Review of Astronomy and Astrophysics, 47(1), 481–522. https://doi.org/10.1146/annurev.astro.46.060407.145222
4+
5+
Kind,,Meteorites,Meteorites,Photosphere,Photosphere
6+
,,Ab,Uncert,Ab,Uncert
7+
Z,Symbol,,,,
8+
1,H,8.22 , 0.04,12.00,
9+
2,He,1.29,,10.93 , 0.01
10+
3,Li,3.26 , 0.05,1.05 , 0.10
11+
4,Be,1.30 , 0.03,1.38 , 0.09
12+
5,B,2.79 , 0.04,2.70 , 0.20
13+
6,C,7.39 , 0.04,8.43 , 0.05
14+
7,N,6.26 , 0.06,7.83 , 0.05
15+
8,O,8.40 , 0.04,8.69 , 0.05
16+
9,F,4.42 , 0.06,4.56 , 0.30
17+
10,Ne,-1.12,,7.93 , 0.10
18+
11,Na,6.27 , 0.02,6.24 , 0.04
19+
12,Mg,7.53 , 0.01,7.60 , 0.04
20+
13,Al,6.43 , 0.01,6.45 , 0.03
21+
14,Si,7.51 , 0.01,7.51 , 0.03
22+
15,P,5.43 , 0.04,5.41 , 0.03
23+
16,S,7.15 , 0.02,7.12 , 0.03
24+
17,Cl,5.23 , 0.06,5.50 , 0.30
25+
18,Ar,-0.05,,6.40 , 0.13
26+
19,K,5.08 , 0.02,5.03 , 0.09
27+
20,Ca,6.29 , 0.02,6.34 , 0.04
28+
21,Sc,3.05 , 0.02,3.15 , 0.04
29+
22,Ti,4.91 , 0.03,4.95 , 0.05
30+
23,V,3.96 , 0.02,3.93 , 0.08
31+
24,Cr,5.64 , 0.01,5.64 , 0.04
32+
25,Mn,5.48 , 0.01,5.43 , 0.04
33+
26,Fe,7.45 , 0.01,7.50 , 0.04
34+
27,Co,4.87 , 0.01,4.99 , 0.07
35+
28,Ni,6.20 , 0.01,6.22 , 0.04
36+
29,Cu,4.25 , 0.04,4.19 , 0.04
37+
30,Zn,4.63 , 0.04,4.56 , 0.05
38+
31,Ga,3.08 , 0.02,3.04 , 0.09
39+
32,Ge,3.58 , 0.04,3.65 , 0.10
40+
33,As,2.30 , 0.04,,
41+
34,Se,3.34 , 0.03,,
42+
35,Br,2.54 , 0.06,,
43+
36,Kr,-2.27,,3.25 , 0.06
44+
37,Rb,2.36 , 0.03,2.52 , 0.10
45+
38,Sr,2.88 , 0.03,2.87 , 0.07
46+
39,Y,2.17 , 0.04,2.21 , 0.05
47+
40,Zr,2.53 , 0.04,2.58 , 0.04
48+
41,Nb,1.41 , 0.04,1.46 , 0.04
49+
42,Mo,1.94 , 0.04,1.88 , 0.08
50+
44,Ru,1.76 , 0.03,1.75 , 0.08
51+
45,Rh,1.06 , 0.04,0.91 , 0.10
52+
46,Pd,1.65 , 0.02,1.57 , 0.10
53+
47,Ag,1.20 , 0.02,0.94 , 0.10
54+
48,Cd,1.71 , 0.03,,
55+
49,In,0.76 , 0.03,0.80 , 0.20
56+
50,Sn,2.07 , 0.06,2.04 , 0.10
57+
51,Sb,1.01 , 0.06,,
58+
52,Te,2.18 , 0.03,,
59+
53,I,1.55 , 0.08,,
60+
54,Xe,-1.95,,2.24 , 0.06
61+
55,Cs,1.08 , 0.02,,
62+
56,Ba,2.18 , 0.03,2.18 , 0.09
63+
57,La,1.17 , 0.02,1.10 , 0.04
64+
58,Ce,1.58 , 0.02,1.58 , 0.04
65+
59,Pr,0.76 , 0.03,0.72 , 0.04
66+
60,Nd,1.45 , 0.02,1.42 , 0.04
67+
62,Sm,0.94 , 0.02,0.96 , 0.04
68+
63,Eu,0.51 , 0.02,0.52 , 0.04
69+
64,Gd,1.05 , 0.02,1.07 , 0.04
70+
65,Tb,0.32 , 0.03,0.30 , 0.10
71+
66,Dy,1.13 , 0.02,1.10 , 0.04
72+
67,Ho,0.47 , 0.03,0.48 , 0.11
73+
68,Er,0.92 , 0.02,0.92 , 0.05
74+
69,Tm,0.12 , 0.03,0.10 , 0.04
75+
70,Yb,0.92 , 0.02,0.84 , 0.11
76+
71,Lu,0.09 , 0.02,0.10 , 0.09
77+
72,Hf,0.71 , 0.02,0.85 , 0.04
78+
73,Ta,-0.12 , 0.04,,
79+
74,W,0.65 , 0.04,0.85 , 0.12
80+
75,Re,0.26 , 0.04,,
81+
76,Os,1.35 , 0.03,1.40 , 0.08
82+
77,Ir,1.32 , 0.02,1.38 , 0.07
83+
78,Pt,1.62 , 0.03,,
84+
79,Au,0.80 , 0.04,0.92 , 0.10
85+
80,Hg,1.17 , 0.08,,
86+
81,Tl,0.77 , 0.03,0.90 , 0.20
87+
82,Pb,2.04 , 0.03,1.75 , 0.10
88+
83,Bi,0.65 , 0.04,,
89+
90,Th,0.06 , 0.03,0.02 , 0.10
90+
92,U,-0.54 , 0.03,,

0 commit comments

Comments
 (0)