mcIDAS EU in McIDAS-V

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

Re: mcIDAS EU in McIDAS-V

Post by ghansham »

It has to be first case I feel because of the limitation of mcidasv of applying the lookup tables linearly.
You can try a simple exercise to find expected and calculated values of indices of color table for a given temperature. You may have to interpolate a few colors when you create table with length greater than 256
But that I feel is the correct solution. Lets discuss more if required. I am expecting someone from core visad team to chime in and put his point of view. May be TomR Sir. I will request him.
It should be 336 colors if both 330 and 163 are to be included (330-163+1)*2 = 336.
Regards
Ghansham
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: mcIDAS EU in McIDAS-V

Post by joleenf »

As far as getting 336 versus 254-256 colors in the table, it depends on the goal. If the goal is to reproduce an image that has the temperature values colored exactly the same as McIDAS-X, then perhaps use the bi-linear formula which would produce a color table of about 254 colors (I am not sure, some values were reserved in McIDAS-X, I think it was 0 and 1). If the goal is to make use of the larger number of colors in McIDAS-V, then we should use 336 levels or higher. Maybe you would like color-11-new.cmap or WV_Dry_Yellow.cmap, they can be directly imported. These both use 2048 colors in McIDAS-V. They are from AWIPS, which also is 24-bit system and has a linear stretch over the color table. WV_Dry_Yellow is very nice. I have attached a picture of what it looks like in McIDAS-X as old 0-255 (notice rough transitions in southwest portion of image) and in the RGB Combine window of McIDAS-X, which would replicate what WV_Dry_Yellow looks like in McIDAS-V.

ftp://ftp.ssec.wisc.edu/pub/incoming/WV_Dry_Yellow.cmap
ftp://ftp.ssec.wisc.edu/pub/incoming/color-11-new.cmap

16-24bit_comparison.png


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

Re: mcIDAS EU in McIDAS-V

Post by ghansham »

I agree with your observations completely. The basic reason fir increasing number of colors is to get similar results as McX as currently there is no support in McV for bilinear color enhancements.
I think its high time that such functionality should be built in McV. Actually there are methods in ViSAD and wrappers for that can be provided in IDV/McV as well. Creativity lies in how to create a UI for defining that function. :-)
Thanks for all the information you shared.

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

Re: mcIDAS EU in McIDAS-V

Post by joleenf »

Ghansham,

I totally agree with you. I can update the rescaleCT code to replicate the exact bi-linear calculation, but it would be nice to have an officially supported way of performing this type of adjustment from linear to bi-linear. It would be even better to increase the number of colors when possible while staying close to the original temperature breakpoints of the old McIDAS-X color tables.

Increasing the number of colors is a little tricky, I think. To interpolate between colors in an old color table, would it be best to identify locations where the colors change significantly (from green to white or yellow to blue)? I am not of the best way to achieve this, but I am hoping that someone in the programming team would have a good idea.

In the meantime, I can ask in the center again about how WV_Dry_Yellow was adjusted to 2048 colors. I think it was based off an old McIDAS-X color table.

Thanks,
Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: mcIDAS EU in McIDAS-V

Post by joleenf »

Ghansham,

Here is my new code which accounts for the half degree increments after 242 K.

rescaleCT.py
(4.28 KiB) Downloaded 351 times


Joleen

Code: Select all


def convertColorTable(inputCT=None, output_file=None, category='User'):
    """
        Usage:  convertColorTable(inputCT='WVJL2', outputCT='WVJL2_163_330', category='User')
 
        inputCT:  this is a color table which is scaling well for pixel "Brightness
                  Values" (UNIT=BRIT or brightness in field selector) values but not for
                  "Brightness Temperature" Values (UNIT=TEMP or Temperature in field selector)
        output_file: desired name and path of output color table as ascii file name.
                  (outputfile will be of form filename.ascii)
                  If no name is provided, the code skips writing any information to
                  a file and does not import a new color table.

        category:  Category name for fileing in color table
                 
    """

    import os
    import ucar.unidata.util.ColorTable as ColorTable

    rgb_list=getColorTableColorList(inputCT)

    if (output_file is not None):
        # create ascii extension for corresponding filename of outputCT (needed for import)
        filename, file_extension = os.path.splitext(output_file)
        if (file_extension != '.ascii'):
            output_file='{}.{}'.format(filename,'ascii')

        outputCT = os.path.splitext(os.path.basename(output_file))[0]
        # Importing twice creates different names, so at least warn that
        # this will happend
        # check color table manager to see if ct in already in manager
        ctm=_mcv.getColorTableManager()
        ct_checkifnew = ctm.getColorTable(outputCT)
        if (ct_checkifnew is not None):
            raise RuntimeError('Color table name already in use: {}'.format(outputCT))

    breakpoints = bilinear(rgb_list)

    if (output_file is not None):
        with open(output_file, 'w+') as fh:
           for breakpoint in breakpoints:
               red=breakpoint[2].getRed()
               grn=breakpoint[2].getGreen()
               blu=breakpoint[2].getBlue()
               rgbLine='{} {} {}\n'.format(red,grn,blu)
               fh.write(rgbLine)
        # import new color table
        test=importEnhancement(filename=output_file, category=category)
    return breakpoints

def getColorTableColorList(color_table):
    """
        Returns a list of RGB colors from an input color table
        Raises Error if color table is not already loaded in McIDAS-V
       
        color_table - color table already in McIDAS-V. 
    """

    import ucar.unidata.util.ColorTable as ColorTable
   
    # load color table
    ctm=_mcv.getColorTableManager()
    ct = ctm.getColorTable(color_table)
    # don't continue if color table is not in list
    if (ct is None):
        raise NameError ('Color Table Not Found In Color Table Manager: {}'.format(color_table))
    else:
        table = ct.getColorTable()
        rgb_list=ct.getColorList()

    return rgb_list

def bilinear(rgb_list):
    """
        Return a zipped array of brightness values corresponding to color level
        after a bi-linear stretch has been applied.
 
        color_list of current McIDAS-V color table (Retrieved by getColorTableList)
                 
    """
    # get scale of newCT from temp to BRIT  (assuming bi-linear scaling applied to 163-330 K)
    minTempScale = 163     # this should remain fixed!!!!!
    maxTempScale = 330     # this should remain fixed!!!!!
    scale = float(maxTempScale - minTempScale)/float(255)
   
    brightness_values=[]
    temperatures=[]
    new_rgb_list=[]

    ct_len=len(rgb_list)
    if (ct_len < 256):
       raise RuntimeError('bilinear stretch expects a color table of 256 colors, this is {}'.format(ct_len))
   
    for temp in range(minTempScale,maxTempScale+1):
        if (temp < 242) or (temp == 330):
            temperatures.append(temp)
        else:
            temperatures.extend([temp,(temp+0.5)])

    for temp in temperatures:
        if (temp < 242):
            # increment by one degree until 242K
            BV = int(418 - temp)
        else:
            BV = int(660 - (2.*float(temp)))

        # these tables came from fortran and I believe that the first index of these tables
        # was actually 1, but here it is 0
        brightness_values.append(BV)

        new_rgb_list.append(rgb_list[BV])
       
    breakpoints=list(zip(brightness_values,temperatures,new_rgb_list))

    return breakpoints
Post Reply