plans for jpeg2000 writer?

27 views
Skip to first unread message

Jonathan Slavin

unread,
Sep 30, 2016, 1:14:24 PM9/30/16
to SunPy
Hi all,

I'm wanting to edit the metadata in jpeg2000 files and output the results.  Sunpy has excellent facilities for reading in the data and metadata, but it seems that the writer is not implemented.  Are there any plans to implement that writer any time soon?  Any suggestions in the meantime?  I've looked at glymur and can read and edit the metadata using it, but I'm still stuck at how to write out the data with the updated metadata.

Regards,
Jon

DVD PS

unread,
Sep 30, 2016, 2:40:31 PM9/30/16
to sunpy
Hi Jon,

I'm wanting to edit the metadata in jpeg2000 files and output the results.  Sunpy has excellent facilities for reading in the data and metadata, but it seems that the writer is not implemented.  Are there any plans to implement that writer any time soon?  Any suggestions in the meantime?  I've looked at glymur and can read and edit the metadata using it, but I'm still stuck at how to write out the data with the updated metadata.

I've not used jpeg 2000 that much... but SunPy uses glymur for it as you've already noticed.

Glymur seems to be able to write a jp2 if you have the right OpenJPEG version (>1.5)
https://glymur.readthedocs.io/en/latest/how_do_i.html#write-images

and I've seen that we have a placeholder to write back to jp2.  I've spend a bit now trying to figure out how this thing works and probably the problem is to convert the "metadata" back into XML and then write it into the file. It doesn't seem too complicate... but probably needs time.

Jack, you've got more experience with this... is there any blocker that makes this "impossible"?

David

Jack Ireland

unread,
Sep 30, 2016, 2:55:48 PM9/30/16
to su...@googlegroups.com
David, Jon,

An application of this functionality would be to write JPEG2000 files for Helioviewer.  There are no show-stoppers that I am aware of.  However, we have yet to try pushing Python/SunPy/Glymur created JPEG2000 files through the full Helioviewer pipeline.  I'll take a look at it in the next couple of weeks.  It would be useful to write Helioviewer-compliant JPEG2000 files using SunPy.

Jack

--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sunpy+unsubscribe@googlegroups.com.
To post to this group, send email to su...@googlegroups.com.
Visit this group at https://groups.google.com/group/sunpy.
For more options, visit https://groups.google.com/d/optout.

Bogdan Nicula

unread,
Oct 1, 2016, 3:38:16 AM10/1/16
to SunPy


On Friday, September 30, 2016 at 8:55:48 PM UTC+2, ji wrote:
David, Jon,

An application of this functionality would be to write JPEG2000 files for Helioviewer.  There are no show-stoppers that I am aware of.  However, we have yet to try pushing Python/SunPy/Glymur created JPEG2000 files through the full Helioviewer pipeline.  I'll take a look at it in the next couple of weeks.  It would be useful to write Helioviewer-compliant JPEG2000 files using SunPy.

Jack
On Fri, Sep 30, 2016 at 2:40 PM, DVD PS <dps....@gmail.com> wrote:
Hi Jon,

I'm wanting to edit the metadata in jpeg2000 files and output the results.  Sunpy has excellent facilities for reading in the data and metadata, but it seems that the writer is not implemented.  Are there any plans to implement that writer any time soon?  Any suggestions in the meantime?  I've looked at glymur and can read and edit the metadata using it, but I'm still stuck at how to write out the data with the updated metadata.

I've not used jpeg 2000 that much... but SunPy uses glymur for it as you've already noticed.

Glymur seems to be able to write a jp2 if you have the right OpenJPEG version (>1.5)
https://glymur.readthedocs.io/en/latest/how_do_i.html#write-images

and I've seen that we have a placeholder to write back to jp2.  I've spend a bit now trying to figure out how this thing works and probably the problem is to convert the "metadata" back into XML and then write it into the file. It doesn't seem too complicate... but probably needs time.

Jack, you've got more experience with this... is there any blocker that makes this "impossible"?

David

--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sunpy+un...@googlegroups.com.

Slavin, Jonathan

unread,
Oct 1, 2016, 10:17:49 AM10/1/16
to su...@googlegroups.com
This looks promising but a little more documentation would be appreciated.

--
You received this message because you are subscribed to a topic in the Google Groups "SunPy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sunpy/QgEr9qczfHw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sunpy+unsubscribe@googlegroups.com.

To post to this group, send email to su...@googlegroups.com.
Visit this group at https://groups.google.com/group/sunpy.
For more options, visit https://groups.google.com/d/optout.



--
________________________________________________________
Jonathan D. Slavin                 Harvard-Smithsonian CfA
jsl...@cfa.harvard.edu       60 Garden Street, MS 83
phone: (617) 496-7981       Cambridge, MA 02138-1516
cell: (781) 363-0035             USA
________________________________________________________

Stuart Mumford

unread,
Oct 1, 2016, 11:49:37 AM10/1/16
to su...@googlegroups.com

Unhelpful comment:

SunPy's output routines for anything are poor, even FITS. :D

Stuart

Bogdan Nicula

unread,
Oct 1, 2016, 3:20:47 PM10/1/16
to SunPy

Sorry, indeed. Also some assembly may be required.
Contributions are welcome. I will give it a bit more attention the following months.
To unsubscribe from this group and all its topics, send an email to sunpy+un...@googlegroups.com.

To post to this group, send email to su...@googlegroups.com.
Visit this group at https://groups.google.com/group/sunpy.
For more options, visit https://groups.google.com/d/optout.



--

Bogdan Nicula

unread,
Oct 1, 2016, 3:47:50 PM10/1/16
to SunPy

I believe you want to do something similar to what is done on lines 35-50 of
Maybe that helps.

Slavin, Jonathan

unread,
Oct 3, 2016, 2:37:57 PM10/3/16
to su...@googlegroups.com
Hi Bogdan,

Thanks for that pointer.  I think I have it working now, though I need to do a little more testing.

Regards,
Jon

--
You received this message because you are subscribed to a topic in the Google Groups "SunPy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sunpy/QgEr9qczfHw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sunpy+unsubscribe@googlegroups.com.

To post to this group, send email to su...@googlegroups.com.
Visit this group at https://groups.google.com/group/sunpy.
For more options, visit https://groups.google.com/d/optout.

Slavin, Jonathan

unread,
Oct 4, 2016, 9:06:35 AM10/4/16
to su...@googlegroups.com
Hi Bogdan,

My code does indeed work now.  It's simpler than I thought.  I read in a jpeg2000 file via:
jp2 = glymur.Jp2k(jp2file)
and then get the metadata that I want:
tree = jp2.box[3].xml # I call it tree because it's an etree
metaroot = tree.getroot() # need element to get at header values
And in my case I must in addition do:
fitshdr = metaroot[0]
But then if I make changes to fitshdr, e.g.
fitshdr.find('NAXIS1').text = naxis1
These changes are in jp2.  So all the things I get our of the metadata, tree, metaroot, fitshdr, are apparently references and not copies.  Then all I need to do is
jp2n = jp2.wrap(newfile,boxes=jp2.box)
and I get what I want.

Regards,
Jon
Reply all
Reply to author
Forward
0 new messages