Open prasanjitdash opened 3 years ago
instead of using
img_data.plot.imshow(rgb='bands', vmin=0, vmax=1)
I'd like to use cartopy+matplotlib as follows:
cs = ax.imshow(img_data, transform=data_crs, vmin=0, vmax=1, zorder=2)
Hi @djhoese
I think you can ignore the single question that I had. It seems like I can use CartoPy to plot a composite image. The single-band image was easy enough, but plotting the composite took me a while to understand. But if you know of a better way, I'd be glad to hear.
composite = 'true_color_lowres'
new_scn
is the resampled scene object.
extent
is the desired extent in [x0, x1, y0, y1]
%%time
with ProgressBar():
target_crs = ccrs.PlateCarree()
data_crs = new_scn[composite].attrs['area'].to_cartopy_crs()
fig, ax = plt.subplots(nrows=1,ncols=1, subplot_kw={'projection': target_crs}, \
figsize=({insert fig size})
ax.set_extent(extent)
ax.add_feature(land, linewidth=1., linestyle='--', alpha=1, zorder=0);
ax.add_feature(ocean, linewidth=1., linestyle='--', alpha=1, zorder=1);
# cs = ax.imshow(img, transform=data_crs, vmin=0, vmax=1, zorder=2)
img_data.plot.imshow(transform=data_crs, vmin=0, vmax=1, rgb='bands', zorder=2)
gl = ax.gridlines(crs=target_crs, draw_labels=True, linewidth=0.5, color='gray', alpha=0.8, linestyle='--')
gl.xformatter, gl.yformatter = LONGITUDE_FORMATTER, LATITUDE_FORMATTER
ax.add_feature(coastline, linewidth=1., linestyle='--', alpha=1, zorder=3);
plt.title(title, fontsize=18);
As Johan mentioned on slack, there is this option:
from satpy.writers import get_enhanced_image
arr = np.moveaxis(get_enhanced_image(scn).data.values, 0, -1)
plt.imshow(arr, ...)
But I personally prefer letting xarray figure it out like you have it.
For your smaller issues, I'll try to check those out today. If you have the actual error messages produced that would help a lot. I know for the dynamic
keyword argument there was a warning message we used to get about it being deprecated but we could never get it to work otherwise. I bet it is finally deprecated and functionality has changed. I'll see what I can figure out.
dask.persist
. What's the error you're seeing?WARNING:param.Image04051: Setting non-parameter attribute dynamic=False using a mechanism intended only for parameters
which is the warning I mentioned in my previous comment. Doing dynamic=True
seemed to work fine for me. Could you describe in more detail the issues you're seeing?As Johan mentioned on slack, there is this option:
from satpy.writers import get_enhanced_image arr = np.moveaxis(get_enhanced_image(scn).data.values, 0, -1) plt.imshow(arr, ...)
But I personally prefer letting xarray figure it out like you have it.
For your smaller issues, I'll try to check those out today. If you have the actual error messages produced that would help a lot. I know for the
dynamic
keyword argument there was a warning message we used to get about it being deprecated but we could never get it to work otherwise. I bet it is finally deprecated and functionality has changed. I'll see what I can figure out.
Thanks. as you rightly stated, xarray
self managing it appears more appealing as it also takes the same arguments in. I am also happy to be aware of the alternative np.moveaxis
option (just in case).
1. I am unable to reproduce any warning or error message with `dask.persist`. What's the error you're seeing? 2. For geoviews, by default dynamic is set to False and I see this warning `WARNING:param.Image04051: Setting non-parameter attribute dynamic=False using a mechanism intended only for parameters` which is the warning I mentioned in my previous comment. Doing `dynamic=True` seemed to work fine for me. Could you describe in more detail the issues you're seeing?
Thanks, again. These are minor issues and could be some version incompatibility as well but documenting it here in case someone else experiences the same.
dask.persist
error:
(if I comment out those two lines, it works, of course defeats the intention to use the persist
functionality)IndexError Traceback (most recent call last)
1. Regarding the resampling/dask error, what version of pyresample are you running? 2. For geoviews, I'm really not sure. I wasn't able to reproduce this and that error seems very very strange (just a number?). Maybe we just say this is a version incompatibility thing. Satpy isn't doing anything too fancy to use these so maybe it is a pandas + xarray + geoviews/holoviews incompatibility that will get fixed if you upgrade or in the future when someone runs into something similar. There is a little bit too much involved with Satpy and everything to be able to file a bug with them unless we can narrow this down to just an xarray + geoviews simple example.
Thanks, below are the versions of the Python stack. Totally agree; with just a number, it is hard to find out the root cause, and perhaps it is due to some incompatibility. Since this is low-hanging fruit, let's revisit this in some time, perhaps when we hear of similar issues. This reporting here is just for the record.
pyresample 1.20.0
satpy 0.29.0
pandas 1.2.3
xarray 0.15.1
geoviews 1.9.1
holoviews 1.14.5
dask 2021.7.1
python 3.8.0
My set-up specs: Windows 10, 32 Gb RAM, 6 cores (12 logical), Python 3.8
Feedback/minor hiccups
dask.persist
throws tuple out of index error but commenting it out allowed to run the script successfully. https://github.com/pytroll/tutorial-satpy-half-day/blob/644a0b9419c628c00f66a94064d7cb70f11b10d6/notebooks/04_resampling.ipynb#L504dynamic=True
created some issues (beyond my understanding!), but setting dynamic=False let it run. https://github.com/pytroll/tutorial-satpy-half-day/blob/644a0b9419c628c00f66a94064d7cb70f11b10d6/notebooks/07_cartopy_geoviews.ipynb#L246Please take a look when possible. These are minor issues.
Question (critical) I have a question related to the plotting of a given composite using
imshow
rather than usingxarray.plot
. The[bands, row, col]
order in the dask/xarray seems like an issue forimshow
and needs to be in image order[row, col, bands]
.For example, in the line: https://github.com/pytroll/tutorial-satpy-half-day/blob/644a0b9419c628c00f66a94064d7cb70f11b10d6/notebooks/05_composites.ipynb#L125
instead of using
img_data.plot.imshow(rgb='bands', vmin=0, vmax=1)
I'd like to use cartopy+matplotlib as follows:
cs = ax.imshow(img_data, transform=data_crs, vmin=0, vmax=1, zorder=2)
The img_data is a dask/xarray_core_array in [bands, row, col] order, e.g., (3 10000 10000). How to change it to image order [row, col, bands] e.g., (10000 10000 3)?
Overall, this is a terrific tool and very well implemented. Thank you, Prasanjit