コード例 #1
0
        private FITSFileSequenceStream(string[] fitsFiles, FITSTimeStampReader timeStampReader, bool zeroOutNegativeValues, out bool hasNegativePixels)
        {
            m_FitsFilesList.AddRange(fitsFiles);

            FirstFrame = 0;
            LastFrame = m_FitsFilesList.Count - 1;
            CountFrames = m_FitsFilesList.Count;
            m_ZeroOutNegativePixels = zeroOutNegativeValues;
            m_TimeStampReader = timeStampReader;

            uint[] pixelsFlat;
            int width;
            int height;
            int bpp;
            DateTime? timestamp;
            double? exposure;
            uint minPixelValue;
            uint maxPixelValue;

            FITSHelper.Load16BitFitsFile(m_FitsFilesList[0], m_TimeStampReader, zeroOutNegativeValues, null, out pixelsFlat, out width, out height, out bpp, out timestamp, out exposure, out minPixelValue, out maxPixelValue, out hasNegativePixels);

            m_MinPixelValueFirstImage = minPixelValue;
            m_MaxPixelValueFirstImage = maxPixelValue;

            Width = width;
            Height = height;
            BitPix = bpp;

            HasUTCTimeStamps = timestamp.HasValue;

            VideoFileType = string.Format("FITS.{0}::SEQ", bpp);
        }
コード例 #2
0
ファイル: frmSortFitsFiles.cs プロジェクト: hpavlov/tangra3
        private void frmSortFitsFiles_Shown(object sender, EventArgs e)
        {
            m_FitsHeaders = new Header[m_FitsFiles.Length];
            m_FitsTimestamps = new DateTime?[m_FitsFiles.Length];

            pbar.Minimum = 0;
            pbar.Maximum = m_FitsFiles.Length;
            pbar.Value = 0;

            var fileSizeInfo = new Dictionary<string, FitsFileFormatInfoRecord>();
            TimeStampReader = null;

            for (int i = 0; i < m_FitsFiles.Length; i++)
            {
                try
                {
                    using (BufferedFile bf = new BufferedFile(m_FitsFiles[i], FileAccess.Read, FileShare.ReadWrite))
                    {
                        Header hdr = Header.ReadHeader(bf);
                        m_FitsHeaders[i] = hdr;

                        int numAxis = -1;
                        int width = -1;
                        int height = -1;
                        int.TryParse(hdr.FindCard("NAXIS") != null ? hdr.FindCard("NAXIS").Value : "0", out numAxis);
                        int.TryParse(hdr.FindCard("NAXIS1") != null ? hdr.FindCard("NAXIS1").Value : "0", out width);
                        int.TryParse(hdr.FindCard("NAXIS2") != null ? hdr.FindCard("NAXIS2").Value : "0", out height);
                        string format = String.Format("{0} x {1}", width, height);
                        if (fileSizeInfo.ContainsKey(format))
                            fileSizeInfo[format].NumFiles++;
                        else
                            fileSizeInfo.Add(format, new FitsFileFormatInfoRecord { FirstFile = Path.GetFileName(m_FitsFiles[i]), NumFiles = 1 });

                        bool isMidPoint;
                        double? fitsExposure = null;
                        DateTime? timestamp = null;
                        try
                        {
                            timestamp = FITSHelper.ParseExposure(hdr, TimeStampReader, out isMidPoint, out fitsExposure);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex.ToString());
                        }

                        if (i == 0 && (!fitsExposure.HasValue || !timestamp.HasValue))
                        {
                            var frm = new frmChooseTimeHeaders(hdr, GetOrderedFitsFileHash());
                            if (frm.ShowDialog(this) == DialogResult.OK)
                            {
                                TimeStampReader = frm.TimeStampReader;
                            }

                            try
                            {
                                timestamp = FITSHelper.ParseExposure(hdr, TimeStampReader, out isMidPoint, out fitsExposure);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(ex.ToString());
                            }
                        }

                        m_FitsTimestamps[i] = timestamp;

                        if (timestamp != null && fitsExposure.HasValue)
                            m_FilesWithExposure++;
                        else
                            m_FilesWithoutExposure++;
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format("Error processing FITS files: {0}", m_FitsFiles[i]), ex);
                }

                pbar.Value = i;
                Application.DoEvents();
            }

            pbar.Value = pbar.Minimum;
            Application.DoEvents();

            if (fileSizeInfo.Count > 1)
            {
                var errorInfo = new StringBuilder();
                foreach (string key in fileSizeInfo.Keys)
                {
                    if (fileSizeInfo[key].NumFiles > 1)
                        errorInfo.AppendFormat("'{1}' and {2} other files: {0}\r\n", key, fileSizeInfo[key].FirstFile, fileSizeInfo[key].NumFiles - 1);
                    else
                        errorInfo.AppendFormat("'{1}' (single file): {0}\r\n", key, fileSizeInfo[key].FirstFile);
                }
                ErrorMessage = string.Format("Cannot load FITS file sequence because there are files with different image dimentions:\r\n\r\n{0}\r\n\r\nPlease ensure that all files in the directory have the same dimention (number of axis).", errorInfo.ToString());

            }
            timer1.Enabled = true;
        }
コード例 #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (rbTimeDuration.Checked)
            {
                if (!m_TimeStampMappingValid)
                {
                    MessageBox.Show("Please choose valid settings for the time timestamp.");
                    return;
                }

                if (!m_ExposureValid)
                {
                    MessageBox.Show("Please choose valid settings for the exposure.");
                    return;
                }

                if (cbxExposureUnits.SelectedIndex == -1)
                {
                    MessageBox.Show("Please choose exposure units.");
                    cbxExposureUnits.Focus();
                    return;
                }

                if (cbxTimestampType.SelectedIndex == -1)
                {
                    MessageBox.Show("Please choose timestamp type.");
                    cbxTimestampType.Focus();
                    return;
                }

                var config = new TangraConfig.FITSFieldConfig()
                {
                    ExposureHeader = cbxExposure.Text,
                    ExposureUnit = (TangraConfig.ExposureUnit) cbxExposureUnits.SelectedIndex,
                    TimeStampType = (TangraConfig.TimeStampType) cbxTimestampType.SelectedIndex,
                    TimeStampHeader = cbxTimeStamp.Text,
                    TimeStampFormat = cbxTimeStampFormat.Text,
                    IsTimeStampAndExposure = true
                };

                TimeStampReader = new FITSTimeStampReader(config);

                config.FileHash = m_FilesHash;
                config.CardNamesHash = m_CardNamesHash;
                TangraConfig.Settings.RecentFITSFieldConfig.Register(config);
                TangraConfig.Settings.Save();

                DialogResult = DialogResult.OK;
                Close();
            }
            else if (rbStartEndTimestamp.Checked)
            {
                if (!m_TimeStampMappingValid)
                {
                    MessageBox.Show("Please choose valid settings for the start time timestamp.");
                    return;
                }

                if (!m_TimeStamp2MappingValid)
                {
                    MessageBox.Show("Please choose valid settings for the end time timestamp.");
                    return;
                }

                var config = new TangraConfig.FITSFieldConfig()
                {
                    TimeStampHeader = cbxTimeStamp.Text,
                    TimeStampFormat = cbxTimeStampFormat.Text,
                    TimeStamp2Header = cbxTimeStamp2.Text,
                    TimeStamp2Format = cbxTimeStamp2Format.Text,
                    IsTimeStampAndExposure = false
                };

                TimeStampReader = new FITSTimeStampReader(config);

                config.FileHash = m_FilesHash;
                config.CardNamesHash = m_CardNamesHash;
                TangraConfig.Settings.RecentFITSFieldConfig.Register(config);
                TangraConfig.Settings.Save();

                DialogResult = DialogResult.OK;
                Close();
            }
        }
コード例 #4
0
        public static FITSFileSequenceStream OpenFolder(string[] fitsFiles, FITSTimeStampReader timeStampReader, bool zeroOutNegativeValues, out bool hasNegativePixels)
        {
            UsageStats.Instance.ProcessedFitsFolderFiles++;
            UsageStats.Instance.Save();

            var rv = new FITSFileSequenceStream(fitsFiles, timeStampReader, zeroOutNegativeValues, out hasNegativePixels);
            rv.FileName = Path.GetDirectoryName(fitsFiles[0]);
            return rv;
        }