Example #1
0
        // once this calibration function is called, the default calibration is
        // overridden.
        public virtual void OverrideDefaultCalibrator(CalibrationType calibType, double A, double B, double C)
        {
            mbln_use_specified_calibration = true;
            menm_calibration_type          = calibType;
            var calib = new Calibrations.Calibrator(menm_calibration_type);

            calib.NumPointsInScan  = mint_num_points_in_scan;
            calib.LowMassFrequency = mdbl_low_mass_freq;
            calib.SampleRate       = mdbl_sample_rate;
            mdbl_calib_const_a     = A;
            mdbl_calib_const_b     = B;
            mdbl_calib_const_c     = C;
            calib.SetCalibrationEquationParams(mdbl_calib_const_a, mdbl_calib_const_b, mdbl_calib_const_c);
            SetCalibrator(calib);
        }
Example #2
0
        private void ExtractSettings(int start_p, string option_str)
        {
            short short_bluff;

            double sample_rate;
            double anal_trap_voltage;
            double conductance_lim_voltage, source_trap_voltage;
            short  calibration_type;
            double low_mass_frequency;

            int temp_int;

            Helpers.GetInt32(option_str, "dataPoints:", start_p, out temp_int);
            mint_num_points_in_scan = temp_int;

            Helpers.GetDouble(option_str, "dwell:", start_p, out sample_rate);

            if (sample_rate != 0)
            {
                sample_rate = 1 / sample_rate;
            }

            if (Helpers.GetInt16(option_str, "Zerofill=true", start_p, out short_bluff))
            {
                mbln_zero_fill = true;
            }

            short temp;

            Helpers.GetInt16(option_str, "ZerofillNumber=", start_p, out temp);
            mshort_num_zero_fill = temp;
            Helpers.GetDouble(option_str, "analyzerTrapVoltage:", start_p, out anal_trap_voltage);
            Helpers.GetDouble(option_str, "conductanceLimitVoltage:", start_p, out conductance_lim_voltage);
            Helpers.GetDouble(option_str, "sourceTrapVoltage:", start_p, out source_trap_voltage);
            Helpers.GetInt16(option_str, "calType:", start_p, out calibration_type);
            Helpers.GetDouble(option_str, "calReferenceFrequency:", start_p, out low_mass_frequency);

            double calib_a = 0;
            bool   found_a;

            found_a = Helpers.GetDouble(option_str, "calC0:", start_p, out calib_a);
            double calib_b = 0;
            bool   found_b;

            found_b = Helpers.GetDouble(option_str, "calC1:", start_p, out calib_b);
            double calib_c = 0;
            bool   found_c;

            found_c = Helpers.GetDouble(option_str, "calC2:", start_p, out calib_c);

            Helpers.GetDouble(option_str, "chirpStartFrequency:", start_p, out low_mass_frequency);

            if (Helpers.GetInt16(option_str, "detectType:analyzer", start_p, out short_bluff))
            {
                calib_b = calib_b * Math.Abs(anal_trap_voltage);
            }
            else
            {
                calib_b = calib_b * Math.Abs(source_trap_voltage);
            }

            if (calibration_type == 2)
            {
                //  Call ErrorMess.LogError("Warning, type 2 calibration, make sure intensity option is defined in calibration generation dialog!", ps.FileName)
                calib_c = calib_c * Math.Abs(anal_trap_voltage);
            }

            if (calib_a == 0 && calib_b == 0 && calib_c == 0)
            {
                //no header cal data found, use defaults!
                //Call ErrorMess.LogError("No calibration data in file, using defaults...", ps.FileName)
                calib_a = 108205311.2284;
                calib_b = -1767155067.018;
                calib_c = 29669467490280;
            }
            menm_calibration_type = (CalibrationType)calibration_type;

            var calib = new Calibrations.Calibrator(menm_calibration_type);

            calib.NumPointsInScan  = this.mint_num_points_in_scan;
            calib.LowMassFrequency = low_mass_frequency;
            calib.SampleRate       = sample_rate;
            calib.SetCalibrationEquationParams(calib_a, calib_b, calib_c);
            SetCalibrator(calib);
        }
Example #3
0
        private bool LoadFile(string f_name, int scan_num)
        {
            const int flt_size = sizeof(float);

            using (var fin = new FileStream(f_name, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                //std.ifstream fin(f_name, std.ios.binary);
                var found_data = ReadHeader(fin);
                if (!found_data)
                {
                    fin.Close();
                    return(false);
                }
                var pos = fin.Position;
                if (mint_allocated_size < mint_num_points_in_scan)
                {
                    mint_allocated_size = mint_num_points_in_scan;
                    if (mptr_data != null)
                    {
                        mptr_data      = null;
                        mptr_data_copy = null;
                    }
                    mptr_data      = new float[mint_num_points_in_scan];
                    mptr_data_copy = new float[mint_num_points_in_scan];
                }
                fin.ReadByte();
                pos = fin.Position;
                fin.Flush();
                fin.Seek(pos, SeekOrigin.Begin);
                var buffer   = new byte[mint_num_points_in_scan * flt_size];
                var num_read = fin.Read(buffer, 0, mint_num_points_in_scan * flt_size);
                //Buffer.BlockCopy(buffer, 0, mptr_data, 0, mint_num_points_in_scan * flt_size);
                Buffer.BlockCopy(buffer, 0, mptr_data, 0, num_read);
            }
            var       max_intensity = -1 * double.MaxValue;
            var       min_intensity = double.MaxValue;
            const int interval_size = 2000;
            var       skip          = (mint_num_points_in_scan - 1) / interval_size + 1;
            var       max_side      = true; // to take reading from max size.

            for (var i = 0; i < mint_num_points_in_scan; i += skip)
            {
                var current_max_intensity = -1 * double.MaxValue;
                var current_min_intensity = double.MaxValue;

                for (var j = i; j < mint_num_points_in_scan && j < i + skip; j++)
                {
                    if (current_max_intensity < mptr_data[j])
                    {
                        current_max_intensity = mptr_data[j];
                    }
                    if (current_min_intensity > mptr_data[j])
                    {
                        current_min_intensity = mptr_data[j];
                    }
                }
                double current_intensity;

                if (max_side)
                {
                    current_intensity = current_max_intensity;
                    max_side          = false;
                }
                else
                {
                    current_intensity = current_min_intensity;
                    max_side          = true;
                }

                if (max_intensity < current_intensity)
                {
                    max_intensity = current_intensity;
                }
                if (min_intensity > current_intensity)
                {
                    min_intensity = current_intensity;
                }
            }
            mdbl_signal_range = (max_intensity - min_intensity);

            if (mbln_tic_file)
            {
                menm_calibration_type = (CalibrationType)5;
            }

            if (menmApodizationType != ApodizationType.NOAPODIZATION)
            {
                Engine.Utilities.Apodization.Apodize(mdbl_apodization_min_x, mdbl_apodization_max_x,
                                                     mdbl_sample_rate, false, menmApodizationType, mptr_data, mint_num_points_in_scan,
                                                     mint_apodization_apex_percent);
            }

            if (mshort_num_zeros != 0)
            {
                mint_allocated_size = mint_num_points_in_scan * (1 << mshort_num_zeros);
                var temp = new float[mint_allocated_size];
                Buffer.BlockCopy(mptr_data, 0, temp, 0, mint_num_points_in_scan * sizeof(float));
                for (var zeroIndex = mint_num_points_in_scan;
                     zeroIndex < mint_allocated_size;
                     zeroIndex++)
                {
                    temp[zeroIndex] = 0;
                }
                if (mptr_data != null)
                {
                    mptr_data      = null;
                    mptr_data_copy = null;
                }
                mptr_data      = temp;
                mptr_data_copy = new float[mint_allocated_size];
            }

            if (!mbln_use_specified_calibration || mobj_calibrator == null)
            {
                var calib = new Calibrations.Calibrator(menm_calibration_type);
                calib.NumPointsInScan  = mint_num_points_in_scan;
                calib.LowMassFrequency = mdbl_low_mass_freq;
                calib.SampleRate       = mdbl_sample_rate;

                //[gord] this hack is meant to reverse the sign of calibrationConstantB, resulting in the correct
                //m/z calculation for CalibrationType 9
                if (menm_calibration_type == (CalibrationType)9)
                {
                    mdbl_calib_const_b = -1 * mdbl_calib_const_b;
                }

                calib.SetCalibrationEquationParams(mdbl_calib_const_a, mdbl_calib_const_b, mdbl_calib_const_c);
                SetCalibrator(calib);
            }
            else
            {
                mobj_calibrator.NumPointsInScan  = mint_num_points_in_scan;
                mobj_calibrator.LowMassFrequency = mdbl_low_mass_freq;
                mobj_calibrator.SampleRate       = mdbl_sample_rate;
            }

            return(true);
        }
Example #4
0
 public virtual void SetCalibrator(Calibrations.Calibrator calib)
 {
     mobj_calibrator = calib;
 }
Example #5
0
        protected RawData()
        {
#if Enable_Obsolete
            mobj_calibrator = null;
#endif
        }
Example #6
0
        private int FindHeaderParams()
        {
            string line;
            string sub;
            var    pos        = 0;
            double ML1        = 0;
            double ML2        = 0;
            double SW_h       = 0;
            double FR_low     = 0;
            var    byte_order = 0;
            var    TD         = 0;
            var    NF         = 0;

            if (!File.Exists(marr_headerName))
            {
                return(-1); // File does not exist!
            }
            // Open header
            using (
                var acqusHeader =
                    new StreamReader(new FileStream(marr_headerName, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                // Read first line
                while (!acqusHeader.EndOfStream)
                {
                    line = acqusHeader.ReadLine();
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    // Find the name,value pair within the acqus header file.
                    if ((pos = line.IndexOf("##$ML1= ", StringComparison.InvariantCulture)) != -1)
                    {
                        pos += 7;
                        ML1  = double.Parse(line.Substring(pos, line.Length - pos - 1));
                    }
                    if ((pos = line.IndexOf("##$ML2= ", StringComparison.InvariantCulture)) != -1)
                    {
                        pos += 7;
                        ML2  = double.Parse(line.Substring(pos, line.Length - pos - 1));
                    }
                    if ((pos = line.IndexOf("##$SW_h= ", StringComparison.InvariantCulture)) != -1)
                    {
                        pos += 8;
                        SW_h = double.Parse(line.Substring(pos, line.Length - pos - 1));
                    }
                    if ((pos = line.IndexOf("##$BYTORDA= ", StringComparison.InvariantCulture)) != -1)
                    {
                        pos       += 12;
                        byte_order = int.Parse(line.Substring(pos, line.Length - pos - 1));
                    }
                    if ((pos = line.IndexOf("##$TD= ", StringComparison.InvariantCulture)) != -1)
                    {
                        pos += 6;
                        TD   = int.Parse(line.Substring(pos, line.Length - pos - 1));
                    }
                    if ((pos = line.IndexOf("##$FR_low= ", StringComparison.InvariantCulture)) != -1)
                    {
                        pos   += 9;
                        FR_low = double.Parse(line.Substring(pos, line.Length - pos - 1));
                    }
                    if ((pos = line.IndexOf("##$NF= ", StringComparison.InvariantCulture)) != -1)
                    {
                        pos += 6;
                        NF   = int.Parse(line.Substring(pos, line.Length - pos - 1));
                    }
                }

                mint_num_spectra = NF;
                // Done.
            }

            // It's in ICR-2LS...
            SW_h *= 2.0;
            if (SW_h > FR_low)
            {
                FR_low = 0.0;
            }

            var calib = new Calibrations.Calibrator(CalibrationType.A_OVER_F_PLUS_B);

            SetDataSize(TD);
            calib.NumPointsInScan  = TD;
            calib.LowMassFrequency = FR_low;
            calib.SampleRate       = SW_h;
            calib.SetCalibrationEquationParams(ML1, ML2, 0.0);
            SetCalibrator(calib);

            return(0); // success

            //[gord] delete later - this has been moved to method: GetNumSpectraFromFileSizeInfo, called elsewhere
            //// Now we need to get the size of the data so we can find out the number of scans.
            //int fh;
            //fh = _open(marr_serName, _O_RDONLY | _O_BINARY );
            //if (fh ==  ENOENT || fh == -1 )
            //{
            //  // try using the fid extention instead of the .ser business.
            //  int len = strlen(marr_serName);
            //  marr_serName[len-3] = 'f';
            //  marr_serName[len-2] = 'i';
            //  marr_serName[len-1] = 'd';
            //  fh = _open(marr_serName, _O_RDONLY | _O_BINARY );
            //}
            ///* Seek the beginning of the file: */
            //__int64 pos64 = 0;
            //pos64 = _lseeki64(fh, 0, SEEK_END );
            //__int64       blockSizeInBytes = (__int64) (sizeof(int) * mint_num_points_in_scan);
            //mint_num_spectra = (int)((pos64+2) / blockSizeInBytes); // add 2 just in case we have an exact multiple - 1.

            //_close( fh );
        }