Exemplo n.º 1
0
  @Test
  public void testFitsDeleteHdu() throws Exception {
    try (Fits fits1 = makeAsciiTable()) {
      fits1.read();
      Exception actual = null;
      try {
        fits1.deleteHDU(-2);
      } catch (FitsException ex) {
        actual = ex;
      }
      Assert.assertNotNull(actual);

      Assert.assertNull(fits1.getHDU(99));
      // will be ignored
      fits1.insertHDU(null, 99);
      fits1.deleteHDU(2);
      fits1.deleteHDU(2);
      writeFile(fits1, TARGET_BASIC_FITS_TEST_FITS);
    }

    Fits fits1 = new Fits(new File(TARGET_BASIC_FITS_TEST_FITS));
    fits1.readHDU();
    AsciiTableHDU hdu2 = (AsciiTableHDU) fits1.readHDU();
    AsciiTableHDU hdu3 = (AsciiTableHDU) fits1.readHDU();
    Assert.assertArrayEquals(new int[] {11}, (int[]) hdu2.getData().getElement(1, 1));
    Assert.assertArrayEquals(new int[] {41}, (int[]) hdu3.getData().getElement(1, 1));
    hdu3.getData();
  }
Exemplo n.º 2
0
 /**
  * this test is only for manual usage with enough memory allocated.
  *
  * @throws Exception
  */
 @Test
 @Ignore
 public void testVeryBigDataFiles() throws Exception {
   Fits f = new Fits();
   ImageData data = new ImageData(new float[50000][50000]);
   Header manufactureHeader = ImageHDU.manufactureHeader(data);
   f.addHDU(FitsFactory.hduFactory(manufactureHeader, data));
   BufferedFile bf = new BufferedFile("target/big.fits", "rw");
   f.write(bf);
   System.out.println(Arrays.toString(ArrayFuncs.getDimensions(f.getHDU(0).getData().getData())));
   f = new Fits("target/big.fits");
   System.out.println(Arrays.toString(ArrayFuncs.getDimensions(f.getHDU(0).getData().getData())));
 }
Exemplo n.º 3
0
  @Test
  public void testFitsSkipHdu() throws Exception {
    Fits fits1 = makeAsciiTable();

    BasicHDU<?> image = fits1.readHDU();
    AsciiTableHDU hdu2 = (AsciiTableHDU) fits1.readHDU();
    fits1.skipHDU(2);
    AsciiTableHDU hdu3 = (AsciiTableHDU) fits1.readHDU();

    hdu2.info(System.out);
    hdu3.info(System.out);
    Assert.assertArrayEquals(new int[] {11}, (int[]) hdu2.getData().getElement(1, 1));
    Assert.assertArrayEquals(new int[] {41}, (int[]) hdu3.getData().getElement(1, 1));
    hdu3.getData();
  }
Exemplo n.º 4
0
  @Test
  public void convertAsciiToBinaryTable() throws Exception {
    FitsFactory.setUseAsciiTables(false);

    Fits fits1 = makeAsciiTable();

    fits1.readHDU();
    BinaryTableHDU hdu2 = (BinaryTableHDU) fits1.readHDU();
    fits1.skipHDU(2);
    BinaryTableHDU hdu3 = (BinaryTableHDU) fits1.readHDU();

    hdu2.info(System.out);
    hdu3.info(System.out);
    Assert.assertArrayEquals(new int[] {11}, (int[]) hdu2.getData().getElement(1, 1));
    Assert.assertArrayEquals(new int[] {41}, (int[]) hdu3.getData().getElement(1, 1));
    hdu3.getData();
  }
Exemplo n.º 5
0
 @Test
 public void testHduFromHeader() throws Exception {
   Header header = new Header();
   header.addValue("SIMPLE", true, "");
   header.addValue("BITPIX", 8, "");
   header.addValue("NAXIS", 2, "");
   header.addValue("NAXIS1", 4, "");
   header.addValue("NAXIS3", 4, "");
   ImageHDU hdu = (ImageHDU) Fits.makeHDU(header);
   Assert.assertNotNull(hdu);
 }
Exemplo n.º 6
0
  @Test
  public void testFitsUndefinedHdu4() throws Exception {
    Fits fits1 = makeAsciiTable();
    fits1.read();
    byte[] undefinedData = new byte[1000];
    for (int index = 0; index < undefinedData.length; index++) {
      undefinedData[index] = (byte) index;
    }
    Data data = UndefinedHDU.encapsulate(undefinedData);
    Header header = new Header();
    header.pointToData(data);

    fits1.addHDU(FitsFactory.hduFactory(header, data));
    BufferedDataOutputStream os =
        new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU4.fits"));
    fits1.write(os);
    os.close();

    Fits fits2 = new Fits("target/UndefindedHDU4.fits");
    BasicHDU<?>[] hdus = fits2.read();

    byte[] rereadUndefinedData =
        (byte[]) ((UndefinedData) hdus[hdus.length - 1].getData()).getData();
    Assert.assertArrayEquals(undefinedData, rereadUndefinedData);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    hdus[hdus.length - 1].info(new PrintStream(out));
    String undefinedInfo = new String(out.toByteArray());

    Assert.assertTrue(undefinedInfo.indexOf("Apparent size:1000") >= 0);
  }
Exemplo n.º 7
0
  private Fits makeAsciiTable() throws Exception {
    // Create the new ASCII table.
    Fits f = new Fits();
    f.addHDU(Fits.makeHDU(getSampleCols(10f)));
    f.addHDU(Fits.makeHDU(getSampleCols(20f)));
    f.addHDU(Fits.makeHDU(getSampleCols(30f)));
    f.addHDU(Fits.makeHDU(getSampleCols(40f)));

    writeFile(f, TARGET_BASIC_FITS_TEST_FITS);

    return new Fits(new File(TARGET_BASIC_FITS_TEST_FITS));
  }
Exemplo n.º 8
0
 // TODO handle uncaught exceptions
 public FitsImage(Fits fitsFile, ImageController controller) throws FitsException, IOException {
   this.controller = controller;
   this.fitsFile = fitsFile;
   this.hdu = (ImageHDU) fitsFile.getHDU(0);
   ;
   width = hdu.getAxes()[1];
   height = hdu.getAxes()[0];
   this.tiler = hdu.getTiler();
   setNanColour(controller.getNanColour());
   prepareData();
   createHistogram();
   minValue = histogram.getMinValue();
   maxValue = histogram.getMaxValue();
   writeImage();
 }
Exemplo n.º 9
0
  @Test
  public void testFitsDeleteHduNewPrimary() throws Exception {
    Fits fits1 = makeAsciiTable();
    fits1.read();
    fits1.deleteHDU(0);
    for (int index = 0; index < 4; index++) {
      fits1.deleteHDU(1);
    }
    BasicHDU<?> dummyHDU = BasicHDU.getDummyHDU();
    dummyHDU.addValue("TEST", "XYZ", null);
    fits1.addHDU(dummyHDU);
    fits1.deleteHDU(0);
    writeFile(fits1, TARGET_BASIC_FITS_TEST_FITS);

    fits1 = new Fits(new File(TARGET_BASIC_FITS_TEST_FITS));
    Assert.assertEquals(1, fits1.read().length);
    Assert.assertEquals("XYZ", fits1.getHDU(0).getTrimmedString("TEST"));
  }
Exemplo n.º 10
0
 @Test
 public void testDifferentTypes() throws Exception {
   FitsException actual = null;
   try {
     new Fits((String) null, false);
   } catch (FitsException ex) {
     actual = ex;
   }
   Assert.assertNotNull(actual);
   try (Fits fits = new Fits("nom/tam/fits/test/test.fits", false)) {
     Assert.assertNotNull(fits.readHDU());
     Assert.assertEquals(1, fits.currentSize());
   }
   try (Fits fits =
       new Fits(
           "file://"
               + new File("src/test/resources/nom/tam/fits/test/test.fits").getAbsolutePath(),
           false)) {
     Assert.assertNotNull(fits.readHDU());
   }
   actual = null;
   try {
     new Fits(
         "file://" + new File("src/test/resources/nom/tam/fits/test/test.fitsX").getAbsolutePath(),
         false);
   } catch (FitsException ex) {
     actual = ex;
   }
   Assert.assertNotNull(actual);
   actual = null;
   try {
     new Fits(
         new URL(
             "file://"
                 + new File("src/test/resources/nom/tam/fits/test/test.fitsX").getAbsolutePath()),
         false);
   } catch (FitsException ex) {
     actual = ex;
   }
   Assert.assertNotNull(actual);
   try (Fits fits = new Fits("src/test/resources/nom/tam/fits/test/test.fits", false)) {
     Assert.assertNotNull(fits.readHDU());
   }
 }
Exemplo n.º 11
0
  @Test
  public void testFitsUndefinedHdu() throws Exception {
    Fits fits1 = makeAsciiTable();
    fits1.read();
    byte[] undefinedData = new byte[1000];
    for (int index = 0; index < undefinedData.length; index++) {
      undefinedData[index] = (byte) index;
    }
    fits1.addHDU(Fits.makeHDU(new UndefinedData(undefinedData)));
    BufferedDataOutputStream os =
        new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU.fits"));
    fits1.write(os);
    os.close();

    Fits fits2 = new Fits("target/UndefindedHDU.fits");
    BasicHDU<?>[] hdus = fits2.read();

    byte[] rereadUndefinedData =
        (byte[]) ((UndefinedData) hdus[hdus.length - 1].getData()).getData();
    Assert.assertArrayEquals(undefinedData, rereadUndefinedData);
  }
Exemplo n.º 12
0
  @Test
  public void testFitsUndefinedHdu3() throws Exception {
    Fits fits1 = makeAsciiTable();
    fits1.read();
    byte[] undefinedData = new byte[1000];
    for (int index = 0; index < undefinedData.length; index++) {
      undefinedData[index] = (byte) index;
    }
    Data data = UndefinedHDU.encapsulate(undefinedData);
    Header header = new Header(data);

    Cursor<String, HeaderCard> iter = header.iterator();

    String[] headers = new String[header.getNumberOfCards() - 1];
    int index = 0;
    while (iter.hasNext()) {
      HeaderCard headerCard = iter.next();
      // the EXTEND key will be deleted later on because the header is no
      // primary header so don't use it
      if (!headerCard.getKey().equals("EXTEND")) {
        headers[index++] = headerCard.toString();
      }
    }
    Header newHeader = new Header(headers);
    for (index = 0; index < headers.length; index++) {
      Assert.assertEquals(header.getCard(index), newHeader.getCard(index));
    }

    fits1.addHDU(FitsFactory.hduFactory(newHeader, data));
    BufferedDataOutputStream os =
        new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU3.fits"));
    fits1.write(os);
    os.close();

    Fits fits2 = new Fits("target/UndefindedHDU3.fits");
    BasicHDU[] hdus = fits2.read();

    for (index = 0; index < headers.length; index++) {
      Assert.assertEquals(header.getCard(index), hdus[5].getHeader().getCard(index));
    }
  }
Exemplo n.º 13
0
  @Test
  public void testFitsUndefinedHdu2() throws Exception {
    Fits fits1 = makeAsciiTable();
    fits1.read();
    byte[] undefinedData = new byte[1000];
    for (int index = 0; index < undefinedData.length; index++) {
      undefinedData[index] = (byte) index;
    }
    Data data = UndefinedHDU.encapsulate(undefinedData);
    Header header = UndefinedHDU.manufactureHeader(data);

    fits1.addHDU(FitsFactory.HDUFactory(header, data));
    BufferedDataOutputStream os =
        new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU2.fits"));
    fits1.write(os);
    os.close();

    Fits fits2 = new Fits("target/UndefindedHDU2.fits");
    BasicHDU<?>[] hdus = fits2.read();

    byte[] rereadUndefinedData =
        (byte[]) ((UndefinedData) hdus[hdus.length - 1].getData()).getData();
    Assert.assertArrayEquals(undefinedData, rereadUndefinedData);
  }
Exemplo n.º 14
0
 private void writeFile(Fits f, String name) throws Exception {
   BufferedFile bf = new BufferedFile(name, "rw");
   f.write(bf);
   bf.flush();
   bf.close();
 }