public static void Write(double[,,] img, string file = "Outputfile") { for (int k = 0; k < img.GetLength(0); k++) { var img2 = new double[img.GetLength(1)][]; for (int i = 0; i < img2.Length; i++) { var gg2 = new double[img.GetLength(2)]; img2[i] = gg2; for (int j = 0; j < img.GetLength(2); j++) { gg2[j] = img[k, i, j]; } } var f = new Fits(); var hhdu = FitsFactory.HDUFactory(img2); f.AddHDU(hhdu); using (BufferedDataStream fstream = new BufferedDataStream(new FileStream(file + k + ".fits", FileMode.Create))) { f.Write(fstream); } } }
internal void SaveFitsFrame(string fileName, int width, int height, uint[] framePixels, DateTime timeStamp, float exposureSeconds) { Fits f = new Fits(); object data = SaveImageData(width, height, framePixels); BasicHDU imageHDU = Fits.MakeHDU(data); nom.tam.fits.Header hdr = imageHDU.Header; hdr.AddValue("SIMPLE", "T", null); hdr.AddValue("BITPIX", 32, null); hdr.AddValue("NAXIS", 2, null); hdr.AddValue("NAXIS1", width, null); hdr.AddValue("NAXIS2", height, null); hdr.AddValue("NOTES", m_Note, null); hdr.AddValue("EXPOSURE", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), "Exposure, seconds"); hdr.AddValue("DATE-OBS", timeStamp.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture), m_DateObsComment); hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), "Tangra version"); hdr.AddValue("END", null, null); f.AddHDU(imageHDU); // Write a FITS file. using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite)) { f.Write(bf); bf.Flush(); } }
static void writeImage(string fileName, Int16[][] img, Header header) { Fits f = new Fits(); BufferedDataStream s = new BufferedDataStream(new FileStream(fileName, FileMode.Create)); //BufferedFile s = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite); BasicHDU h = FitsFactory.HDUFactory(img); Header hdr = h.Header; f.AddHDU(h); f.Write(s); }
public void saveImageToFitsForSolveOnly(string path, imageInfo image, Array imgArray) { var imageData = (Array)ArrayFuncs.Flatten(imgArray); const double bZero = 0; const double bScale = 1.0; if (image.MaxADU <= 65535) { //bZero = 32768; //imageData = (ushort[])ArrayFuncs.ConvertArray(imageData, typeof(ushort)); } int[] dims = ArrayFuncs.GetDimensions(imgArray); // put the image data in a basic HDU of the fits BasicHDU imageHdu = FitsFactory.HDUFactory(ArrayFuncs.Curl(imageData, dims)); // Add the other fits fields to the HDU imageHdu.AddValue("BZERO", bZero, ""); imageHdu.AddValue("BSCALE", bScale, ""); imageHdu.AddValue("DATAMIN", 0.0, ""); // should this reflect the actual data values imageHdu.AddValue("DATAMAX", image.MaxADU, "pixel values above this level are considered saturated."); imageHdu.AddValue("DATE-OBS", image.LastExposureStartTime, ""); imageHdu.AddValue("XPIXSZ", image.PixelSizeX * image.BinX, "physical X dimension of the sensor's pixels in microns"); // (present only if the information is provided by the camera driver). Includes binning. imageHdu.AddValue("YPIXSZ", image.PixelSizeY * image.BinY, "physical Y dimension of the sensor's pixels in microns"); // (present only if the information is provided by the camera driver). Includes binning. imageHdu.AddValue("XBINNING", image.BinX, ""); imageHdu.AddValue("YBINNING", image.BinY, ""); imageHdu.AddValue("OBJCTRA", image.RA, "Approximate Right Ascension of image centre"); imageHdu.AddValue("OBJCTDEC", image.Dec, "Approximate Declination of image centre"); // save it var fitsImage = new Fits(); fitsImage.AddHDU(imageHdu); //Adds the actual image data (the header info already exists in imageHDU) FileStream fs = null; try { fs = new FileStream(path, FileMode.Create); using (var bds = new BufferedDataStream(fs)) { fs = null; fitsImage.Write(bds); } } finally { if (fs != null) { fs.Dispose(); } } }
internal static void SaveDarkOrFlatFrame(string fileName, int width, int height, string notes, float[,] averagedData, float exposureSeconds, int numFrames) { Fits f = new Fits(); object data = SaveImageData(width, height, averagedData); BasicHDU imageHDU = Fits.MakeHDU(data); nom.tam.fits.Header hdr = imageHDU.Header; hdr.AddValue("SIMPLE", "T", null); hdr.AddValue("BITPIX", -32 /* Floating Point Data*/, null); hdr.AddValue("NAXIS", 2, null); hdr.AddValue("NAXIS1", width, null); hdr.AddValue("NAXIS2", height, null); if (notes.Length > HeaderCard.MAX_VALUE_LENGTH) { notes = notes.Substring(0, HeaderCard.MAX_VALUE_LENGTH); } hdr.AddValue("NOTES", notes, null); if (exposureSeconds > 0) { hdr.AddValue("EXPOSURE", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), null); hdr.AddValue("EXPTIME", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), null); } hdr.AddValue("SNAPSHOT", numFrames.ToString(), null); hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), null); if (TangraConfig.Settings.Generic.ReverseGammaCorrection) { hdr.AddValue("TANGAMMA", TangraConfig.Settings.Photometry.EncodingGamma.ToString("0.0000", CultureInfo.InvariantCulture), null); } if (TangraConfig.Settings.Generic.ReverseCameraResponse) { hdr.AddValue("TANCMRSP", ((int)TangraConfig.Settings.Photometry.KnownCameraResponse).ToString(CultureInfo.InvariantCulture), null); } f.AddHDU(imageHDU); // Write a FITS file. using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite)) { f.Write(bf); bf.Flush(); } }
// Make FITS file public void MakeFile(string FileName, float[][] ImgArray) { //Create a FITS file from an image: Fits f = new Fits(); //BasicHDU h = FitsFactory.HDUFactory(ImgArray); BasicHDU h = Fits.MakeHDU(ImgArray); Header hdr = h.Header; //添加关键字 hdr.AddValue("OBS2", "hss", "Observer"); f.AddHDU(h); BufferedDataStream bf = new BufferedDataStream(new FileStream(FileName, FileMode.Create)); f.Write(bf); bf.Flush(); bf.Close(); }
internal void SaveFitsFrame(string fileName, Header header, int width, int height, object data) { Fits f = new Fits(); BasicHDU imageHDU = Fits.MakeHDU(data); nom.tam.fits.Header hdr = imageHDU.Header; hdr.AddValue("SIMPLE", "T", null); hdr.AddValue("BZERO", 0, null); hdr.AddValue("BSCALE", 1, null); hdr.AddValue("NAXIS", 2, null); hdr.AddValue("NAXIS1", width, null); hdr.AddValue("NAXIS2", height, null); string[] RESERVED_KEYS = new string[] { "SIMPLE", "NAXIS", "NAXIS1", "NAXIS2", "BZERO", "BSCALE", "END" }; var cursor = header.GetCursor(); while (cursor.MoveNext()) { HeaderCard card = header.FindCard((string)cursor.Key); if (card != null && !string.IsNullOrWhiteSpace(card.Key) && !RESERVED_KEYS.Contains(card.Key)) { hdr.AddValue(card.Key, card.Value, card.Comment); } } hdr.AddValue("NOTES", m_Note, null); hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), "Tangra version"); hdr.AddValue("END", null, null); f.AddHDU(imageHDU); // Write a FITS file. using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite)) { f.Write(bf); bf.Flush(); } }
public void WriteFrameImpl(IntPtr intPtr, int p, RawFrameInfo info) { object data = MarshalToCLR(intPtr, p); Fits fits = new Fits(); BasicHDU hdu = FitsFactory.HDUFactory(data); if ((data is short[][] || data is short[][][]) && _significantBitDepth > 8) { hdu.AddValue("BZERO", 32768.0, ""); } AddMetadataToFrame(info, hdu); fits.AddHDU(hdu); using (FileStream fs = File.Create(Path.GetTempFileName())) { using (BufferedDataStream f = new BufferedDataStream(fs)) { fits.Write(f); } } }
public static void Save(string strFile) { float[][] x = new float[30][]; for (int i = 0; i < x.Length; i++) { x[i] = new float[30]; for (int j = 0; j < x[i].Length; j++) { x[i][j] = 3; } } bool t = typeof(Array).Equals(x.GetType()); Fits f = new Fits(); Header hdr = new Header(); hdr.Bitpix = 8; hdr.Simple = true; hdr.Naxes = 2; hdr.AddValue("NAXIS1", 30, ""); hdr.AddValue("NAXIS2", 30, ""); FitsFactory.UseAsciiTables = false; Data d = FitsFactory.DataFactory(hdr); BasicHDU h = FitsFactory.HDUFactory(x); f.addHDU(h); FileStream os = new FileStream(strFile, FileMode.Create); f.Write(os); }
public static void Write <T>(T[,] img, string file = "Outputfile.fits") { var img2 = new T[img.GetLength(0)][]; for (int i = 0; i < img2.Length; i++) { var row = new T[img.GetLength(1)]; img2[i] = row; for (int j = 0; j < img.GetLength(1); j++) { row[j] = img[i, j]; } } var f = new Fits(); var hhdu = FitsFactory.HDUFactory(img2); f.AddHDU(hhdu); using (BufferedDataStream fstream = new BufferedDataStream(new FileStream(file, FileMode.Create))) { f.Write(fstream); } }
public static void WriteImag(Complex[,] img, string file = "Outputfile_imag.fits") { var img2 = new double[img.GetLength(0)][]; for (int i = 0; i < img2.Length; i++) { var gg2 = new double[img.GetLength(1)]; img2[i] = gg2; for (int j = 0; j < img.GetLength(1); j++) { gg2[j] = img[i, j].Imaginary; } } var f = new Fits(); var hhdu = FitsFactory.HDUFactory(img2); f.AddHDU(hhdu); using (BufferedDataStream fstream = new BufferedDataStream(new FileStream(file, FileMode.Create))) { f.Write(fstream); } }
internal void SaveFitsFrame(int frameNo, string fileName, int width, int height, uint[] framePixels, DateTime timeStamp, float exposureSeconds) { Fits f = new Fits(); object data = m_ExportAs8BitFloat ? (object)SaveNormalizedFloatImageData(width, height, framePixels) : (object)SaveImageData(width, height, framePixels); BasicHDU imageHDU = Fits.MakeHDU(data); nom.tam.fits.Header hdr = imageHDU.Header; hdr.AddValue("SIMPLE", "T", null); hdr.AddValue("BITPIX", m_ExportAs8BitFloat ? -32 : 32, null); hdr.AddValue("BZERO", 0, null); hdr.AddValue("BSCALE", 1, null); hdr.AddValue("NAXIS", 2, null); hdr.AddValue("NAXIS1", width, null); hdr.AddValue("NAXIS2", height, null); hdr.AddValue("EXPOSURE", exposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), "Exposure, seconds"); hdr.AddValue("DATE-OBS", timeStamp.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture), m_DateObsComment); hdr.AddValue("CAMERA", m_VideoCamera, "Video camera model (observer specified)"); hdr.AddValue("FILENAME", m_VideoController.FileName, null); hdr.AddValue("FRAMENO", frameNo, null); if (m_VideoFormat == VideoFileFormat.AAV || m_VideoFormat == VideoFileFormat.AAV2) { hdr.AddValue("NOTES", "No instrumental delay has been applied to DATE-OBS.", null); if (m_ExportAs8BitFloat) { hdr.AddValue("VIDEOFMT", m_NativeFormat, "Native analogue video format"); if (m_IntegrationRate > 0) { hdr.AddValue("INTGRRTE", m_IntegrationRate.ToString(), "Integration rate in video frames"); } } } else { hdr.AddValue("NOTES", string.Format("Converted from {0} file.", m_VideoFormat), null); } foreach (var kvp in m_AdditionalFileHeaders) { hdr.AddValue(kvp.Key, kvp.Value.Item1, kvp.Value.Item2); } hdr.AddValue("TANGRAVE", string.Format("{0} v{1}", VersionHelper.AssemblyProduct, VersionHelper.AssemblyFileVersion), "Tangra version"); hdr.AddValue("END", null, null); f.AddHDU(imageHDU); // Write a FITS file. using (BufferedFile bf = new BufferedFile(fileName, FileAccess.ReadWrite, FileShare.ReadWrite)) { f.Write(bf); bf.Flush(); } }
public void saveImageToFits(string path, clsSharedData sd) { var imageData = (Array)ArrayFuncs.Flatten(sd.imgArray); const double bZero = 0; const double bScale = 1.0; if (sd.theImage.MaxADU <= 65535) { //bZero = 32768; //imageData = (ushort[])ArrayFuncs.ConvertArray(imageData, typeof(ushort)); } int[] dims = ArrayFuncs.GetDimensions(sd.imgArray); //Array image = ArrayFuncs.Curl(imageData, dims); // put the image data in a basic HDU of the fits BasicHDU imageHdu = FitsFactory.HDUFactory(ArrayFuncs.Curl(imageData, dims)); // put the other data in the HDU imageHdu.AddValue("BZERO", bZero, ""); imageHdu.AddValue("BSCALE", bScale, ""); imageHdu.AddValue("DATAMIN", 0.0, ""); // should this reflect the actual data values imageHdu.AddValue("DATAMAX", sd.theImage.MaxADU, "pixel values above this level are considered saturated."); imageHdu.AddValue("INSTRUME", sd.theImage.Description, ""); imageHdu.AddValue("EXPTIME", sd.theImage.LastExposureDuration, "duration of exposure in seconds."); imageHdu.AddValue("DATE-OBS", sd.theImage.LastExposureStartTime, ""); imageHdu.AddValue("XPIXSZ", sd.theImage.PixelSizeX * sd.theImage.BinX, "physical X dimension of the sensor's pixels in microns"); // (present only if the information is provided by the camera driver). Includes binning. imageHdu.AddValue("YPIXSZ", sd.theImage.PixelSizeY * sd.theImage.BinY, "physical Y dimension of the sensor's pixels in microns"); // (present only if the information is provided by the camera driver). Includes binning. imageHdu.AddValue("XBINNING", sd.theImage.BinX, ""); imageHdu.AddValue("YBINNING", sd.theImage.BinY, ""); imageHdu.AddValue("XORGSUBF", sd.theImage.StartX, "subframe origin on X axis in binned pixels"); imageHdu.AddValue("YORGSUBF", sd.theImage.StartY, "subframe origin on Y axis in binned pixels"); imageHdu.AddValue("CBLACK", (double)sd.theImage.Min, ""); imageHdu.AddValue("CWHITE", (double)sd.theImage.Max, ""); imageHdu.AddValue("SWCREATE", "Nite Ops", "string indicating the software used to create the file"); imageHdu.AddValue("OBJCTRA", sd.theImage.RA, "Approximate Right Ascension of image centre"); imageHdu.AddValue("OBJCTDEC", sd.theImage.Dec, "Approximate Declination of image centre"); imageHdu.AddValue("OBJCTALT", sd.theImage.Alt, "Approximate Altitude of image centre"); imageHdu.AddValue("OBJCTAZ", sd.theImage.Az, "Approximate Azimuth of image centre"); // extensions as specified by SBIG try { imageHdu.AddValue("CCD_TEMP", sd.theImage.CCDTemperature, "sensor temperature in degrees C"); // TODO sate this at the start of exposure . Absent if temperature is not available. } catch (Exception) { imageHdu.Info(); } if (sd.theImage.CanSetCCDTemperature) { imageHdu.AddValue("SET-TEMP", sd.theImage.SetCCDTemperature, "CCD temperature setpoint in degrees C"); } if (sd.theImage.objectName != "") { imageHdu.AddValue("OBJECT", sd.theImage.objectName, "The name of the object"); } else { imageHdu.AddValue("OBJECT", "Unknown", "The name of the object"); } imageHdu.AddValue("TELESCOP", Properties.Settings.Default.imaging_telescope, "Telescope used to acquire this image"); // user-entered information about the telescope used. imageHdu.AddValue("OBSERVER", Properties.Settings.Default.your_name, "Name of the observer"); // user-entered information; the observer’s name. //DARKTIME – dark current integration time, if recorded. May be longer than exposure time. imageHdu.AddValue("IMAGETYP", sd.theImage.frameType + " Frame", "Type of image"); //ISOSPEED – ISO camera setting, if camera uses ISO speeds. //JD_GEO – records the geocentric Julian Day of the start of exposure. //JD_HELIO – records the Heliocentric Julian Date at the exposure midpoint. //NOTES – user-entered information; free-form notes. //READOUTM – records the selected Readout Mode (if any) for the camera. //imageHdu.AddValue("SBSTDVER", "SBFITSEXT Version 1.0", "version of the SBIG FITS extensions supported"); // save it var fitsImage = new Fits(); fitsImage.AddHDU(imageHdu); //Adds the actual image data (the header info already exists in imageHDU) FileStream fs = null; try { fs = new FileStream(path, FileMode.Create); using (var bds = new BufferedDataStream(fs)) { fs = null; fitsImage.Write(bds); } } finally { if (fs != null) { fs.Dispose(); } } }