public String getHeaderString() { Header hdr = hdu.getHeader(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); hdr.dumpHeader(ps); String hdrString = baos.toString(); try { baos.close(); } catch (IOException e) { e.printStackTrace(); } ps.close(); return hdrString; }
public String getWcsHeaderCardsString() { Header header = hdu.getHeader(); Header filteredHeader = new Header(); // now adjust WCS values: ArrayList<HeaderCard> cards = new ArrayList<HeaderCard>(); cards.add(header.findCard("CTYPE1")); cards.add(header.findCard("CTYPE2")); cards.add(header.findCard("RADESYS")); cards.add(header.findCard("RADECSYS")); cards.add(header.findCard("CRVAL1")); cards.add(header.findCard("CRVAL2")); cards.add(header.findCard("CDELT1")); cards.add(header.findCard("CDELT2")); cards.add(header.findCard("EQUINOX")); cards.add(header.findCard("BUNIT")); cards.add(header.findCard("EPOCH")); cards.add(header.findCard("CD1_1")); cards.add(header.findCard("CD1_2")); cards.add(header.findCard("CD2_1")); cards.add(header.findCard("CD2_2")); cards.add(header.findCard("CRPIX1")); cards.add(header.findCard("CRPIX2")); cards.add(header.findCard("END")); cards.forEach( (card) -> { if (card != null) { try { filteredHeader.addLine(card); } catch (Exception e) { e.printStackTrace(); } } }); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); filteredHeader.dumpHeader(ps); String wcsHdrString = baos.toString(); try { baos.close(); } catch (IOException e) { e.printStackTrace(); } ps.close(); return wcsHdrString; }