@@ -1486,6 +1486,70 @@ def select(self, meta, proc_aman=None, in_place=True):
14861486 else :
14871487 return keep
14881488
1489+ class LoadPremadeFlags (_Preprocess ):
1490+ """Load premade flags from aman.
1491+
1492+ Saves results in proc_aman under the "premade_flags_name" field of aman.
1493+ In addtion, you can select detectors based on the loaded flags.
1494+ This is mainly used for simulation for planet mapmaking.
1495+ When simulated planet is made, we need corresponding flags
1496+ to carry out the same preprocessing as the real planet mapmaking.
1497+ This class is useful whenever you want to premake custum flags and use it.
1498+
1499+ E.g., if aman contains 'sim_jupiter_flag', you can load it to proc_aman as follows:
1500+
1501+ Example config block::
1502+
1503+ - name : "load_premade_flags"
1504+ load_premade_flag_name: 'sim_jupiter_flag'
1505+ calc:
1506+ inv_flag: True
1507+ save: True
1508+ select: # optional
1509+ kind: "any"
1510+ invert: True
1511+
1512+ """
1513+ name = "load_premade_flags"
1514+ def __init__ (self , step_cfgs ):
1515+ self .premade_flags_name = step_cfgs .get ('load_premade_flag_name' , 'premade_flags' )
1516+ super ().__init__ (step_cfgs )
1517+
1518+ def calc_and_save (self , aman , proc_aman ):
1519+ print ('flags_name' , self .premade_flags_name )
1520+ premade_flags = aman .flags .get (self .premade_flags_name )
1521+ source_aman = core .AxisManager (aman .dets , aman .samps )
1522+ source_aman .wrap (self .premade_flags_name , premade_flags , [(0 , 'dets' ), (1 , 'samps' )])
1523+
1524+ if self .calc_cfgs .get ('inv_flag' ):
1525+ source_aman .wrap (self .premade_flags_name + '_inv' ,
1526+ RangesMatrix .from_mask (~ premade_flags .mask ()),
1527+ [(0 , 'dets' ), (1 , 'samps' )])
1528+
1529+ self .save (proc_aman , source_aman )
1530+ return aman , proc_aman
1531+
1532+ def save (self , proc_aman , source_aman ):
1533+ if self .save_cfgs is None :
1534+ return
1535+ if self .save_cfgs :
1536+ proc_aman .wrap (self .premade_flags_name , source_aman )
1537+
1538+ def select (self , meta , proc_aman = None , in_place = True ):
1539+ if self .select_cfgs is None :
1540+ return meta
1541+ if proc_aman is None :
1542+ proc_aman = meta .preprocess
1543+ keep = flag_cut_select (proc_aman [self .premade_flags_name ][self .premade_flags_name ],
1544+ kind = self .select_cfgs .get ("kind" , 'all' ),
1545+ invert = self .select_cfgs .get ('invert' , False ))
1546+ if in_place :
1547+ meta .restrict ("dets" , meta .dets .vals [keep ])
1548+ return meta
1549+ else :
1550+ return keep
1551+
1552+
14891553class SourceFlags (_Preprocess ):
14901554 """Calculate the source flags in the data.
14911555 All calculation configs go to `get_source_flags`.
@@ -2685,6 +2749,7 @@ def process(self, aman, proc_aman, sim=False):
26852749_Preprocess .register (DetBiasFlags )
26862750_Preprocess .register (SSOFootprint )
26872751_Preprocess .register (DarkDets )
2752+ _Preprocess .register (LoadPremadeFlags )
26882753_Preprocess .register (SourceFlags )
26892754_Preprocess .register (HWPAngleModel )
26902755_Preprocess .register (GetStats )
0 commit comments