Sandwich rgb

How do I...?
Post Reply
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Sandwich rgb

Post by ghansham »

Hi all
Did anyone try sandwich rgb for nowcasting in mcv?
I have seen a publication in which kris badka sir is co author?
It triea to mix high resolution visible with tir bt.
Visible is in grey scale and tir bt is applied rainbow color table with range set to 240 to 200. And the values above 240 are made transparent with alpha set to zero.
If you want I can upload.
Regards
Ghansham
User avatar
stormchasing101
Posts: 37
Joined: Sun Sep 06, 2015 6:24 am

Re: Sandwich rgb

Post by stormchasing101 »

Hi,
Yes please do upload the picture of it or a sample bundle. Sounds really interesting. Thanks.
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Sandwich rgb

Post by joleenf »

Ghansham,

Mike Hiley came up with a function to create a sandwich product. HP has found it works best to adjust the gamma after the display to get the ideal contrast. Mike's function is posted here

viewtopic.php?f=31&t=1637&hilit=sandwich

It requires an IR and a visible. I generally use a modification of the MODIS AOD color table (attached).

2014_04_03_SuomiNPPSandwich_zoom.png
Attachments
Sandwich.xml
(8.58 KiB) Downloaded 359 times
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: Sandwich rgb

Post by ghansham »

Hi Joleen
Thanks for the informative reply..
Its pretty interesting...
I think its really good.
But one insight..
As far as image creation is concerned is perfect,
but if we see from an analyst point of view, doing a probe using
center mouse click in McIDAS-V, I dont think we will get any information
about the convective cell, I mean the BT and Visible data value.
So the better way could have been to display one layer over the another. (IR BT over Visible).
with VISIBLE layer as the base layer and
lookup table for IR data made in such a way that it has the colors as per the fixed RGB (MODIS RGB color table
as it is recommended by paper)
for the defined range and else where it should have been transparent.
And we could have a derived data choice in a multispectral data source (called sandwich RGB).
And clicking on that datachoice should give the option to user to set the base layer and
top layer, initial IR data range (say 240-200) in the data selection component.
And composite displayable called blend-displayable that actually takes to data choices as input.
The displayable should give user option to change the top layer range.
Gamma value and Alpha value of both the layers.
And probe should return the value of both the layers one above the other.
Forecaster will like it better.
That is my point of view.

regards
Ghansham
User avatar
bobc
Posts: 987
Joined: Mon Nov 15, 2010 5:57 pm

Re: Sandwich rgb

Post by bobc »

Hi Ghansham -

Joleen put in some work on this sandwich RGB, and here is an updated version of Mike's original function:

Code: Select all

def sandwich(imgIR, imgVIS, minIR=180, maxIR=280, colorTable='Sandwich',useNaN=True):

   """
     Input:
        enhancementTableIR: Name of chosen ehancement table for IR image
        imgIR:  The IR image being displayed
        imgVIS: The VIS image being displayed
     Output:
        rgbImg:  an RGB sandwich
   """
   if (imgIR.isFlatField()):
     imgIR = imgIR
   else:
     imgIR = imgIR[0]

   if (imgIR.isFlatField()):
     imgVIS = imgVIS
   else:
     imgVIS = imgVIS[0]


   # this is where the "blend" stuff starts...

   # get the 'rainbow' color table, i.e. Sanwich (low value is transparent otherwise 40%)

   if (useNaN):
      noIRContribution = float('nan')
   else:
      noIRContribution = 1

   ct = _mcv.getColorTableManager().getColorTable(colorTable)
   table = ct.getColorTable()
   # get the rgb values for each index of the rainbow table
   # flip the color table here so that cold temperatures are red
   rTable = table[0][::-1]   # should use ColorTable.IDX_RED etc.
   gTable = table[1][::-1]
   bTable = table[2][::-1]
   aTable = table[3][::-1] # alpha layer... all 1's for rainbow table
   nCols = len(rTable) - 1  # TODO: why minus 1?

   # scale the IR image from 0 to 1
   floatsIR = imgIR.getFloats(False)[0]
   scaledIR = (imgIR-minIR) / (maxIR-minIR)
   scaledFloats = scaledIR.getFloats(False)[0]
           
   # set up the r, g, b arrays to put the image in to
   rIR = imgIR.clone()
   gIR = imgIR.clone()
   bIR = imgIR.clone()
   rFloats = rIR.getFloats(False)[0]
   gFloats = gIR.getFloats(False)[0]
   bFloats = bIR.getFloats(False)[0]

   # make rainbow enhanced IR image in rgb-space
   for i, pixel in enumerate(scaledFloats):
       # set anything colder than threshold to r,g,b from color table,
       # otherwise just set to 1 (so that result after multiply is just the vis image)
       if (floatsIR[i] < maxIR):

           # if anything falls below the minIR, set it to the minIR (scaledFloats=0)
           if (floatsIR[i] < minIR):
              pixel = 0

           # need to convert float ranging from 0.0 to 1.0 into integer index
           # ranging from 0 to nCols
           # testing

           ind = int(pixel*nCols)
           
           try:
              rFloats[i] = rTable[ind]
              gFloats[i] = gTable[ind]
              bFloats[i] = bTable[ind]   
           except IndexError:
              errorMsg= 'Index Error:' + ' Pixel=' + str(pixel) +' nCols='+str(floatsIR[i]) +' ind=' + str(ind)
              raise(errorMsg)       
       else:
           rFloats[i] = noIRContribution    # previously was set to 1
           gFloats[i] = noIRContribution    # see note for rFloats
           bFloats[i] = noIRContribution    # see note for rFloats

   # now scale rgb values by visible image to make the "sandwich" product
   imgVIS=noUnit(imgVIS)
   rIR=noUnit(rIR)
   gIR=noUnit(gIR)
   bIR=noUnit(bIR)

   rOutput = imgVIS*rIR     #+alpha*rIR
   gOutput = imgVIS*gIR     #+alpha*gIR
   bOutput = imgVIS*bIR     #+alpha*bIR
 
   
   # display the sandwich layer
   
   rgbImg = mycombineRGB(rOutput, gOutput, bOutput)

   return rgbImg
#=================================================================

Some notable changes to this from Mike's function:

  1. The enhancement table has been renamed from enhancementTableIR to sandwich. This sandwich enhancement is just the MODIS > Aerosol Optical Depth color table, where the lower end has been made 100% transparent in the upper end is set to red instead of white.
  2. There is a new useNaN keyword, so that rFloats, gFloats, and bFloats at lines 78-80 can be either 1 or NaN dependent on the user choice. Previously, this was set to 1. Using a value of 1 only displays the IR portion of the sandwich display. Using a value of 0 displays the same IR portion of the display, as well as the visible data outside of it.
  3. There is an added check for an image sequence at lines 11-19.
  4. In the decision block, noIRContribution is used when the cloud top is too warm (i.e. not a cold overshooting cloud top):
    • When noIRContribution is set to 1, the final red, green and blue contribution will be the visibleValue*1. This would mean that the final rgb in those locations reflects the original visible input.
    • When noIRContribution is set to NaN, the final red,green, blue contribution in that region is missing, so that any layer underneath can be viewed.
    • If noIRContribution is set to 0, there will be a black section in regions where there is noIR contribution to the RGB.

This function can be run through the Jython Shell, or it can be run directly through the GUI by creating a derived field. Here is the process of doing that (assuming this sandwich function is in your local Jython Library):

  1. Set up a parameter group for the data you want to work with. Get to the Parameter Groups Editor in the Main Display window through Tools > Parameters > Groups. I defined my parameter group like this:
    Parameter Groups Editor
    Parameter Groups Editor

    Only the last group in the list for 'sandwich' is used here. You can set the name/description of the group to be whatever you want. The Params column is for the actual parameters you want to use with the sandwich function. This case is with GOES-East data, where I set the shortname of band 4 temperature and band 1 albedo as my two fields (comma separated). You will see the use of the parameter group later when setting up the formula.
  2. Open the Formula Editor window from the Main Display window (Tools > Formulas > Edit). Enter the following in the editor:
    Formula Editor 1
    Formula Editor 1

    • Description: Sandwich from (%N1% and %N2%)
      This is how the derived field will list in the Field Selector. N1 and N2 are variables to include the field names (D1 and D2 defined later) that were used to generate the derived field. In this case, the derived field will list as: 'Sandwich (from 180_Band4_TEMP & 180_Band1_ALB)'
    • Name: Sandwich
      This is how the derived field can be referenced in a parameter default.
    • Formula: sandwich(D1[label=longwaveIR],D2[label=visible],float(minIR[isuser=true,default=170]),float(maxIR[isuser=true,default=280]),str(colorTable[isuser=true,type=choice,choices=Sandwich; Temperature; Aerosol Optical Depth]),bool(float(useNaN[isuser=true,default=1])))
      ... This lengthy formula passes the following through the sandwich function:
      • D1 - The first field that will be passed through the formula (the IR data). 'label' sets the labeling of the Field Selector window when evaluating the formula.
      • D2 - Same as D1, but the second field passed through the formula, the VIS data.
      • minIR - The low end of the IR being displayed.
      • maxIR - The high end of the IR being displayed.
      • colorTable - Allows for specifying which enhancement to use for the IR data (Sandwich, Temperature, or Aerosol Optical Depth).
      • useNaN - Allows for setting if visible data will be displayed in the sandwich product or not. 0 shows the visible and 1 does not.
  3. At the bottom of the window, in the Settings tab, I checked the display types for RGB data, '3 Color (RGB) Image', '3 Color (RGB) Image Over Topography', and 'RGB Composite'. These are the display types that will list in the Field Selector when the derived field or formula is selected.
  4. In the Derived tab, check both options for 'For end user' and 'Create derived quantities'. Having 'For end user' enabled will list this formula out with the rest of the native formulas in the Field Selector. Having 'Create derived quantities' enabled will allow for the creation of a derived field from the data. Use the Parameter Groups dropdown to select the parameter group that was created in step 1 for the GOES-East IR and VIS data. Note that the listing in this Parameter Groups dropdown lists the 'Description' that was given to the parameter group.
    - This is where the parameter group becomes useful. If you are working with multiple satellites, each with different shortnames, this is an easy way to allow this derived field to work for multiple satellites. For example, you could add a new line in the Parameter Defaults of the sandwich for GOES-West, MSG, MTSAT, etc.
    Formula Editor 2
    Formula Editor 2
  5. Click Add Formula.

Once this is done, load in your data source. In the Field Selector, at the bottom of the listing of bands, you should see a new field called something like 'Sandwich (from 180_Band4_TEMP & 180_Band1_ALB)'. This can be displayed with the RGB Composite display type.

When you evaluate this formula, a Select Input window will pop up:
Select Input window
Select Input window

This window allows you to set the following:
  • minIR - The minimum IR value that will be plotted. The 170 default comes from how it was set in the formula.
  • maxIR - The maximum IR value that will be plotted. The 280 default comes from how it was set in the formula.
  • colorTable - This dropdown menu lists the three enhancements that can be used for the display, as defined in the formula.
  • useNaN - Sets if the VIS data will be displayed or not outside of the IR data. 0 displays the VIS data and 1 does not. 1 is the default as defined in the formula.

Note that you can't probe the data from this display. In this case, we would recommend doing a standard Image Display of whatever bands you would be interested in probing (Band 4 Temperature, Band 1 Albedo, ...), and then overlay this with your sandwich RGB Composite display. You can even turn off the visibility of the Image Display layers and you can still probe the display to see temperature/albedo values at each location. This type of approach bridges the qualitative RGB with the quantitative thermal information.

If you have any questions about this procedure, please let us know.

Thanks -
Bob Carp

NOTE: This post was edited on 12/11 for the following explaining the difference between this function and Mike's original function:
  • There is a new useNaN keyword, so that rFloats, gFloats, and bFloats at lines 78-80 can be either 1 or NaN depndent on the user choice. Previously, this was set to 0. Using a value of 1 only displays the IR portion of the sandwich display. Using a value of 0 displays the same IR portion of the display, as well as the visible data outside of it.
    ... was changed to:
    There is a new useNaN keyword, so that rFloats, gFloats, and bFloats at lines 78-80 can be either 1 or NaN dependent on the user choice. Previously, this was set to 1. Using a value of 1 only displays the IR portion of the sandwich display. Using a value of 0 displays the same IR portion of the display, as well as the visible data outside of it.
  • Added section to explain the noIRContribution in the decision block of the code
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: Sandwich rgb

Post by ghansham »

How do we plot colorbar for this using the writeImage python function. Do we have param strings defined for plotting any colorbar ? Because here we are plotting a rgbcomposite control.


Regards
Ghansham
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: Sandwich rgb

Post by joleenf »

Ghansham,

I plot the IR layer underneath the visible and the rgb layers or make the IR layer transparent. Then, I turn the color table on for the IR layer. I always have to be careful that I am using the same range, but in reverse from the sandwich input:

Code: Select all

irLayer=panel[0].createLayer('Image Display', ir)
visLayer=panel[0].createLayer('Image Display', vis)

rgb=sandwich(vis,ir,minIR=180, maxIR=280, colorTable='Sandwich', useNaN=True)

rgbLayer=panel[0].createLayer('RGB Composite',rgb)

irLayer.setEnhancement('Sandwich', range=(280,180), transparency=100) 

irLayer.setColorScale(visible=True, placement='Top', font='Arial-BoldMT', size=24, color='white', showUnit=True)


Joleen
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: Sandwich rgb

Post by ghansham »

R/All


I just want to thank all who contributed to this topic. After a long time, I got some time out to post the results that we achieved for sandwich RGB using INSAT-3D data.
Wanted to mention here that we resampled IR to bring to VIS resolution.
One part is still left, that is square root enhancement on visible.

Please provide critical feedback.

And I did it using mostly python and c.

Thanks once again.

regards
Ghansham
Attachments
only_results.pptx
(3.87 MiB) Downloaded 64 times
User avatar
ghansham
Posts: 175
Joined: Thu Nov 11, 2010 5:40 pm

Re: Sandwich rgb

Post by ghansham »

Hi All,

I have added this capability in the wms server that serves images
for
https://rapid.imd.gov.in/r2v
You can choose 3DIMG or 3RIMG sensor.
Product type composite and sandwich layer.
We have given option to user to set range visible and thermal
IR layer.
It is usable in daytime only.
I am grateful to satpy community and all at SSEC who have contributed
to this post.

Regards
Ghansham
User avatar
bobc
Posts: 987
Joined: Mon Nov 15, 2010 5:57 pm

Re: Sandwich rgb

Post by bobc »

Hi Ghansham,

That page looks great and all of the functionality seems to be working well for me. Thanks for keeping us updated on the progress of this work!

Bob
Post Reply