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

Fix NameError when writing grid text in certain cases #70

Merged
merged 2 commits into from
Nov 7, 2022

Conversation

djhoese
Copy link
Member

@djhoese djhoese commented Nov 6, 2022

As described on the mailing list, somewhere in the refactor of #63 I introduced a bug. As can be seen in the code the iteration variable index_array is used after the for loop, but if the iteration never happens (empty iterator) then this variable isn't defined. This PR fixes this issue with the least disruptive way I could think of. In my refactor I had made things into generators so doing a simple len on the index_arrays isn't possible.

More worrying is that this copied test should have completely different results (right @lobsiger?) since it has write_text=True, but the same expected result .png compares successfully.

TODO:

  • Some refactoring
  • Closes #xxxx
  • Tests added
  • Tests passed
  • Passes git diff origin/main **/*py | flake8 --diff
  • Fully documented

@djhoese djhoese added the bug label Nov 6, 2022
@djhoese djhoese self-assigned this Nov 6, 2022
@coveralls
Copy link

coveralls commented Nov 6, 2022

Coverage Status

Coverage decreased (-0.1%) to 94.993% when pulling 93e9bbc on djhoese:bugfix-grid-index-array-nameerror into 11303e6 on pytroll:main.

@djhoese
Copy link
Member Author

djhoese commented Nov 6, 2022

Ok, so now I understand, this is a flaw in pycoast in my opinion. @lobsiger I'm curious what your thoughts are. The reason the write_text False case and True case result in the same image is that the labeling only looks for points on the line that intersect the edge of the image. In the geostationary full disk case all the lon/lat lines are on the inside of the image.

I won't be fixing this in this PR, but it is pretty annoying that I feel like could be added. For example, check all the edges, if no edges then put labels on the ends of the lines.

@djhoese
Copy link
Member Author

djhoese commented Nov 6, 2022

@mraspaud @pnuu I think I'd like to keep the original test and my new test (which is a copy of it with one keyword difference) as two separate tests knowing that the results should change in a future PR. I can refactor them more if needed. 🤔 Or maybe I should parametrize them with pytest and in the future I just have two versions of the end result.

@djhoese
Copy link
Member Author

djhoese commented Nov 6, 2022

FYI I avoided doing stuff I should be doing and tried rewriting some of the important code in pycoast to use more numpy. It ended up being slower...so probably won't be wasting time doing that for a while.

@lobsiger
Copy link
Contributor

lobsiger commented Nov 7, 2022

@djhoese I entered your PR 70 manually and get no grid labels anymore. This explains IMHO why your test passed with "write_text=False" or without "write_text=True". Did I miss something? Here is an improved script to test. It uses s = scale and t = translation. As published it should produce my latest image on the google list that I still made with PyCoast 1.5.0.

PyCoast-1-6-0-BUG.py.txt

@lobsiger
Copy link
Contributor

lobsiger commented Nov 7, 2022

@djhoese sorry Dave. I DID actually miss something. I have played yesterday with lon_placement, lat_placement and these are still in my code empty. So everything works as before. I propose to let it as is with labels only at the sides of the area_extent[].
Cheers,
Ernst

@djhoese
Copy link
Member Author

djhoese commented Nov 7, 2022

@lobsiger I agree on the test passing because there are no labels being written/drawn. Unfortunate that some a "basic" use case doesn't have labels.

I'm not sure I understand your second comment. With this PR, is everything as expected?

@lobsiger
Copy link
Contributor

lobsiger commented Nov 7, 2022

@djhoese as you can see in the script I attaches above I have:

cw.add_grid(img, area_def, (10., 10.), (2., 2.), lat_placement='', lon_placement='', write_text=write_text, outline='white')

This is left from yesterday when I wanted to test "write_text=True" but without label placements. It did not work with PyCoast 1.6.0. Now today I patched my PyCoast 1.6.0 according to your [PR 70] and tested with the above script again and was confused not to see any labels (at first). Only one hour later I remembered the placement and noted it's still empty. I deleted this like

cw.add_grid(img, area_def, (10., 10.), (2., 2.), write_text=write_text, outline='white')

and everything worked as expected. Default grid label placement is lon_placement='b', lat_placement='lr' IIRC.

@djhoese
Copy link
Member Author

djhoese commented Nov 7, 2022

So I guess with that answer, this PR is ready for review @mraspaud @pnuu

Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for switching to pytest at the same time.

@djhoese djhoese merged commit 85efe8b into pytroll:main Nov 7, 2022
@djhoese djhoese deleted the bugfix-grid-index-array-nameerror branch November 7, 2022 16:46
@djhoese
Copy link
Member Author

djhoese commented Nov 7, 2022

FYI version 1.6.1 is available on PyPI and was just merged on conda-forge. Should be available for download from conda-forge in the next hour or so.

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

Successfully merging this pull request may close these issues.

4 participants