Examples of Fits


Examples of net.ivoa.fits.Fits

    FitsFactory.setUseAsciiTables(false);
  }

  public void testFile1() throws Exception {
    file = new Fits("data/testbinarytable1.fits");
    bt = (BinaryTableHDU) file.getHDU(1);
  }
View Full Code Here

Examples of net.ivoa.fits.Fits

    file = new Fits("data/testbinarytable1.fits");
    bt = (BinaryTableHDU) file.getHDU(1);
  }

  public void testFile2() throws Exception {
    file = new Fits("data/testbinarytable2.fits");
    bt = (BinaryTableHDU) file.getHDU(1);
  }
View Full Code Here

Examples of net.ivoa.fits.Fits

   *  
   * 
   * </pre>
   */
  public void testTable1() throws Exception {
    Fits f = new Fits();
    f.addHDU(Fits.makeHDU(new Object[]{bytes, bits, bools, shorts, ints,
        floats, doubles, longs, strings}));

    BinaryTableHDU bhdu = (BinaryTableHDU) f.getHDU(1);
    bhdu.setColumnName(0, "bytes", null);
    bhdu.setColumnName(1, "bits", "bits later on");
    bhdu.setColumnName(6, "doubles", null);
    bhdu.setColumnName(5, "floats", "4 x 4 array");

    BufferedFile bf = new BufferedFile("bt1.fits", "rw");

    f.write(bf);
    bf.flush();
    bf.close();

    // read file
    f = new Fits("bt1.fits");
    BasicHDU hdu;

    f.read();
    for (int i = 0; i < f.getNumberOfHDUs(); i += 1) {
      hdu = f.getHDU(i);
    }

    BinaryTableHDU thdu = (BinaryTableHDU) f.getHDU(1);
    byte[] tb = (byte[]) thdu.getColumn(0);
    byte[][] tbits = (byte[][]) thdu.getColumn(1);
    boolean[] tbools = (boolean[]) thdu.getColumn(2);
    short[][] tsh = (short[][]) thdu.getColumn(3);
    int[] tints = (int[]) thdu.getColumn(4);
View Full Code Here

Examples of net.ivoa.fits.Fits

  }

  public void testTable2() throws Exception {
    BasicHDU hdu = Fits.makeHDU(new Object[]{floats, vf, vs, vd, shorts,
        vbool});
    Fits f = new Fits();
    f.addHDU(hdu);

    BufferedDataOutputStream bdos = new BufferedDataOutputStream(
        new FileOutputStream("bt2.fits"));
    f.write(bdos);

    f = new Fits("bt2.fits");
    f.read();
    for (int i = 0; i < f.getNumberOfHDUs(); i += 1) {
      f.getHDU(i).toString();
    }

    BinaryTableHDU bhdu = (BinaryTableHDU) f.getHDU(1);

    float[][] tvf = (float[][]) bhdu.getColumn(1);
    short[][] tvs = (short[][]) bhdu.getColumn(2);
    double[][] tvd = (double[][]) bhdu.getColumn(3);
    boolean[][] tvbool = (boolean[][]) bhdu.getColumn(5);
View Full Code Here

Examples of net.ivoa.fits.Fits

    btab.addColumn(vf);
    btab.addColumn(strings);
    btab.addColumn(vbool);
    btab.addColumn(ints);

    Fits f = new Fits();
    f.addHDU(Fits.makeHDU(btab));

    BufferedDataOutputStream bdos = new BufferedDataOutputStream(
        new FileOutputStream("bt3.fits"));
    f.write(bdos);

    f = new Fits("bt3.fits");
    BinaryTableHDU bhdu = (BinaryTableHDU) f.getHDU(1);
    btab = (BinaryTable) bhdu.getData();

    float[] flatfloat = (float[]) btab.getFlattenedColumn(0);
    float[][] tvf = (float[][]) btab.getColumn(1);
    String[] xstr = (String[]) btab.getColumn(2);
    boolean[][] tvbool = (boolean[][]) btab.getColumn(3);

    for (int i = 0; i < 50; i += 3) {
      assertEquals(flatfloat[16 * i], flatfloat[16 * i + 1], 0);
      assertEquals(vf[i].length, tvf[i].length);
      for (int j = 0; j < vf[i].length; j++) {
        assertEquals(vf[i][j], tvf[i][j], 0);
      }
      assertEquals(strings[i], xstr[i]);
      assertEquals(vbool[i].length, tvbool[i].length);
      for (int j = 0; j < vbool[i].length; j++) {
        assertEquals(vbool[i][j], tvbool[i][j]);
      }
    }

    // add again some columns
    btab.addColumn(floats);
    btab.addColumn(vf);
    btab.addColumn(strings);
    btab.addColumn(vbool);
    btab.addColumn(ints);
       
    // add 50 rows..
    for (int i = 0; i < 50; i += 1) {
      Object[] row = btab.getRow(i);
      // test that we really have 10 cols
      assertEquals(10, row.length);
      float[] qx = (float[]) row[1];

      assertEquals(strings[i], (String) row[2]);
      // change string to new string
      row[2] = "new string:" + i;
      btab.addRow(row);
    }

    f = new Fits();
    f.addHDU(Fits.makeHDU(btab));
    BufferedFile bf = new BufferedFile("bt4.fits", "rw");
    f.write(bf);
    bf.flush();
    bf.close();

    f = new Fits("bt4.fits");

    btab = (BinaryTable) f.getHDU(1).getData();

    // Try getting data before we read in the table.

    xstr = (String[]) btab.getColumn(2);

        //char[] c = btab.getTypes();
        //System.out.println(c[3]);
        boolean[] batest = (boolean[]) btab.getElement(99, 3);
        System.out.println(batest.length);
       
        boolean[] ob = new boolean[]{true, false, true, false};
        System.out.println(ob[0] + " " + ob[1] + " " + ob[2] + " " + ob[3]);
        System.out.println(batest[0] + " " + batest[1] + " " + batest[2] + " " + batest[3]);
       
        btab.setElement(99, 3, ob);
       
    for (int i = 0; i < xstr.length; i++) {

      boolean[] ba = (boolean[]) btab.getElement(i, 3);
      float[] fx = (float[]) btab.getElement(i, 1);
      float[][] tst = (float[][]) btab.getElement(i, 0);
      String s = (String) btab.getElement(i, 2);

      int trow = i % 50;

            System.out.println(vbool[trow].length + " " + ba.length);
      assertEquals(vbool[trow].length, ba.length);
      for (int j = 0; j < ba.length; j += 1) {
        assertEquals(ba[j], vbool[trow][j]);
      }

      assertEquals(vf[trow].length, fx.length);
      for (int j = 0; j < fx.length; j += 1) {
        assertEquals(vf[trow][j], fx[j], 0);
      }
      if (i >= 50)
        assertEquals("new string:" + trow, s);
      else
        assertEquals(strings[i], s);

      // that's for second set of cols
      ba = (boolean[]) btab.getElement(i, 8);
      fx = (float[]) btab.getElement(i, 6);
      tst = (float[][]) btab.getElement(i, 5);
      s = (String) btab.getElement(i, 7);

      assertEquals(vbool[trow].length, ba.length);
      for (int j = 0; j < ba.length; j += 1) {
        assertEquals(ba[j], vbool[trow][j]);
      }

      assertEquals(vf[trow].length, fx.length);
      for (int j = 0; j < fx.length; j += 1) {
        assertEquals(vf[trow][j], fx[j], 0);
      }
      assertEquals(strings[trow], s);
    }
    // Fill the table.
    f.getHDU(1).getData();

    xstr = (String[]) btab.getColumn(2);

    for (int i = 0; i < xstr.length; i += 3) {
      int trow = i % 50;

      String s = (String) btab.getElement(i, 2);
      if (i > 50)
        assertEquals("new string:" + trow, s);
      else
        assertEquals(strings[i], s);
      assertEquals(s, xstr[i]);
    }

    /** * Create a binary table from an Object[][] array */
    Object[][] x = new Object[5][3];
    for (int i = 0; i < 5; i += 1) {
      x[i][0] = new float[]{i};
      x[i][1] = new String("AString" + i);
      x[i][2] = new int[][]{{i, 2 * i}, {3 * i, 4 * i}};
    }

    f = new Fits();
    FitsFactory.setUseAsciiTables(false);
    BasicHDU hdu = Fits.makeHDU(x);
    hdu.toString();
    f.addHDU(hdu);
    bf = new BufferedFile("bt5.fits", "rw");
    f.write(bf);
    bf.close();

    /*File fi = new File("bt1.fits");
    fi.delete();
    fi = new File("bt2.fits");
View Full Code Here

Examples of nom.tam.fits.Fits

    @Override
    public void retrieveObservations() throws ObservationReadError,
        InterruptedException {

      try {
        Fits fits = new Fits(getInputStreams().get(0));
        BasicHDU[] hdus = fits.read();
        retrieveKeplerObservations(hdus);
      } catch (FitsException e) {
        throw new ObservationReadError(e.getLocalizedMessage());
      }
    }
View Full Code Here

Examples of nom.tam.fits.Fits

    @Override
    public void retrieveObservations() throws ObservationReadError,
        InterruptedException {

      try {
        Fits fits = new Fits(getInputStreams().get(0));
        BasicHDU[] hdus = fits.read();
        double jdRef = retrieveJDReference(hdus);
        retrieveObservations(hdus, jdRef);
      } catch (FitsException e) {
        throw new ObservationReadError(e.getLocalizedMessage());
      }
View Full Code Here

Examples of nom.tam.fits.Fits

                configList.add(getConfig(text, font, fill));
            }
            i++;
        }

        Fits fits = fitsImage.getFits();
        _deleteBinaryTable(fits, extName);
        BinaryTable table = new BinaryTable();
        FitsFactory.setUseAsciiTables(false);
        table.addColumn(typeList.toArray(new String[typeList.size()]));
        table.addColumn(coordList.toArray(new String[coordList.size()]));
        table.addColumn(configList.toArray(new String[configList.size()]));
        BinaryTableHDU hdu = (BinaryTableHDU) Fits.makeHDU(table);
        hdu.getHeader().addValue("EXTNAME", extName, "Contains saved JSkyCat graphics");
        hdu.setColumnName(0, "type", null);
        hdu.setColumnName(1, "coords", null);
        hdu.setColumnName(2, "config", null);
        deleteHDU(extName);
        fits.addHDU(hdu);
        imageDisplay.checkExtensions(true);
    }
View Full Code Here

Examples of nom.tam.fits.Fits

        if (name != null) {
            // Check for a stored StarTable, which has a corresponding VOTMETA HDU with more info
            String votMetaName = VOTMETA + name.replace(TABLE_SUFFIX, "");
            BasicHDU votMetaHdu = findHDU(fits, votMetaName);
            if (votMetaHdu != null) {
                Fits tmpFits = new Fits();
                tmpFits.addHDU(votMetaHdu);
                tmpFits.addHDU(hdu);
                votMetaHdu.getHeader().removeCard("EXTNAME"); // not expected by FitsPlusTableBuilder
                votMetaHdu.getHeader().removeCard("EXTEND"); // not expected by FitsPlusTableBuilder
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                BufferedDataOutputStream bos = new BufferedDataOutputStream(os);
                tmpFits.write(bos);
                bos.flush();
                // Restore the name that was removed above
                votMetaHdu.getHeader().addValue("EXTNAME", votMetaName, "Table metadata in VOTable format");
                ByteArrayDataSource dataSrc = new ByteArrayDataSource(filename, os.toByteArray());
                bos.close();
View Full Code Here

Examples of nom.tam.fits.Fits

     * @throws IOException              if there is a problem reading the file
     * @throws IllegalArgumentException if not a FITS table
     */
    public static NavigatorFITSTable getFitsTable(String filename)
            throws FitsException, IOException {
        Fits fits = new Fits(filename);
        fits.read();
        int n = fits.getNumberOfHDUs();
        if (n != 2) {
            throw new IllegalArgumentException(
                    "Wrong file format: Expected FITS file with one table.");
        }
        BasicHDU basicHDU = fits.getHDU(1);
        if (!(basicHDU instanceof TableHDU)) {
            throw new IllegalArgumentException(
                    "Wrong file format: First FITS extension is not a table.");
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.