@@ -316,26 +316,36 @@ def calculate(self,
316
316
**kwargs : `dict`
317
317
Unused kwargs that are always passed to a plugin.
318
318
"""
319
- n_bands = len (diaSources ["band" ].unique ())
319
+
320
+ bands_arr = diaSources ['band' ].unique ().values
321
+ unique_bands = np .unique (np .concatenate (bands_arr ))
320
322
# Check and initialize output columns in diaObjects.
321
323
if (periodCol := "multiPeriod" ) not in diaObjects .columns :
322
324
diaObjects [periodCol ] = np .nan
323
325
if (powerCol := "multiPower" ) not in diaObjects .columns :
324
326
diaObjects [powerCol ] = np .nan
325
327
if (fapCol := "multiFap" ) not in diaObjects .columns :
326
328
diaObjects [fapCol ] = np .nan
327
- if (ampCol := "multiAmp" ) not in diaObjects .columns :
328
- diaObjects [ampCol ] = pd .Series ([np .nan ]* n_bands , dtype = "object" )
329
- if (phaseCol := "multiPhase" ) not in diaObjects .columns :
330
- diaObjects [phaseCol ] = pd .Series ([np .nan ]* n_bands , dtype = "object" )
331
-
332
- def _calculate_period_multi (df , min_detections = 9 , oversampling_factor = 5 , nyquist_factor = 100 ):
329
+ ampCol = "multiAmp"
330
+ phaseCol = "multiPhase"
331
+ for i in range (len (unique_bands )):
332
+ ampCol_band = f"{ unique_bands [i ]} _{ ampCol } "
333
+ if ampCol_band not in diaObjects .columns :
334
+ diaObjects [ampCol_band ] = np .nan
335
+ phaseCol_band = f"{ unique_bands [i ]} _{ phaseCol } "
336
+ if phaseCol_band not in diaObjects .columns :
337
+ diaObjects [phaseCol_band ] = np .nan
338
+
339
+ def _calculate_period_multi (df , all_unique_bands ,
340
+ min_detections = 9 , oversampling_factor = 5 , nyquist_factor = 100 ):
333
341
"""Calculate the multi-band Lomb-Scargle periodogram.
334
342
335
343
Parameters
336
344
----------
337
345
df : `pandas.DataFrame`
338
346
The input DataFrame.
347
+ all_unique_bands : `list` of `str`
348
+ List of all bands present in the diaSource table that is being worked on.
339
349
min_detections : `int`, optional
340
350
The minimum number of detections, including all bands.
341
351
oversampling_factor : `int`, optional
@@ -352,11 +362,14 @@ def _calculate_period_multi(df, min_detections=9, oversampling_factor=5, nyquist
352
362
np .isnan (df ["midpointMjdTai" ]))]
353
363
354
364
if (len (tmpDf )) < min_detections :
355
- return pd .Series ({periodCol : np .nan ,
356
- powerCol : np .nan ,
357
- fapCol : np .nan ,
358
- ampCol : pd .Series ([np .nan ]* n_bands , dtype = "object" ),
359
- phaseCol : pd .Series ([np .nan ]* n_bands , dtype = "object" )})
365
+ pd_tab_nodet = pd .Series ({periodCol : np .nan ,
366
+ powerCol : np .nan ,
367
+ fapCol : np .nan })
368
+ for band in all_unique_bands :
369
+ pd_tab_nodet [f"{ band } _{ ampCol } " ] = np .nan
370
+ pd_tab_nodet [f"{ band } _{ phaseCol } " ] = np .nan
371
+
372
+ return pd_tab_nodet
360
373
361
374
time = tmpDf ["midpointMjdTai" ].to_numpy ()
362
375
flux = tmpDf ["psfFlux" ].to_numpy ()
@@ -378,15 +391,29 @@ def _calculate_period_multi(df, min_detections=9, oversampling_factor=5, nyquist
378
391
379
392
pd_tab = pd .Series ({periodCol : period [np .argmax (power )],
380
393
powerCol : np .max (power ),
381
- fapCol : fap_estimate ,
382
- ampCol : params_table_new [0 ],
383
- phaseCol : params_table_new [1 ]
394
+ fapCol : fap_estimate
384
395
})
385
396
397
+ # Initialize the per-band amplitude/phase columns as NaNs
398
+ for band in all_unique_bands :
399
+ pd_tab [f"{ band } _{ ampCol } " ] = np .nan
400
+ pd_tab [f"{ band } _{ phaseCol } " ] = np .nan
401
+
402
+ # Populate the values of only the bands that have data for this diaSource
403
+ unique_bands = np .unique (bands )
404
+ for i in range (len (unique_bands )):
405
+ pd_tab [f"{ unique_bands [i ]} _{ ampCol } " ] = params_table_new [0 ][i ]
406
+ pd_tab [f"{ unique_bands [i ]} _{ phaseCol } " ] = params_table_new [1 ][i ]
407
+
386
408
return pd_tab
387
409
388
- diaObjects .loc [:, [periodCol , powerCol , fapCol , ampCol , phaseCol ]
389
- ] = diaSources .apply (_calculate_period_multi )
410
+ columns_list = [periodCol , powerCol , fapCol ]
411
+ for i in range (len (unique_bands )):
412
+ columns_list .append (f"{ unique_bands [i ]} _{ ampCol } " )
413
+ columns_list .append (f"{ unique_bands [i ]} _{ phaseCol } " )
414
+
415
+ diaObjects .loc [:, columns_list
416
+ ] = diaSources .apply (_calculate_period_multi , unique_bands )
390
417
391
418
392
419
class MeanDiaPositionConfig (DiaObjectCalculationPluginConfig ):
0 commit comments