-
Notifications
You must be signed in to change notification settings - Fork 287
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
Plotting Scene with Cartopy gives correct borders but red background #2161
Comments
Try passing |
Thanks for your quick response! Unfortunately:
When I see the CRS description in the plot title, the |
I just tried something similar with MSG data, and it looks like the data passed to matplotlib is to big. (the enhancements we usually apply to imagery before saving is not applied when calling |
Ah, I got something better with this: img = get_enhanced_image(new_scn[composite])
img.data.plot.imshow(rgb="bands", transform=CRS, origin="upper")
plt.show() Not as straightforward as I would have wished, but seems to work. |
Thanks Martin! This gives me a gray image:
|
@christianversloot Your script with import os
from satpy import Scene
from glob import glob
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from pyresample import create_area_def
# Print channel files used
fn = glob("/data/satellite/abi/20170920/*.nc")
print(fn)
# Create scene and define composite
scn = Scene(filenames=fn, reader='abi_l1b')
composite = 'true_color'
scn.load([composite])
# Create area definition
ext = [-110.629439, 31.594328, -95.933875, 37.384890]
width = 3840
height = 2160
area_def = create_area_def('TX/OK/NM',
{'proj': 'longlat', 'datum': 'WGS84'},
area_extent=ext,
shape=(height, width),
units='degrees',
description='TX/OK/NM border')
# Resample to AreaDefinition
new_scn = scn.resample(area_def)
new_scn.load([composite])
# Save without Cartopy
new_scn.save_dataset(composite, filename='no_cartopy.png')
# Plot composite
CRS = new_scn[composite].attrs['area'].to_cartopy_crs()
fig = plt.figure(figsize=(30,25))
ax = fig.add_subplot(1, 1, 1, projection=CRS)
from satpy.writers import get_enhanced_image
img = get_enhanced_image(new_scn[composite])
img.data.plot.imshow(rgb='bands', transform=CRS, origin='upper', ax=ax)
ax.add_feature(ccrs.cartopy.feature.STATES, linewidth=0.25)
# Save plot
plt.savefig('example.png') Note: This was with some old GOES-16 data I had in the "TEST" position but both your data and mine should cover Texas just fine. I also should note your second |
I have it working now! For reference of anyone else running into this problem: ensure that your version of Thanks both for your help! |
Glad you got it working. My recommendation for anyone working with cartopy would be to use conda and install packages from conda-forge. Mixing apt and PROJ/cartopy is going to be difficult. |
First things first: thanks for making such a well-supported library for satellite image processing.
Secondly: I'm aware that my question is Cartopy-oriented, but I'm opening an issue here because it is grounded in code one of Satpy's maintainers wrote in another issue (#1714). More specifically: #1714 (comment).
The problem: I am using Satpy to resample GOES-16 imagery using an area definition spanning the Texas/Oklahoma/New Mexico border area, using the
true_color
composite. I am trying to add borders with Cartopy. After resampling, I do get what I want:Then, when using the resampled Scene as a Cartopy CRS, I do see the borders - but the background is red:
I have tried to tinker a lot, using other examples as well, but I have no clue what I'm doing wrong. The code posted in the other issue (although slightly older than a year) seems to have worked, so why isn't mine :) What am I missing?
Thanks for your help!
The text was updated successfully, but these errors were encountered: