def __init__(self, *args, **kwargs): self.constraints = Constraint([ Constraint_Base(), Constraint_Single_Science(self.has_science), Constraint( [ DMSAttrConstraint( name='opt_elem2', sources=['grating'], value='mirror' ) ], reduce=Constraint.notany ), DMSAttrConstraint( name='instrument', sources=['instrume'], value='nirspec' ), DMSAttrConstraint( name='opt_elem', sources=['filter'], value='opaque' ), ]) super(Asn_Lv2NRSLAMPSpectral, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.constraints = Constraint([ # Basic constraints Constraint_Base(), Constraint_Target(), # Allow WFSS exposures but account for the direct imaging. Constraint([ # Constrain on the WFSS exposure Constraint([ DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nis_wfss|nrc_wfss', ), Constraint_Mode(), Constraint_Single_Science(self.has_science), ]), # Or select related imaging exposures. DMSAttrConstraint( name='image_exp_type', sources=['exp_type'], value='nis_image|nrc_image', force_reprocess=ProcessList.EXISTING, only_on_match=True, ), ], reduce=Constraint.any) ]) super(Asn_Lv2WFSS, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint( [ DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nrs_ifu' ), DMSAttrConstraint( name='expspcin', sources=['expspcin'], ), DMSAttrConstraint( name='patttype', sources=['patttype'], value=['2-point-nod|4-point-nod'], force_unique=True ) ] ), ]) # Now check and continue initialization. super(Asn_Lv2NRSIFUNod, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup target acquisition inclusion constraint_acqs = Constraint([ DMSAttrConstraint(name='acq_exp', sources=['exp_type'], value='|'.join(ACQ_EXP_TYPES), force_unique=False), DMSAttrConstraint( name='acq_obsnum', sources=['obs_num'], value=lambda: '(' + '|'.join(self.constraints['obs_num']. found_values) + ')', force_unique=False, ) ], name='acq_constraint', work_over=ProcessList.EXISTING) # Put all constraints together. self.constraints = Constraint([ Constraint_Base(), DMSAttrConstraint(sources=['is_imprt'], force_undefined=True), Constraint([ Constraint( [self.constraints, Constraint_Obsnum()], name='rule'), constraint_acqs ], name='acq_check', reduce=Constraint.any), ], name='dmsbase_bkg') super(AsnMixin_BkgScience, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint_Spectral_Science( exclude_exp_types=['nis_wfss', 'nrc_wfss', 'nrs_fixedslit', 'nrs_msaspec'] ), Constraint( [ Constraint_Single_Science(self.has_science), SimpleConstraint( value='science', test=lambda value, item: self.get_exposure_type(item) != value, force_unique=False, ) ], reduce=Constraint.any ), Constraint( [ Constraint_TSO(), DMSAttrConstraint( name='patttype', sources=['patttype'], value=['2-point-nod|4-point-nod'], ) ], reduce=Constraint.notany ) ]) # Now check and continue initialization. super(Asn_Lv2Spec, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint( [ DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nrs_msaspec' ), DMSAttrConstraint( sources=['msametfl'] ), DMSAttrConstraint( name='expspcin', sources=['expspcin'], ) ] ) ]) # Now check and continue initialization. super(Asn_Lv2NRSMSA, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint_Spectral_Science( exclude_exp_types=['nrs_msaspec', 'nrs_fixedslit'] ), Constraint_Single_Science(self.has_science), Constraint_TSO(), Constraint( [ Constraint([ DMSAttrConstraint( name='exp_type', sources=['exp_type'], value=['nrc_tsgrism'], ), DMSAttrConstraint( name='pupil', sources=['pupil'], value=['clear'], )], ) ], reduce=Constraint.notany ) ]) # Now check and continue initialization. super(Asn_Lv2SpecTSO, self).__init__(*args, **kwargs)
def test_constraint_reprocess_nomatch(): """Test options for reprocessing""" sc = SimpleConstraint(value='my_value') c = Constraint([sc], reprocess_on_fail=True) match, reprocess = c.check_and_set('bad_value') assert not match assert len(reprocess)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Image_Science(), Constraint_Single_Science(self.has_science), Constraint_WFSC(), Constraint( [ DMSAttrConstraint( name='dms_note', sources=['dms_note'], value=['wfsc_los_jitter'], ), DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nrc_image' ), ], reduce=Constraint.notall ) ]) # Now check and continue initialization. super(Asn_Lv2WFSC, self).__init__(*args, **kwargs)
class TestDupNames: """Test duplicate names in Constraint""" # Sub constraints sc1 = SimpleConstraint(name='sc1') sc2 = SimpleConstraint(name='sc2') c1 = Constraint([sc1, sc2], name='c1') c2 = Constraint([sc1, sc1], name='c2') c3 = Constraint([sc1, sc2], name='sc1') @pytest.mark.parametrize('constraints, expected', [ ([sc1], {}), ([sc1, sc2], {}), ([sc1, sc1], { 'sc1': [sc1, sc1] }), ([c1], {}), ([c2], { 'sc1': [sc1, sc1] }), ([c3], { 'sc1': [sc1, c3] }), ]) def test_dups(self, constraints, expected): c = Constraint(constraints) dups = c.dup_names assert set(dups.keys()) == set(expected.keys()) for name, constraints in dups.items(): assert set(dups[name]) == set(expected[name])
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='mir_lrs-fixedslit' ), DMSAttrConstraint( name='patttype', sources=['patttype'], value=['along-slit-nod'], ), SimpleConstraint( value=True, test=lambda value, item: self.acid.type != 'background', force_unique=False ), Constraint( [ Constraint( [ DMSAttrConstraint( name='patt_num', sources=['patt_num'], ), Constraint_Single_Science( self.has_science, reprocess_on_match=True, work_over=ProcessList.EXISTING ) ] ), Constraint( [ DMSAttrConstraint( name='is_current_patt_num', sources=['patt_num'], value=lambda: '((?!{}).)*'.format(self.constraints['patt_num'].value), ), SimpleConstraint( name='force_match', value=None, sources=lambda item: False, test=lambda constraint, obj: True, force_unique=True, ) ] ) ], reduce=Constraint.any ) ]) # Now check and continue initialization. super(Asn_Lv2MIRLRSFixedSlitNod, self).__init__(*args, **kwargs)
def test_constraint_all(): """Test the all operation""" sc1 = SimpleConstraint(value='value_1') sc2 = SimpleConstraint(value='value_2') c = Constraint([sc1, sc2]) match, reprocess = c.check_and_set('value_1') assert not match
def __init__(self): super(Constraint_Mode, self).__init__([ DMSAttrConstraint( name='instrument', sources=['instrume'] ), DMSAttrConstraint( name='detector', sources=['detector'] ), DMSAttrConstraint( name='opt_elem', sources=['filter', 'band'] ), DMSAttrConstraint( name='opt_elem2', sources=['pupil', 'grating'], required=False, ), DMSAttrConstraint( name='subarray', sources=['subarray'], required=False, ), DMSAttrConstraint( name='channel', sources=['channel'], required=False, ), Constraint( [ DMSAttrConstraint( sources=['detector'], value='nirspec' ), DMSAttrConstraint( sources=['filter'], value='opaque' ), ], reduce=Constraint.notany ), Constraint( [ DMSAttrConstraint( sources=['visitype'], value='.+wfsc.+', ), ], reduce=Constraint.notany ), DMSAttrConstraint( name='slit', sources=['fxd_slit'], required=False, ) ])
def test_constraint_get_all_attr(): """Get attribute value of all constraints in a constraint""" names = ['sc1', 'sc2'] constraints = [SimpleConstraint(name=name) for name in names] c = Constraint(constraints, name='c1') expected = [(constraint, constraint.name) for constraint in constraints] expected.append((c, 'c1')) result = c.get_all_attr('name') assert set(result) == set(expected)
def test_constraint_default(): """Test constraint operations""" sc1 = SimpleConstraint() sc2 = SimpleConstraint() c = Constraint([sc1, sc2]) match, reprocess = c.check_and_set('my_value') assert match for constraint in c.constraints: assert constraint.value == 'my_value'
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint( [ Constraint( [ DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nrs_fixedslit' ), SimpleConstraint( value='science', test=lambda value, item: self.get_exposure_type(item) != value, force_unique=False ) ] ), Constraint( [ DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nrs_fixedslit' ), DMSAttrConstraint( name='expspcin', sources=['expspcin'], ), DMSAttrConstraint( name='nods', sources=['numdthpt'], ), DMSAttrConstraint( name='subpxpns', sources=['subpxpns'], ), SimpleConstraint( value='science', test=lambda value, item: self.get_exposure_type(item) == value, force_unique=False ) ] ), ], reduce=Constraint.any ) ]) # Now check and continue initialization. super(Asn_Lv2NRSFSS, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint_Image_Science(), Constraint_Single_Science(self.has_science), Constraint([Constraint_TSO()], reduce=Constraint.notany) ]) # Now check and continue initialization. super(Asn_Lv2Image, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.constraints = Constraint([ Constraint_Base(), Constraint_Single_Science(self.has_science), DMSAttrConstraint(name='exp_type', sources=['exp_type'], value='nrs_autoflat|nrs_autowave|nrs_lamp'), DMSAttrConstraint(name='opt_elem', sources=['filter'], value='opaque'), Constraint([ Constraint([ DMSAttrConstraint( name='opmode', sources=['opmode'], value='msaspec', ) ], reduce=Constraint.notany), Constraint([ DMSAttrConstraint(sources=['opmode'], value='msaspec'), DMSAttrConstraint(sources=['msametfl']) ]), ], reduce=Constraint.any), DMSAttrConstraint( name='lamp', sources=['lamp'], ), Constraint([ DMSAttrConstraint( sources=['grating'], value='mirror', force_unique=False, ), DMSAttrConstraint( sources=['opmode'], value='grating-only', force_unique=False, ), DMSAttrConstraint( sources=['lamp'], value='nolamp', force_unique=False, ), ], reduce=Constraint.notany), ]) super(Asn_Lv2NRSLAMPSpectral, self).__init__(*args, **kwargs)
def __init__(self): super(Constraint_Image_Nonscience, self).__init__( [ Constraint_TargetAcq(), DMSAttrConstraint( name='non_science', sources=['exp_type'], value='|'.join(IMAGE2_NONSCIENCE_EXP_TYPES), ), Constraint( [ DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nrs_msaspec' ), DMSAttrConstraint( sources=['msastate'], value='primarypark_allopen' ), DMSAttrConstraint( sources=['grating'], value='mirror' ) ] ) ], reduce=Constraint.any )
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nrs_ifu' ), SimpleConstraint( value=True, test=lambda value, item: nrsifu_valid_detector(item), force_unique=False ), DMSAttrConstraint( name='expspcin', sources=['expspcin'], ), DMSAttrConstraint( name='patttype', sources=['patttype'], value=['2-point-nod|4-point-nod'], force_unique=True ) ]) # Now check and continue initialization. super(Asn_Lv2NRSIFUNod, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Single_Science(self.has_science), DMSAttrConstraint( name='exp_type', sources=['exp_type'], value=('fgs_image' '|fgs_focus'), ), Constraint([Constraint_WFSC()], reduce=Constraint.notany) ]) super(Asn_Lv2FGS, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Single_Science(self.has_science), Constraint_ExtCal(), Constraint([ DMSAttrConstraint(name='wfsc', sources=['visitype'], value='.+wfsc.+', force_unique=True) ]) ]) # Now check and continue initialization. super(Asn_Lv2WFSC, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): super(Constraint_WFSC, self).__init__([ Constraint([ DMSAttrConstraint(name='wfsc', sources=['visitype'], value='.+wfsc.+', force_unique=True) ]) ])
def test_iteration(): """Test various iterations""" sc = SimpleConstraint() for idx in sc: assert isinstance(idx, SimpleConstraint) c = Constraint([sc, sc]) count = 0 for idx in c: assert isinstance(idx, SimpleConstraint) count += 1 assert count == 2 c = Constraint([Constraint([sc, sc]), Constraint([sc, sc])]) count = 0 for idx in c: assert isinstance(idx, SimpleConstraint) count += 1 assert count == 4 # Not 6
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Image_Nonscience(), Constraint_Single_Science(self.has_science), ]) # Now check and continue initialization. super(Asn_Lv2ImageNonScience, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint_Spectral_Science() ]) # Now check and continue initialization. super(Asn_Lv2Spec, self).__init__(*args, **kwargs)
def test_name_index(): """Test for name indexing""" sc1 = SimpleConstraint(name='sc1', value='value1') sc2 = SimpleConstraint(name='sc2', value='value2') c1 = Constraint([sc1, sc2]) assert c1['sc1'].value assert c1['sc2'].value sc3 = SimpleConstraint(name='sc3', value='value3') sc4 = SimpleConstraint(name='sc4', value='value4') c2 = Constraint([sc3, sc4, c1]) assert c2['sc1'].value assert c2['sc2'].value assert c2['sc3'].value assert c2['sc4'].value with pytest.raises(KeyError): c2['nonexistant'].value with pytest.raises(AttributeError): c2['sc1'].nonexistant
def __init__(self, *args, **kwargs): # Setup constraints self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), Constraint_Spectral_Science( exclude_exp_types=['nrs_msaspec', 'nrs_fixedslit']) ]) # Now check and continue initialization. super(Asn_Lv2Spec, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): constraints = SimpleConstraint( name='single_science', value=False, sources=lambda item: self.has_science(item)) if self.constraints is None: self.constraints = constraints else: self.constraints = Constraint([self.constraints, constraints]) # Now, lets see if item belongs to us. super(AsnMixin_Lv2Singleton, self).__init__(*args, **kwargs)
def __init__(self, *args, **kwargs): self.constraints = Constraint([ Constraint_Base(), Constraint_Mode(), DMSAttrConstraint( name='exp_type', sources=['exp_type'], value='nis_wfss', ) ]) super(Asn_Lv2WFSS_NIS, self).__init__(*args, **kwargs)