Skip to content

Commit bda1d9a

Browse files
committed
👍 Add work_dir option
1 parent 8a8f825 commit bda1d9a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

ndradex/grid.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class Vars(Enum):
4545
# main function
4646
@ndradex.utils.set_defaults(**ndradex.config['grid'])
4747
def run(query, QN_ul, T_kin=100, N_mol=1e15, n_H2=1e3,
48-
n_pH2=None, n_oH2=None, n_e=None, n_H=None,
49-
n_He=None, n_Hp=None, T_bg=2.73, dv=1.0, geom='uni', *,
50-
squeeze=True, progress=True, timeout=None, n_procs=None):
48+
n_pH2=None, n_oH2=None, n_e=None, n_H=None, n_He=None,
49+
n_Hp=None, T_bg=2.73, dv=1.0, geom='uni', *, squeeze=True,
50+
progress=True, timeout=None, n_procs=None, work_dir=None):
5151
"""Run grid RADEX calculation and get results as xarray.Dataset.
5252
5353
This is the main function of ndRADEX. It provides 13 parameters
@@ -98,6 +98,11 @@ def run(query, QN_ul, T_kin=100, N_mol=1e15, n_H2=1e3,
9898
Default is None (unlimited run time is permitted).
9999
n_procs (int, optional): Number of processes for asynchronous
100100
RADEX calculations. Default is None (<number of CPU count>-1).
101+
work_dir (path-like, optional): Path of a temporary working
102+
directory where intermediate files are stored. It is sure to
103+
be automatically created and deleted even if the function is
104+
interrupted by some errors. Default is None (it is created
105+
under the OS-native temporary directory).
101106
102107
Returns:
103108
dataset (xarray.Dataset): Dataset which contains DataArrays of:
@@ -149,16 +154,16 @@ def run(query, QN_ul, T_kin=100, N_mol=1e15, n_H2=1e3,
149154
empty = get_empty_array(QN_ul, T_kin, N_mol, n_H2, n_pH2, n_oH2,
150155
n_e, n_H, n_He, n_Hp, T_bg, dv, geom)
151156

152-
with TemporaryDirectory(dir='.') as tempdir, \
153-
ndradex.db.LAMDA(query, tempdir) as lamda:
157+
with TemporaryDirectory(dir=work_dir) as temp_dir, \
158+
ndradex.db.LAMDA(query, temp_dir) as lamda:
154159
# make an empty dataset and flattened args
155160
dataset = get_empty_dataset(lamda, empty)
156161
iterables = [generate_inputs(lamda, empty),
157162
generate_radex_paths(lamda, empty),
158163
repeat(timeout)]
159164

160165
# run RADEX with multiprocess and update dataset
161-
execute(dataset, *iterables, dir=tempdir,
166+
execute(dataset, *iterables, dir=temp_dir,
162167
progress=progress, n_procs=n_procs)
163168

164169
return finalize(dataset, squeeze)

0 commit comments

Comments
 (0)