public void ReadByElement() { Fits f = null; try { f = new Fits(TestFileSetup.GetTargetFilename("at2.fits"), FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); for (int i = 0; i < data.NRows; i += 1) { Object[] row = (Object[])data.GetRow(i); for (int j = 0; j < data.NCols; j += 1) { Object val = data.GetElement(i, j); Assert.AreEqual(true, ArrayFuncs.ArrayEquals(val, row[j])); } } } finally { if (f != null) { f.Close(); } } }
public void ReadByRow() { Fits f = null; try { f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.Read); Object[] cols = GetSampleCols(); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); Console.WriteLine("Reading Table by Row"); for (int i = 0; i < data.NRows; i += 1) { Assert.AreEqual(50, data.NRows); Object[] row = (Object[])data.GetRow(i); Assert.AreEqual(1f, ((float[])cols[0])[i] / ((float[])row[0])[0], Math.Pow(10, -6)); Assert.AreEqual(((int[])cols[1])[i], ((int[])row[1])[0]); Assert.AreEqual(((long[])cols[2])[i], ((long[])row[2])[0]); Assert.AreEqual(1f, ((double[])cols[3])[i] / ((double[])row[3])[0], Math.Pow(10, -14)); String[] st = (String[])row[4]; st[0] = st[0].Trim(); Assert.AreEqual(((String[])cols[4])[i], ((String[])row[4])[0]); } } finally { if (f != null) { f.Close(); } } }
public void ReadByColumn() { Fits f = new Fits("at1.fits", FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); Object[] cols = GetSampleCols(); Assertion.AssertEquals("Number of rows", data.NRows, 50); Assertion.AssertEquals("Number of columns", data.NCols, 5); for (int j = 0; j < data.NCols; j += 1) { Object col = data.GetColumn(j); if (j == 4) { String[] st = (String[])col; for (int i = 0; i < st.Length; i += 1) { st[i] = st[i].Trim(); } } Assertion.AssertEquals("Ascii Columns:" + j, true, ArrayFuncs.ArrayEquals(cols[j], col, Math.Pow(10, -6), Math.Pow(10, -14))); } }
/// <summary> /// Create an ascii table header/data unit /// </summary> /// <param name="h">The template specifying the ascii table.</param> /// <param name="d"> The FITS data structure containing the table data.</param> /// <exception cref="FitsException"> FitsException if there was a problem with the header.</exception> public AsciiTableHDU(Header h, Data d) : base((TableData) d) { myHeader = h; data = (AsciiTable) d; myData = d; }
public void CreateByRow() { Fits f = null; try { f = new Fits(); AsciiTable data = new AsciiTable(); Object[] row = new Object[4]; System.Console.Out.WriteLine("\n\n**** Create a table column by Row ****"); for (int i = 0; i < 50; i += 1) { data.AddRow(GetRow(i)); } f.AddHDU(Fits.MakeHDU(data)); WriteFile(f, TestFileSetup.GetTargetFilename("at2.fits")); f.Close(); // Read it back. f = new Fits(TestFileSetup.GetTargetFilename("at2.fits"), FileAccess.Read); Object[] output = (Object[])f.GetHDU(1).Kernel; Object[] input = GetRowBlock(50); for (int i = 0; i < 50; i += 1) { String[] str = (String[])output[2]; String[] istr = (String[])input[2]; int len1 = str[1].Length; str[i] = str[i].Trim(); // The first row would have set the length for all the // remaining rows... if (istr[i].Length > len1) { istr[i] = istr[i].Substring(0, len1); } } for (int j = 0; j < 3; j += 1) { Assert.AreEqual(true, ArrayFuncs.ArrayEquals(input[j], output[j], Math.Pow(10, -6), Math.Pow(10, -14))); } } finally { if (f != null) { f.Close(); } } }
public void ReadByElement() { Fits f = new Fits("at2.fits", FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); for (int i = 0; i < data.NRows; i += 1) { Object[] row = (Object[])data.GetRow(i); for (int j = 0; j < data.NCols; j += 1) { Object val = data.GetElement(i, j); Assertion.AssertEquals("Ascii readElement", true, ArrayFuncs.ArrayEquals(val, row[j])); } } }
public void CreateByRow() { Fits f = new Fits(); AsciiTable data = new AsciiTable(); Object[] row = new Object[4]; System.Console.Out.WriteLine("\n\n**** Create a table column by Row ****"); for (int i = 0; i < 50; i += 1) { data.AddRow(GetRow(i)); } f.AddHDU(Fits.MakeHDU(data)); WriteFile(f, "at2.fits"); // Read it back. f = new Fits("at2.fits", FileAccess.Read); Object[] output = (Object[])f.GetHDU(1).Kernel; Object[] input = GetRowBlock(50); for (int i = 0; i < 50; i += 1) { String[] str = (String[])output[2]; String[] istr = (String[])input[2]; int len1 = str[1].Length; str[i] = str[i].Trim(); // The first row would have set the length for all the // remaining rows... if (istr[i].Length > len1) { istr[i] = istr[i].Substring(0, len1); } } for (int j = 0; j < 3; j += 1) { Assertion.AssertEquals("ByRow:" + j, true, ArrayFuncs.ArrayEquals(input[j], output[j], Math.Pow(10, -6), Math.Pow(10, -14))); } }
public static Data Encapsulate(Object o) { if (o != null && o.GetType().IsArray) { if (ArrayFuncs.IsArrayOfArrays(o)) { Array oo = (Array)o; AsciiTable d = new AsciiTable(); for (int i = 0; i < oo.Length; i += 1) { d.AddColumn(oo.GetValue(i)); } return(d); } else { throw new Exception("OOPS. FIX AsciiTableHDU.Encapsulate(Object o)."); } } return(null); }
public void ReadByRow() { Fits f = new Fits("at1.fits", FileAccess.Read); Object[] cols = GetSampleCols(); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); Console.WriteLine("Reading Table by Row"); for (int i = 0; i < data.NRows; i += 1) { Assertion.AssertEquals("Rows:" + i, 50, data.NRows); Object[] row = (Object[])data.GetRow(i); Assertion.AssertEquals("Ascii Rows: float" + i, 1f, ((float[])cols[0])[i] / ((float[])row[0])[0], Math.Pow(10, -6)); Assertion.AssertEquals("Ascii Rows: int" + i, ((int[])cols[1])[i], ((int[])row[1])[0]); Assertion.AssertEquals("Ascii Rows: long" + i, ((long[])cols[2])[i], ((long[])row[2])[0]); Assertion.AssertEquals("Ascii Rows: double" + i, 1f, ((double[])cols[3])[i] / ((double[])row[3])[0], Math.Pow(10, -14)); String[] st = (String[])row[4]; st[0] = st[0].Trim(); Assertion.AssertEquals("Ascii Rows: Str" + i, ((String[])cols[4])[i], ((String[])row[4])[0]); } }
public void ReadByColumn() { Fits f = null; try { f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.Read); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); Object[] cols = GetSampleCols(); Assert.AreEqual(data.NRows, 50); Assert.AreEqual(data.NCols, 5); for (int j = 0; j < data.NCols; j += 1) { Object col = data.GetColumn(j); if (j == 4) { String[] st = (String[])col; for (int i = 0; i < st.Length; i += 1) { st[i] = st[i].Trim(); } } Assert.AreEqual(true, ArrayFuncs.ArrayEquals(cols[j], col, Math.Pow(10, -6), Math.Pow(10, -14))); } } finally { if (f != null) { f.Close(); } } }
public void ModifyTable() { Fits f = null; try { f = new Fits(TestFileSetup.GetTargetFilename("at1.fits"), FileAccess.ReadWrite); Object[] samp = GetSampleCols(); AsciiTableHDU hdu = (AsciiTableHDU)f.GetHDU(1); AsciiTable data = (AsciiTable)hdu.GetData(); float[] f1 = (float[])data.GetColumn(0); float[] f2 = (float[])f1.Clone(); for (int i = 0; i < f2.Length; i += 1) { f2[i] = 2 * f2[i]; } data.SetColumn(0, f2); f1 = new float[] { 3.14159f }; data.SetElement(3, 0, f1); hdu.SetNullString(0, "**INVALID**"); data.SetNull(5, 0, true); data.SetNull(6, 0, true); Object[] row = new Object[5]; row[0] = new float[] { 6.28f }; row[1] = new int[] { 22 }; row[2] = new long[] { 0 }; row[3] = new double[] { -3 }; row[4] = new String[] { "A string" }; data.SetRow(5, row); data.SetElement(4, 2, new long[] { 54321 }); BufferedFile bf = new BufferedFile(TestFileSetup.GetTargetFilename("at1x.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); f.Write(bf); bf.Flush(); bf.Close(); bf.Dispose(); f.Close(); f = new Fits(TestFileSetup.GetTargetFilename("at1x.fits"), FileAccess.Read); AsciiTable tab = (AsciiTable)f.GetHDU(1).Data; Object[] kern = (Object[])tab.Kernel; float[] fx = (float[])kern[0]; int[] ix = (int[])kern[1]; long[] lx = (long[])kern[2]; double[] dx = (double[])kern[3]; String[] sx = (String[])kern[4]; float[] fy = (float[])samp[0]; int[] iy = (int[])samp[1]; long[] ly = (long[])samp[2]; double[] dy = (double[])samp[3]; String[] sy = (String[])samp[4]; Assert.AreEqual(true, tab.IsNull(6, 0)); Assert.AreEqual(false, tab.IsNull(5, 0)); for (int i = 0; i < data.NRows; i += 1) { if (i != 5) { if (i != 6) { // Null Assert.AreEqual(1f, f2[i] / fx[i], Math.Pow(10, -6)); } Assert.AreEqual(iy[i], ix[i]); if (i == 4) { Assert.AreEqual(54321L, lx[i]); } else { Assert.AreEqual(ly[i], lx[i]); } Assert.AreEqual(1f, dy[i] / dx[i], Math.Pow(10, -14)); Assert.AreEqual(sy[i], sx[i].Trim()); } } Object[] r5 = (Object[])data.GetRow(5); String[] st = (String[])r5[4]; st[0] = st[0].Trim(); for (int i = 0; i < r5.Length; i++) { Assert.AreEqual(true, ArrayFuncs.ArrayEquals(row[i], r5[i], Math.Pow(10, -6), Math.Pow(10, -14))); } } finally { if (f != null) { f.Close(); } } }
/// <summary> /// Create a ASCII table data structure from /// an array of objects representing the columns. /// </summary> public static Data Encapsulate(Object o) { if(o != null && o.GetType().IsArray) { if(ArrayFuncs.IsArrayOfArrays(o)) { Array oo = (Array)o; AsciiTable d = new AsciiTable(); for (int i = 0; i < oo.Length; i += 1) { d.AddColumn(oo.GetValue(i)); } return d; } else { throw new Exception("OOPS. FIX AsciiTableHDU.Encapsulate(Object o)."); } } return null; }
/// <summary> Create an ascii table header/data unit.</summary> /// <param name="header">the template specifying the ascii table.</param> /// <exception cref=""> FitsException if there was a problem with the header.</exception> public AsciiTableHDU(Header h, Data d) : base((TableData)d) { myHeader = h; data = (AsciiTable)d; myData = d; }