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

Create ocean bathymetry example #2195

Merged
merged 7 commits into from
Jul 14, 2023
Merged

Conversation

lgolston
Copy link
Contributor

Rationale

In a previous pull request (#1916) @mattphysics created a notebook for plotting ocean bathymetry using Natural Earth data, but it was not finished. I have here converted it to converted it to a script, reduced the length in some places, and propose adding it to the example gallery.

Implications

The shapereader.natural_earth interface does not work on this particular file, since the .zip contains multiple shapefiles corresponding to different depths. I think it is a nice example using cartopy's shapereader.Reader interface. The axis extent is set to [90, 160, -15, 60] to help speed up the script versus plotting the whole world.
test

@lgolston
Copy link
Contributor Author

This time the page built successfully on circleci: bathymetry example

@lgolston
Copy link
Contributor Author

Several changes: I realized this fits better under lines_and_polygons, so moved the file there. There is also now more text at top introducing the example, and the colorbar now has an arrow to indicate the depth can go below -10,000 m. Link to current version

I should also bring up the earlier commit adding bbox=None to the BasicReader class. This was because the circleci docs builder is not using fiona and passing a bbox as in this example threw an error. Since the two classes are treated interchangeably, I would not expect this to cause an error. Therefore, now the behavior is that passing a bbox will not cause an error but will be silently ignored unless you are using FionaReader. Is this reasonable, or maybe that situation should raise a warning instead noting that the bounding box will not be used?


# Construct colormap:
# Depth levels in the colorbar are spaced as in the data
norm = matplotlib.colors.Normalize(vmin=-10000, vmax=0) # in meters
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to quantize this and use BoundaryNorm() here since you have explicit levels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this comment @greglucas . I have switched it to use BoundaryNorm. This ended up helping better link the data to the colorbar.

# Add custom colorbar
axi = fig.add_axes([0.85, 0.1, 0.025, 0.8])
ax.add_feature(cfeature.BORDERS, linestyle=':')
matplotlib.colorbar.ColorbarBase(ax=axi,
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 use fig.colorbar() here instead since I think that is more typical than going for the base classes in an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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.

Nice, this reads much simpler to me now. Just a few minor comments.

examples/lines_and_polygons/ocean_bathymetry.py Outdated Show resolved Hide resolved
examples/lines_and_polygons/ocean_bathymetry.py Outdated Show resolved Hide resolved
examples/lines_and_polygons/ocean_bathymetry.py Outdated Show resolved Hide resolved
@lgolston
Copy link
Contributor Author

Thanks for providing those comments. When working through them, I found the color displayed for depth=0 was not matching the colorbar, which is fixed now. Hopefully things are squared away now but please let me know if you see any other issues.

@greglucas greglucas merged commit 299a40d into SciTools:main Jul 14, 2023
@greglucas
Copy link
Contributor

Thanks @lgolston!

@mattphysics
Copy link

mattphysics commented Jul 14, 2023 via email

@lgolston lgolston deleted the bathymetry-example branch July 18, 2023 16:22
@QuLogic QuLogic added this to the 0.22 milestone Sep 3, 2024
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