Get pixel rgb value

My name is Ger from the Netherlands and have a question:
I have this : area = new_scn[chan].attrs[‘area’]
How I can I get the pixel RGB value from scene new_scn[chan] by coordinate or row,col from image

Thanks in advance for an answer

Thanks for moving this here. Can you give us more complete code with imports, including what new_scn is? That doesn’t particularly look like matplotlib.

Again sorry and glad that this is possible. I have data from weather satellite and via Satpy process the decoding of the scene to image. I also process this data with Matplotlib to create a temperature map. In this map I can add places based on coordinators, but I also want to process the temperature in an excel sheet. That’s why I need the pixel value. I also want to read the plot generated by Matplotlib the pixel color for comparison or possibly adjust.

new_scn[chan] is the scene of the channel processed by Satpy and this is where Matplotlib takes over.

Nu de script
crs = new_scn[chan].attrs[‘area’].to_cartopy_crs()
ax = plt.axes(projection=crs)

chan_data = new_scn[chan]-273.15 # plot data
im = plt.imshow(chan_data, transform=crs, extent=crs.bounds, origin=‘upper’, cmap=“coolwarm”)
cbar = plt.colorbar()

lon = 4.666
lat = 52.496
area = new_scn[chan].attrs[‘area’]
print('lon-lat ',lon, lat)
col, row = area.get_xy_from_lonlat(lon, lat)
print('col-row ',col, row)

global temp
temp = int(new_scn[chan].values[row, col]-273.15) #<-- Here i read the data of the pixel
print('temp-col-row ',temp, col, row)


I hope I come across clearly and you can help me

Thanks in advance

You want to know what color of the coolwarm colormap your data maps to?

norm = im.norm
rgb= cmap(norm(data))

should work, where data is one of your pixels.

Thanks for the fast replay and help.
I get color numbers, perfect
One small question, can you tell me how to translate the numbers
rgb = [[0.70567316 0.01555616 0.15023281 1. ]
[0.70567316 0.01555616 0.15023281 1. ]]

dear jklymak ,
I think i do something wrong because every time i get the same value.

norm = im.norm
data = row,col
rgb= cmap(norm(data))
print('rgb = ', rgb)

What do i wrong?

Impossible for us to know if you don’t tel us how you are specifying data

I have coordinate lon = 4.666 lat = 52.496
I made an area → area = new_scn[chan].attrs[‘area’]
I made column and row from the coordinates → col, row = area.get_xy_from_lonlat(lon, lat)
And that coordinate i wil read from the plot.

Same as i read the temperature value from the pixel (temp = int(new_scn[chan].values[row, col]-273.15) ), i ask if it is possible to read also the RGB color value.

I will just offer generic advice here - use lots of print statements and try to figure out what is going on.

@jklymak , one other question.
I install complete new Satpy installation on Raspberry Pi. It works but one thing:
When the script have to make image from Satpy scene the program stops with no error.
I write in Python:
image = np.asarray(local_scn[“natural_color”]).transpose(1,2,0)
After this the program stops with:
=============================== RESTART: Shell ===============================
What do i have to install to make ik work oke.

The old installation have no problems.

Thanks for answer

Everything is working wel now but one thing.
I make my own cmap colormap and is working but get error when i use the mouse for getting temperature from the map:

ValueError: BoundaryNorm is not invertible
Traceback (most recent call last):
File “/usr/local/lib/python3.7/dist-packages/matplotlib/cbook/”, line 287, in process
func(*args, **kwargs)
File “/usr/local/lib/python3.7/dist-packages/matplotlib/”, line 3056, in mouse_move
s = self._mouse_event_to_message(event)
File “/usr/local/lib/python3.7/dist-packages/matplotlib/”, line 3048, in _mouse_event_to_message
data_str = a.format_cursor_data(data).rstrip()
File “/usr/local/lib/python3.7/dist-packages/matplotlib/”, line 1283, in format_cursor_data
(int(self.norm(data) * n) + np.array([0, 1])) / n)
File “/usr/local/lib/python3.7/dist-packages/matplotlib/”, line 1832, in inverse
raise ValueError(“BoundaryNorm is not invertible”)
ValueError: BoundaryNorm is not invertible

Can someone explain how to solve this

Thanks and greetings Ger