Exemple #1
0
def getDataPD(callerdata, RSLTS, b_usePDFocalPlane):
    import math
    if not (comdefs.cst_PD_ORIEL in callerdata):
        print('no PD data available')
        x_intensity_FocalPlane = []
    else:

        # the PD st sphere has inverted polarity and is normally read via the Keithley instrument
        # during measurement in 2016 (SOLO/PHI/METIS)idx the Oriel picoamperemeter was used to read the PD in the sphere
        # these measurements can be distinguished by having a negative polarity in the Oriel reading

        #if math.isnan(data[comdefs.cst_PD_KEITHLEY][0]): b_usePDFocalPlane=True # old dataset that used the Oriel Reading
        b_only_Orieldata = False
        data = {}
        b_filtercorrection = False
        if callerdata == []:  #use results
            if b_usePDFocalPlane == False:
                # if the High Power LED 627nm with the 627nm filter was used, data has to be corrected
                # try to get info about lamp used
                s1 = ''
                s2 = ''
                s3 = Helpers.getvalue_in_RSLTS(
                    RSLTS, comdefs.cst_Filter
                )  # was: s3 = RSLTS[comdefs.cst_Filter].value
                if comdefs.cst_Lamp in RSLTS:
                    s1 = str(Helpers.getvalue_in_RSLTS(RSLTS,
                                                       comdefs.cst_Lamp))
                if comdefs.cst_LampWavelength in RSLTS:
                    s2 = str(
                        Helpers.getvalue_in_RSLTS(RSLTS,
                                                  comdefs.cst_LampWavelength))
                if ('LED' in (s1 or s2)) and (('617.30nm' in (s1 or s2) or
                                               ('617.30nm' in s3))):
                    b_filtercorrection = True
            data[comdefs.cst_PD_ORIEL] = Helpers.getarray_from_RSLTS(
                RSLTS, comdefs.cst_PD_ORIEL)
            data[comdefs.cst_PD_KEITHLEY] = Helpers.getarray_from_RSLTS(
                RSLTS, comdefs.cst_PD_KEITHLEY)
        else:
            if b_usePDFocalPlane == False:
                # if the High Power LED 627nm with the 627nm filter was used, data has to be corrected
                # try to get info about lamp used
                s1 = ''
                s2 = ''
                val = Helpers.getvalue_in_RSLTS(callerdata, comdefs.cst_Filter)

                if isinstance(val, list) and (len(val) > 0):
                    val = val[0]
                    s3 = val  # was: s3 = RSLTS[comdefs.cst_Filter].value
                else:
                    s3 = ''

                if comdefs.cst_Lamp in callerdata:
                    val = Helpers.getvalue_in_RSLTS(callerdata,
                                                    comdefs.cst_Lamp)
                    if isinstance(val, list):
                        val = val[0]
                    s1 = str(val)
                if comdefs.cst_LampWavelength in callerdata:
                    val = Helpers.getvalue_in_RSLTS(callerdata,
                                                    comdefs.cst_LampWavelength)
                    if isinstance(val, list):
                        val = val[0]
                    s2 = str(val)
                if ('LED' in (s1 or s2)) and (('617.30nm' in (s1 or s2) or
                                               ('617.30nm' in s3))):
                    b_filtercorrection = True

            if isinstance(callerdata[comdefs.cst_PD_ORIEL], Helpers.RSLT):
                data[comdefs.cst_PD_ORIEL] = callerdata[
                    comdefs.cst_PD_ORIEL].value
                data[comdefs.cst_PD_KEITHLEY] = callerdata[
                    comdefs.cst_PD_KEITHLEY].value
            else:
                data[comdefs.cst_PD_ORIEL] = callerdata[comdefs.cst_PD_ORIEL]
                data[comdefs.cst_PD_KEITHLEY] = callerdata[
                    comdefs.cst_PD_KEITHLEY]

        if np.average(
                data[comdefs.cst_PD_ORIEL]
        ) < 0:  # normally it is measures the focal plane annd is positive, if not, the PD current at in the sphere was measured
            # this indicates that the PD in the Sphere was read via the Oriel instrument
            RSLTS['PD_USED'] = Helpers.RSLT('PD current',
                                            ' measured in Int. Sphere !', '',
                                            '{}', '')
            # data from Sphere is acquired with Oriel
            if (isinstance(data[comdefs.cst_PD_ORIEL], list)):
                x_intensity_Sphere = [
                    float(i) * -1 for i in data[comdefs.cst_PD_ORIEL]
                ]  # convert strings to floats
            else:
                x_intensity_Sphere = float(data[
                    comdefs.cst_PD_ORIEL]) * -1  # convert strings to floats
            b_only_Orieldata = True
        else:
            # get data for focal plane and sphere
            if (isinstance(data[comdefs.cst_PD_KEITHLEY], list)):
                x_intensity_Sphere = [
                    float(i) * -1 for i in data[comdefs.cst_PD_KEITHLEY]
                ]  #convert strings to floats
            else:
                x_intensity_Sphere = float(data[
                    comdefs.cst_PD_KEITHLEY]) * -1  # convert strings to floats
            if (isinstance(data[comdefs.cst_PD_ORIEL], list)):
                x_intensity_FocalPlane = [
                    float(i) for i in data[comdefs.cst_PD_ORIEL]
                ]  #convert strings to floats
            else:
                x_intensity_FocalPlane = float(
                    data[comdefs.cst_PD_ORIEL])  # convert strings to floats

        if math.isnan(x_intensity_Sphere[0]): b_usePDFocalPlane = True
        if b_usePDFocalPlane:
            RSLTS['PD_USED'] = Helpers.RSLT('PD current ',
                                            'measured near Focal Plane !', '',
                                            '{}', '')
            s = Helpers.printresult(RSLTS['PD_USED'])
        else:
            # to get the PD effective current at the focal plane
            # the ratio between PD_FP and PD_Spaher has to be applied
            print('applying ratio 150 between PD_FP and PD_Sphere ..')
            RSLTS['PD_CORRECTION'] = Helpers.RSLT(
                'PD curr. correction: divided by ',
                cst_RatioPD_Sphere_to_PD_FocalPlane, '', '{:7.1f}', '')
            s = Helpers.printresult(RSLTS['PD_CORRECTION'])
            x_intensity_FocalPlane = np.divide(
                x_intensity_Sphere, cst_RatioPD_Sphere_to_PD_FocalPlane)

            # Note: when using the LED with the narrow band 617nm filter
            # the relation between PD current at sphere to PD current at Focal plane may shift with the operating current
            # of the LED !
            # a correction formula has to be added then !!!
            if b_filtercorrection == True:
                print('correcting for 617nm filter..')
                RSLTS['PD_CORRECTION'] = Helpers.RSLT(
                    'PD curr.', ' corrected for 617nm Filter  !', '', '{}', '')
                s = Helpers.printresult(RSLTS['PD_CORRECTION'])
                # correct red LED, 627nm filter
                x_intensity_FocalPlane = CorrectPD_Current_627nm(
                    x_intensity_Sphere)
            '''if RSLTS[comdefs.cst_LampWavelength].value == 'Xenon':
                print('Xenon run  .. keep PD data untouched')
                x_intensity_FocalPlane = x_intensity_Sphere  # diodes where swapped for the measurement
            
            elif (RSLTS[comdefs.cst_LampWavelength].value == 'LED 627nm'):
                    #x_intensity_FocalPlane = np.reshape(x_intensity_FocalPlane, (len(x_intensity_FocalPlane), 1))
            else:
               exit('getDataPD - Error - lamp wavelength not defined ! - expected "LED 627nm" or "Xenon" ')
            '''
        x_intensity_FocalPlane = np.reshape(x_intensity_FocalPlane,
                                            (len(x_intensity_FocalPlane)))
        print(x_intensity_FocalPlane)
    RSLTS[comdefs.cst_IntensityFocalPlane] = Helpers.RSLT(
        comdefs.cst_IntensityFocalPlane, x_intensity_FocalPlane, '', '', '')
    return RSLTS  #data