Ejemplo n.º 1
0
        private ThreeAxisFITSCubeFrameStream(
            string fileName, Fits fitsFile, BufferedFile bufferedFile, BasicHDU imageHDU,
            FITSTimeStampReader timeStampReader,
            int widthIndex, int heightIndex, int frameIndex,
            short minPixelValue, uint maxPixelValue, int bitPix, int negPixCorrection)
        {
            m_FileName = fileName;

            bool   isMidPoint;
            double?exposureSecs;
            var    startExposure = timeStampReader.ParseExposure(null, imageHDU.Header, out isMidPoint, out exposureSecs);

            if (startExposure.HasValue && exposureSecs.HasValue)
            {
                m_ExposureSeconds   = exposureSecs.Value;
                m_FirstFrameMidTime = startExposure.Value;
            }

            m_MinPixelValue = minPixelValue;
            m_MaxPixelValue = maxPixelValue;
            m_Bpp           = bitPix;

            m_FitsFile        = fitsFile;
            m_TimeStampReader = timeStampReader;

            m_BufferedFile = bufferedFile;
            m_ImageHDU     = imageHDU;

            m_HeightIndex = heightIndex;
            m_WidthIndex  = widthIndex;
            m_FrameIndex  = frameIndex;

            m_NumFrames = m_ImageHDU.Axes[frameIndex];
            m_Height    = m_ImageHDU.Axes[heightIndex];
            m_Width     = m_ImageHDU.Axes[widthIndex];

            m_ArrayData        = (Array)m_ImageHDU.Data.DataArray;
            m_BZero            = FITSHelper2.GetBZero(m_ImageHDU);
            m_NegPixCorrection = negPixCorrection;

            m_Cards = new Dictionary <string, string>();
            var cursor = m_ImageHDU.Header.GetCursor();

            while (cursor.MoveNext())
            {
                HeaderCard card = m_ImageHDU.Header.FindCard((string)cursor.Key);
                if (card != null && !string.IsNullOrWhiteSpace(card.Key) && card.Key != "END")
                {
                    if (m_Cards.ContainsKey(card.Key))
                    {
                        m_Cards[card.Key] += "\r\n" + card.Value;
                    }
                    else
                    {
                        m_Cards.Add(card.Key, card.Value);
                    }
                }
            }


            HasUTCTimeStamps = startExposure.HasValue;

            VideoFileType = string.Format("FITS.{0}::Cube3D", bitPix);
        }
Ejemplo n.º 2
0
        public frmChooseTimeHeaders(string fileName, string filesHash, VideoController videoController)
            : this()
        {
            m_VideoController = videoController;

            FITSData fitsData;

            m_VideoController.SetCursor(Cursors.WaitCursor);
            try
            {
                fitsData = FITSHelper2.LoadFitsFile(fileName, null, 0);

                BZero           = FITSHelper2.GetBZero(fitsData.HDU);
                m_BelowZeroCorr = Math.Max(BZero, Math.Abs(fitsData.PixelStats.MinPixelValue) - BZero);

                fitsData = FITSHelper2.LoadFitsFile(fileName, null, BZero - m_BelowZeroCorr);
            }
            finally
            {
                m_VideoController.SetCursor(Cursors.Default);
            }

            m_FilesHash = filesHash;

            var hasher = new SHA1CryptoServiceProvider();

            hasher.Initialize();
            var orderedCardNames = new List <string>();

            var cursor = fitsData.HDU.Header.GetCursor();

            while (cursor.MoveNext())
            {
                var card = fitsData.HDU.Header.FindCard((string)cursor.Key);
                if (card != null)
                {
                    m_AllCards.Add(new HeaderEntry(card));
                }
                orderedCardNames.Add((string)cursor.Key);
            }

            orderedCardNames.Sort();
            byte[] combinedCardNamesBytes = Encoding.UTF8.GetBytes(string.Join("|", orderedCardNames));
            var    hash = hasher.ComputeHash(combinedCardNamesBytes, 0, combinedCardNamesBytes.Length);

            m_CardNamesHash = Convert.ToBase64String(hash);

            cbxExposure.Items.AddRange(m_AllCards.ToArray());

            cbxExposureUnits.Items.Clear();
            cbxExposureUnits.Items.AddRange(Enum.GetNames(typeof(TangraConfig.ExposureUnit)));
            cbxExposureUnits.SelectedIndex = 0;

            m_TimeStampHelper = new FitsTimestampHelper(m_FilesHash, m_AllCards, UseRecentFITSConfig);
            ucTimestampControl.Initialise(m_AllCards, m_FilesHash, m_CardNamesHash, m_TimeStampHelper);
            ucTimestampControl2.Initialise(m_AllCards, m_FilesHash, m_CardNamesHash, m_TimeStampHelper);
            ucTimestampControl2.SetTimeStampType(TangraConfig.TimeStampType.EndExposure, false);
            m_TimeStampHelper.TryIdentifyPreviousConfigApplyingForCurrentFiles();

            if (fitsData.PixelStats.HasNegativePixels)
            {
                NegPixCorrection = fitsData.PixelStats.MinPixelValue;
            }
            else
            {
                // No requirement to review the pixel mapping if there are no negative pixels
                // We can go with the defaults
                m_PixelMappingReviewed = true;
                NegPixCorrection       = 0;
            }

            Pixels            = fitsData.PixelsFlat;
            MinPixelValue     = fitsData.PixelStats.MinPixelValue;
            MaxPixelValue     = fitsData.PixelStats.MaxPixelValue;
            HasNegativePixels = fitsData.PixelStats.HasNegativePixels;
            BitPix            = fitsData.PixelStats.BitPix;
        }