Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Satpy font error #6

Closed
gersmit opened this issue Jan 11, 2021 · 20 comments
Closed

Satpy font error #6

gersmit opened this issue Jan 11, 2021 · 20 comments
Labels
question Further information is requested

Comments

@gersmit
Copy link

gersmit commented Jan 11, 2021

Dear @djhoese ,
I thought I was there, had the hard part but unfortunately not. You already close the other issue so i hope it is no problem to ask you how to write text on a easy way into the image.
As i say, i works fine but.....
I have a python routine that put text into an image. But i think with satpy is that also possible.
I have this and is working good until i set "write_text : False" to True, then ik get different errors

import aggdraw
from aggdraw import Draw, Brush, Pen, Font
#font = aggdraw.Font('blue','/home/pi/eumetview/arial.ttf', size = 12)
# Font takes only 4 arguments
local_scn.save_dataset('overview', data_img_warmte + 'test.png',
overlay={'coast_dir': '/home/pi/eumetview/GSHHS_DATA_ROOT/',
"overlays": {
"coasts": {
"outline": (255, 255, 0),
"width": 1.5,
"level": 1,
"resolution": "f"},
'grid': {
'major_lonlat': (10, 10),
'write_text': False,
'outline': (224, 224, 224),
'width': 0.5,
"lakes": {
"outline": (255, 0, 0),
"width": 1.5,
"level": 1,
"resolution": "f"},
'text': {'txt': 'start_time_txt',
'align': {'top_bottom': 'bottom', 'left_right': 'right'},
'font':'/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf',
'outline': (224, 224, 224),
'font_size': 12,
'height': 30,
'bg': 'black',
'bg_opacity': 255,
'line': 'white'},
"borders": {
"outline": (0, 0, 0),
"width": 1.5,
"level": 3,
"resolution": "f"}}}})

Traceback (most recent call last):
File "/home/pi/eumetview/maak_sneeuw_kaart.py", line 275, in
"resolution": "f"}}}})
File "/home/pi/.local/lib/python3.7/site-packages/satpy/scene.py", line 1314, in save_dataset
compute=compute, **save_kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/satpy/writers/init.py", line 829, in save_dataset
return self.save_image(img, filename=filename, compute=compute, fill_value=fill_value, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/satpy/writers/simple_image.py", line 65, in save_image
return img.save(filename, compute=compute, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/trollimage/xrimage.py", line 423, in save
compute=compute, **format_kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/trollimage/xrimage.py", line 617, in pil_save
return delay.compute()
File "/home/pi/.local/lib/python3.7/site-packages/dask/base.py", line 167, in compute
(result,) = compute(self, traverse=False, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/dask/base.py", line 452, in compute
results = schedule(dsk, keys, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/dask/threaded.py", line 84, in get
**kwargs
File "/home/pi/.local/lib/python3.7/site-packages/dask/local.py", line 486, in get_async
raise_exception(exc, tb)
File "/home/pi/.local/lib/python3.7/site-packages/dask/local.py", line 316, in reraise
raise exc
File "/home/pi/.local/lib/python3.7/site-packages/dask/local.py", line 222, in execute_task
result = _execute_task(task, data)
File "/home/pi/.local/lib/python3.7/site-packages/dask/core.py", line 121, in _execute_task
return func(*(_execute_task(a, cache) for a in args))
File "/home/pi/.local/lib/python3.7/site-packages/trollimage/xrimage.py", line 643, in _delayed_apply_pil
new_img = fun(pil_image, image_metadata, *fun_args, **fun_kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/satpy/writers/init.py", line 183, in burn_overlay
cw
.add_overlay_from_dict(overlays, area, background=img)
File "/home/pi/.local/lib/python3.7/site-packages/pycoast/cw_base.py", line 891, in add_overlay_from_dict
lat_placement=lat_placement)
File "/home/pi/.local/lib/python3.7/site-packages/pycoast/cw_agg.py", line 364, in add_grid
lat_placement=lat_placement)
File "/home/pi/.local/lib/python3.7/site-packages/pycoast/cw_base.py", line 383, in _add_grid
txt, font, **kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/pycoast/cw_base.py", line 123, in _draw_grid_labels
font = self._get_font(kwargs.get('outline', 'black'), font, 12)
File "/home/pi/.local/lib/python3.7/site-packages/pycoast/cw_agg.py", line 648, in _get_font
return aggdraw.Font(outline, font_file, size=font_size)
TypeError: Font() argument 2 must be str, not None

When i use font=aggdraw.Font('blue', 'home/pi/eumetview/arial.ttf, size=12)
Error ==
Traceback (most recent call last):
File "/home/pi/eumetview/maak_sneeuw_kaart.py", line 242, in
font = aggdraw.Font('blue','/home/pi/eumetview/arial.ttf', size = 12)
OSError: cannot load font (no text renderer)

Where am I making the mistake, thanks for helping me

@djhoese
Copy link
Member

djhoese commented Jan 11, 2021

Try removing font_size and instead create a font object like this:

import aggdraw
font =  aggdraw.Font('black', '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf', size=12)

and do:

...
'font': font,
...

In your parameters.

@djhoese djhoese added the question Further information is requested label Jan 11, 2021
@gersmit
Copy link
Author

gersmit commented Jan 11, 2021

I no what you mean but when python runs the row:
font = aggdraw.Font('black', '/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf', size=12) I immediately get the error
File "/home/pi/eumetview/maak_sneeuw_kaart.py", line 242, in
font = aggdraw.Font('blue','/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf', size=12)
OSError: cannot load font (no text renderer)

Before it start the routine overlay=
I removed aggdraw as someone say (install it again) and try other solutions.

@djhoese
Copy link
Member

djhoese commented Jan 11, 2021

Does that font actually exist on your system? Meaning does the file /usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf exist?

@gersmit
Copy link
Author

gersmit commented Jan 11, 2021

dejavu

@djhoese
Copy link
Member

djhoese commented Jan 11, 2021

How did you install aggdraw? With pip? You could try making sure that your system has the "freetype" library (include the dev version) installed. Maybe that's the issue (based on other issues we've had with this in the past with aggdraw).

I'm currently rereading: ejeschke/ginga#664

@gersmit
Copy link
Author

gersmit commented Jan 11, 2021

Yes, i read sommething about that.
I read on StackOverflow that freetype give problem with aggdraw?
Do you have instruction for me how to install freetype, And do i have to use this also? -> https://github.com/pytroll/aggdraw

@djhoese
Copy link
Member

djhoese commented Jan 11, 2021

I believe freetype is used to read the .ttf fonts. If it isn't installed then aggdraw can't use it. You already have aggdraw installed as it is a requirement of pycoast. How old was the stackoverflow question? Pytroll (me) has revived the project and made some big improvements for finding freetype.

Installing freetype can either be done by install freetype-py (the python package) or using your system's package manager? It is different for each operating system.

@gersmit
Copy link
Author

gersmit commented Jan 12, 2021

Pip3 list show this:
pycoast 1.4.0, freetype-py 2.2.0, aggdraw 1.3.12
Only pytroll is not in the list, is that the problem?

I think i am going to remove and make an new install from the modules.

@djhoese
Copy link
Member

djhoese commented Jan 12, 2021

"pytroll" is not a package that gets installed. "pytroll" is the community and "suite" of tools. You may be thinking of "satpy"?

Uninstalling/reinstalling aggdraw and freetype-py may be useful. I'm sorry, but I'm not sure how to help beyond this as this seems to be an issue specific to your system right now.

@gersmit
Copy link
Author

gersmit commented Jan 12, 2021

@djhoese, thanks,
Problem and i wil use other RPI to test.
Also i try wit pil and pillow but get still aggdraw error.
Can you tell me what error message under means, perhaps we can find solution there:

80, in add_points
font = self._get_font(outline, font_file, font_size)
File "/home/pi/.local/lib/python3.7/site-packages/pycoast/cw_agg.py", line 648, in _get_font
return aggdraw.Font(outline, font_file, size=font_size)
TypeError: Font() argument 2 must be str, not FreeTypeFont

@djhoese
Copy link
Member

djhoese commented Jan 12, 2021

Also i try wit pil and pillow but get still aggdraw error.

What do you mean by this? How did you change your code?

The error message you are receiving is because pycoast mixing up its fonts and passing a Pillow-style FreeTypeFont object, but the AGGContourWriter wants a string (the path to a font).

Also, I forgot you were on a raspberry pi. You may want to install freetype using your system's package manager rather than from freetype-py. If you are on a debian/ubuntu-style system you may be able to do something like "sudo apt-get install libfreetype6" and then reinstall aggdraw.

@gersmit
Copy link
Author

gersmit commented Jan 14, 2021

It remains a problem and after trying everything and searching with Google I find out that it is not only my problem. I read several issues with your name that it is a problem for many. I thought I found something: pytroll/pycoast#43, but these solutions also lead to nothing. The main thing is Aggdraw which gives the problems.
return aggdraw.Font(outline, font_file, size=font_size)
TypeError: Font() argument 2 must be str, not None

Last question: no workaround has been developed that solves the problem. Incidentally, the border - coast and other lines work perfectly, only the control font crashes.

@djhoese
Copy link
Member

djhoese commented Jan 14, 2021

@gersmit This error you pasted:

TypeError: Font() argument 2 must be str, not None

Is fixed by passing the aggdraw Font object as I described originally. The error you got after that about OSError: cannot load font (no text renderer) is a different issue and something to do with your installation as far as I can tell. Do you have another machine you can test on that isn't a rpi?

@gersmit
Copy link
Author

gersmit commented Jan 14, 2021

Yes, i wil try on other RPI but i better going to see what Windows do. 👍

@gersmit
Copy link
Author

gersmit commented Jan 15, 2021

@djhoese,

I think solved problem.
Find aggdraw special for python3.
I think no more problems for the users with the same problem.
aggdraw

@djhoese
Copy link
Member

djhoese commented Jan 15, 2021

Glad you got it working. I'm not sure I understand what you did to fix it, but still glad it works.

I'm going to close this issue now. Feel free to file bug reports on the specific packages you are using (satpy, pycoast, etc) if you run into future issues. That way the people who work on those packages will see the issues rather than just me.

@djhoese djhoese closed this as completed Jan 15, 2021
@gersmit
Copy link
Author

gersmit commented Jan 15, 2021

@gersmit
Copy link
Author

gersmit commented Aug 1, 2021

@djhoese hi, I have a question about making parts of a scene image transparent.
Is it possible to add transparency if, for example, the given temperature is higher or lower than, say, 240 Kelvin?
I then want to keep the pixels that are 240 degrees and remove the rest, make them transparent.

Thanks in advance for an answer

@djhoese
Copy link
Member

djhoese commented Aug 1, 2021

@gersmit In the future please create a new separate issue for any questions you have. You should also make your questions on the Satpy repository (https://github.com/pytroll/satpy) if they aren't specific to something in this tutorial. That way other Satpy developers can see and answer your question.

As for your question, you'll probably want to look at using the MaskingCompositor: https://satpy.readthedocs.io/en/stable/api/satpy.composites.html?highlight=MaskingCompositor#satpy.composites.MaskingCompositor

@gersmit
Copy link
Author

gersmit commented Aug 1, 2021

Sorry about this, I'll keep an eye out for it and thanks for the answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants