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

Coastlines update #1823

Merged
merged 1 commit into from
Aug 11, 2021
Merged

Coastlines update #1823

merged 1 commit into from
Aug 11, 2021

Conversation

MHBalsmeier
Copy link
Contributor

Rationale

The GSHHS coastlines that cartopy was automatically downloading were quite old, lots of newer versions came out. Several issues were raised about this (#1353, #1659). I updated the coastlines from 2.2.0 to 2.3.6.

Implications

More up-to-date and better coastlines are used that include bugfixes and resolve some shape warnings that were frequently thrown.

@MHBalsmeier
Copy link
Contributor Author

MHBalsmeier commented Jul 29, 2021

Undid 00f95f1 and instead used black to achieve correct code format.
Sorry this PR looks chaotic now but I had a hard time with this stickler-ci.

I do not know why the Mac OS test fails though.

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

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

I wonder if it is possible to get the latest version?
https://www.ngdc.noaa.gov/mgg/shorelines/data/gshhg/latest/
That would be complicated by the version number being updated in the URL, but it would be nice to just always get the latest updates when possible.

Can you squash all of your commits? It is a bit complicated to follow when adding/removing content. You can safely ignore the Python3.6 failing test right now, it isn't related to your PR.

lib/cartopy/io/shapereader.py Outdated Show resolved Hide resolved
@MHBalsmeier
Copy link
Contributor Author

The changing URL is indeed the reason for me not choosing the latest version. I agree this would be nice, but I cannot think of a safe way to implement this. I could try something like *shp*.zip, but that is not safe either if the next version should be named differently.

I implemented your suggestion about the c4 combination. Now I will try to squash the commits.

@greglucas
Copy link
Contributor

👍 That may be overcomplicating things to parse the latest page to grab the url. I wonder if adding a version number to the arguments of the downloader would be useful though, so we could just update the version number when it is bumped? Then you could try both the latest location and old location to download that version number which would gracefully handle the move from latest to old. Something like:

try:
    self._urlopen(latest_url)
except HTTPError:
    self._urlopen(oldversions_url)

I think what you have is a good update though, so don't feel obligated to add the suggestion, it can be handled in a follow-up PR as well.

@MHBalsmeier
Copy link
Contributor Author

Okay I will try this, let's do this in this PR.

try:
shapefile_online = self._urlopen(url)
except HTTPError:
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that if ngdc updates to a new version, users are going to get a warning that they can't fix (without resorting to a warning filter)? I'm not a fan of issuing warnings when users are doing nothing wrong and can't fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is what it means, but ...

  • it happens only once (and a Download warning also happens when the coastlines are downloaded anyway)
  • it is better than having no warning but the bugs of an old coastline data set.

Alternative would be to either download the older version in the first place as before or leave the warning away.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a third option, which is what I was trying to hint at, which is to put a version number in somewhere.

_GSHHS_URL_TEMPLATE = f'https://www.ngdc.noaa.gov/mgg/shorelines/data/gshhg/latest/gshhg-shp-{version}.zip'

Then on the except you would do:

url = f'https://www.ngdc.noaa.gov/mgg/shorelines/data/gshhs/oldversions/version{version}/gshhg-shp-{version}.zip'

I assume that the 2.3.7 will be moved over to the archive at some point when a new one comes up, and this would catch that case assuming they keep their naming convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't we have something in the except that works even if the naming convention is changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Add a fallback if both of those fail to the 2.3.6 version if both throw the URL not found error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, here is my attempt

@MHBalsmeier
Copy link
Contributor Author

Okay, did squash everything into one again. Maybe someone can check.

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

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

Worked for me locally! Just one minor request to update the docs.

zfh = ZipFile(io.BytesIO(shapefile_online.read()), 'r')
shapefile_online.close()

# Iterate through all scales and levels and extract relevant files.
modified_format_dict = dict(format_dict)
scales = ('c', 'l', 'i', 'h', 'f')
levels = (1, 2, 3, 4)
levels = (1, 2, 3, 4, 5, 6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the documentation to indicate it goes up to 6 now?

A list of integers 1-4 corresponding to the desired GSHHS feature
levels to draw (default is [1] which corresponds to coastlines).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did that, will squash once more

@MHBalsmeier MHBalsmeier requested a review from greglucas July 30, 2021 15:29
@MHBalsmeier
Copy link
Contributor Author

sorry this review request was a mistake of mine

@MHBalsmeier
Copy link
Contributor Author

MHBalsmeier commented Jul 30, 2021

Looks like I did something wrong with the squash.
Maybe we should close this and I do it all in one new clean pull request from a new clone.

@greglucas
Copy link
Contributor

Keep going with this PR if you can. You're close on the rebase I think!

Try this:

git fetch upstream
git rebase -i upstream/master

Then delete the extra commit from your work and keep this one.

error handling and doc update.
@MHBalsmeier
Copy link
Contributor Author

Okay, thanks. Let's see.

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

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

@dopplershift, I think the warning you were concerned with is removed now. I'll leave open for a bit in case you have any comments on this.

@MHBalsmeier
Copy link
Contributor Author

MHBalsmeier commented Jul 30, 2021

@dopplershift, I think the warning you were concerned with is removed now. I'll leave open for a bit in case you have any comments on this.

Yes I removed it.

@greglucas greglucas merged commit e5d636b into SciTools:master Aug 11, 2021
@greglucas
Copy link
Contributor

Thanks for updating this, @MHBalsmeier!

@MHBalsmeier MHBalsmeier deleted the coastlines_update branch August 11, 2021 05:37
@greglucas greglucas added this to the 0.20 milestone Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants