Skip to content

Commit 71a7726

Browse files
authored
#81 Merge pull request from astropenguin/astropenguin/issue78
Remove aliases
2 parents 83f105e + 7de9c11 commit 71a7726

File tree

4 files changed

+23
-133
lines changed

4 files changed

+23
-133
lines changed

ndradex/consts.py

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,6 @@
66
# radex-related
77
"RADEX_BIN",
88
"RADEX_VERSION",
9-
# defaults
10-
"DV",
11-
"N",
12-
"N_E",
13-
"N_H",
14-
"N_H2",
15-
"N_HE",
16-
"N_HP",
17-
"N_OH2",
18-
"N_PH2",
19-
"PARALLEL",
20-
"PROGRESS",
21-
"RADEX",
22-
"SQUEEZE",
23-
"T_BG",
24-
"T_KIN",
25-
"TIMEOUT",
26-
"WORKDIR",
27-
# aliases
28-
"DATAFILE",
29-
"LEVEL",
30-
"TRANSITION",
31-
# helper functions
32-
"alias",
339
]
3410

3511

@@ -48,11 +24,6 @@
4824

4925

5026
# helper functions
51-
def alias(name: str, aliases: dict[str, str]) -> str:
52-
"""Get the alias of a name if it exists."""
53-
return aliases.get(name, name)
54-
55-
5627
def ensure(toml: Path) -> Path:
5728
"""Create an empty TOML file if it does not exist."""
5829
if not toml.exists():
@@ -115,67 +86,3 @@ def getval(toml: Path, keys: str, default: Any) -> Any:
11586

11687
RADEX_VERSION = "30nov2011"
11788
"""Supported version of the RADEX binaries."""
118-
119-
120-
# defaults
121-
DV = getval(NDRADEX_CONFIG, "defaults.dv", 1.0)
122-
"""Default value for the ``dv`` argument."""
123-
124-
N = getval(NDRADEX_CONFIG, "defaults.N", 1e15)
125-
"""Default value for the ``N_mol`` argument."""
126-
127-
N_E = getval(NDRADEX_CONFIG, "defaults.n_e", 0.0)
128-
"""Default value for the ``n_e`` argument."""
129-
130-
N_H = getval(NDRADEX_CONFIG, "defaults.n_H", 0.0)
131-
"""Default value for the ``n_H`` argument."""
132-
133-
N_H2 = getval(NDRADEX_CONFIG, "defaults.n_H2", 1e3)
134-
"""Default value for the ``n_H2`` argument."""
135-
136-
N_HE = getval(NDRADEX_CONFIG, "defaults.n_He", 0.0)
137-
"""Default value for the ``n_He`` argument."""
138-
139-
N_HP = getval(NDRADEX_CONFIG, "defaults.n_Hp", 0.0)
140-
"""Default value for the ``n_Hp`` argument."""
141-
142-
N_OH2 = getval(NDRADEX_CONFIG, "defaults.n_oH2", 0.0)
143-
"""Default value for the ``n_oH2`` argument."""
144-
145-
N_PH2 = getval(NDRADEX_CONFIG, "defaults.n_pH2", 0.0)
146-
"""Default value for the ``n_pH2`` argument."""
147-
148-
PARALLEL = getval(NDRADEX_CONFIG, "defaults.parallel", int)
149-
"""Default value for the ``parallel`` argument."""
150-
151-
PROGRESS = getval(NDRADEX_CONFIG, "defaults.progress", False)
152-
"""Default value for the ``progress`` argument."""
153-
154-
RADEX = getval(NDRADEX_CONFIG, "defaults.radex", "radex-1")
155-
"""Default value for the ``radex`` argument."""
156-
157-
SQUEEZE = getval(NDRADEX_CONFIG, "defaults.squeeze", True)
158-
"""Default value for the ``squeeze`` argument."""
159-
160-
T_BG = getval(NDRADEX_CONFIG, "defaults.T_bg", 2.73)
161-
"""Default value for the ``T_bg`` argument."""
162-
163-
T_KIN = getval(NDRADEX_CONFIG, "defaults.T_kin", 100.0)
164-
"""Default value for the ``T_kin`` argument."""
165-
166-
TIMEOUT = getval(NDRADEX_CONFIG, "defaults.timeout", float)
167-
"""Default value for the ``timeout`` argument."""
168-
169-
WORKDIR = getval(NDRADEX_CONFIG, "defaults.workdir", Path)
170-
"""Default value for the ``workdir`` argument."""
171-
172-
173-
# aliases
174-
DATAFILE = getval(NDRADEX_CONFIG, "aliases.datafile", dict[str, str]())
175-
"""Aliases for the ``datafile`` argument."""
176-
177-
LEVEL = getval(NDRADEX_CONFIG, "aliases.level", dict[str, str]())
178-
"""Aliases for the ``level`` argument."""
179-
180-
TRANSITION = getval(NDRADEX_CONFIG, "aliases.transition", dict[str, str]())
181-
"""Aliases for the ``transition`` argument."""

ndradex/lamda.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from astroquery.lamda import Lamda, parse_lamda_datafile, write_lamda_datafile
1818
from requests_cache import CachedSession
1919
from typing_extensions import Self
20-
from .consts import DATAFILE, LEVEL, TRANSITION, alias
2120

2221

2322
# type hints
@@ -128,7 +127,7 @@ def query(datafile: str, *, cache: bool = True, timeout: Timeout = None) -> LAMD
128127
LAMDA object created from the RADEX datafile.
129128
130129
"""
131-
if URL_REGEX.match(datafile := alias(datafile, DATAFILE)):
130+
if URL_REGEX.match(datafile):
132131
return get_lamda_by_url(datafile, cache=cache, timeout=timeout)
133132

134133
try:
@@ -175,7 +174,7 @@ def get_level_id(level: LevelLike, lamda: LAMDA) -> int:
175174
return level
176175

177176
if isinstance(level, str):
178-
level = alias(level, LEVEL).strip()
177+
level = level.strip()
179178

180179
frame = lamda.levels.to_pandas(False).set_index(LEVEL_NAME_COLUMN)
181180
return int(frame[LEVEL_COLUMN].loc[level])
@@ -190,7 +189,7 @@ def get_transition_id(transition: TransitionLike, lamda: LAMDA) -> int:
190189
return transition
191190

192191
if isinstance(transition, str):
193-
transition = split_transition(alias(transition, TRANSITION))
192+
transition = split_transition(transition)
194193

195194
uplow = tuple(get_level_id(level, lamda) for level in transition)
196195
frame = lamda.transitions.to_pandas(False).set_index(UPLOW_COLUMNS)

ndradex/nd.py

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,6 @@
1717
from astropy.units import Quantity
1818
from tqdm import tqdm
1919
from xarray_dataclasses import AsDataset, DataModel, Attr, Coordof, Data, Dataof
20-
from .consts import (
21-
DV,
22-
N,
23-
N_E,
24-
N_H,
25-
N_H2,
26-
N_HE,
27-
N_HP,
28-
N_OH2,
29-
N_PH2,
30-
PARALLEL,
31-
PROGRESS,
32-
RADEX,
33-
SQUEEZE,
34-
T_BG,
35-
T_KIN,
36-
TIMEOUT,
37-
WORKDIR,
38-
)
3920
from .lamda import query
4021
from .radex import Input, Parallel, Timeout, Workdir, runmap, to_input
4122

@@ -70,24 +51,24 @@ def run(
7051
datafile: PathLike,
7152
transition: Multiple[str],
7253
*,
73-
T_kin: Multiple[float] = T_KIN,
74-
n_H2: Multiple[float] = N_H2,
75-
n_pH2: Multiple[float] = N_PH2,
76-
n_oH2: Multiple[float] = N_OH2,
77-
n_e: Multiple[float] = N_E,
78-
n_H: Multiple[float] = N_H,
79-
n_He: Multiple[float] = N_HE,
80-
n_Hp: Multiple[float] = N_HP,
81-
T_bg: Multiple[float] = T_BG,
82-
N: Multiple[float] = N,
83-
dv: Multiple[float] = DV,
84-
radex: Multiple[PathLike] = RADEX,
54+
T_kin: Multiple[float] = 1e2,
55+
n_H2: Multiple[float] = 1e3,
56+
n_pH2: Multiple[float] = 0.0,
57+
n_oH2: Multiple[float] = 0.0,
58+
n_e: Multiple[float] = 0.0,
59+
n_H: Multiple[float] = 0.0,
60+
n_He: Multiple[float] = 0.0,
61+
n_Hp: Multiple[float] = 0.0,
62+
T_bg: Multiple[float] = 2.73,
63+
N: Multiple[float] = 1e15,
64+
dv: Multiple[float] = 1.0,
65+
radex: Multiple[PathLike] = "radex-uni",
8566
# options
86-
parallel: Parallel = PARALLEL,
87-
progress: bool = PROGRESS,
88-
squeeze: bool = SQUEEZE,
89-
timeout: Timeout = TIMEOUT,
90-
workdir: Workdir = WORKDIR,
67+
parallel: Parallel = None,
68+
progress: bool = False,
69+
squeeze: bool = True,
70+
timeout: Timeout = None,
71+
workdir: Workdir = None,
9172
) -> xr.Dataset:
9273
"""Run RADEX with multidimensional parameters.
9374

tests/test_lamda.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
with catch_warnings():
1515
simplefilter("ignore")
1616
datafiles = list(Lamda.molecule_dict)
17+
datafiles.remove("si-h")
18+
datafiles.remove("so2@lowT")
19+
datafiles.remove("PO_hfs")
1720

1821
levels = [
1922
# (datafile, level, expected level ID)

0 commit comments

Comments
 (0)