Examples of BinaryTableHDU


Examples of net.ivoa.fits.hdu.BinaryTableHDU

  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);
    float[][][] tflt = (float[][][]) thdu.getColumn(5);
    double[] tdoub = (double[]) thdu.getColumn(6);
    long[] tlong = (long[]) thdu.getColumn(7);
    String[] tstr = (String[]) thdu.getColumn(8);

    for (int i = 0; i < tb.length; i += 1) {
      assertEquals(bytes[i], tb[i]);
      for (int j = 0; j < 2; j += 1) {
        assertEquals(bits[i][j], tbits[i][j]);
View Full Code Here

Examples of net.ivoa.fits.hdu.BinaryTableHDU

    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);

    for (int i = 0; i < 50; i += 10) {
      assertEquals(vf[i].length, tvf[i].length);
      assertEquals(vs[i].length, tvs[i].length);
      assertEquals(vd[i].length, tvd[i].length);
View Full Code Here

Examples of net.ivoa.fits.hdu.BinaryTableHDU

    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);
View Full Code Here

Examples of net.ivoa.fits.hdu.BinaryTableHDU

    } else if (d instanceof RandomGroupsData) {
      return new RandomGroupsHDU(hdr, d);
    } else if (d instanceof AsciiTable) {
      return new AsciiTableHDU(hdr, d);
    } else if (d instanceof BinaryTable) {
      return new BinaryTableHDU(hdr, d);
    } else if (d instanceof UndefinedData) {
      return new UndefinedHDU(hdr, d);
    }

    return null;
View Full Code Here

Examples of nom.tam.fits.BinaryTableHDU

      double minMagErr = Double.MAX_VALUE;
      double maxMagErr = Double.MIN_VALUE;

      for (BasicHDU hdu : hdus) {
        if (hdu instanceof BinaryTableHDU) {
          BinaryTableHDU tableHDU = (BinaryTableHDU) hdu;

          for (int row = 0; row < tableHDU.getNRows()
              && !wasInterrupted(); row++) {
            try {
              double barytime = ((double[]) tableHDU.getElement(
                  row, 0))[0];
              float ap_corr_flux = ((float[]) tableHDU
                  .getElement(row, 7))[0];
              float ap_corr_err = ((float[]) tableHDU.getElement(
                  row, 8))[0];

              // Include only valid magnitude fluxes.
              // Question: why do we see such values in Kepler
              // data sets?
              if (!Float.isInfinite(ap_corr_flux)
                  && !Float.isInfinite(ap_corr_err)
                  && !Float.isNaN(ap_corr_flux)
                  && !Float.isNaN(ap_corr_err)) {

                double hjd = barytime + 2454833.0;
                double mag = 15.0 - 2.5
                    * Math.log(ap_corr_flux)
                    / Math.log(10.0);

                double magErr = 1.086 * ap_corr_err
                    / ap_corr_flux;

                if (magErr < minMagErr) {
                  minMagErr = magErr;
                } else if (magErr > maxMagErr) {
                  maxMagErr = magErr;
                }

                ValidObservation ob = new ValidObservation();
                ob.setDateInfo(new DateInfo(hjd));
                ob.setMagnitude(new Magnitude(mag, magErr));
                ob.setBand(keplerSeries);
                ob.setRecordNumber(row);
                collectObservation(ob);
              }
            } catch (Exception e) {
              String input = tableHDU.getRow(row).toString();
              String error = e.getLocalizedMessage();
              InvalidObservation ob = new InvalidObservation(
                  input, error);
              ob.setRecordNumber(row);
              addInvalidObservation(ob);
View Full Code Here

Examples of nom.tam.fits.BinaryTableHDU

      double minMagErr = Double.MAX_VALUE;
      double maxMagErr = Double.MIN_VALUE;

      for (BasicHDU hdu : hdus) {
        if (hdu instanceof BinaryTableHDU) {
          BinaryTableHDU tableHDU = (BinaryTableHDU) hdu;

          for (int row = 0; row < tableHDU.getNRows()
              && !wasInterrupted(); row++) {
            try {
              int tmid = ((int[]) tableHDU.getElement(row, 0))[0];
              float flux = ((float[]) tableHDU.getElement(row, 1))[0];
              float fluxErr = ((float[]) tableHDU.getElement(row,
                  2))[0];

              float tamFlux = ((float[]) tableHDU.getElement(row,
                  3))[0];
              float tamFluxErr = ((float[]) tableHDU.getElement(
                  row, 4))[0];
              String imageId = (String) tableHDU.getElement(row,
                  5);
              short ccdX = ((short[]) tableHDU.getElement(row, 6))[0];
              short ccdY = ((short[]) tableHDU.getElement(row, 7))[0];
              // short flag = ((short[]) tableHDU.getElement(row,
              // 8))[0];

              if (flux > 1 && flux - fluxErr > 0) {
                double hjd = tmid / 86400.0 + jdRef;
                double mag = 15.0 - 2.5 * Math.log(flux)
                    / Math.log(10.0);
                double magErr = 1.086 * fluxErr / flux;

                if (magErr < minMagErr) {
                  minMagErr = magErr;
                } else if (magErr > maxMagErr) {
                  maxMagErr = magErr;
                }

                ValidObservation ob = new ValidObservation();
                ob.setDateInfo(new DateInfo(hjd));
                ob.setMagnitude(new Magnitude(mag, magErr));
                ob.setBand(superWaspSeries);
                ob.setRecordNumber(row);
                ob.addDetail("IMAGE_ID", imageId, "Image ID");
                ob.addDetail("CCDX", ccdX + "", "CCD X");
                ob.addDetail("CCDY", ccdY + "", "CCD Y");
                ob.addDetail("FLUX", tamFlux + "", "Flux");
                ob.addDetail("FLUXERR", tamFluxErr + "",
                    "Flux Error");
//                ob.addDetail("FLAG", flag + "", "Flag");
                obs.add(ob);
              }
            } catch (Exception e) {
              String input = tableHDU.getRow(row).toString();
              String error = e.getLocalizedMessage();
              InvalidObservation ob = new InvalidObservation(
                  input, error);
              ob.setRecordNumber(row);
              addInvalidObservation(ob);
View Full Code Here

Examples of nom.tam.fits.BinaryTableHDU

        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.BinaryTableHDU

        if (name == null) {
            return null;
        }

        // find the "CATINFO" table, if it exists
        BinaryTableHDU hdu = findBinaryTableHDU(fits, CATINFO);
        if (hdu == null) {
            return null;
        }

        int ncols = hdu.getNCols();

        // find the entry for this table
        int rowIndex = findConfigEntryRow(hdu, name);
        if (rowIndex == -1) {
            return null;
        }

        // if we get here, we found the entry
        Object[] row = hdu.getRow(rowIndex);
        Properties properties = new Properties();
        properties.setProperty("serv_type", "local");
        properties.setProperty("long_name", name);
        properties.setProperty("url", getFilename());
        for (int colIndex = 0; colIndex < ncols; colIndex++) {
            String value = (String) row[colIndex];
            if (value.length() != 0) {
                properties.setProperty(hdu.getColumnName(colIndex).toLowerCase(), value);
            }
        }
        return new SkycatConfigEntry(properties);
    }
View Full Code Here

Examples of nom.tam.fits.BinaryTableHDU

        //
        // XXX Note: the Fits class doesn't currently handle empty columns correctly,
        //           so we have to add one row with dummy values ("-").
        int ncols = CATINFO_COLUMNS.length;
        Object[][] data;
        BinaryTableHDU hdu = findBinaryTableHDU(fits, CATINFO);
        int newRowIndex = 0;
        if (hdu != null) {
            // merge data from old table to new table
            int nrows = hdu.getNRows();
            int entryIndex = findConfigEntryRow(hdu, name);
            int dummyIndex = findConfigEntryRow(hdu, "-");
            int n = nrows;
            if (entryIndex == -1) {
                n++;
            }
            if (dummyIndex == -1) {
                n++;
            }
            data = new Object[n][];
            for (int rowIndex = 0; rowIndex < nrows; rowIndex++) {
                if (rowIndex == entryIndex) {
                    continue;
                }
                if (rowIndex == dummyIndex) {
                    continue;
                }
                data[newRowIndex++] = _copyCatInfoRow(hdu, hdu.getRow(rowIndex));
            }
            deleteTable(fits, CATINFO);
        } else {
            data = new Object[2][];
        }

        // add a new row for the given table
        Object[] row = new Object[ncols];
        row[0] = name;  // use the given name rather than the original one
        if (table instanceof SkycatTable) {
            SkycatConfigEntry entry = ((SkycatTable) table).getConfigEntry();
            Properties properties = entry.getProperties();
            for (int colIndex = 1; colIndex < ncols; colIndex++) {
                String value = properties.getProperty(CATINFO_COLUMNS[colIndex].toLowerCase());
                if (value != null) {
                    row[colIndex] = value;
                } else {
                    row[colIndex] = "";
                }
            }
        } else {
            for (int colIndex = 1; colIndex < ncols; colIndex++) {
                row[colIndex] = "";
            }
        }
        data[newRowIndex++] = row;

        // add a dummy row as a workaround to a Fits lib bug with empty columns
        row = new Object[ncols];
        for (int colIndex = 0; colIndex < ncols; colIndex++) {
            row[colIndex] = "-";
        }
        data[newRowIndex] = row;

        BinaryTable binTable = new BinaryTable(data);
        FitsFactory.setUseAsciiTables(false);
        hdu = (BinaryTableHDU) Fits.makeHDU(binTable);
        hdu.getHeader().addValue("EXTNAME", CATINFO, "Contains catalog config info");
        for (int i = 0; i < ncols; i++) {
            hdu.setColumnName(i, CATINFO_COLUMNS[i], null);
        }
        fits.addHDU(hdu);
    }
View Full Code Here

Examples of nom.tam.fits.BinaryTableHDU

     * @param name the name to give the FITS table
     */
    private static void _removeCatInfo(Fits fits, String name)
            throws FitsException, IOException {

        BinaryTableHDU hdu = findBinaryTableHDU(fits, CATINFO);
        if (hdu != null) {
            int rowIndex = findConfigEntryRow(hdu, name);
            if (rowIndex != -1) {
                hdu.deleteRows(rowIndex, 1);
            }
            if (hdu.getNRows() <= 1) {
                deleteTable(fits, CATINFO);
            }
        }
    }
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.