Skip to content

Commit 2e4fa9a

Browse files
author
magmist magmist
committed
refactor dust model input to use a dictionary
1 parent 3fb5ff0 commit 2e4fa9a

2 files changed

Lines changed: 93 additions & 71 deletions

File tree

radprocess/pipeline/Pipeline.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -544,17 +544,18 @@ def convert_subboxes(self, which_rad="radmc",
544544

545545
def run_polaris_opacity(
546546
self,
547-
dust_components,
548-
dust_size_min=None,
549-
dust_size_max=None,
550-
dust_size_powerlaw=None,
551-
mean_molecular_weight=None,
552-
mass_fraction=None,
553-
nr_threads=None,
554-
grid_path=None,
555-
n_dust_override=None,
556-
polaris_binary=None,
557-
cleanup=True,
547+
# dust_components,
548+
# dust_size_min = None,
549+
# dust_size_max = None,
550+
# dust_size_powerlaw = None,
551+
dust_mixtures,
552+
mean_molecular_weight = None,
553+
mass_fraction = None,
554+
nr_threads = None,
555+
grid_path = None,
556+
n_dust_override = None,
557+
polaris_binary = None,
558+
cleanup = True,
558559
):
559560
"""
560561
Run POLARIS with 1 photon package to generate dust opacity tables.
@@ -609,12 +610,12 @@ def run_polaris_opacity(
609610
pc = self.configparams.polaris
610611

611612
# Use dataclass defaults for any parameter not explicitly set
612-
if dust_size_min is None:
613-
dust_size_min = pc.dust_size_min
614-
if dust_size_max is None:
615-
dust_size_max = pc.dust_size_max
616-
if dust_size_powerlaw is None:
617-
dust_size_powerlaw = pc.dust_size_powerlaw
613+
# if dust_size_min is None:
614+
# dust_size_min = pc.dust_size_min
615+
# if dust_size_max is None:
616+
# dust_size_max = pc.dust_size_max
617+
# if dust_size_powerlaw is None:
618+
# dust_size_powerlaw = pc.dust_size_powerlaw
618619
if mean_molecular_weight is None:
619620
mean_molecular_weight = pc.mean_molecular_weight
620621
if mass_fraction is None:
@@ -636,20 +637,21 @@ def run_polaris_opacity(
636637
print(f"Auto-detected POLARIS grid: {grid_path}")
637638

638639
data_dir = run_opacity(
639-
ramses_dir=ramses_dir,
640-
polaris_dir=polaris_dir,
641-
grid_path=grid_path,
642-
dust_components=dust_components,
643-
dust_size_min=dust_size_min,
644-
dust_size_max=dust_size_max,
645-
dust_size_powerlaw=dust_size_powerlaw,
646-
mean_molecular_weight=mean_molecular_weight,
647-
mass_fraction=mass_fraction,
648-
nr_threads=nr_threads,
649-
f_acc=f_acc,
650-
n_dust_override=n_dust_override,
651-
polaris_binary=polaris_binary,
652-
cleanup=cleanup,
640+
ramses_dir = ramses_dir,
641+
polaris_dir = polaris_dir,
642+
grid_path = grid_path,
643+
# dust_components = dust_components,
644+
# dust_size_min = dust_size_min,
645+
# dust_size_max = dust_size_max,
646+
# dust_size_powerlaw = dust_size_powerlaw,
647+
dust_mixtures = dust_mixtures,
648+
mean_molecular_weight = mean_molecular_weight,
649+
mass_fraction = mass_fraction,
650+
nr_threads = nr_threads,
651+
f_acc = f_acc,
652+
n_dust_override = n_dust_override,
653+
polaris_binary = polaris_binary,
654+
cleanup = cleanup,
653655
)
654656

655657
return data_dir

radprocess/polaris/opacity.py

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,15 @@ def write_opacity_cmd(
194194
output_path,
195195
stars,
196196
n_dust,
197-
dust_components,
198-
dust_size_min,
199-
dust_size_max,
200-
dust_size_powerlaw=-3.5,
201-
mean_molecular_weight=2.37,
202-
mass_fraction=1,
203-
nr_threads=8,
204-
output_num=0,
197+
# dust_components,
198+
# dust_size_min,
199+
# dust_size_max,
200+
# dust_size_powerlaw = -3.5,
201+
dust_mixtures,
202+
mean_molecular_weight = 2.37,
203+
mass_fraction = 1,
204+
nr_threads = 1,
205+
output_num = 0,
205206
):
206207
"""
207208
Write a POLARIS command file for the opacity-only run.
@@ -245,23 +246,40 @@ def write_opacity_cmd(
245246
cmd_path.parent.mkdir(parents=True, exist_ok=True)
246247

247248
# Log-spaced size bin edges
248-
size_edges = np.logspace(np.log10(dust_size_min),
249-
np.log10(dust_size_max), n_dust + 1)
249+
# size_edges = np.logspace(np.log10(dust_size_min),
250+
# np.log10(dust_size_max), n_dust + 1)
250251

251252
print(f"Writing POLARIS opacity command file: {cmd_path}")
252253

253254
with open(cmd_path, "w") as f:
254255
# --- <common> block ---
255256
f.write("<common>\n")
256257

257-
for i in range(n_dust):
258-
for comp in dust_components:
258+
# for i in range(n_dust):
259+
# for comp in dust_components:
260+
# f.write(
261+
# f'\n\t<dust_component id = "{i}"> '
262+
# f'"{comp["path"]}" "plaw" {comp["weight"]} 0 '
263+
# f'{size_edges[i]:.2e} {size_edges[i+1]:.2e} '
264+
# f'{dust_size_powerlaw}'
265+
# )
266+
267+
for mixture, components in dust_mixtures.items():
268+
for component in components.values():
259269
f.write(
260-
f'\n\t<dust_component id = "{i}"> '
261-
f'"{comp["path"]}" "plaw" {comp["weight"]} 0 '
262-
f'{size_edges[i]:.2e} {size_edges[i+1]:.2e} '
263-
f'{dust_size_powerlaw}'
270+
f'\n\t<dust_component id = "{mixture}"> '
271+
f'"{component["path"]}" '
272+
f'"{component["distribution"]}" '
273+
f'{component["fraction"]} '
274+
f'{component["density"]} '
275+
f'{component["amin"]:.2e} '
276+
f'{component["amax"]:.2e}'
264277
)
278+
index = component['index'] if isinstance(component['index'], list) else [component['index']]
279+
for i in index:
280+
f.write(
281+
f' {i}'
282+
)
265283

266284
f.write(f"\n\n\t<nr_threads> {nr_threads}\n")
267285
f.write("\n</common>\n")
@@ -359,17 +377,18 @@ def run_opacity(
359377
ramses_dir,
360378
polaris_dir,
361379
grid_path,
362-
dust_components,
363-
dust_size_min,
364-
dust_size_max,
365-
dust_size_powerlaw=-3.5,
366-
mean_molecular_weight=2.37,
367-
mass_fraction=0.01,
368-
nr_threads=8,
369-
f_acc=0.1,
370-
n_dust_override=None,
371-
polaris_binary="polaris",
372-
cleanup=True,
380+
# dust_components,
381+
# dust_size_min,
382+
# dust_size_max,
383+
# dust_size_powerlaw = -3.5,
384+
dust_mixtures,
385+
mean_molecular_weight = 2.37,
386+
mass_fraction = 0.01,
387+
nr_threads = 1,
388+
f_acc = 0.1,
389+
n_dust_override = None,
390+
polaris_binary = "polaris",
391+
cleanup = True,
373392
):
374393
"""
375394
Full Step 4: derive stellar properties, write the POLARIS command file,
@@ -440,19 +459,20 @@ def run_opacity(
440459
cmd_path = polaris_dir / cmd_filename
441460

442461
write_opacity_cmd(
443-
cmd_path=cmd_path,
444-
grid_path=grid_path,
445-
output_path=polaris_dir,
446-
stars=stars,
447-
n_dust=n_dust,
448-
dust_components=dust_components,
449-
dust_size_min=dust_size_min,
450-
dust_size_max=dust_size_max,
451-
dust_size_powerlaw=dust_size_powerlaw,
452-
mean_molecular_weight=mean_molecular_weight,
453-
mass_fraction=mass_fraction,
454-
nr_threads=nr_threads,
455-
output_num=output_num,
462+
cmd_path = cmd_path,
463+
grid_path = grid_path,
464+
output_path = polaris_dir,
465+
stars = stars,
466+
n_dust = n_dust,
467+
# dust_components = dust_components,
468+
# dust_size_min = dust_size_min,
469+
# dust_size_max = dust_size_max,
470+
# dust_size_powerlaw = dust_size_powerlaw,
471+
dust_mixtures = dust_mixtures,
472+
mean_molecular_weight = mean_molecular_weight,
473+
mass_fraction = mass_fraction,
474+
nr_threads = nr_threads,
475+
output_num = output_num
456476
)
457477

458478
# 5) Cleanup previous run

0 commit comments

Comments
 (0)