Package net.ivoa.fits.hdu

Examples of net.ivoa.fits.hdu.ImageHDU


  public void testHeader() throws Exception {
    float[][] img = new float[300][300];

    Fits f = new Fits();

    ImageHDU hdu = (ImageHDU) Fits.makeHDU(img);
    BufferedFile bf = new BufferedFile("ht1.fits", "rw");
    f.addHDU(hdu);
    f.write(bf);
    bf.close();

    f = new Fits("ht1.fits");
    hdu = (ImageHDU) f.getHDU(0);
    Header hdr = hdu.getHeader();

    Cursor c = hdr.iterator();

    c.setKey("XXX");
    c.add("CTYPE1", new HeaderCard("CTYPE1", "GLON-CAR",
View Full Code Here


   * Given Header and data objects return the appropriate type of HDU.
   */
  public static BasicHDU HDUFactory(Header hdr, Data d) throws FitsException {

    if (d instanceof ImageData) {
      return new ImageHDU(hdr, d);
    } 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) {
View Full Code Here

    // Read a FITS file
    f = new Fits("image2.fits");

    BasicHDU[] hdus = f.read();

    ImageHDU h = (ImageHDU) hdus[1];

    // Put this HDU at the beginning of the FITS file
    f.insertHDU(h, 0);

    // Make it an extension again!
    f.insertHDU(hdus[0], 0);

    // Check out image tiling from files.

    ImageTiler t = h.getTiler();
    short[] stile = (short[]) t.getTile(new int[]{10, 10}, new int[]{2, 2});
    assertEquals(4, stile.length);
    assertEquals(20, stile[0]);
    assertEquals(21, stile[1]);
    assertEquals(21, stile[2]);
    assertEquals(22, stile[3]);

    stile = (short[]) t.getTile(new int[]{20, 20}, new int[]{2, 2});
    assertEquals(40, stile[0]);
    assertEquals(41, stile[1]);
    assertEquals(41, stile[2]);
    assertEquals(42, stile[3]);

    short[] xtile = new short[4];
    t.getTile(xtile, new int[]{20, 20}, new int[]{2, 2});
    assertEquals(40, xtile[0]);
    assertEquals(41, xtile[1]);
    assertEquals(41, xtile[2]);
    assertEquals(42, xtile[3]);

    // Check a 3-d image.
    h = (ImageHDU) hdus[6];
    t = h.getTiler();
    int[] itile = (int[]) t.getTile(new int[]{3, 3, 3}, new int[]{2, 2, 2});
    assertEquals(8, itile.length);
    assertEquals(9, itile[0]);
    assertEquals(10, itile[1]);
    assertEquals(10, itile[2]);
    assertEquals(11, itile[3]);
    assertEquals(10, itile[4]);
    assertEquals(11, itile[5]);
    assertEquals(11, itile[6]);
    assertEquals(12, itile[7]);

    // How about a 1-d image.
    h = (ImageHDU) hdus[7];
    t = h.getTiler();
    double[] dtile = (double[]) t.getTile(new int[]{410}, new int[]{3});
    assertEquals(3, dtile.length);
    assertEquals(20.0d, dtile[0], 0d);
    assertEquals(21.0d, dtile[1], 0d);
    assertEquals(22.0d, dtile[2], 0d);

    // Check from memory tiling!

    t = ((ImageHDU) hdus[1]).getTiler();
    stile = (short[]) t.getTile(new int[]{20, 20}, new int[]{2, 2});
    assertEquals(40, stile[0]);
    assertEquals(41, stile[1]);
    assertEquals(41, stile[2]);
    assertEquals(42, stile[3]);

    stile = (short[]) t.getTile(new int[]{25, 25}, new int[]{2, 2});
    assertEquals(50, stile[0]);
    assertEquals(51, stile[1]);
    assertEquals(51, stile[2]);
    assertEquals(52, stile[3]);

    h = (ImageHDU) hdus[6];
    t = h.getTiler();
    itile = (int[]) t.getTile(new int[]{3, 3, 3}, new int[]{2, 2, 2});
    assertEquals(8, itile.length);
    assertEquals(9, itile[0]);
    assertEquals(10, itile[1]);
    assertEquals(10, itile[2]);
    assertEquals(11, itile[3]);
    assertEquals(10, itile[4]);
    assertEquals(11, itile[5]);
    assertEquals(11, itile[6]);
    assertEquals(12, itile[7]);

    h = (ImageHDU) hdus[7];
    t = h.getTiler();
    dtile = (double[]) t.getTile(new int[]{410}, new int[]{3});
    assertEquals(3, dtile.length);
    assertEquals(20.0d, dtile[0], 0d);
    assertEquals(21d, dtile[1], 0d);
    assertEquals(22d, dtile[2], 0d);
View Full Code Here

TOP

Related Classes of net.ivoa.fits.hdu.ImageHDU

Copyright © 2018 www.massapicom. 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.