
This is the third part of this series. Please find the other parts at the following links:
- Python Script Examples to Generate GOES-16 / 17 RGB’s: Part I
- Python Script Examples to Generate GOES-16 / 17 RGB’s: Part I
Please find below other Python example scripts to generate GOES-16 / 17 RGB’s:
- Day Cloud Convection RGB (Quick Guide)

Hurricane Barbara – GOES-16 – July 3rd 2019, 17:00 UTC – Day Cloud Convection RGB created with Python
#######################################################################################################
# LICENSE
# Copyright (C) 2019 - INPE - NATIONAL INSTITUTE FOR SPACE RESEARCH
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
#######################################################################################################
# Python Script: Day Cloud Convection
# Quick Guide: http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_DayCloudConvectionRGB_final.pdf
# Required modules
import matplotlib.pyplot as plt # Import the Matplotlib package
import numpy as np # Import the Numpy package
from netCDF4 import Dataset # Import the NetCDF Python interface
from remap import remap # Import the Remap function
from mpl_toolkits.basemap import Basemap # Import the Basemap utility
# File to read
image1 = "OR_ABI-L2-CMIPF-M6C02_G16_s20191841700283_e20191841709591_c20191841710072-114300_0.nc"
# Read the file using the NetCDF library
file1 = Dataset(image1)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the reflectances
grid = remap(image1, extent, resolution)
# Read the data as an array
data1 = grid.ReadAsArray()
# File to read
image2 = "OR_ABI-L2-CMIPF-M6C13_G16_s20191841700283_e20191841710002_c20191841710081.nc"
# Read the file using the NetCDF library
file2 = Dataset(image2)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image2, extent, resolution)
# Read the data as an array
data2 = grid.ReadAsArray()
# Convert to Celsius
data2 = data2 - 273.15
# Define the size of the saved picture=================================================================
#plt.figure(figsize=(10,6))
DPI = 150
fig = plt.figure(figsize=(data1.shape[1]/float(DPI), data1.shape[0]/float(DPI)), frameon=False, dpi=DPI)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax = plt.axis('off')
# ====================================================================================================
# RGB Components
R = data1
G = data1
B = data2
# Minimuns and Maximuns
Rmin = 0.0
Rmax = 1.0
Gmin = 0.0
Gmax = 1.0
Bmin = 49.85
Bmax = -70.15
R[RRmax] = Rmax
G[GGmax] = Gmax
B[B>Bmin] = Bmin
B[B<Bmax] = Bmax
# Choose the gamma
gamma_R = 1.7
gamma_G = 1.7
gamma_B = 1
# Normalize the data
R = ((R - Rmin) / (Rmax - Rmin)) ** (1/gamma_R)
G = ((G - Gmin) / (Gmax - Gmin)) ** (1/gamma_G)
B = ((B - Bmin) / (Bmax - Bmin)) ** (1/gamma_B)
# Create the RGB
RGB = np.stack([R, G, B], axis=2)
# ====================================================================================================
# Create the basemap
bmap = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[1], urcrnrlon=extent[2], urcrnrlat=extent[3], epsg=4326, resolution = 'i')
# Plot the image
bmap.imshow(RGB, origin='upper')
# Insert a shapefile
bmap.readshapefile('estados_2010','estados_2010',linewidth=0.3,color='white')
# Configure the map
bmap.drawcoastlines(linewidth=0.6, linestyle='solid', color='gold')
bmap.drawcountries(linewidth=0.6, linestyle='solid', color='orange')
bmap.drawparallels(np.arange(-90.0, 90.0, 5.0), dashes = [4 ,4], linewidth=0.8, color='cyan', labels=[True,False,False,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
bmap.drawmeridians(np.arange(0.0, 360.0, 5.0), dashes = [4,4], linewidth=0.8, color='cyan', labels=[False,False,True,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
# Save the image
plt.savefig('RGB_Day_Cloud_Convection.png', dpi=DPI, pad_inches=0)
- 24-Hour Microphysics RGB (Quick Guide)

Hurricane Barbara – GOES-16 – July 3rd 2019, 17:00 UTC – 24-hour Microphysics RGB created with Python
#######################################################################################################
# LICENSE
# Copyright (C) 2019 - INPE - NATIONAL INSTITUTE FOR SPACE RESEARCH
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
#######################################################################################################
# Python Script: 24-hour Microphysics
# Quick Guide: http://eumetrain.org/rgb_quick_guides/quick_guides/24MicroRGB.pdf
# Required modules
import matplotlib.pyplot as plt # Import the Matplotlib package
import numpy as np # Import the Numpy package
from netCDF4 import Dataset # Import the NetCDF Python interface
from remap import remap # Import the Remap function
from mpl_toolkits.basemap import Basemap # Import the Basemap utility
# File to read
image1 = "OR_ABI-L2-CMIPF-M6C15_G16_s20191841700283_e20191841709596_c20191841710080.nc"
# Read the file using the NetCDF library
file1 = Dataset(image1)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image1, extent, resolution)
# Read the data as an array
data1 = grid.ReadAsArray()
# Convert to Celsius
data1 = data1 - 273.15
# File to read
image2 = "OR_ABI-L2-CMIPF-M6C13_G16_s20191841700283_e20191841710002_c20191841710081.nc"
# Read the file using the NetCDF library
file2 = Dataset(image2)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image2, extent, resolution)
# Read the data as an array
data2 = grid.ReadAsArray()
# Convert to Celsius
data2 = data2 - 273.15
# File to read
image3 = "OR_ABI-L2-CMIPF-M6C11_G16_s20191841700283_e20191841709591_c20191841710080.nc"
# Read the file using the NetCDF library
file3 = Dataset(image3)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image3, extent, resolution)
# Read the data as an array
data3 = grid.ReadAsArray()
# Convert to Celsius
data3 = data3 - 273.15
# Define the size of the saved picture=================================================================
#plt.figure(figsize=(10,6))
DPI = 150
fig = plt.figure(figsize=(data1.shape[1]/float(DPI), data1.shape[0]/float(DPI)), frameon=False, dpi=DPI)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax = plt.axis('off')
# ====================================================================================================
# RGB Components
R = data1 - data2
G = data2 - data3
B = data2
# Minimuns and Maximuns
Rmin = -4.0
Rmax = 2.0
Gmin = 0.0
Gmax = 6.0
Bmin = -25.10
Bmax = 29.8
R[RRmax] = Rmax
G[GGmax] = Gmax
B[BBmax] = Bmax
# Choose the gamma
gamma_R = 1
gamma_G = 1.2
gamma_B = 1
# Normalize the data
R = ((R - Rmin) / (Rmax - Rmin)) ** (1/gamma_R)
G = ((G - Gmin) / (Gmax - Gmin)) ** (1/gamma_G)
B = ((B - Bmin) / (Bmax - Bmin)) ** (1/gamma_B)
# Create the RGB
RGB = np.stack([R, G, B], axis=2)
# ====================================================================================================
# Create the basemap
bmap = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[1], urcrnrlon=extent[2], urcrnrlat=extent[3], epsg=4326, resolution = 'i')
# Plot the image
bmap.imshow(RGB, origin='upper')
# Insert a shapefile
bmap.readshapefile('estados_2010','estados_2010',linewidth=0.6,color='white')
# Configure the map
bmap.drawcoastlines(linewidth=0.6, linestyle='solid', color='gold')
bmap.drawcountries(linewidth=0.6, linestyle='solid', color='orange')
bmap.drawparallels(np.arange(-90.0, 90.0, 5.0), dashes = [4 ,4], linewidth=0.8, color='cyan', labels=[True,False,False,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
bmap.drawmeridians(np.arange(0.0, 360.0, 5.0), dashes = [4,4], linewidth=0.8, color='cyan', labels=[False,False,True,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
# Save the image
plt.savefig('RGB_24h_Microphysics.png', dpi=DPI, pad_inches=0)
- Night Microphysics RGB (Quick Guide)

Hurricane Barbara – GOES-16 – July 3rd 2019, 17:00 UTC – Night Microphysics RGB created with Python
#######################################################################################################
# LICENSE
# Copyright (C) 2019 - INPE - NATIONAL INSTITUTE FOR SPACE RESEARCH
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
#######################################################################################################
# Python Script: Night Microphysics
# Quick Guide: http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_GOESR_NtMicroRGB_final.pdf
# Required modules
import matplotlib.pyplot as plt # Import the Matplotlib package
import numpy as np # Import the Numpy package
from netCDF4 import Dataset # Import the NetCDF Python interface
from remap import remap # Import the Remap function
from mpl_toolkits.basemap import Basemap # Import the Basemap utility
# File to read
image1 = "OR_ABI-L2-CMIPF-M6C15_G16_s20191850300287_e20191850310001_c20191850310084.nc"
# Read the file using the NetCDF library
file1 = Dataset(image1)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image1, extent, resolution)
# Read the data as an array
data1 = grid.ReadAsArray()
# Convert to Celsius
data1 = data1 - 273.15
# File to read
image2 = "OR_ABI-L2-CMIPF-M6C13_G16_s20191850300287_e20191850310006_c20191850310084.nc"
# Read the file using the NetCDF library
file2 = Dataset(image2)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image2, extent, resolution)
# Read the data as an array
data2 = grid.ReadAsArray()
# Convert to Celsius
data2 = data2 - 273.15
# File to read
image3 = "OR_ABI-L2-CMIPF-M6C07_G16_s20191850300287_e20191850310006_c20191850310078.nc"
# Read the file using the NetCDF library
file3 = Dataset(image3)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image3, extent, resolution)
# Read the data as an array
data3 = grid.ReadAsArray()
# Convert to Celsius
data3 = data3 - 273.15
# Define the size of the saved picture=================================================================
#plt.figure(figsize=(10,6))
DPI = 150
fig = plt.figure(figsize=(data1.shape[1]/float(DPI), data1.shape[0]/float(DPI)), frameon=False, dpi=DPI)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax = plt.axis('off')
# ====================================================================================================
# RGB Components
R = data1 - data2
G = data2 - data3
B = data2
# Minimuns and Maximuns
Rmin = -6.7
Rmax = 2.6
Gmin = -3.1
Gmax = 5.2
Bmin = -29.60
Bmax = 19.5
R[RRmax] = Rmax
G[GGmax] = Gmax
B[BBmax] = Bmax
# Choose the gamma
gamma_R = 1
gamma_G = 1
gamma_B = 1
# Normalize the data
R = ((R - Rmin) / (Rmax - Rmin)) ** (1/gamma_R)
G = ((G - Gmin) / (Gmax - Gmin)) ** (1/gamma_G)
B = ((B - Bmin) / (Bmax - Bmin)) ** (1/gamma_B)
# Create the RGB
RGB = np.stack([R, G, B], axis=2)
# ====================================================================================================
# Create the basemap
bmap = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[1], urcrnrlon=extent[2], urcrnrlat=extent[3], epsg=4326, resolution = 'i')
# Plot the image
bmap.imshow(RGB, origin='upper')
# Insert a shapefile
bmap.readshapefile('estados_2010','estados_2010',linewidth=0.6,color='white')
# Configure the map
bmap.drawcoastlines(linewidth=0.6, linestyle='solid', color='gold')
bmap.drawcountries(linewidth=0.6, linestyle='solid', color='orange')
bmap.drawparallels(np.arange(-90.0, 90.0, 5.0), dashes = [4 ,4], linewidth=0.8, color='cyan', labels=[True,False,False,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
bmap.drawmeridians(np.arange(0.0, 360.0, 5.0), dashes = [4,4], linewidth=0.8, color='cyan', labels=[False,False,True,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
# Save the image
plt.savefig('RGB_Night_Microphysics.png', dpi=DPI, pad_inches=0)
- Cloud Phase RGB (Quick Guide)

Hurricane Barbara – GOES-16 – July 3rd 2019, 17:00 UTC – Cloud Phase RGB created with Python
#######################################################################################################
# LICENSE
# Copyright (C) 2019 - INPE - NATIONAL INSTITUTE FOR SPACE RESEARCH
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
#######################################################################################################
# Python Script: Day Land Cloud RGB
# Quick Guide: http://eumetrain.org/rgb_quick_guides/quick_guides/CloudPhaseRGB.pdf
# File to read
image1 = "OR_ABI-L2-CMIPF-M6C05_G16_s20191841700283_e20191841709591_c20191841710071.nc"
# Read the file using the NetCDF library
file1 = Dataset(image1)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the reflectances
grid = remap(image1, extent, resolution)
# Read the data as an array
data1 = grid.ReadAsArray()
# File to read
image2 = "OR_ABI-L2-CMIPF-M6C06_G16_s20191841700283_e20191841709596_c20191841710062.nc"
# Read the file using the NetCDF library
file2 = Dataset(image2)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the reflectances
grid = remap(image2, extent, resolution)
# Read the data as an array
data2 = grid.ReadAsArray()
# File to read
image3 = "OR_ABI-L2-CMIPF-M6C02_G16_s20191841700283_e20191841709591_c20191841710072-114300_0.nc"
# Read the file using the NetCDF library
file3 = Dataset(image3)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the reflectances
grid = remap(image3, extent, resolution)
# Read the data as an array
data3 = grid.ReadAsArray()
# Calculates the solar zenith angle
from pyorbital import astronomy
from datetime import datetime
lat = np.linspace(extent[3], extent[1], data1.shape[0])
lon = np.linspace(extent[0], extent[2], data1.shape[1])
xx,yy = np.meshgrid(lon,lat)
lats = xx.reshape(data1.shape[0], data1.shape[1])
lons = yy.reshape(data1.shape[0], data1.shape[1])
# Get the year month day hour and minute to apply the zenith correction
utc_time = datetime(2019, 7, 3, 17, 00)
sun_zenith = np.zeros((data1.shape[0], data1.shape[1]))
sun_zenith = astronomy.sun_zenith_angle(utc_time, lats, lons)
# Apply the sun zenith correction
data1 = (data1)/(np.cos(np.deg2rad(sun_zenith)))
data2 = (data2)/(np.cos(np.deg2rad(sun_zenith)))
data3 = (data3)/(np.cos(np.deg2rad(sun_zenith)))
# Define the size of the saved picture=================================================================
#plt.figure(figsize=(10,6))
DPI = 150
fig = plt.figure(figsize=(data1.shape[1]/float(DPI), data1.shape[0]/float(DPI)), frameon=False, dpi=DPI)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax = plt.axis('off')
# ====================================================================================================
# RGB Components
R = data1
G = data2
B = data3
# Minimuns and Maximuns
Rmin = 0
Rmax = 1
Gmin = 0
Gmax = 1
Bmin = 0
Bmax = 1
R[RRmax] = Rmax
G[GGmax] = Gmax
B[BBmax] = Bmax
# Choose the gamma
gamma_R = 1
gamma_G = 1
gamma_B = 1
# Normalize the data
R = ((R - Rmin) / (Rmax - Rmin)) ** (1/gamma_R)
G = ((G - Gmin) / (Gmax - Gmin)) ** (1/gamma_G)
B = ((B - Bmin) / (Bmax - Bmin)) ** (1/gamma_B)
# Create the RGB
RGB = np.stack([R, G, B], axis=2)
# ====================================================================================================
# Create the basemap
bmap = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[1], urcrnrlon=extent[2], urcrnrlat=extent[3], epsg=4326, resolution = 'i')
# Plot the image
bmap.imshow(RGB, origin='upper')
# Insert a shapefile
bmap.readshapefile('estados_2010','estados_2010',linewidth=0.3,color='white')
# Configure the map
bmap.drawcoastlines(linewidth=0.6, linestyle='solid', color='gold')
bmap.drawcountries(linewidth=0.6, linestyle='solid', color='orange')
bmap.drawparallels(np.arange(-90.0, 90.0, 5.0), dashes = [4 ,4], linewidth=0.8, color='cyan', labels=[True,False,False,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
bmap.drawmeridians(np.arange(0.0, 360.0, 5.0), dashes = [4,4], linewidth=0.8, color='cyan', labels=[False,False,True,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
# Save the image
plt.savefig('RGB_Cloud_Phase.png', dpi=DPI, pad_inches=0)
- SO2 RGB (Quick Guide)

Hurricane Barbara – GOES-16 – July 3rd 2019, 17:00 UTC – SO2 RGB created with Python
#######################################################################################################
# LICENSE
# Copyright (C) 2019 - INPE - NATIONAL INSTITUTE FOR SPACE RESEARCH
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
#######################################################################################################
# Python Script: SO2
# Quick Guide: http://rammb.cira.colostate.edu/training/visit/quick_guides/Quick_Guide_SO2_RGB.pdf
# Required modules
import matplotlib.pyplot as plt # Import the Matplotlib package
import numpy as np # Import the Numpy package
from netCDF4 import Dataset # Import the NetCDF Python interface
from remap import remap # Import the Remap function
from mpl_toolkits.basemap import Basemap # Import the Basemap utility
# File to read
image1 = "OR_ABI-L2-CMIPF-M6C09_G16_s20191841700283_e20191841709596_c20191841710081.nc"
# Read the file using the NetCDF library
file1 = Dataset(image1)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image1, extent, resolution)
# Read the data as an array
data1 = grid.ReadAsArray()
# Convert to Celsius
data1 = data1 - 273.15
# File to read
image2 = "OR_ABI-L2-CMIPF-M6C10_G16_s20191841700283_e20191841710002_c20191841710078.nc"
# Read the file using the NetCDF library
file2 = Dataset(image2)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image2, extent, resolution)
# Read the data as an array
data2 = grid.ReadAsArray()
# Convert to Celsius
data2 = data2 - 273.15
# File to read
image3 = "OR_ABI-L2-CMIPF-M6C13_G16_s20191841700283_e20191841710002_c20191841710081.nc"
# Read the file using the NetCDF library
file3 = Dataset(image3)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image3, extent, resolution)
# Read the data as an array
data3 = grid.ReadAsArray()
# Convert to Celsius
data3 = data3 - 273.15
# File to read
image4 = "OR_ABI-L2-CMIPF-M6C11_G16_s20191841700283_e20191841709591_c20191841710080.nc"
# Read the file using the NetCDF library
file4 = Dataset(image3)
# Desired resolution
resolution = 2
# Desired extent
extent = [-138, 5.0, -112, 24.0]
# Remap and get the brightness temperatures
grid = remap(image3, extent, resolution)
# Read the data as an array
data4 = grid.ReadAsArray()
# Convert to Celsius
data4 = data4 - 273.15
# Define the size of the saved picture=================================================================
#plt.figure(figsize=(10,6))
DPI = 150
fig = plt.figure(figsize=(data1.shape[1]/float(DPI), data1.shape[0]/float(DPI)), frameon=False, dpi=DPI)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax = plt.axis('off')
# ====================================================================================================
# RGB Components
R = data1 - data2
G = data3 - data4
B = data3
# Minimuns and Maximuns
Rmin = -4.0
Rmax = 2.0
Gmin = -4.0
Gmax = 5.0
Bmin = -30.1
Bmax = 29.8
R[RRmax] = Rmax
G[GGmax] = Gmax
B[BBmax] = Bmax
# Choose the gamma
gamma_R = 1
gamma_G = 1.2
gamma_B = 1
# Normalize the data
R = ((R - Rmin) / (Rmax - Rmin)) ** (1/gamma_R)
G = ((G - Gmin) / (Gmax - Gmin)) ** (1/gamma_G)
B = ((B - Bmin) / (Bmax - Bmin)) ** (1/gamma_B)
# Create the RGB
RGB = np.stack([R, G, B], axis=2)
# ====================================================================================================
# Create the basemap
bmap = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[1], urcrnrlon=extent[2], urcrnrlat=extent[3], epsg=4326, resolution = 'i')
# Plot the image
bmap.imshow(RGB, origin='upper')
# Insert a shapefile
bmap.readshapefile('estados_2010','estados_2010',linewidth=0.6,color='white')
# Configure the map
bmap.drawcoastlines(linewidth=0.6, linestyle='solid', color='gold')
bmap.drawcountries(linewidth=0.6, linestyle='solid', color='orange')
bmap.drawparallels(np.arange(-90.0, 90.0, 5.0), dashes = [4 ,4], linewidth=0.8, color='cyan', labels=[True,False,False,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
bmap.drawmeridians(np.arange(0.0, 360.0, 5.0), dashes = [4,4], linewidth=0.8, color='cyan', labels=[False,False,True,False], fmt='%g', labelstyle="+/-", xoffset= 0.00, yoffset= 0.00, size=7)
# Save the image
plt.savefig('RGB_SO2.png', dpi=DPI, pad_inches=0)