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

fixes plotting error in declarative with hires data #1595

Merged
merged 1 commit into from Dec 2, 2020

Conversation

kgoebber
Copy link
Collaborator

@kgoebber kgoebber commented Dec 2, 2020

Description Of Changes

This fix to the declarative syntax is to address the issue brought up by @marcinkawka in Issue #1590 where they were experiencing issues with contouring values. Upon a deep dive into the declarative code, I believe that this issue arose due to the high resolution of the data being used and the use of a modulo in generating x-component values for plotting that were problematic.

The fix to this problem is to not take the modulo of the x values being computed when transforming points from lat/lon to projection coordinates. I don't know why this was needed initially as none of the tests fail with that removed (also removed from the barb plotting aspect as well with similar result).

I have added a new test dataset based on the data used in the issue in ensure this issue is covered.

Here is an example using the new test data that reproduces the bad behavior:

from datetime import datetime

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
from metpy.cbook import get_test_data
import numpy as np
import xarray as xr

read_test_data = xr.open_dataset(get_test_data('CAM_test.nc', False))

x, y, _ = ccrs.PlateCarree().transform_points(ccrs.PlateCarree(),
                                              *np.meshgrid(read_test_data.longitude,
                                                           read_test_data.latitude)).T
x = x[:, 0] % 360
y = y[0, :]

fig = plt.figure(1)
ax = fig.add_subplot(111, projection=ccrs.PlateCarree())
cs = ax.contour(x, y, read_test_data.PN[0,0].values, range(0, 1400, 4), linewidths=2)
ax.add_feature(cfeature.BORDERS.with_scale('50m'))
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))

plt.clabel(cs, fmt='%d')
plt.show()

To get the appropriate behavior, simply remove the % 360 on the x variable.

Checklist

Copy link
Member

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

I know we needed this when we did our initial testing for the declarative. Maybe differences in datasets that are 0->360 vs. -180-> 180? I dunno, without a test we're philosophically safe to drop it.

We'll just end up having to find a way to fix it properly when we get a bug report about this...because of course we will.

@dopplershift dopplershift added Area: Plots Pertains to producing plots Type: Bug Something is not working like it should labels Dec 2, 2020
@dopplershift dopplershift added this to the 1.0 milestone Dec 2, 2020
@dopplershift dopplershift merged commit 49e041d into Unidata:master Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Plots Pertains to producing plots Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Contour interpolation problem
2 participants