-
Notifications
You must be signed in to change notification settings - Fork 4
/
base.py
719 lines (595 loc) · 26 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
import os
import json
import numpy as np
from astra.contrib.aspcap import continuum, utils
from astra.tools.continuum.base import Continuum
from astra.tools.continuum.scalar import Scalar
from typing import Union, List, Tuple, Optional, Callable
from astra import log, __version__
from astra.base import TaskInstance, TupleParameter
from astra.utils import bundler, deserialize, expand_path, serialize_executable
from astra.database.astradb import (
database,
FerreOutput,
AspcapOutput,
Output,
TaskOutput,
Source,
Task,
Bundle,
TaskBundle,
DataProduct,
TaskInputDataProducts,
)
from astra.contrib.ferre.base import Ferre
from astra.contrib.ferre.utils import read_ferre_headers, sanitise
from astra.contrib.ferre.bitmask import ParamBitMask
FERRE_TASK_NAME = serialize_executable(Ferre)
FERRE_DEFAULTS = Ferre.get_defaults()
def initial_guess_doppler(
data_product: DataProduct,
source: Optional[Source] = None,
star = None,
) -> dict:
"""
Return an initial guess for FERRE from Doppler given a data product.
:param data_product:
The data product to be analyzed with FERRE.
:param source: [optional]
The associated Source in the Astra database for this data product.
:param star: [optional]
The associated Star in the APOGEE DRP database for this data product.
"""
if star is None:
from astra.database.apogee_drpdb import Star
if source is None:
(source,) = data_product.sources
# Be sure to get the record of the Star with the latest and greatest stack,
# and latest and greatest set of Doppler values.
star = (
Star.select()
.where(Star.catalogid == source.catalogid)
.order_by(Star.created.desc())
.first()
)
if star is None:
return None
return dict(
telescope=star.telescope,
mean_fiber=int(star.meanfib),
teff=np.round(star.rv_teff, 0),
logg=np.round(star.rv_logg, 3),
metals=np.round(star.rv_feh, 3),
log10vdop=utils.approximate_log10_microturbulence(star.rv_logg),
lgvsini=1.0,
c=0,
n=0,
o_mg_si_s_ca_ti=0,
)
def initial_guess_apogeenet(data_product: DataProduct, star) -> dict:
"""
Return an initial guess for FERRE from APOGEENet given a data product.
:param data_product:
The data prodcut to be analyzed with FERRE.
"""
from astra.database.astradb import ApogeeNetOutput, TaskInputDataProducts, Task
q = (
ApogeeNetOutput
.select()
.join(Task, on=(ApogeeNetOutput.task_id == Task.id))
.join(TaskInputDataProducts)
.where(TaskInputDataProducts.data_product_id == data_product.id)
.where(Task.name == "astra.contrib.apogeenet.StellarParameters")
.order_by(ApogeeNetOutput.snr.desc())
)
output = q.first()
if output is None:
return None
teff, logg, metals = (output.teff, output.logg, output.fe_h)
if star is None:
print(f"WARNING: TODO: Fix this andy")
return None
return dict(
telescope=star.telescope,
mean_fiber=int(star.meanfib),
teff=np.round(teff, 0),
logg=np.round(logg, 3),
metals=np.round(metals, 3),
log10vdop=utils.approximate_log10_microturbulence(logg),
lgvsini=1.0,
c=0,
n=0,
o_mg_si_s_ca_ti=0,
)
def initial_guesses(data_product: DataProduct) -> List[dict]:
"""
Return initial guesses for FERRE given a data product.
:param data_product:
The data product containing 1D spectra for a source.
"""
# TODO: get defaults from Star (telescope, mean_fiber, etc) in a not-so-clumsy way
from astra.database.apogee_drpdb import Star
(source,) = data_product.sources
# Be sure to get the record of the Star with the latest and greatest stack,
# and latest and greatest set of Doppler values.
star = (
Star.select()
.where(Star.catalogid == source.catalogid)
.order_by(Star.created.desc())
.first()
)
try:
int(star.meanfib)
except:
return []
# TODO: Add estimates from other pipelines? Gaia?
return [
initial_guess_doppler(data_product, star=star),
initial_guess_apogeenet(data_product, star=star)
]
def create_initial_stellar_parameter_tasks(
input_data_products,
header_paths: Optional[Union[List[str], Tuple[str], str]] = "$MWM_ASTRA/component_data/aspcap/synspec_dr17_marcs_header_paths.list",
weight_path: Optional[str] = "$MWM_ASTRA/component_data/aspcap/global_mask_v02.txt",
continuum_method: Optional[Union[Continuum, str]] = Scalar,
continuum_kwargs: Optional[dict] = dict(method="median"),
data_slice: Optional[List[Tuple[int]]] = [(0, 1)],
initial_guess_callable: Optional[Callable] = None,
**kwargs,
) -> List[Union[Task, int]]:
"""
Create tasks that will use FERRE to estimate the stellar parameters given a data product.
:param input_data_products:
The input data products, or primary keys for those data products.
:param header_paths:
A list of FERRE header path files, or a path to a file that has one FERRE header path per line.
:param weight_path: [optional]
The weights path to supply to FERRE. By default this is set to the global mask used by SDSS.
:param continuum_method: [optional]
The method to use for continuum normalization before FERRE is executed. By default this is set to
:param data_slice: [optional]
Slice the input spectra and only analyze those rows that meet the slice. This is only relevant for ApStar
input data products, where the first spectrum represents the stacked spectrum. The parmaeter is ignored
for all other input data products.
:param initial_guess_callable: [optional]
A callable function that takes in a data product and returns a list of dictionaries of initial guesses.
Each dictionary should contain at least the following keys:
- telescope
- mean_fiber
- teff
- logg
- metals
- log10vdop
- lgvsini
- c
- n
- o_mg_si_s_ca_ti
If the callable cannot supply an initial guess for a data product, it should return None instead of a dict.
"""
log.debug(f"Data products {type(input_data_products)}: {input_data_products}")
# Data products.
input_data_products = deserialize(input_data_products, DataProduct)
# Header paths.
if isinstance(header_paths, str):
if header_paths.lower().endswith(".hdr"):
header_paths = [header_paths]
else:
# Load from file.
with open(os.path.expandvars(os.path.expanduser(header_paths)), "r") as fp:
header_paths = [line.strip() for line in fp]
if continuum_method is not None:
continuum_method = serialize_executable(continuum_method)
grid_info = utils.parse_grid_information(header_paths)
if initial_guess_callable is None:
initial_guess_callable = initial_guesses
# Round the initial guesses to something sensible.
round = lambda _, d=3: np.round(_, d).astype(float)
# For each (data product, initial guess) permutation we need to create tasks based on suitable grids.
task_data_products = []
for data_product in input_data_products:
for initial_guess in initial_guess_callable(data_product):
if initial_guess is None:
continue
for header_path, meta in utils.yield_suitable_grids(
grid_info, **initial_guess
):
frozen_parameters = {}
if meta["gd"] == "d":
# If it's a main-sequence grid, we freeze C and N in the initial round.
frozen_parameters.update(c=True, n=True)
kwds = dict(
header_path=header_path,
weight_path=weight_path,
continuum_method=continuum_method,
continuum_kwargs=continuum_kwargs,
data_slice=data_slice,
frozen_parameters=frozen_parameters,
initial_parameters=dict(
teff=round(initial_guess["teff"], 0),
logg=round(initial_guess["logg"]),
metals=round(initial_guess["metals"]),
o_mg_si_s_ca_ti=round(initial_guess["o_mg_si_s_ca_ti"]),
lgvsini=round(initial_guess["lgvsini"]),
c=round(initial_guess["c"]),
n=round(initial_guess["n"]),
log10vdop=round(initial_guess["log10vdop"]),
),
)
parameters = FERRE_DEFAULTS.copy()
parameters.update(kwds)
parameters.update(
{k: v for k, v in kwargs.items() if k in FERRE_DEFAULTS}
)
# Create a task.
task = Task(
name=FERRE_TASK_NAME, version=__version__, parameters=parameters
)
task_data_products.append((task, data_product))
with database.atomic():
Task.bulk_create([t for t, dp in task_data_products])
TaskInputDataProducts.insert_many([
{ "task_id": t.id, "data_product_id": dp.id } for t, dp in task_data_products
]).execute()
return [t for t, dp in task_data_products]
def create_initial_stellar_parameter_task_bundles(
input_data_products,
header_paths: Optional[Union[List[str], Tuple[str], str]] = "$MWM_ASTRA/component_data/aspcap/synspec_dr17_marcs_header_paths.list",
weight_path: Optional[str] = "$MWM_ASTRA/component_data/aspcap/global_mask_v02.txt",
continuum_method: Optional[Union[Continuum, str]] = Scalar,
continuum_kwargs: Optional[dict] = dict(method="median"),
data_slice: Optional[List[Tuple[int]]] = [(0, 1)],
initial_guess_callable: Optional[Callable] = None,
**kwargs,
) -> List[Union[Bundle, int]]:
tasks = create_initial_stellar_parameter_tasks(
input_data_products=input_data_products,
header_paths=header_paths,
weight_path=weight_path,
continuum_method=continuum_method,
continuum_kwargs=continuum_kwargs,
data_slice=data_slice,
initial_guess_callable=initial_guess_callable,
**kwargs
)
log.info(f"Created {len(tasks)} tasks")
bundles = bundler(tasks)
log.info(f"Created {len(bundles)} bundles")
return [bundle.id for bundle in bundles]
def create_stellar_parameter_task_bundles(
initial_task_bundles,
weight_path: Optional[str] = "$MWM_ASTRA/component_data/aspcap/global_mask_v02.txt",
continuum_method: Optional[Union[Continuum, str]] = continuum.MedianFilter,
continuum_kwargs: Optional[dict] = None,
**kwargs,
):
"""
Create FERRE tasks to estimate stellar parameters, given the best result from the
initial round of stellar parameters.
"""
#initial_task_bundles = deserialize(initial_task_bundles, Task)
if isinstance(initial_task_bundles, str):
initial_task_bundles = json.loads(initial_task_bundles)
q = (
Task
.select()
.join(TaskBundle)
.where(TaskBundle.bundle_id.in_(initial_task_bundles))
)
bitmask = ParamBitMask()
bad_grid_edge = bitmask.get_value("GRIDEDGE_WARN") | bitmask.get_value(
"GRIDEDGE_BAD"
)
# Get all results per data product.
results = {}
for task in q:
# TODO: Here we are assuming one data product per task, but it doesn't have to be this way.
# It just makes it tricky if there are many data products + results per task, as we would
# have to infer which result for which data product.
(data_product,) = task.input_data_products
parsed_header = utils.parse_header_path(
expand_path(task.parameters["header_path"])
)
N_outputs = task.count_outputs()
if N_outputs == 0:
log.warning(f"Task {task} has no outputs!")
continue
results.setdefault(data_product.id, [])
for output in task.outputs:
penalized_log_chisq_fit = 0
penalized_log_chisq_fit += output.log_chisq_fit
# Penalise chi-sq in the same way they did for DR17.
# See github.com/sdss/apogee/python/apogee/aspcap/aspcap.py#L658
if parsed_header["spectral_type"] == "GK" and output.teff < 3900:
log.debug(f"Increasing \chisq because spectral type GK")
penalized_log_chisq_fit += np.log10(10)
if output.bitmask_logg & bad_grid_edge:
log.debug(
f"Increasing \chisq because bitmask on logg {output.bitmask_logg} is bad edge ({bad_grid_edge})"
)
penalized_log_chisq_fit += np.log10(5)
if output.bitmask_teff & bad_grid_edge:
log.debug(
f"Increasing \chisq because bitmask on teff {output.bitmask_teff} is bad edge ({bad_grid_edge})"
)
penalized_log_chisq_fit += np.log10(5)
result = (penalized_log_chisq_fit, task, output)
results[data_product.id].append(result)
# Let's update these tasks with their penalized values!
with database.atomic():
for _, task_results in results.items():
for (penalized_log_chisq_fit, task, output) in task_results:
log.info(
f"Setting penalized log chisq = {penalized_log_chisq_fit} for task {task} and output {output}"
)
rows = (
FerreOutput.update(penalized_log_chisq_fit=penalized_log_chisq_fit)
.where(FerreOutput.output == output)
.execute()
)
assert rows == 1
# Order all results from (best, recent) to (worst, older).
# The initial round of stellar parameters should only have one result per task.
# If there are multiple results per task, it means the task has been re-executed a few times.
# Here we will take the lowest log_chisq_fit, highest task (more recent), and highest output (more recent).
results = {
dp: sorted(values, key=lambda row: (row[0], -row[1].id, -row[2].output.id))
for dp, values in results.items()
}
for dp, values in results.items():
log.info(f"For data product {dp}:")
for i, (log_chisq_fit, task, output) in enumerate(values):
log.info(
f"\t{i:.0f}: \chi^2 = {log_chisq_fit:.3f} for task {task} and output {output}"
)
if continuum_method is not None:
continuum_method = serialize_executable(continuum_method)
task_data_products = []
for data_product_id, (result, *_) in results.items():
log_chisq_fit, task, output = result
# For the normalization we will do a median filter correction using the previous result.
if continuum_method is not None:
_continuum_kwargs = (continuum_kwargs or {}).copy()
_continuum_kwargs.update(upstream_task_id=task.id)
else:
_continuum_kwargs = FERRE_DEFAULTS["continuum_kwargs"]
parameters = FERRE_DEFAULTS.copy()
parameters.update(
header_path=task.parameters["header_path"],
weight_path=weight_path,
continuum_method=continuum_method,
continuum_kwargs=_continuum_kwargs,
initial_parameters=dict(
teff=output.teff,
logg=output.logg,
metals=output.metals,
o_mg_si_s_ca_ti=output.o_mg_si_s_ca_ti,
lgvsini=output.lgvsini,
c=output.c,
n=output.n,
log10vdop=output.log10vdop,
),
)
parameters.update({k: v for k, v in kwargs.items() if k in FERRE_DEFAULTS})
task = Task(
name=FERRE_TASK_NAME, version=__version__, parameters=parameters
)
task_data_products.append((task, data_product_id))
with database.atomic():
Task.bulk_create([t for t, _ in task_data_products])
TaskInputDataProducts.insert_many([
{ "task_id": t.id, "data_product_id": dp_id } for t, dp_id in task_data_products
]).execute()
tasks = [t for t, _ in task_data_products]
# Create bundles
log.info(f"Created {len(tasks)} tasks")
bundles = bundler(tasks)
log.info(f"Created {len(bundles)} bundles")
return [bundle.id for bundle in bundles]
def get_element(weight_path):
return os.path.basename(weight_path)[:-5]
def create_abundance_tasks(
stellar_parameter_tasks,
weight_paths: str = "$MWM_ASTRA/component_data/aspcap/element_masks.list",
as_primary_keys: bool = False,
**kwargs,
) -> List[Task]:
"""
Create FERRE tasks to estimate chemical abundances, given the stellar parameters determined from previous tasks.
"""
stellar_parameter_tasks = deserialize(stellar_parameter_tasks, Task)
# Load the weight paths.
with open(expand_path(weight_paths), "r") as fp:
weight_paths = list(map(str.strip, fp.readlines()))
all_headers = {}
abundance_keywords = {}
tasks = []
for task in stellar_parameter_tasks:
header_path = task.parameters["header_path"]
if header_path not in abundance_keywords:
abundance_keywords[header_path] = {}
headers, *segment_headers = read_ferre_headers(expand_path(header_path))
all_headers[header_path] = (headers, *segment_headers)
for weight_path in weight_paths:
element = get_element(weight_path)
abundance_keywords[header_path][element] = utils.get_abundance_keywords(
element, headers["LABEL"]
)
# Set initial parameters to the stellar parameters determined from the previous task.
initial_parameters = []
for output in task.outputs:
initial_parameters.append(
dict(
teff=output.teff,
logg=output.logg,
metals=output.metals,
o_mg_si_s_ca_ti=output.o_mg_si_s_ca_ti,
lgvsini=output.lgvsini,
c=output.c,
n=output.n,
log10vdop=output.log10vdop,
)
)
log.debug(
f"From task {task} with {list(task.input_data_products)} input {len(initial_parameters)} stellar parameters"
)
for weight_path in weight_paths:
element = get_element(weight_path)
frozen_parameters, ferre_abundance_kwds = abundance_keywords[header_path][
element
]
parameters = FERRE_DEFAULTS.copy()
parameters.update(task.parameters)
parameters.update(
weight_path=weight_path,
initial_parameters=initial_parameters,
frozen_parameters=frozen_parameters,
)
parameters.update({k: v for k, v in kwargs.items() if k in FERRE_DEFAULTS})
parameters["ferre_kwds"] = parameters["ferre_kwds"] or dict()
parameters["ferre_kwds"].update(ferre_abundance_kwds)
# Check to see if all parameters are going to be frozen.
n_of_dim = all_headers[header_path][0]["N_OF_DIM"]
n_frozen_dim = sum(frozen_parameters.values())
n_free_dim = n_of_dim - n_frozen_dim
if n_free_dim == 0:
log.warning(
f"Not creating task {FERRE_TASK_NAME} with weight path {weight_path} from task {task} "
f"because all parameters are frozen (n_of_dim: {n_of_dim}, n_frozen: {n_frozen_dim}):\n{parameters}"
)
continue
print(f"TODO: insert tasks in bulk instead")
abundance_task = Task.create(
name=FERRE_TASK_NAME, version=__version__, parameters=parameters
)
log.debug(f"Created {abundance_task} from it")
for data_product in task.input_data_products:
TaskInputDataProducts.create(
task=abundance_task, data_product=data_product
)
tasks.append(abundance_task)
if as_primary_keys:
return [task.id for task in tasks]
return tasks
class Aspcap(TaskInstance):
stellar_parameter_task_ids = TupleParameter("stellar_parameter_task_ids")
abundance_task_ids = TupleParameter("abundance_task_ids")
def execute(self):
results = []
for task, input_data_products, parameters in self.iterable():
stellar_parameter_task = Task.get_by_id(
int(parameters["stellar_parameter_task_ids"])
)
log.debug(
f"ASPCAP task {task} got stellar parameter task {stellar_parameter_task}"
)
for data_product in stellar_parameter_task.input_data_products:
log.debug(f"Assigned data product {data_product} to ASPCAP task {task}")
TaskInputDataProducts.create(task=task, data_product=data_product)
abundance_tasks = deserialize(parameters["abundance_task_ids"], Task)
log.debug(f"ASPCAP task {task} got abundance tasks {abundance_tasks}")
task_results = []
for output in stellar_parameter_task.outputs:
result = dict(
snr=output.snr,
log_chisq_fit=output.log_chisq_fit,
log_snr_sq=output.log_snr_sq,
frac_phot_data_points=output.frac_phot_data_points,
meta=output.meta,
)
for key in (
"teff",
"logg",
"metals",
"o_mg_si_s_ca_ti",
"log10vdop",
"lgvsini",
"c",
"n",
):
result[key] = getattr(output, key)
result[f"u_{key}"] = getattr(output, f"u_{key}")
result[f"bitmask_{key}"] = getattr(output, f"bitmask_{key}")
task_results.append(result)
for abundance_task in abundance_tasks:
if abundance_task.count_outputs() == 0:
log.warning(
f"No outputs for abundance task {abundance_task} on stellar parameter task {stellar_parameter_task}. "
"Skipping!"
)
continue
# get the element
element = get_element(abundance_task.parameters["weight_path"])
# Check which parameters are frozen.
initial = abundance_task.parameters["initial_parameters"]
initial = initial[0] if isinstance(initial, list) else initial
initial = sanitise([k for k, v in initial.items() if v is not None])
frozen = sanitise(
[
k
for k, v in abundance_task.parameters[
"frozen_parameters"
].items()
if v
]
)
parameter_name = set(initial).difference(frozen)
if len(parameter_name) > 1:
log.warning(f"Parameter names thawed: {parameter_name}")
parameter_name = parameter_name.difference({"lgvsini"})
if len(parameter_name) == 0:
log.warning(f"No free parameters for {abundance_task}")
log.debug(
f"initial: {initial}: {abundance_task.parameters['initial_parameters']}"
)
log.debug(
f"frozen: {frozen}: {abundance_task.parameters['frozen_parameters']}"
)
continue
assert len(parameter_name) == 1
(parameter_name,) = parameter_name
key = f"{element.lower()}_h"
for i, output in enumerate(abundance_task.outputs):
task_results[i][key] = getattr(output, parameter_name)
task_results[i][f"u_{key}"] = getattr(output, f"u_{parameter_name}")
task_results[i][f"bitmask_{key}"] = getattr(
output, f"bitmask_{parameter_name}"
)
task_results[i][f"log_chisq_fit_{key}"] = output.log_chisq_fit
for result in task_results:
output = Output.create()
TaskOutput.create(task=task, output=output)
AspcapOutput.create(task=task, output=output, **result)
results.append(task_results)
return results
def create_and_execute_summary_tasks(
stellar_parameter_tasks,
abundance_tasks,
):
"""
Create a row in the AspcapOutput database table for each input data product,
given the stellar parameter tasks and the abundance tasks.
"""
stellar_parameter_tasks = deserialize(stellar_parameter_tasks, Task)
abundance_tasks = deserialize(abundance_tasks, Task)
# Join by input data product.
grouped = {}
for task in stellar_parameter_tasks:
(data_product_id,) = task.input_data_products
grouped[data_product_id] = [task.id]
for task in abundance_tasks:
(data_product_id,) = task.input_data_products
grouped[data_product_id].append(task.id)
# Create and execute tasks.
for data_product_id, (
stellar_parameter_task_ids,
*abundance_task_ids,
) in grouped.items():
log.debug(
f"Creating Aspcap summary task for data product {data_product_id} with stellar parameter task {stellar_parameter_task_ids} and abundance tasks {abundance_task_ids}"
)
task = Aspcap(
stellar_parameter_task_ids=stellar_parameter_task_ids,
abundance_task_ids=abundance_task_ids,
)
task.execute()
return None