unicodedata cp437

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

unicodedata cp437

Post by joleenf »

Hi,

I don't know much about unicodedata, I am confused, why doesn't cp437 contain a reference to 'GREEK SMALL LETTER MU'?

Screen Shot 2013-10-30 at 12.02.16 PM.png



Even though it is unlikely that I will get this to work, I was trying to find a path to printing a "mu" character on an output image using writeImage. Even though it is possible to annotate with greek characters using annotate (µ), there were some problems getting annotate to plot consistently in a script. Therefore, writeImage is being used. Even if annotate was working consistently, writeImage would be needed to plot text because the final display will be rotated.

Joleen
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: unicodedata cp437

Post by ghansham »

Hi joleen
Sometime back I wrote hindi string on indian satellite data.
Will that be of any help to you?
Regards
Ghansham
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: unicodedata cp437

Post by joleenf »

Ghansham,

It might, I may encounter other problems with writeImage, but it would help to have a working example. I am not sure if I am using the code tables correctly. Specifically for 'GREEK SMALL LETTER MU', I get the following results...

Code: Select all

import unicodedata as ud
import sys

print sys.getdefaultencoding()

sys.setdefaultencoding('iso8859-7')
print 'iso8859-7: ',ud.lookup('GREEK SMALL LETTER MU')

sys.setdefaultencoding('mac-greek')

print 'mac-greek: ', ud.lookup('GREEK SMALL LETTER MU')

sys.setdefaultencoding('cp437')
print 'cp437: ', ud.lookup('GREEK SMALL LETTER MU')



returns

ascii
iso8859-7: Ï
mac-greek: Ì
cp437: Traceback (most recent call last):
File "", line 14, in
File "/Users/joleenf/Documents/McIDAS-V/jython2.5.2/Lib/encodings/cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u03bc' in position 0: character maps to <undefined>


I probably should not be changing the default encoding, but I could not figure out why I could not get this to work. After I have a solution to getting a greek symbol, it still might be difficult to pass that to writeImage, I am not sure how information gets interpreted through that function.

Joleen
User avatar
tomw
Posts: 296
Joined: Tue Dec 23, 2008 3:40 pm

Re: unicodedata cp437

Post by tomw »

The issue is that the XML parsing being used by "writeImage()" needs to explicitly request UTF-8 encoding and not whatever the default is. We have verified this on Windows and OS-X.

I have submitted the change to Unidata.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: unicodedata cp437

Post by joleenf »

Once this change is incorporated, it should be possible to insert the symbol directly in the writeImage command...

writeImage("/temp/idvimg.png", "overlay text=11.7 µm anchor=UM place=UM,0,70 color=green fontsize=32 fontface=Arial")

On a mac that is "alt-m", on window, the micro entity can be selected.

Joleen
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: unicodedata cp437

Post by ghansham »

I think it is possible without that. What I did was last time
as far as I remember was inserted the unicode string in a properties file and used filereader constructor of java.util.properties to read that string in java and it worked. I didnt get time to send you a demo.
Will try to send a sample script.
Ghansham
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: unicodedata cp437

Post by joleenf »

Thanks Ghansham, when you have the time, I still would be really interested in seeing that script.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: unicodedata cp437

Post by joleenf »

Hi Bob,

It looks like
http://mcidas.ssec.wisc.edu/inquiry-v/?inquiry=1832

Is still an issue....I have tried various combinations for getting the proper encoding through the writeImage formatting, and still can't get a proper symbol.

p=buildWindow()[0]
p.captureImage('test.png', formatting=[TextOverlay(text='amp \\\u00fb \u00fb µm', place='MM,0,0', anchor='MM', color='yellow')])

I have posted to the IDV user group as well to find out if any IDV users found a work around, but have received no responses so far.

Thanks,
Joleen
User avatar
bobc
Posts: 990
Joined: Mon Nov 15, 2010 5:57 pm

Re: unicodedata cp437

Post by bobc »

Hi Joleen -

You're correct that this is still an issue. I spent some time trying to find a workaround, but I was unsuccessful. I added a note to Inquiry 1832 that you came across the problem again. Please let us know if you hear anything back from the IDV user's list or if you are able to find a workaround yourself.

Thanks -
Bob
Post Reply