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

add_grid color and font handling is confusing #52

Open
djhoese opened this issue Mar 4, 2021 · 1 comment
Open

add_grid color and font handling is confusing #52

djhoese opened this issue Mar 4, 2021 · 1 comment
Assignees

Comments

@djhoese
Copy link
Member

djhoese commented Mar 4, 2021

I was working on a code example to show how the fill keyword argument on add_grid doesn't do anything (which it doesn't), but I couldn't even get an example to work without it being obvious why it didn't work. Let me explain:

  1. fill is actually not used anywhere from add_grid as far as I can tell.
  2. If font is None it fails:

pycoast/pycoast/cw_base.py

Lines 121 to 123 in c9584be

if font is None:
# NOTE: Default font does not use font size in PIL writer
font = self._get_font(kwargs.get('outline', 'black'), font, 12)

This code makes very little sense as we just checked if font is None and then we use it. For the AGG writer this is expected to be the path to the font file...but if we provide a font file path then it doesn't get used because we only create the font object if it is None!?!? 😕

So then you, the user, think "oh I'll just provide a font object", well at that point you aren't using the font size or the fill because aggdraw Fonts have to have the color defined when they are created.

from PIL import Image
import numpy as np
from pycoast import ContourWriterAGG
from pyresample.geometry import AreaDefinition

area_def = AreaDefinition('test', 'test', 'test', {'ellps': 'GRS80', 'h': '35786023', 'lon_0': '-75', 'proj': 'geos', 'units': 'm'}, 1000, 1000, area_extent=(-3600000, -3600000, 3600000, 3600000))

data = np.zeros((1000, 1000, 3), dtype=np.uint8)
img = Image.fromarray(data)
cw = ContourWriterAGG('/data/gshhg_shapefiles')
cw.add_grid(img, area_def, (5, 5), (1, 1), font=aggdraw.Font('green', '/home/davidh/repos/git/pydecorate/pydecorate/fonts/DejaVuSerif.ttf'), outline='red', fill='blue', width=10)
img.save('test.png')

test

So...this needs to be improved. This is confusing to say the least.

@djhoese djhoese self-assigned this Mar 4, 2021
lobsiger added a commit to lobsiger/pycoast that referenced this issue May 3, 2022
@djhoese
Copy link
Member Author

djhoese commented May 6, 2022

@lobsiger I'm going to think about this a little more before closing. I think the code is still confusing and if things are rearranged (ex. not creating a default font inside a low-level method) things would be more clear. I will do this as part of my larger refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant