-
Notifications
You must be signed in to change notification settings - Fork 4
/
fgcmFitCycle.py
1920 lines (1746 loc) · 85.6 KB
/
fgcmFitCycle.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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# See COPYRIGHT file at the top of the source tree.
#
# This file is part of fgcmcal.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
# (https://www.lsst.org).
# See the COPYRIGHT file at the top-level directory of this distribution
# for details of code ownership.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Perform a single fit cycle of FGCM.
This task runs a single "fit cycle" of fgcm. Prior to running this task
one must run both fgcmMakeLut (to construct the atmosphere and instrumental
look-up-table) and fgcmBuildStars (to extract visits and star observations
for the global fit).
The fgcmFitCycle is meant to be run multiple times, and is tracked by the
'cycleNumber'. After each run of the fit cycle, diagnostic plots should
be inspected to set parameters for outlier rejection on the following
cycle. Please see the fgcmcal Cookbook for details.
"""
import sys
import traceback
import copy
import numpy as np
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
from lsst.pipe.base import connectionTypes
import lsst.afw.table as afwTable
from .utilities import makeConfigDict, translateFgcmLut, translateVisitCatalog
from .utilities import extractReferenceMags
from .utilities import computeCcdOffsets, makeZptSchema, makeZptCat
from .utilities import makeAtmSchema, makeAtmCat, makeStdSchema, makeStdCat
from .sedterms import SedboundarytermDict, SedtermDict
from .utilities import lookupStaticCalibrations
import fgcm
__all__ = ['FgcmFitCycleConfig', 'FgcmFitCycleTask', 'FgcmFitCycleRunner']
MULTIPLE_CYCLES_MAX = 10
class FgcmFitCycleConnections(pipeBase.PipelineTaskConnections,
dimensions=("instrument",),
defaultTemplates={"previousCycleNumber": "-1",
"cycleNumber": "0"}):
camera = connectionTypes.PrerequisiteInput(
doc="Camera instrument",
name="camera",
storageClass="Camera",
dimensions=("instrument",),
lookupFunction=lookupStaticCalibrations,
isCalibration=True,
)
fgcmLookUpTable = connectionTypes.PrerequisiteInput(
doc=("Atmosphere + instrument look-up-table for FGCM throughput and "
"chromatic corrections."),
name="fgcmLookUpTable",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmVisitCatalog = connectionTypes.Input(
doc="Catalog of visit information for fgcm",
name="fgcmVisitCatalog",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmStarObservations = connectionTypes.Input(
doc="Catalog of star observations for fgcm",
name="fgcmStarObservations",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmStarIds = connectionTypes.Input(
doc="Catalog of fgcm calibration star IDs",
name="fgcmStarIds",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmStarIndices = connectionTypes.Input(
doc="Catalog of fgcm calibration star indices",
name="fgcmStarIndices",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmReferenceStars = connectionTypes.Input(
doc="Catalog of fgcm-matched reference stars",
name="fgcmReferenceStars",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmFlaggedStarsInput = connectionTypes.PrerequisiteInput(
doc="Catalog of flagged stars for fgcm calibration from previous fit cycle",
name="fgcmFlaggedStars{previousCycleNumber}",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmFitParametersInput = connectionTypes.PrerequisiteInput(
doc="Catalog of fgcm fit parameters from previous fit cycle",
name="fgcmFitParameters{previousCycleNumber}",
storageClass="Catalog",
dimensions=("instrument",),
deferLoad=True,
)
fgcmFitParameters = connectionTypes.Output(
doc="Catalog of fgcm fit parameters from current fit cycle",
name="fgcmFitParameters{cycleNumber}",
storageClass="Catalog",
dimensions=("instrument",),
)
fgcmFlaggedStars = connectionTypes.Output(
doc="Catalog of flagged stars for fgcm calibration from current fit cycle",
name="fgcmFlaggedStars{cycleNumber}",
storageClass="Catalog",
dimensions=("instrument",),
)
fgcmZeropoints = connectionTypes.Output(
doc="Catalog of fgcm zeropoint data from current fit cycle",
name="fgcmZeropoints{cycleNumber}",
storageClass="Catalog",
dimensions=("instrument",),
)
fgcmAtmosphereParameters = connectionTypes.Output(
doc="Catalog of atmospheric fit parameters from current fit cycle",
name="fgcmAtmosphereParameters{cycleNumber}",
storageClass="Catalog",
dimensions=("instrument",),
)
fgcmStandardStars = connectionTypes.Output(
doc="Catalog of standard star magnitudes from current fit cycle",
name="fgcmStandardStars{cycleNumber}",
storageClass="SimpleCatalog",
dimensions=("instrument",),
)
# Add connections for running multiple cycles
# This uses vars() to alter the class __dict__ to programmatically
# write many similar outputs.
for cycle in range(MULTIPLE_CYCLES_MAX):
vars()[f"fgcmFitParameters{cycle}"] = connectionTypes.Output(
doc=f"Catalog of fgcm fit parameters from fit cycle {cycle}",
name=f"fgcmFitParameters{cycle}",
storageClass="Catalog",
dimensions=("instrument",),
)
vars()[f"fgcmFlaggedStars{cycle}"] = connectionTypes.Output(
doc=f"Catalog of flagged stars for fgcm calibration from fit cycle {cycle}",
name=f"fgcmFlaggedStars{cycle}",
storageClass="Catalog",
dimensions=("instrument",),
)
vars()[f"fgcmZeropoints{cycle}"] = connectionTypes.Output(
doc=f"Catalog of fgcm zeropoint data from fit cycle {cycle}",
name=f"fgcmZeropoints{cycle}",
storageClass="Catalog",
dimensions=("instrument",),
)
vars()[f"fgcmAtmosphereParameters{cycle}"] = connectionTypes.Output(
doc=f"Catalog of atmospheric fit parameters from fit cycle {cycle}",
name=f"fgcmAtmosphereParameters{cycle}",
storageClass="Catalog",
dimensions=("instrument",),
)
vars()[f"fgcmStandardStars{cycle}"] = connectionTypes.Output(
doc=f"Catalog of standard star magnitudes from fit cycle {cycle}",
name=f"fgcmStandardStars{cycle}",
storageClass="SimpleCatalog",
dimensions=("instrument",),
)
def __init__(self, *, config=None):
super().__init__(config=config)
if not config.doReferenceCalibration:
self.inputs.remove("fgcmReferenceStars")
if str(int(config.connections.cycleNumber)) != config.connections.cycleNumber:
raise ValueError("cycleNumber must be of integer format")
if str(int(config.connections.previousCycleNumber)) != config.connections.previousCycleNumber:
raise ValueError("previousCycleNumber must be of integer format")
if int(config.connections.previousCycleNumber) != (int(config.connections.cycleNumber) - 1):
raise ValueError("previousCycleNumber must be 1 less than cycleNumber")
if int(config.connections.cycleNumber) == 0:
self.prerequisiteInputs.remove("fgcmFlaggedStarsInput")
self.prerequisiteInputs.remove("fgcmFitParametersInput")
if not self.config.doMultipleCycles:
# Single-cycle run
if not self.config.isFinalCycle and not self.config.outputStandardsBeforeFinalCycle:
self.outputs.remove("fgcmStandardStars")
if not self.config.isFinalCycle and not self.config.outputZeropointsBeforeFinalCycle:
self.outputs.remove("fgcmZeropoints")
self.outputs.remove("fgcmAtmosphereParameters")
# Remove all multiple cycle outputs
for cycle in range(0, MULTIPLE_CYCLES_MAX):
self.outputs.remove(f"fgcmFitParameters{cycle}")
self.outputs.remove(f"fgcmFlaggedStars{cycle}")
self.outputs.remove(f"fgcmZeropoints{cycle}")
self.outputs.remove(f"fgcmAtmosphereParameters{cycle}")
self.outputs.remove(f"fgcmStandardStars{cycle}")
else:
# Multiple-cycle run
# Remove single-cycle outputs
self.outputs.remove("fgcmFitParameters")
self.outputs.remove("fgcmFlaggedStars")
self.outputs.remove("fgcmZeropoints")
self.outputs.remove("fgcmAtmosphereParameters")
self.outputs.remove("fgcmStandardStars")
# Remove outputs from cycles that are not used
for cycle in range(self.config.multipleCyclesFinalCycleNumber + 1,
MULTIPLE_CYCLES_MAX):
self.outputs.remove(f"fgcmFitParameters{cycle}")
self.outputs.remove(f"fgcmFlaggedStars{cycle}")
self.outputs.remove(f"fgcmZeropoints{cycle}")
self.outputs.remove(f"fgcmAtmosphereParameters{cycle}")
self.outputs.remove(f"fgcmStandardStars{cycle}")
# Remove non-final-cycle outputs if necessary
for cycle in range(self.config.multipleCyclesFinalCycleNumber):
if not self.config.outputZeropointsBeforeFinalCycle:
self.outputs.remove(f"fgcmZeropoints{cycle}")
self.outputs.remove(f"fgcmAtmosphereParameters{cycle}")
if not self.config.outputStandardsBeforeFinalCycle:
self.outputs.remove(f"fgcmStandardStars{cycle}")
class FgcmFitCycleConfig(pipeBase.PipelineTaskConfig,
pipelineConnections=FgcmFitCycleConnections):
"""Config for FgcmFitCycle"""
doMultipleCycles = pexConfig.Field(
doc="Run multiple fit cycles in one task",
dtype=bool,
default=False,
)
multipleCyclesFinalCycleNumber = pexConfig.RangeField(
doc="Final cycle number in multiple cycle mode",
dtype=int,
default=5,
min=2,
max=MULTIPLE_CYCLES_MAX,
inclusiveMax=True,
)
bands = pexConfig.ListField(
doc="Bands to run calibration",
dtype=str,
default=[],
)
fitFlag = pexConfig.ListField(
doc=("Flag for which bands are directly constrained in the FGCM fit. "
"Bands set to 0 will have the atmosphere constrained from observations "
"in other bands on the same night. Must be same length as config.bands, "
"and matched band-by-band."),
dtype=int,
default=(0,),
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use fitBands instead."),
)
fitBands = pexConfig.ListField(
doc=("Bands to use in atmospheric fit. The bands not listed here will have "
"the atmosphere constrained from the 'fitBands' on the same night. "
"Must be a subset of `config.bands`"),
dtype=str,
default=[],
)
requiredFlag = pexConfig.ListField(
doc=("Flag for which bands are required for a star to be considered a calibration "
"star in the FGCM fit. Typically this should be the same as fitFlag. Must "
"be same length as config.bands, and matched band-by-band."),
dtype=int,
default=(0,),
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use requiredBands instead."),
)
requiredBands = pexConfig.ListField(
doc=("Bands that are required for a star to be considered a calibration star. "
"Must be a subset of `config.bands`"),
dtype=str,
default=[],
)
filterMap = pexConfig.DictField(
doc="Mapping from 'filterName' to band.",
keytype=str,
itemtype=str,
default={},
deprecated=("This field is no longer used, and has been deprecated by "
"DM-28088. It will be removed after v22. Use "
"physicalFilterMap instead.")
)
# The following config will not be necessary after Gen2 retirement.
# In the meantime, it is set to 'filterDefinitions.filter_to_band' which
# is easiest to access in the config file.
physicalFilterMap = pexConfig.DictField(
doc="Mapping from 'physicalFilter' to band.",
keytype=str,
itemtype=str,
default={},
)
doReferenceCalibration = pexConfig.Field(
doc="Use reference catalog as additional constraint on calibration",
dtype=bool,
default=True,
)
refStarSnMin = pexConfig.Field(
doc="Reference star signal-to-noise minimum to use in calibration. Set to <=0 for no cut.",
dtype=float,
default=50.0,
)
refStarOutlierNSig = pexConfig.Field(
doc=("Number of sigma compared to average mag for reference star to be considered an outlier. "
"Computed per-band, and if it is an outlier in any band it is rejected from fits."),
dtype=float,
default=4.0,
)
applyRefStarColorCuts = pexConfig.Field(
doc="Apply color cuts to reference stars?",
dtype=bool,
default=True,
)
nCore = pexConfig.Field(
doc="Number of cores to use",
dtype=int,
default=4,
)
nStarPerRun = pexConfig.Field(
doc="Number of stars to run in each chunk",
dtype=int,
default=200000,
)
nExpPerRun = pexConfig.Field(
doc="Number of exposures to run in each chunk",
dtype=int,
default=1000,
)
reserveFraction = pexConfig.Field(
doc="Fraction of stars to reserve for testing",
dtype=float,
default=0.1,
)
freezeStdAtmosphere = pexConfig.Field(
doc="Freeze atmosphere parameters to standard (for testing)",
dtype=bool,
default=False,
)
precomputeSuperStarInitialCycle = pexConfig.Field(
doc="Precompute superstar flat for initial cycle",
dtype=bool,
default=False,
)
superStarSubCcd = pexConfig.Field(
doc="Compute superstar flat on sub-ccd scale",
dtype=bool,
default=True,
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use superStarSubCcdDict instead."),
)
superStarSubCcdDict = pexConfig.DictField(
doc=("Per-band specification on whether to compute superstar flat on sub-ccd scale. "
"Must have one entry per band."),
keytype=str,
itemtype=bool,
default={},
)
superStarSubCcdChebyshevOrder = pexConfig.Field(
doc=("Order of the 2D chebyshev polynomials for sub-ccd superstar fit. "
"Global default is first-order polynomials, and should be overridden "
"on a camera-by-camera basis depending on the ISR."),
dtype=int,
default=1,
)
superStarSubCcdTriangular = pexConfig.Field(
doc=("Should the sub-ccd superstar chebyshev matrix be triangular to "
"suppress high-order cross terms?"),
dtype=bool,
default=False,
)
superStarSigmaClip = pexConfig.Field(
doc="Number of sigma to clip outliers when selecting for superstar flats",
dtype=float,
default=5.0,
)
focalPlaneSigmaClip = pexConfig.Field(
doc="Number of sigma to clip outliers per focal-plane.",
dtype=float,
default=4.0,
)
ccdGraySubCcd = pexConfig.Field(
doc="Compute CCD gray terms on sub-ccd scale",
dtype=bool,
default=False,
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use ccdGraySubCcdDict instead."),
)
ccdGraySubCcdDict = pexConfig.DictField(
doc=("Per-band specification on whether to compute achromatic per-ccd residual "
"('ccd gray') on a sub-ccd scale."),
keytype=str,
itemtype=bool,
default={},
)
ccdGraySubCcdChebyshevOrder = pexConfig.Field(
doc="Order of the 2D chebyshev polynomials for sub-ccd gray fit.",
dtype=int,
default=1,
)
ccdGraySubCcdTriangular = pexConfig.Field(
doc=("Should the sub-ccd gray chebyshev matrix be triangular to "
"suppress high-order cross terms?"),
dtype=bool,
default=True,
)
ccdGrayFocalPlaneDict = pexConfig.DictField(
doc=("Per-band specification on whether to compute focal-plane residual "
"('ccd gray') corrections."),
keytype=str,
itemtype=bool,
default={},
)
ccdGrayFocalPlaneFitMinCcd = pexConfig.Field(
doc=("Minimum number of 'good' CCDs required to perform focal-plane "
"gray corrections. If there are fewer good CCDs then the gray "
"correction is computed per-ccd."),
dtype=int,
default=1,
)
ccdGrayFocalPlaneChebyshevOrder = pexConfig.Field(
doc="Order of the 2D chebyshev polynomials for focal plane fit.",
dtype=int,
default=3,
)
cycleNumber = pexConfig.Field(
doc=("FGCM fit cycle number. This is automatically incremented after each run "
"and stage of outlier rejection. See cookbook for details."),
dtype=int,
default=None,
)
isFinalCycle = pexConfig.Field(
doc=("Is this the final cycle of the fitting? Will automatically compute final "
"selection of stars and photometric exposures, and will output zeropoints "
"and standard stars for use in fgcmOutputProducts"),
dtype=bool,
default=False,
)
maxIterBeforeFinalCycle = pexConfig.Field(
doc=("Maximum fit iterations, prior to final cycle. The number of iterations "
"will always be 0 in the final cycle for cleanup and final selection."),
dtype=int,
default=50,
)
deltaMagBkgOffsetPercentile = pexConfig.Field(
doc=("Percentile brightest stars on a visit/ccd to use to compute net "
"offset from local background subtraction."),
dtype=float,
default=0.25,
)
deltaMagBkgPerCcd = pexConfig.Field(
doc=("Compute net offset from local background subtraction per-ccd? "
"Otherwise, use computation per visit."),
dtype=bool,
default=False,
)
utBoundary = pexConfig.Field(
doc="Boundary (in UTC) from day-to-day",
dtype=float,
default=None,
)
washMjds = pexConfig.ListField(
doc="Mirror wash MJDs",
dtype=float,
default=(0.0,),
)
epochMjds = pexConfig.ListField(
doc="Epoch boundaries in MJD",
dtype=float,
default=(0.0,),
)
minObsPerBand = pexConfig.Field(
doc="Minimum good observations per band",
dtype=int,
default=2,
)
# TODO: When DM-16511 is done, it will be possible to get the
# telescope latitude directly from the camera.
latitude = pexConfig.Field(
doc="Observatory latitude",
dtype=float,
default=None,
)
brightObsGrayMax = pexConfig.Field(
doc="Maximum gray extinction to be considered bright observation",
dtype=float,
default=0.15,
)
minStarPerCcd = pexConfig.Field(
doc=("Minimum number of good stars per CCD to be used in calibration fit. "
"CCDs with fewer stars will have their calibration estimated from other "
"CCDs in the same visit, with zeropoint error increased accordingly."),
dtype=int,
default=5,
)
minCcdPerExp = pexConfig.Field(
doc=("Minimum number of good CCDs per exposure/visit to be used in calibration fit. "
"Visits with fewer good CCDs will have CCD zeropoints estimated where possible."),
dtype=int,
default=5,
)
maxCcdGrayErr = pexConfig.Field(
doc="Maximum error on CCD gray offset to be considered photometric",
dtype=float,
default=0.05,
)
minStarPerExp = pexConfig.Field(
doc=("Minimum number of good stars per exposure/visit to be used in calibration fit. "
"Visits with fewer good stars will have CCD zeropoints estimated where possible."),
dtype=int,
default=600,
)
minExpPerNight = pexConfig.Field(
doc="Minimum number of good exposures/visits to consider a partly photometric night",
dtype=int,
default=10,
)
expGrayInitialCut = pexConfig.Field(
doc=("Maximum exposure/visit gray value for initial selection of possible photometric "
"observations."),
dtype=float,
default=-0.25,
)
expGrayPhotometricCut = pexConfig.ListField(
doc=("Maximum (negative) exposure gray for a visit to be considered photometric. "
"Must be same length as config.bands, and matched band-by-band."),
dtype=float,
default=(0.0,),
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use expGrayPhotometricCutDict instead."),
)
expGrayPhotometricCutDict = pexConfig.DictField(
doc=("Per-band specification on maximum (negative) achromatic exposure residual "
"('gray term') for a visit to be considered photometric. Must have one "
"entry per band. Broad-band filters should be -0.05."),
keytype=str,
itemtype=float,
default={},
)
expGrayHighCut = pexConfig.ListField(
doc=("Maximum (positive) exposure gray for a visit to be considered photometric. "
"Must be same length as config.bands, and matched band-by-band."),
dtype=float,
default=(0.0,),
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use expGrayHighCutDict instead."),
)
expGrayHighCutDict = pexConfig.DictField(
doc=("Per-band specification on maximum (positive) achromatic exposure residual "
"('gray term') for a visit to be considered photometric. Must have one "
"entry per band. Broad-band filters should be 0.2."),
keytype=str,
itemtype=float,
default={},
)
expGrayRecoverCut = pexConfig.Field(
doc=("Maximum (negative) exposure gray to be able to recover bad ccds via interpolation. "
"Visits with more gray extinction will only get CCD zeropoints if there are "
"sufficient star observations (minStarPerCcd) on that CCD."),
dtype=float,
default=-1.0,
)
expVarGrayPhotometricCut = pexConfig.Field(
doc="Maximum exposure variance to be considered possibly photometric",
dtype=float,
default=0.0005,
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use expVarGrayPhotometricCutDict instead."),
)
expVarGrayPhotometricCutDict = pexConfig.DictField(
doc=("Per-band specification on maximum exposure variance to be considered possibly "
"photometric. Must have one entry per band. Broad-band filters should be "
"0.0005."),
keytype=str,
itemtype=float,
default={},
)
expGrayErrRecoverCut = pexConfig.Field(
doc=("Maximum exposure gray error to be able to recover bad ccds via interpolation. "
"Visits with more gray variance will only get CCD zeropoints if there are "
"sufficient star observations (minStarPerCcd) on that CCD."),
dtype=float,
default=0.05,
)
aperCorrFitNBins = pexConfig.Field(
doc=("Number of aperture bins used in aperture correction fit. When set to 0"
"no fit will be performed, and the config.aperCorrInputSlopes will be "
"used if available."),
dtype=int,
default=10,
)
aperCorrInputSlopes = pexConfig.ListField(
doc=("Aperture correction input slope parameters. These are used on the first "
"fit iteration, and aperture correction parameters will be updated from "
"the data if config.aperCorrFitNBins > 0. It is recommended to set this"
"when there is insufficient data to fit the parameters (e.g. tract mode). "
"If set, must be same length as config.bands, and matched band-by-band."),
dtype=float,
default=[],
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use aperCorrInputSlopeDict instead."),
)
aperCorrInputSlopeDict = pexConfig.DictField(
doc=("Per-band specification of aperture correction input slope parameters. These "
"are used on the first fit iteration, and aperture correction parameters will "
"be updated from the data if config.aperCorrFitNBins > 0. It is recommended "
"to set this when there is insufficient data to fit the parameters (e.g. "
"tract mode)."),
keytype=str,
itemtype=float,
default={},
)
sedFudgeFactors = pexConfig.ListField(
doc=("Fudge factors for computing linear SED from colors. Must be same length as "
"config.bands, and matched band-by-band."),
dtype=float,
default=(0,),
optional=True,
deprecated=("This field has been deprecated and will be removed after v20. "
"Please use sedSlopeTermMap and sedSlopeMap."),
)
sedboundaryterms = pexConfig.ConfigField(
doc="Mapping from bands to SED boundary term names used is sedterms.",
dtype=SedboundarytermDict,
)
sedterms = pexConfig.ConfigField(
doc="Mapping from terms to bands for fgcm linear SED approximations.",
dtype=SedtermDict,
)
sigFgcmMaxErr = pexConfig.Field(
doc="Maximum mag error for fitting sigma_FGCM",
dtype=float,
default=0.01,
)
sigFgcmMaxEGray = pexConfig.ListField(
doc=("Maximum (absolute) gray value for observation in sigma_FGCM. "
"May be 1 element (same for all bands) or the same length as config.bands."),
dtype=float,
default=(0.05,),
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use sigFgcmMaxEGrayDict instead."),
)
sigFgcmMaxEGrayDict = pexConfig.DictField(
doc=("Per-band specification for maximum (absolute) achromatic residual (gray value) "
"for observations in sigma_fgcm (raw repeatability). Broad-band filters "
"should be 0.05."),
keytype=str,
itemtype=float,
default={},
)
ccdGrayMaxStarErr = pexConfig.Field(
doc=("Maximum error on a star observation to use in ccd gray (achromatic residual) "
"computation"),
dtype=float,
default=0.10,
)
approxThroughput = pexConfig.ListField(
doc=("Approximate overall throughput at start of calibration observations. "
"May be 1 element (same for all bands) or the same length as config.bands."),
dtype=float,
default=(1.0, ),
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use approxThroughputDict instead."),
)
approxThroughputDict = pexConfig.DictField(
doc=("Per-band specification of the approximate overall throughput at the start of "
"calibration observations. Must have one entry per band. Typically should "
"be 1.0."),
keytype=str,
itemtype=float,
default={},
)
sigmaCalRange = pexConfig.ListField(
doc="Allowed range for systematic error floor estimation",
dtype=float,
default=(0.001, 0.003),
)
sigmaCalFitPercentile = pexConfig.ListField(
doc="Magnitude percentile range to fit systematic error floor",
dtype=float,
default=(0.05, 0.15),
)
sigmaCalPlotPercentile = pexConfig.ListField(
doc="Magnitude percentile range to plot systematic error floor",
dtype=float,
default=(0.05, 0.95),
)
sigma0Phot = pexConfig.Field(
doc="Systematic error floor for all zeropoints",
dtype=float,
default=0.003,
)
mapLongitudeRef = pexConfig.Field(
doc="Reference longitude for plotting maps",
dtype=float,
default=0.0,
)
mapNSide = pexConfig.Field(
doc="Healpix nside for plotting maps",
dtype=int,
default=256,
)
outfileBase = pexConfig.Field(
doc="Filename start for plot output files",
dtype=str,
default=None,
)
starColorCuts = pexConfig.ListField(
doc="Encoded star-color cuts (to be cleaned up)",
dtype=str,
default=("NO_DATA",),
)
colorSplitIndices = pexConfig.ListField(
doc="Band indices to use to split stars by color",
dtype=int,
default=None,
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use colorSplitBands instead."),
)
colorSplitBands = pexConfig.ListField(
doc="Band names to use to split stars by color. Must have 2 entries.",
dtype=str,
length=2,
default=('g', 'i'),
)
modelMagErrors = pexConfig.Field(
doc="Should FGCM model the magnitude errors from sky/fwhm? (False means trust inputs)",
dtype=bool,
default=True,
)
useQuadraticPwv = pexConfig.Field(
doc="Model PWV with a quadratic term for variation through the night?",
dtype=bool,
default=False,
)
instrumentParsPerBand = pexConfig.Field(
doc=("Model instrumental parameters per band? "
"Otherwise, instrumental parameters (QE changes with time) are "
"shared among all bands."),
dtype=bool,
default=False,
)
instrumentSlopeMinDeltaT = pexConfig.Field(
doc=("Minimum time change (in days) between observations to use in constraining "
"instrument slope."),
dtype=float,
default=20.0,
)
fitMirrorChromaticity = pexConfig.Field(
doc="Fit (intraband) mirror chromatic term?",
dtype=bool,
default=False,
)
coatingMjds = pexConfig.ListField(
doc="Mirror coating dates in MJD",
dtype=float,
default=(0.0,),
)
outputStandardsBeforeFinalCycle = pexConfig.Field(
doc="Output standard stars prior to final cycle? Used in debugging.",
dtype=bool,
default=False,
)
outputZeropointsBeforeFinalCycle = pexConfig.Field(
doc="Output standard stars prior to final cycle? Used in debugging.",
dtype=bool,
default=False,
)
useRepeatabilityForExpGrayCuts = pexConfig.ListField(
doc=("Use star repeatability (instead of exposures) for computing photometric "
"cuts? Recommended for tract mode or bands with few exposures. "
"May be 1 element (same for all bands) or the same length as config.bands."),
dtype=bool,
default=(False,),
optional=True,
deprecated=("This field is no longer used, and has been deprecated by DM-23699. "
"It will be removed after v20. Use useRepeatabilityForExpGrayCutsDict instead."),
)
useRepeatabilityForExpGrayCutsDict = pexConfig.DictField(
doc=("Per-band specification on whether to use star repeatability (instead of exposures) "
"for computing photometric cuts. Recommended for tract mode or bands with few visits."),
keytype=str,
itemtype=bool,
default={},
)
autoPhotometricCutNSig = pexConfig.Field(
doc=("Number of sigma for automatic computation of (low) photometric cut. "
"Cut is based on exposure gray width (per band), unless "
"useRepeatabilityForExpGrayCuts is set, in which case the star "
"repeatability is used (also per band)."),
dtype=float,
default=3.0,
)
autoHighCutNSig = pexConfig.Field(
doc=("Number of sigma for automatic computation of (high) outlier cut. "
"Cut is based on exposure gray width (per band), unless "
"useRepeatabilityForExpGrayCuts is set, in which case the star "
"repeatability is used (also per band)."),
dtype=float,
default=4.0,
)
quietMode = pexConfig.Field(
doc="Be less verbose with logging.",
dtype=bool,
default=False,
)
doPlots = pexConfig.Field(
doc="Make fgcm QA plots.",
dtype=bool,
default=True,
)
randomSeed = pexConfig.Field(
doc="Random seed for fgcm for consistency in tests.",
dtype=int,
default=None,
optional=True,
)
def validate(self):
super().validate()
if self.connections.previousCycleNumber != str(self.cycleNumber - 1):
msg = "cycleNumber in template must be connections.previousCycleNumber + 1"
raise RuntimeError(msg)
if self.connections.cycleNumber != str(self.cycleNumber):
msg = "cycleNumber in template must be equal to connections.cycleNumber"
raise RuntimeError(msg)
for band in self.fitBands:
if band not in self.bands:
msg = 'fitBand %s not in bands' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.fitBands, self, msg)
for band in self.requiredBands:
if band not in self.bands:
msg = 'requiredBand %s not in bands' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.requiredBands, self, msg)
for band in self.colorSplitBands:
if band not in self.bands:
msg = 'colorSplitBand %s not in bands' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.colorSplitBands, self, msg)
for band in self.bands:
if band not in self.superStarSubCcdDict:
msg = 'band %s not in superStarSubCcdDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.superStarSubCcdDict,
self, msg)
if band not in self.ccdGraySubCcdDict:
msg = 'band %s not in ccdGraySubCcdDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.ccdGraySubCcdDict,
self, msg)
if band not in self.expGrayPhotometricCutDict:
msg = 'band %s not in expGrayPhotometricCutDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.expGrayPhotometricCutDict,
self, msg)
if band not in self.expGrayHighCutDict:
msg = 'band %s not in expGrayHighCutDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.expGrayHighCutDict,
self, msg)
if band not in self.expVarGrayPhotometricCutDict:
msg = 'band %s not in expVarGrayPhotometricCutDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.expVarGrayPhotometricCutDict,
self, msg)
if band not in self.sigFgcmMaxEGrayDict:
msg = 'band %s not in sigFgcmMaxEGrayDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.sigFgcmMaxEGrayDict,
self, msg)
if band not in self.approxThroughputDict:
msg = 'band %s not in approxThroughputDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.approxThroughputDict,
self, msg)
if band not in self.useRepeatabilityForExpGrayCutsDict:
msg = 'band %s not in useRepeatabilityForExpGrayCutsDict' % (band)
raise pexConfig.FieldValidationError(FgcmFitCycleConfig.useRepeatabilityForExpGrayCutsDict,
self, msg)
class FgcmFitCycleRunner(pipeBase.ButlerInitializedTaskRunner):
"""Subclass of TaskRunner for fgcmFitCycleTask
fgcmFitCycleTask.run() takes one argument, the butler, and uses
stars and visits previously extracted from dataRefs by
fgcmBuildStars.
This Runner does not perform any dataRef parallelization, but the FGCM
code called by the Task uses python multiprocessing (see the "ncores"
config option).
"""
@staticmethod
def getTargetList(parsedCmd):
"""
Return a list with one element, the butler.
"""
return [parsedCmd.butler]
def __call__(self, butler):
"""
Parameters
----------
butler: `lsst.daf.persistence.Butler`
Returns
-------
exitStatus: `list` with `pipeBase.Struct`
exitStatus (0: success; 1: failure)
"""
task = self.TaskClass(config=self.config, log=self.log)
exitStatus = 0
if self.doRaise:
task.runDataRef(butler)
else:
try:
task.runDataRef(butler)
except Exception as e:
exitStatus = 1
task.log.fatal("Failed: %s" % e)
if not isinstance(e, pipeBase.TaskError):
traceback.print_exc(file=sys.stderr)
task.writeMetadata(butler)
# The task does not return any results:
return [pipeBase.Struct(exitStatus=exitStatus)]
def run(self, parsedCmd):
"""
Run the task, with no multiprocessing
Parameters
----------
parsedCmd: ArgumentParser parsed command line
"""
resultList = []
if self.precall(parsedCmd):
targetList = self.getTargetList(parsedCmd)
# make sure that we only get 1
resultList = self(targetList[0])
return resultList