private XYDataArray calibrateSpectrum(DataReader DUTFile,DataReader REFFile,DataReader CALFile,ref XYDataArray deviceQE,
            ref XYDataArray devicePhotocurrent, ref XYDataArray calibratedREF,double lowerbound,double upperbound)
        {
            XYDataArray origCAL = new XYDataArray(ref CALFile.dataArray1, ref CALFile.dataArray2);
            //newCAL is the calibrated photodiode QE based on the wavelength scanned in reference file
            XYDataArray newCAL = origCAL.generateNewXYArray(ref REFFile.dataArray1);

            XYDataArray origREF = new XYDataArray(ref REFFile.dataArray1, ref REFFile.dataArray2);
            //newCAL = newCAL.YByACoef(0.01);
            newCAL = newCAL.Yinverse();

            double[] tempArr = newCAL.getDataArray(0);
            //the array size of newCAL may be less the origREF.Xarray,
            //so we need to generate the new array again
            calibratedREF = origREF.generateNewXYArray(ref tempArr);

            calibratedREF = calibratedREF.Yproduct(ref newCAL);

            //This data array is for keeping the for the original photocurrent data
            devicePhotocurrent = new XYDataArray(ref DUTFile.dataArray1, ref DUTFile.dataArray2);

            //This data array is for later conversion
            deviceQE = new XYDataArray(ref DUTFile.dataArray1, ref DUTFile.dataArray2);

            XYDataArray calibratedREFtoDev = calibratedREF.generateNewXYArray(ref DUTFile.dataArray1);
            tempArr = calibratedREFtoDev.getDataArray(0);
            deviceQE = deviceQE.generateNewXYArray(ref tempArr);
            calibratedREFtoDev = calibratedREFtoDev.Yinverse();
            deviceQE = deviceQE.Yproduct(ref calibratedREFtoDev);
            //deviceQE = deviceQE.YByACoef(100);
            deviceQE.showData();

            //trim the data based on the selected range
            XYDataArray tmp_deviceQE = deviceQE.selectRange(lowerbound, upperbound);
            deviceQE = tmp_deviceQE;

            XYDataArray tmp_devicePC = deviceQE.selectRange(lowerbound, upperbound);
            devicePhotocurrent = tmp_devicePC;

            XYDataArray tmp_calibratedREF = calibratedREF.selectRange(lowerbound, upperbound);
            calibratedREF = tmp_calibratedREF;

            return deviceQE;
        }
Esempio n. 2
0
        public static XYDataArray concate(XYDataArray A, XYDataArray B)
        {
            int ALength = A.XYData.GetLength(0);
            int BLength = B.XYData.GetLength(0);

            double[] newXDataArray = new double[ALength+BLength];
            double[] newYDataArray = new double[ALength + BLength];

            for (int i = 0; i < ALength; i++)
            {
                    newXDataArray[i] = A.XYData[i].XData;
                    newYDataArray[i] = A.XYData[i].YData;
            }

            for (int i = 0; i < BLength; i++)
            {
                newXDataArray[i + ALength] = B.XYData[i].XData;
                newYDataArray[i + ALength] = B.XYData[i].YData;
            }

            return new XYDataArray(ref newXDataArray, ref newYDataArray);
        }
Esempio n. 3
0
        public XYDataArray generateNewXYArray(ref double[] arrayX)
        {
            //double tempX = XYData[0].XData;

            //create a new array X and array Y
            double[] newArrayX = new double[0];
            double[] newArrayY = new double[0];

            //index that counts the length of newly created array
            int newArrayIdx=0;

            int refArrayIndex = 0;
            int arrayXidx = 0;
            foreach (double newX in arrayX)
            {
                while (refArrayIndex <= XYData.GetUpperBound(0))
                {
                    if (newX < XYData[refArrayIndex].XData)
                    {

                        if (refArrayIndex == 0)
                        {
                            //do extrapolation if at boundary

                            //discard boundary for the time being
                            //newArrayY[arrayXidx] = -1000;
                            break;
                        }
                        else
                        {
                            //do interpolation betwen XYData[j] and XYData[j-1]
                            double tempX = XYData[refArrayIndex].XData;
                            double nextTempX = XYData[refArrayIndex-1].XData;
                            double tempY = XYData[refArrayIndex].YData;
                            double nextTempY = XYData[refArrayIndex-1].YData;

                            Array.Resize(ref newArrayX, newArrayIdx+1);
                            Array.Resize(ref newArrayY, newArrayIdx+1);

                            newArrayX[newArrayIdx] = newX;
                            newArrayY[newArrayIdx] = interpolate(tempX, nextTempX, tempY, nextTempY,newX);
                            newArrayIdx++;
                            break;
                        }
                    }
                    else if (newX > XYData[refArrayIndex].XData)
                    {
                        //continue, go to next index
                        if (refArrayIndex <= XYData.GetUpperBound(0))
                        {
                            refArrayIndex++;
                        }
                    }
                    else if (newX == XYData[refArrayIndex].XData)
                    {
                        Array.Resize(ref newArrayX, newArrayIdx + 1);
                        Array.Resize(ref newArrayY, newArrayIdx + 1);

                        newArrayX[newArrayIdx] = newX;
                        newArrayY[newArrayIdx] = XYData[refArrayIndex].YData;
                        newArrayIdx++;
                        break;
                    }
                }
                arrayXidx++;
            }

            //create a XYDataArray to store the generated  X Y values
            XYDataArray newXYDataArray = new XYDataArray(ref newArrayX, ref newArrayY);
            return newXYDataArray;
        }
Esempio n. 4
0
 public XYDataArray(XYDataArray data)
 {
     this.XYData = data.XYData;
 }
Esempio n. 5
0
 public XYDataArray Yproduct(ref XYDataArray data)
 {
     double[] tempArray1 = this.getDataArray(0);
     double[] tempArray2 = this.getDataArray(1);
     XYDataArray productData = new XYDataArray(ref tempArray1, ref tempArray2);
     if (XYData.Length != data.XYData.Length)
     {
         return null;
     }
     else
     {
         for (int i = 0; i < XYData.Length; i++)
         {
             productData.XYData[i].YData = this.XYData[i].YData * data.XYData[i].YData;
         }
     }
     return productData;
 }
Esempio n. 6
0
 public XYDataArray Yinverse()
 {
     XYDataArray newData = new XYDataArray(this);
     for (int i = 0; i < XYData.Length; i++)
     {
         newData.XYData[i].YData = 1 / newData.XYData[i].YData;
     }
     return newData;
 }
Esempio n. 7
0
 public XYDataArray YByACoef(double coefficient)
 {
     XYDataArray newData = new XYDataArray(this);
     for (int i = 0; i < XYData.Length; i++)
     {
         newData.XYData[i].YData *= coefficient;
     }
     return newData;
 }
        private void convertButton_Click(object sender, EventArgs e)
        {
            string visRangeFilePath = @"C:\SpectralResponseAQSettingFiles\mirror_cali_vis.txt";
            string nirRangeFilePath = @"C:\SpectralResponseAQSettingFiles\mirror_cali_NIR.txt";

            DataReader CALFile = new DataReader(mirrorRefFullFilePath, 0, 1);       //calibrated mirror reflectivity file
            DataReader REFFile = new DataReader(REFFullFilePath, LoadFileType.KHcsv); //mirror reflectance file
            DataReader DUTFile = new DataReader(DUTFullFilePath, LoadFileType.KHcsv);

            DataReader CALFileRange1 = new DataReader(visRangeFilePath, 0, 1);
            DataReader CALFileRange2 = new DataReader(nirRangeFilePath, 0, 1);

            string DUTFileName = System.IO.Path.GetFileNameWithoutExtension(DUTFullFilePath);
            string DUTDir = System.IO.Path.GetDirectoryName(DUTFullFilePath);
            string DUText = System.IO.Path.GetExtension(DUTFullFilePath);
            string newDUTFullPathForRange1 = System.IO.Path.Combine(DUTDir, DUTFileName + "_converted1" + DUText);
            string newDUTFullPathFoAllRange = System.IO.Path.Combine(DUTDir, DUTFileName + "_converted" + DUText);

            double[] REFPhotocurrent=new double[]{0};
            double switchWavelength = Convert.ToDouble(switchWavelengthTextBox.Text);

            XYDataArray deviceQERange1 = new XYDataArray();
            XYDataArray devicePCRange1 = new XYDataArray();
            XYDataArray calibratedREFRange1 = new XYDataArray();

            calibrateSpectrum(DUTFile,REFFile,CALFileRange1,ref deviceQERange1,
                ref devicePCRange1, ref calibratedREFRange1,0, switchWavelength);

            QEDataWriter dWriter = new QEDataWriter(DUTFile.headerPart);
            dWriter.addColumn("Wavelength (nm)", deviceQERange1.getDataArray(0));
            dWriter.addColumn("Reflectivity (%)", deviceQERange1.getDataArray(1));
            dWriter.addColumn("DUT Reflectance (nA)", devicePCRange1.getDataArray(1));
            dWriter.addColumn("Mirror Reflectance (nA)", calibratedREFRange1.getDataArray(1));
             //           dWriter.writeDataAndHeaderIntoFile(newDUTFullPathForRange1);

            XYDataArray deviceQERange2 = new XYDataArray();
            XYDataArray devicePCRange2 = new XYDataArray();
            XYDataArray calibratedREFRange2 = new XYDataArray();

            calibrateSpectrum(DUTFile, REFFile, CALFileRange2, ref deviceQERange2,
                ref devicePCRange2, ref calibratedREFRange2, switchWavelength,2000);

            XYDataArray allDeviceQE = XYDataArray.concate(deviceQERange1, deviceQERange2);
            XYDataArray allDevicePC = XYDataArray.concate(devicePCRange1, devicePCRange2);
            XYDataArray allCalibratedREF = XYDataArray.concate(calibratedREFRange1, calibratedREFRange2);

            dWriter = new QEDataWriter(DUTFile.headerPart);
            dWriter.addColumn("Wavelength (nm)", allDeviceQE.getDataArray(0));
            dWriter.addColumn("Reflectivity (%)", allDeviceQE.getDataArray(1));
            dWriter.addColumn("DUT Reflectance (nA)", allDevicePC.getDataArray(1));
            dWriter.addColumn("Mirror Reflectance (nA)", allCalibratedREF.getDataArray(1));

            dWriter.writeDataAndHeaderIntoFile(newDUTFullPathFoAllRange);
        }
        private void convertSingleRange()
        {
            DataReader CALFile = new DataReader(@"C:\SpectralResponseAQSettingFiles\818-UV_calibration_report.csv", 0, 1);

            if (detector1SettingBox.SelectedIndex == 0)
            {
                CALFile = new DataReader(@"C:\SpectralResponseAQSettingFiles\818-UV_calibration_report.csv", 0, 1);
            }
            else if (detector1SettingBox.SelectedIndex == 1)
            {
                CALFile = new DataReader(@"C:\SpectralResponseAQSettingFiles\818-IR-L_calibration_report.csv", 0, 2);
            }

            DataReader REFFile = new DataReader(range1REFFullFilePath, LoadFileType.KHcsv);
            DataReader DUTFile = new DataReader(DUTFullFilePath, LoadFileType.KHcsv);

            string DUTFileName = System.IO.Path.GetFileNameWithoutExtension(DUTFullFilePath);
            string DUTDir = System.IO.Path.GetDirectoryName(DUTFullFilePath);
            string DUText = System.IO.Path.GetExtension(DUTFullFilePath);
            string newDUTFullPath = System.IO.Path.Combine(DUTDir, DUTFileName + "_converted" + DUText);

            XYDataArray origCAL = new XYDataArray(ref CALFile.dataArray1, ref CALFile.dataArray2);
            //newCAL is the calibrated photodiode QE based on the wavelength scanned in reference file
            XYDataArray newCAL = origCAL.generateNewXYArray(ref REFFile.dataArray1);

            XYDataArray origREF = new XYDataArray(ref REFFile.dataArray1, ref REFFile.dataArray2);
            //newCAL = newCAL.YByACoef(0.01);
            newCAL = newCAL.Yinverse();

            double[] tempArr = newCAL.getDataArray(0);
            //the array size of newCAL may be less the origREF.Xarray,
            //so we need to generate the new array again
            XYDataArray calibratedREF = origREF.generateNewXYArray(ref tempArr);
            //store calibratedREF data for writing into data file
            double[] REFPhotocurrent = calibratedREF.getDataArray(1);

            calibratedREF = calibratedREF.Yproduct(ref newCAL);

            XYDataArray deviceQE = new XYDataArray(ref DUTFile.dataArray1, ref DUTFile.dataArray2);
            XYDataArray calibratedREFtoDev = calibratedREF.generateNewXYArray(ref DUTFile.dataArray1);
            tempArr = calibratedREFtoDev.getDataArray(0);
            deviceQE = deviceQE.generateNewXYArray(ref tempArr);
            calibratedREFtoDev = calibratedREFtoDev.Yinverse();
            deviceQE = deviceQE.Yproduct(ref calibratedREFtoDev);
            deviceQE = deviceQE.YByACoef(100);
            deviceQE.showData();

            QEDataWriter dWriter = new QEDataWriter(DUTFile.headerPart);
            dWriter.addColumn("Wavelength (nm)", deviceQE.getDataArray(0));
            dWriter.addColumn("EQE (%)", deviceQE.getDataArray(1));
            dWriter.addColumn("Photocurrent (nA)", DUTFile.dataArray2);
            dWriter.addColumn("Reference (nA)", REFPhotocurrent);
            //dWriter.writeDataIntoFile(@"C:\TEMP\testoutput.csv");
            //dWriter.writeDataIntoDBFormatFile(@"C:\TEMP\testoutput2.csv");
            dWriter.writeDataAndHeaderIntoFile(newDUTFullPath);
        }