5

does anybody has experience in exporting data as a FITS file with custom Metadata (FITS header) information? So far I was only able to generate FITS files with the standard Mathematica FITS header template. The documentation gives no hint on whether custom Metadata export is supported and how it might be done.

The following suggestions from comp.soft-sys.math.mathematica do not work:

header=Import[<some FITS file>, "Metadata"]; 
Export<"test.fits",data ,"Metadata"->header] 

or

Export["test.fits",{"Data"->data,"Metadata"->header}]

What is the proper way to export my own Metadata to a FITS file ?

Cheers,

Markus

Update: response from Wolfram Support: "Mathematica does not yet support Export of metadata for FITS file. The example are referring to importing of this data. We do plan to support this in the future..." "There are also plans to include binary tables into FITS import functionality."

I will try to come up with some workaround.

askewchan
  • 45,161
  • 17
  • 118
  • 134
Markus Roellig
  • 530
  • 3
  • 13
  • Hi Markus. Welcome to stackoverflow. I've edited your question to markup your code. (And sorry I don't know anything about FITS files...) – Simon Apr 12 '11 at 08:16
  • @Markus The error reporting in the Export[] command is very deficient. I found it just fails silently sometimes... so debugging is very difficult. – Dr. belisarius Apr 12 '11 at 11:55
  • Tried all kinds of tricks. Nothing works. ExportString doesn't seem to work for FITS either. Perhaps time for a bug report? – Sjoerd C. de Vries Apr 12 '11 at 12:57
  • @Sjoerd I did the same here. Import works pretty well, but Export[] seems to be able to deal with the images only. Seems more a non-implemented feature than a bug. – Dr. belisarius Apr 12 '11 at 13:01
  • @belisarius Indeed. I tried "Image" and that works and mma generates "Metadata" itself which you can read back but not set. "Author", "Comments" when exported yield None and {} when Imported. – Sjoerd C. de Vries Apr 12 '11 at 13:11
  • @rcollyer True. Somewhere in mathgroups I found `ConversionOptions->{"Verbose"->True}` did this in v5.2 – Dr. belisarius Apr 12 '11 at 13:23
  • @belisarius, As far as poor error reporting, I've found that with png files, mma offloads the processing to an external program and you have to wait for it to be finished before you have a real picture. Something similar most probably happens with other formats, too. – rcollyer Apr 12 '11 at 13:34
  • @belisarius, sorry. I deleted the comment on version as the docs for v.7 and v.8 are identical. – rcollyer Apr 12 '11 at 13:35
  • @rcollyer Yes. The program here is `fits.exe`. I disassembled it a little to see if something comes out quickly, to no avail – Dr. belisarius Apr 12 '11 at 13:40
  • @belisarius I sent a bug report to Wolfram. – Markus Roellig Apr 13 '11 at 09:17
  • Thanks for all the comments and for your time. – Markus Roellig Apr 13 '11 at 09:18

2 Answers2

0

Mathematica 9 now allows export of metadata (header) entries, which are additive to the standard required entries. In the Help browser, search "FITS" and there is an example that shows this (with Export followed by Import to verify).

0

According to the documentation for v.7 and v.8, there is a couple of ways of accomplishing what you want, and you almost have the rule form correct:

Export["test.fits", {"Data" -> data, "Metadata" -> header}, "Rules"]

The other ways are

Export["test.fits", header, "Metadata"]
Export["test.fits", {data, header}, {{"Data", "Metadata"}}]

note the double brackets around the element labels in the second method.

Edit: After some testing, due to prodding from @belisarius, whenever I include the "Metadata" element, I get an error stating that it is not a valid export element. Also, you can't export a "RawData" element, either. So, I'd submit a bug for two reasons: the metadata isn't user settable which is vitally important for any serious application. At a minimum, the user should at least be able to augment the default Mathematica metadata. Second, the documentation is woefully inadequate in describing what is a "valid" export element vs. import element. Of course, I'd describe all of the documentation for v.6 and beyond as woefully inadequate, so this is par for the course.

rcollyer
  • 10,475
  • 4
  • 48
  • 75
  • @Markus, I noticed. As I said, the documentation is really very poor. – rcollyer Apr 13 '11 at 12:37
  • @belisarius Only that Export of Metadata is not yet supported and planned for the future. The examples in the documentation refer to the Import functionality. In the meantime i experimented with linking to Pythonika and PyFits to manipulate FITS header. It works but I failed to incorporate this into a usable Package. If you are interested, I can send you the experimental notebook I played around with. – Markus Roellig Sep 26 '11 at 09:03
  • @Markus Thanks for the offering, but I just wanted to document here the status of the problem! – Dr. belisarius Sep 26 '11 at 10:18