Skip to content

Commit

Permalink
sync with McV
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanho committed Feb 27, 2024
1 parent 90a4e44 commit f4399e4
Showing 1 changed file with 68 additions and 38 deletions.
106 changes: 68 additions & 38 deletions src/ucar/unidata/idv/resources/python/ABIFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def ABITruColRGB(red, grn, blu):

# The functions below were created using the Quick Guides
# linked from CIRA's VISIT Quick Guides page:
# http://rammb.cira.colostate.edu/training/visit/quick_guides/
# https://rammb2.cira.colostate.edu/training/visit/quick_reference/#tab17
# Information about each RGB/band subtraction below can be
# found on the above webpage. Note that these RGBs and band
# subtractions were submitted by a variety of sources, all of
Expand All @@ -62,18 +62,18 @@ def ABITruColRGB(red, grn, blu):

# ABI Airmass RGB
def ABIAirmassRGB(b8T, b10T, b12T, b13T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_GOESR_AirMassRGB_final.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_GOESR_AirMassRGB_final-1.pdf
# red = band8 - band10; -26.2C to 0.6C rescaled to 0 to 255
# grn = band12 - band13; -43.2C to 6.7C rescaled to 0 to 255
# blu = band8; 243.9K to 208.5K rescaled to 0 to 255
# blu = band8 inverted; 243.65K to 208.53K rescaled to 0 to 255
red = rescale(b8T-b10T, -26.2, 0.6, 0, 255)
grn = rescale(b12T-b13T, -43.2, 6.7, 0, 255)
blu = rescale(b8T, 243.9, 208.5, 0, 255)
blu = rescale(b8T, 243.65, 208.53, 0, 255)
return combineRGB(red, grn, blu)

# ABI SO2 RGB
def ABISo2RGB(b9T, b10T, b11T, b13T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/Quick_Guide_SO2_RGB.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/Quick_Guide_SO2_RGB-1.pdf
# red = band9 - band10; -4C to 2C rescaled to 0 to 255
# grn = band13 - band11; -4C to 5C rescaled to 0 to 255
# blu = band13; 243.05K to 302.95K rescaled to 0 to 255
Expand All @@ -84,7 +84,7 @@ def ABISo2RGB(b9T, b10T, b11T, b13T):

# ABI Day Cloud Phase Distinction RGB
def ABIDayCloudPhaseRGB(b2A, b5A, b13T):
# https://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_DayCloudPhaseDistinction_final_v2.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_DayCloudPhaseDistinction_final_v2.pdf
# red = band 13; 280.65K to 219.65K rescaled to 0 to 255
# grn = band 2; 0% to 78% rescaled to 0 to 255
# blu = band 5; 1% to 59% rescaled to 0 to 255
Expand All @@ -98,7 +98,7 @@ def ABIDayCloudPhaseRGB(b2A, b5A, b13T):

# ABI Ash RGB
def ABIAshRGB(b11T, b13T, b14T, b15T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/GOES_Ash_RGB.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/GOES_Ash_RGB-1.pdf
# red = band15 - band13; -6.7C to 2.6C rescaled to 0 to 255
# grn = band14 - band11; -6.0C to 6.3C rescaled to 0 to 255
# blu = band13; 243.6K to 302.4K rescaled to 0 to 255
Expand All @@ -109,7 +109,7 @@ def ABIAshRGB(b11T, b13T, b14T, b15T):

# ABI Day Land Cloud RGB
def ABIDayLandCloudRGB(b2A, b3A, b5A):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_GOESR_daylandcloudRGB_final.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_GOESR_daylandcloudRGB_final-1.pdf
# red = band5; 0% to 97.5% rescaled to 0 to 255
# grn = band3; 0% to 108.6% rescaled to 0 to 255
# blu = band2; 0% to 100% rescaled to 0 to 255
Expand All @@ -121,9 +121,9 @@ def ABIDayLandCloudRGB(b2A, b3A, b5A):
blu = rescale(b2A, 0, 100, 0, 255)
return combineRGB(red, grn, blu)

# ABI Day Land Cloud Fire RGB
def ABIDayLandCloudFireRGB(b2A, b3A, b6A):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_GOESR_DayLandCloudFireRGB_final.pdf
# ABI Day Fire RGB
def ABIDayFireRGB(b2A, b3A, b6A):
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_GOESR_DayLandCloudFireRGB_final-1.pdf
# red = band6; 0% to 100% rescaled to 0 to 255
# grn = band3; 0% to 100% rescaled to 0 to 255
# blu = band2; 0% to 100% rescaled to 0 to 255
Expand All @@ -137,7 +137,7 @@ def ABIDayLandCloudFireRGB(b2A, b3A, b6A):

# ABI Night-time Microphysics RGB
def ABINightMicrophysicsRGB(b7T, b13T, b15T):
# https://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_GOESR_NtMicroRGB_Final_20191206.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_GOESR_NtMicroRGB_Final_20191206-1.pdf
# red = band15 - band13; -6.7C to 2.6C rescaled to 0 to 255
# grn = band13 - band7; -3.1C to 5.2C rescaled to 0 to 255
# blu = band13; 243.55K to 292.65K rescaled to 0 to 255
Expand All @@ -148,8 +148,8 @@ def ABINightMicrophysicsRGB(b7T, b13T, b15T):

# ABI Simple Water Vapor RGB
def ABISimpleWaterVaporRGB(b8T, b10T, b13T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/Simple_Water_Vapor_RGB.pdf
# red = band13; 278.96K to 202.29K rescaled to 0 to 255
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/Simple_Water_Vapor_RGB-1.pdf
# red = band13 inverted; 278.96K to 202.29K rescaled to 0 to 255
# grn = band8; 242.67K to 214.66K rescaled to 0 to 255
# blu = band10; 261.03K to 245.12K rescaled to 0 to 255
red = rescale(b13T, 278.96, 202.29, 0, 255)
Expand All @@ -159,65 +159,65 @@ def ABISimpleWaterVaporRGB(b8T, b10T, b13T):

# ABI Day Snow Fog RGB
def ABIDaySnowFogRGB(b3A, b5A, b7T, b13T):
# https://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_DaySnowFogRGB_final_v2.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_DaySnowFogRGB_final_v2.pdf
# red = band3; 0% to 100% rescaled to 0 to 255; gamma 1.7
# grn = band5; 0% to 70% rescaled to 0 to 255; gamma 1.7
# blu = band7 - band13; 0C to 30C rescaled to 0 to 255; gamma 1.7
red = 255*(rescale(b3A, 0, 100, 0, 1)**0.5882)
grn = 255*(rescale(b5A, 0, 70, 0, 1)**0.5882)
blu = 255*(rescale(b7T-b13T, 0, 30, 0, 1)**0.5882)
red = 255*(rescale(b3A, 0, 100, 0, 1)**(1/1.7))
grn = 255*(rescale(b5A, 0, 70, 0, 1)**(1/1.7))
blu = 255*(rescale(b7T-b13T, 0, 30, 0, 1)**(1/1.7))
return combineRGB(red, grn, blu)

# ABI Day Cloud Convection RGB
def ABIDayCloudConvectionRGB(b2A, b13T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_DayCloudConvectionRGB_final.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_DayCloudConvectionRGB_final-1.pdf
# red = band2; 0% to 100% rescaled to 0 to 255; gamma 1.7
# grn = band2; 0% to 100% rescaled to 0 to 255; gamma 1.7
# blu = band13; 323K to 203K rescaled to 0 to 255; gamma 1.0
red = 255*(rescale(b2A, 0, 100, 0, 1)**0.5882)
grn = 255*(rescale(b2A, 0, 100, 0, 1)**0.5882)
red = 255*(rescale(b2A, 0, 100, 0, 1)**(1/1.7))
grn = 255*(rescale(b2A, 0, 100, 0, 1)**(1/1.7))
blu = rescale(b13T, 323, 203, 0, 255)
return combineRGB(red, grn, blu)

# ABI Fire Temperature RGB
def ABIFireTemperatureRGB(b5A, b6A, b7T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/Fire_Temperature_RGB.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/Fire_Temperature_RGB-1.pdf
# red = band7; 0C to 60C rescaled to 0 to 255; gamma 0.4
# grn = band6; 0% to 100% rescaled to 0 to 255; gamma 1.0
# blu = band5; 0% to 75% rescaled to 0 to 255; gamma 1.0
time_steps = b7T.getLength()
for i in range(time_steps):
b7T.setSample(i, resampleGrid(b7T[i], b5A[i]))
red = 255*(rescale(b7T, 273.15, 333.15, 0, 1)**2.5)
red = 255*(rescale(b7T, 273.15, 333.15, 0, 1)**(1/.4))
grn = rescale(b6A, 0, 100, 0, 255)
blu = rescale(b5A, 0, 75, 0, 255)
return combineRGB(red, grn, blu)

# ABI Dust RGB
def ABIDustRGB(b11T, b13T, b14T, b15T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/Dust_RGB_Quick_Guide.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/Dust_RGB_Quick_Guide-1.pdf
# red = band15 - band13; -6.7C to 2.6C rescaled to 0 to 255; gamma 1.0
# grn = band14 - band11; -0.5C to 20.0C rescaled to 0 to 255; gamma 2.5
# blu = band13; -11.95C to 15.55C rescaled to 0 to 255; gamma 1.0
red = rescale(b15T-b13T, -6.7, 2.5, 0, 255)
grn = 255*(rescale(b14T-b11T, -0.5, 20, 0, 1)**0.4)
red = rescale(b15T-b13T, -6.7, 2.6, 0, 255)
grn = 255*(rescale(b14T-b11T, -0.5, 20, 0, 1)**(1/2.5))
blu = rescale(b13T, 261.2, 288.7, 0, 255)
return combineRGB(red, grn, blu)

# ABI Differential Water Vapor RGB
def ABIDifferentialWaterVaporRGB(b8T, b10T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_GOESR_DifferentialWaterVaporRGB_final.pdf
# red = band10 - band8; 30C to -3C rescaled to 0 to 255; gamma 0.2587
# grn = band10; 5C to -60C rescaled to 0 to 255; gamma 0.4
# blu = band8; -29.25C to -64.65C rescaled to 0 to 255; gamma 0.4
red = 255*(rescale(b10T-b8T, 30, -3, 0, 1)**3.8655)
grn = 255*(rescale(b10T, 278.15, 213.15, 0, 1)**2.5)
blu = 255*(rescale(b8T, 243.9, 208.5, 0, 1)**2.5)
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_GOESR_DifferentialWaterVaporRGB_final-1.pdf
# red = band10 - band8 inverted; 30C to -3C rescaled to 0 to 255; gamma 0.2587
# grn = band10 inverted; 5C to -60C rescaled to 0 to 255; gamma 0.4
# blu = band8 inverted; -29.25C to -64.65C rescaled to 0 to 255; gamma 0.4
red = 255*(rescale(b10T-b8T, 30, -3, 0, 1)**(1/.2587))
grn = 255*(rescale(b10T, 278.15, 213.15, 0, 1)**(1/.4))
blu = 255*(rescale(b8T, 243.9, 208.5, 0, 1)**(1/.4))
return combineRGB(red, grn, blu)

# ABI Day Convection RGB
def ABIDayConvectionRGB(b2A, b5A, b7T, b8T, b10T, b13T):
# http://rammb.cira.colostate.edu/training/visit/quick_guides/QuickGuide_GOESR_DayConvectionRGB_final.pdf
# https://rammb2.cira.colostate.edu/wp-content/uploads/2020/01/QuickGuide_GOESR_DayConvectionRGB_final-1.pdf
# red = band8 - band10; -35C to 5C rescaled to 0 to 255; gamma 1.0
# grn = band7 - band13; -5C to 60C rescaled to 0 to 255; gamma 1.0
# blu = band5 - band2; -0.75% to 0.25% rescaled to 0 to 255; gamma 1.0
Expand All @@ -239,9 +239,9 @@ def ABICloudTypeRGB(b4A, b2A, b5A):
time_steps = b4A.getLength()
for i in range(time_steps):
b4A.setSample(i, resampleGrid(b4A[i], b2A[i]))
red = 255*(rescale(b4A, 0, 10, 0, 1)**0.4)
grn = 255*(rescale(b2A, 0, 50, 0, 1)**0.7)
blu = 255*(rescale(b5A, 0, 50, 0, 1)**0.7)
red = 255*(rescale(b4A, 0, 10, 0, 1)**(1/2.5))
grn = 255*(rescale(b2A, 0, 50, 0, 1)**(1/1.4))
blu = 255*(rescale(b5A, 0, 50, 0, 1)**(1/1.5))
return combineRGB(red, grn, blu)

# ABI Day Rocket Plume RGB
Expand Down Expand Up @@ -304,4 +304,34 @@ def ABISplitWindowDifference(b15T, b13T):
def ABINightFogDifference(b13T, b7T):
# http://cimss.ssec.wisc.edu/goes/OCLOFactSheetPDFs/ABIQuickGuide_NightFogBTD.pdf
# band13 temperature - band7 temperature
return sub(b13T, b7T)
return sub(b13T, b7T)

# The two functions below are designed to work with ABI L1b and L2 CMIP files loaded
# as gridded data sources to give temperature as a calibration for L1b and radiance
# as a calibration for L2 CMIP data.

def abiRadToTemp(data):
# Function to convert ABI L1b netCDF file radiance to temperature
# Valid only for bands 7 through 16
# Formula to calculate temberature from the NOAA ATBD:
# https://www.star.nesdis.noaa.gov/goesr/docs/ATBD/Imagery.pdf
# fk1/2 and bc1/2 values are extracted from the data then used in the function
fk1 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_fk1').read()))
fk2 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_fk2').read()))
bc1 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_bc1').read()))
bc2 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_bc2').read()))
T = ( fk2 / (log((fk1 /data) + 1)) - bc1 ) / bc2
return T

def abiTempToRad(data):
# Function to convert ABI L2 CMIP netCDF file temperatue to radiance
# Valid only for bands 7 through 16
# Formula to calculate radiance from the NOAA ATBD:
# https://www.star.nesdis.noaa.gov/goesr/docs/ATBD/Imagery.pdf
# fk1/2 and bc1/2 values are extracted from the data then used in the function
fk1 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_fk1').read()))
fk2 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_fk2').read()))
bc1 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_bc1').read()))
bc2 = float(str(data[0].geoGrid.dataset.getDataVariable('planck_bc2').read()))
R = fk1 / (exp (fk2 / (bc1 + (bc2 * data))) -1)
return R

0 comments on commit f4399e4

Please sign in to comment.