Ejemplo n.º 1
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);
  }
Ejemplo n.º 2
0
 @Before
 public void setup() {
   FitsFactory.setUseAsciiTables(true);
   try {
     new File(TARGET_BASIC_FITS_TEST_FITS).delete();
   } catch (Exception e) {
     // ignore
   }
 }
Ejemplo n.º 3
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())));
 }
Ejemplo 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();
  }
Ejemplo n.º 5
0
  @Test
  public void testFitsSettings() throws InterruptedException {
    boolean longstring = FitsFactory.isLongStringsEnabled();
    final Boolean[] testFitsSettingsVlaue = new Boolean[6];
    try {
      FitsFactory.setLongStringsEnabled(true);
      new Thread(
              new Runnable() {

                @Override
                public void run() {
                  try {
                    FitsFactory.useThreadLocalSettings(true);
                    for (int index = 0; index < testFitsSettingsVlaue.length; index++) {
                      waitForThread(testFitsSettingsVlaue, 1);
                      testFitsSettingsVlaue[index++] = FitsFactory.isLongStringsEnabled();
                      if (testFitsSettingsVlaue[index] != null) {
                        FitsFactory.setLongStringsEnabled(testFitsSettingsVlaue[index]);
                      }
                    }
                  } catch (InterruptedException e) {
                    Arrays.fill(testFitsSettingsVlaue, null);
                  }
                }
              })
          .start();
      testFitsSettingsVlaue[1] = false;
      waitForThread(testFitsSettingsVlaue, 0);
      Assert.assertEquals(Boolean.valueOf(true), testFitsSettingsVlaue[0]);
      Assert.assertEquals(Boolean.valueOf(false), testFitsSettingsVlaue[1]);
      Assert.assertEquals(true, FitsFactory.isLongStringsEnabled());
      testFitsSettingsVlaue[3] = true;
      waitForThread(testFitsSettingsVlaue, 0);
      Assert.assertEquals(Boolean.valueOf(false), testFitsSettingsVlaue[2]);
      Assert.assertEquals(Boolean.valueOf(true), testFitsSettingsVlaue[3]);
      Assert.assertEquals(true, FitsFactory.isLongStringsEnabled());
      FitsFactory.setLongStringsEnabled(false);
      testFitsSettingsVlaue[5] = true;
      waitForThread(testFitsSettingsVlaue, 0);
      Assert.assertEquals(Boolean.valueOf(false), testFitsSettingsVlaue[2]);
      Assert.assertEquals(Boolean.valueOf(true), testFitsSettingsVlaue[3]);
      Assert.assertEquals(false, FitsFactory.isLongStringsEnabled());
    } finally {
      FitsFactory.setLongStringsEnabled(longstring);
    }
  }
Ejemplo n.º 6
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));
    }
  }
Ejemplo n.º 7
0
  @Test
  public void testFitsUndefinedHdu5() throws Exception {
    Header head = new Header();
    head.setXtension("UNKNOWN");
    head.setBitpix(BasicHDU.BITPIX_BYTE);
    head.setNaxes(1);
    head.addValue("NAXIS1", 1000, null);
    head.addValue("PCOUNT", 0, null);
    head.addValue("GCOUNT", 2, null);
    UndefinedHDU hdu = (UndefinedHDU) FitsFactory.hduFactory(head);
    byte[] data = (byte[]) hdu.getData().getData();
    Assert.assertEquals(2000, data.length);
    Arrays.fill(data, (byte) 1);
    BufferedFile buf = new BufferedFile("target/testFitsUndefinedHdu5", "rw");
    hdu.write(buf);
    buf.close();
    Arrays.fill(data, (byte) 2);

    buf = new BufferedFile("target/testFitsUndefinedHdu5", "rw");
    hdu.read(buf);
    data = (byte[]) hdu.getData().getData();
    buf.close();
    Assert.assertEquals((byte) 1, data[0]);
  }
Ejemplo n.º 8
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);
  }