Exemple #1
0
def secondary_check(param, value, ipos, dat_dict, mchk):
    """
    check the secondary condition for the violation
    input:  param   --- parameter name
            value   --- value of the parameter
            ipos    --- a position in the violation list which will correspond in the secondary list
            dat_dict--- current data dictionary
    output  violation   --- a list of viorations. each item has [related param name, condition]
    """

#
#--- read the secondary condition list for the given parameter
#
    vcondition = pr.showCondition(param)
#
#--- start reading the list; mainly checking whether other parameters need to be
#--- required for this parameter
#
    violation = []
    if vcondition != 'NA':
        for entry in vcondition:
            if entry[0] == 'NA':
                continue
            try:
                test = dat_dict[entry[0]]
            except:
                test = None

            vcond = entry[1][ipos]
            if vcond == 'O':                                        #--- no restriction
                continue 
            elif vcond == 'C':                                      #--- the condition is custom
                if ocf.null_value(test) or ocf.none_value(test):
                    violation.append([entry[0], 'M'])               #--- the parameter  must have a value 
                else:
                    continue 

            elif vcond == 'N':                                      #--- the parameter should not have a value 
                if ocf.null_value(test) or ocf.none_value(test):
                    continue
                else:
                    violation.append([entry[0], 'N'])
            else:                                                   #--- this is mostly 'M' case
                if mchk == 2:
                    if ocf.null_value(test) or ocf.none_value(test):
                        violation.append([entry[0], 'O'])
                    else:
                        violation.append([entry[0], 'M'])
                else:
                    if ocf.null_value(test) or ocf.none_value(test):
                        violation.append([entry[0], 'M'])
                    else:
                        violation.append([entry[0], 'O'])

    return violation
Exemple #2
0
    def checkValue(self, param, value):
        """
        for a given parameter and numeric value, return whether the value is in the range
        this also include 'NULL' value
        """
        vrange = self.showRange(
            param
        )  #--- a value or the list of possible values for the parameter
        v_list = re.split('\,', vrange)

        mchk = 0  #--- whether the value is in the vrange. if so 1. if 2, skip the secondary test.

        if vrange == 'MUST':
            if ocf.null_value(value) != True:
                mchk = 1
                ipos = 0

        elif vrange == 'OPEN' or vrange == 'NA':
            mchk = 1
            ipos = 0
            if ocf.null_value(value):
                mchk = 2

        elif ocf.null_value(value):  #--- value is "NULL" case
            if ocf.find_pattern('NULL', vrange):
                mchk = 1
                ipos = 0

        elif mcf.chkNumeric(value):  #--- value is a numeric case
            for ipos in range(0, len(v_list)):
                if v_list[ipos] == 'OPEN':
                    mchk = 1
                    break
                elif ocf.find_pattern('<>', v_list[ipos]):
                    cond = re.split('<>', v_list[ipos])
                    vtest = float(value)
                    lower = float(cond[0])
                    upper = float(cond[1])
                    if vtest >= lower and vtest <= upper:
                        mchk = 1
                        break
        else:  #--- value is a word case
            for ipos in range(0, len(v_list)):
                if value == v_list[ipos]:
                    mchk = 1
                    break

        return [mchk, ipos]
Exemple #3
0
def check_special_cases(dat_dict):
    """
    check the cases which need more than standard condition checkings 
    input:  dat_idct    --- current data dictionary
    output: warning     --- a list of warnings
    """

    warning = []
#
#--- check time constraint changes and order of start and stop time
#
    tval = int(float(dat_dict['time_ordr']))
    if tval > 0:
        wchk = 0
        for j in range(0, tval):
            k = j + 1
            [tstart, ostart, nstart] = ocf.convert_back_time_form('tstart', k, dat_dict)
            [tstop,  ostop,  nstop]  = ocf.convert_back_time_form('tstop',  k, dat_dict)

            try:
                start = ocf.convert_time_in_axaf_time(nstart)
            except:
                start = 0
            try:
                stop  = ocf.convert_time_in_axaf_time(nstop)
            except:
                stop  = 0

            if start >= stop:
                line =  'The observation starting time is later than the observation '
                line = line + 'ending time in rank ' + str(k) + ': '
                line = line + 'tstart: ' + str(nstart) + ' /  tstop: ' + str(nstop)
                warning.append(line)

            if (wchk == 0) and  (ostart != nstart or ostop != nstop):
                line = 'Changes in window constraint impact constraints or preferences.'
                line = line + ' Verify you have indicated CDO approval in the comments.'
                warning.append(line)
                wchk = 1
#
#--- check pha range
#
    try:
        val = float(dat_dict['pha_range'])
        if val > 13:
            line = 'In many configurations, an Energy Range above 13 keV will risk telemetry saturation.'
            line = line + ' pha_range: ' + str(val)
            warning.append(line)
    except:
        pass
#
#--- check energy filter low
#
    try:
        val = float(dat_dict['eventfilter_lower'])
        if (val > 0.5) and ocf.null_value(dat_dict['ordr']):
            line = 'If eventfilter_lower > 0.5, ACIS spatial window parameters must be filled.'
            warning.append(line)
    except:
        pass
#
#--- check ACIS window constrain: lower_threshold:
#
    try:
        ordr = float(dat_dict['ordr'])
        ordr = int(ordr)
    except:
        ordr = 0
    if ordr >= 1:
        val2 = dat_dict['eventfilter_lower']
        for j in range(0, ordr):
            k = j + 1
            pname = 'lower_threshold' + str(k)
            try:
                val1 = float(dat_dict[pname])
            except:
                val1 = None

            if (ocf.null_value(val2) or ocf.none_value(val2)) and (val1 != None):
                line = 'ACIS window constraint lower_threshold has a value: '
                line = line + 'eventfilter_lower must have a value smaller than lower_threshold.'
                warning.append(line)
            else:
                try:
                    val2 = float(val2)
                    if val1 > val2:
                        line = 'ACIS window constraint lower_threshold must be '
                        line = line + 'larger than eventfilter_lower: ' + str(val2)
                        warning.append(line)
                except:
                    pass
#
#--- montioring and group observations
#
    if dat_dict['monitor_flag'] == 'Y':
        if dat_dict['group_id'] !='' and dat_dict['group_id'] != 'None':
        #if dat_dict['group_id']:
            warning['group_id'] = 'Group_id is set. A monitor_flag must be NULL.'
        else:
            try:
                if ocf.null_value(dat_dict['pre_id']) or ocf.null_value(dat_dict['pre_min_lead'])  \
                    or ocf.null_value(dat_dict['pre_max_lead']):
                    if dat_dict['time_ordr'] == 0:
                        line = 'If this is a montoring observation, '
                        line = line + ' you need to fill  pre_id, pre_min_lead, and pre_max_lead.'
                        warning.append(line)
            except:
                pass

    else:
        if dat_dict['group_id'] and not (dat_dict['group_id'] in non_list):
            if ocf.null_value(dat_dict['pre_id']) or ocf.null_value(dat_dict['pre_min_lead']) \
                or ocf.null_value(dat_dict['pre_max_lead']):

                if dat_dict['time_ordr'] == 0:
                    line = 'group_id is set. You need to fill pre_id,  pre_min_lead and pre_max_lead.'
                    warning.append(line)

    try:
        if dat_dict['pre_id'] and dat_dict['pre_id'] == dat_dict['obsid']:
            line = 'pre_id cannot be same as obsid: ' + str(db.newValue('obsid'))
            warning.append(line)
    except:
        pass

    try:
        val1 = float(dat_dict['pre_min_lead'])
        val2 = float(dat_dict['pre_max_lead'])
    except:
        val1 = val2 = 0

    if val1 > val2:
        line = 'pre_min_lead should be smaller than pre_max_lead: ' + str(db.newValue('pre_max_lead'))
        warning.append(line)
#
#--- si mode change
#
    change_list = []
    if  dat_dict['si_mode'] == 'New Value Requsted':
        for param in ['est_cnt_rate', 'forder_cnt_rate', 'raster_scan', \
                       'grating', 'instrument', 'dither_flag']:

            oparam = 'org_' + param

            if dat_dict[oparam] != dat_dict[param]:
                change_list.append(param)

        clen = len(change_list)
        if clen == 1:
            line = 'SI Mode is reset to "New Value Requsted" because the parameter  '
        else:
            line = 'SI Mode is reset to "New Value Requsted" because the  parameters '

        for pname in change_list:
            line = line + ' "' + str(pname) + '", '

        if clen == 1:
            line = line + ' is modified.'
        else:
            line = line + ' are modified.'

        warning.append(line)
#
#--- dither amplitude check. if amplitudes are too small (<0.1), poc could input them in degree.
#
    if dat_dict['dither_flag'] == 'Y':
        y_amp = float(dat_dict['y_amp_asec'])
        z_amp = float(dat_dict['z_amp_asec'])
        y_frq = float(dat_dict['y_freq_asec'])
        z_frq = float(dat_dict['z_freq_asec'])
        if y_amp < 0.0001 or z_amp < 0.0001 or y_frq < 0.0001 or z_frq < 0.0001:
            line = 'Please check Dither Y/Z Amplitude. They must be in arc-sec.'
            warning.append(line)

    return warning
Exemple #4
0
def check_param(param, value,  dat_dict):
    """
    check the parameter value satisfies the restriction
    input:  param       --- parameter name
            dat_dict    --- current data dictionary
    output: violation/None  --- if there is violations, return the condition. otherwise return None
    """

#
#--- check whether this is ordered param
#--- if so, remove the digit part from the param
#
    test = str(param)
    if ocf.chkNumeric(test[-1]):
        param = test[:-1]
#
#---read a value or the list of possible values for the parameter    
#
    vrange = pr.showRange(param)
    v_list = re.split('\,', vrange)

    mchk   = 0
#
#---- first check the value is in the given vrange
#
    if vrange == 'MUST':
        if ocf.null_value(value) != True:
            mchk = 1
            ipos = 0
    elif vrange == 'OPEN' or vrange == 'NA':
        mchk = 1
        ipos = 0
        if ocf.null_value(value):
            mchk = 2
    elif ocf.null_value(value):
#
#--- for the case the "value" is not assigned
#
        for test in non_list:
            if ocf.find_pattern(test, vrange):
                mchk = 2
                ipos = 0
                break
    elif ocf.chkNumeric(value):
#
#--- for the case the value is numeric
#
        for ipos in range(0, len(v_list)):
            if v_list[ipos] == 'NULL':
               if ocf.null_value(value) or ocf.none_value(value): 
                    mchk = 1
                    break
            elif v_list[ipos] == 'OPEN':
                mchk = 1
                break
            elif ocf.find_pattern('<>', v_list[ipos]):
                cond  =  re.split('<>', v_list[ipos])
                vtest = float(value)
                lower = float(cond[0])
                upper = float(cond[1])
                if vtest >= lower and vtest <=upper:
                    mchk = 1
                    break
    else:
#
#---- for the case the value is a word. "OPEN" is one of choice, accept all data
#
        for ipos in range(0, len(v_list)):
            if value == v_list[ipos]:
                mchk = 1
                break
            if v_list[ipos] == 'OPEN':
                mchk = 1
                break        
    if param.lower() == 'dither_flag':
        mchk = 1
        if value == 'Y':
            ipos = 2
        elif value == 'N':
            ipos = 1
        else:
            ipso = 0
#
#--- if the parameter value is in the correct range, check the extra restriction
#
    if mchk > 0 :
        violation = secondary_check(param, value, ipos, dat_dict, mchk)
#
#--- return result
#
    if mchk == 0:
        return vrange
    elif len(violation) > 0:
        return violation
    else:
        return None