Exemplo n.º 1
0
def makeLocalADDEEntry(dataset, mask, format, imageType=None, save=False):
    """Creates a local ADDE entry in the server table.
    
    Required Args:
        dataset: Name of the group associated with the created dataset.
        imageType: Image type name for local server entry. The image type name is limited to twelve characters or less. (default=format_dataset)
        mask: Directory containing the files used by the created dataset.
        save: True saves entry into the server table. False will cause the entry to be removed at the end of this McIDAS-V session. (default=False)
        format: Data format of the files within the dataset. Either the Full Name or Short Name can be used as valid options:
            
            =========================================================  ============
            Full Name                                                  Short Name  
            =========================================================  ============
            "AMSR-E Rain Product"                                      "AMRR"
            "AMSR-E L 1b"                                              "AMSR"
            "LRIT GOES-9"                                              "FSDX_G9"
            "LRIT GOES-10"                                             "FSDX_G10"
            "LRIT GOES-11"                                             "FSDX_G11"
            "LRIT GOES-12"                                             "FSDX_G12"
            "LRIT MET-5"                                               "FSDX_M5"
            "LRIT MET-7"                                               "FSDX_M7"
            "LRIT MTSAT-1R"                                            "FSDX_MT"
            "McIDAS Area"                                              "AREA"
            "Meteosat OpenMTP"                                         "OMTP"
            "Metop AVHRR L 1b"                                         "LV1B_METOP"
            "MODIS MOD 02 - Level-1B Calibrated Geolocated Radiances"  "MODS"
            "MODIS MOD 04 - Aerosol Product"                           "MOD4"
            "MODIS MOD 06 - Cloud Product"                             "MODX_06"
            "MODIS MOD 07 - Atmospheric Profiles"                      "MODX_07"
            "MODIS MOD 28 - Sea Surface Temperature"                   "MOD8"
            "MODIS MOD 35 - Cloud Mask"                                "MODX_35"
            "MODIS MOD R - Corrected Reflectance"                      "MODR"
            "MSG HRIT FD"                                              "MSGT_FD"
            "MSG HRIT HRV"                                             "MSGT_HRV"
            "MTSAT HRIT"                                               "MTST"
            "NOAA AVHRR L 1b"                                          "LV1B_NOAA"
            "SSMI"                                                     "SMIN"
            "TRMM"                                                     "TMIN"
            "GINI"                                                     "GINI"
            =========================================================  ============
                    
    Returns:
        The newly created local ADDE dataset.
    """
    
    if len(dataset) > 8 or not dataset.isupper() or any(c in dataset for c in "/. []%"):
        raise AddeJythonInvalidDatasetError("Dataset '%s' is not valid." % (dataset))
        
    convertedFormat = _formats.get(format, AddeFormat.INVALID)
    
    if convertedFormat is AddeFormat.INVALID:
        raise AddeJythonError("Unknown format '%s' specified." % (format))
        
    if not imageType:
        imageType = "%s_%s" % (format, dataset)
        
    localEntry = LocalAddeEntry.Builder(imageType, dataset, mask, convertedFormat).status(EntryStatus.ENABLED).temporary((not save)).build()
    getStaticMcv().getServerManager().addEntry(localEntry)
    return localEntry
Exemplo n.º 2
0
def checkLocalServerStatus():
    """Check the status of mcservl.
    
    Returns:
        True if things are working as expected, False if mcservl does not have
        write access to the userpath.
        
    Raises:
        RuntimeError: if getStaticMcv() fails (which should not happen).
    """
    mcv = getStaticMcv()
    if mcv:
        return mcv.getServerManager().testLocalServer()
    raise RuntimeError('Could not get reference to McIDAS-V!')
Exemplo n.º 3
0
def describeActions(pattern=None):
    """Print out a list of the McIDAS-V actions.
    
    The output is ordered alphabetically and grouped by functionality. Each
    identifier can be "run" like so:
    
    performAction(identifier)
    performAction('edit.paramdefaults')
    
    Args:
        pattern: Searches for the given pattern within the action identifier
                 strings as well as action descriptions.
    """
    # actions = _mcv.getIdvUIManager().getCachedActions().getAllActions()
    actions = getStaticMcv().getIdvUIManager().getCachedActions().getAllActions()
    print sorted([action.getId() for action in actions])
Exemplo n.º 4
0
def getLocalADDEEntry(dataset, imageType):
    """Get the local ADDE entry matching the given dataset and imageType.
    
    Args:
        dataset: Local ADDE entry dataset name.
        
        imageType: Image type name of local ADDE entry.
        
    Returns: 
        Valid local ADDE entry or None if no match was found.
    """
    # get a list of local ADDE server entries
    localEntries = getStaticMcv().getServerManager().getLocalEntries()
    for entry in localEntries:
        if entry.getName() == imageType and entry.getGroup() == dataset:
            return entry
    # no matching descriptor was found so return an error value:
    return None
Exemplo n.º 5
0
def getLocalADDEEntry(dataset, imageType):
    """Get the local ADDE entry matching the given dataset and imageType.
    
    Args:
        dataset: Local ADDE entry dataset name.
        
        imageType: Image type name of local ADDE entry.
        
    Returns: 
        Valid local ADDE entry or None if no match was found.
    """
    # get a list of local ADDE server entries
    localEntries = getStaticMcv().getServerManager().getLocalEntries()
    for entry in localEntries:
        if entry.getName() == imageType and entry.getGroup() == dataset:
            return entry
    # no matching descriptor was found so return an error value:
    return None
Exemplo n.º 6
0
def getDescriptor(dataset, imageType):
    """Get the descriptor for a local ADDE entry
    
    (this wasn't included in the 1.2 release, but enough people are using it
    that we'll want to keep it for backward compatibility.)
        
    Args:
        dataset: Dataset field from local ADDE server
        imageType: Image Type field from local ADDE server
        
    Returns: valid descriptor string or -1 if no match was found
    """
    # get a list of local ADDE server entries
    localEntries = getStaticMcv().getServerManager().getLocalEntries()
    for entry in localEntries:
        if entry.getName() == imageType and entry.getGroup() == dataset:
            # descriptor found; convert to upper case and return it
            desc = str(entry.getDescriptor()).upper()
            return desc
    # no matching descriptor was found so return an error value:
    return -1
Exemplo n.º 7
0
def getDescriptor(dataset, imageType):
    """Get the descriptor for a local ADDE entry
    
    (this wasn't included in the 1.2 release, but enough people are using it
    that we'll want to keep it for backward compatibility.)
        
    Args:
        dataset: Dataset field from local ADDE server
        imageType: Image Type field from local ADDE server
        
    Returns: valid descriptor string or -1 if no match was found
    """
    # get a list of local ADDE server entries
    localEntries = getStaticMcv().getServerManager().getLocalEntries()
    for entry in localEntries:
        if entry.getName() == imageType and entry.getGroup() == dataset:
            # descriptor found; convert to upper case and return it
            desc = str(entry.getDescriptor()).upper()
            return desc
    # no matching descriptor was found so return an error value:
    return -1
Exemplo n.º 8
0
def editFile(path, encoding=None, cleanup=False):
    """Import file contents into the Jython Shell input field.
    
    Args:
        path: Required string value that represents a path to a file. The string
              is validated with expandpath, so paths like "~/test.py" will work.
              
        encoding: Optional string value that defaults to None. If given a value,
                  no attempt will be made to check the encoding of the given
                  file.
              
        cleanup: Optional boolean value that defaults to False. If set to True,
                 calls to removeAllData() and removeAllLayers() are added to the 
                 beginning of the Jython Shell input text field.
    """
    from edu.wisc.ssec.mcidasv.util import DetectCharset
    import codecs
    
    filepath = expandpath(path)
    encoding = encoding or DetectCharset.detect(filepath)
    
    # detection may have failed
    if not encoding:
        raise RuntimeError('Could not detect encoding of "%s". Please verify the file\'s encoding and then run "editFile(\'%s\', encoding=\'ENCODING_HERE\', cleanup=%s)".' % (path, path, cleanup))
        
    fp = codecs.open(filepath, 'r', encoding=encoding)
    try:
        shell = getStaticMcv().getJythonManager().getShell()
        lines = u''
        if cleanup:
            lines += u'# removeAllData and removeAllLayers were added because editFile was called with "cleanup" set to True.\nremoveAllData()\nremoveAllLayers()\n\n'
        once = False
        for line in fp:
            lines += line
        shell.setMultilineText(lines)
    except UnicodeDecodeError:
        detected = DetectCharset.detect(filepath)
        raise RuntimeError('Could not decode contents of "%s" using "%s"! You may want to retry by running "editFile(\'%s\', encoding=\'%s\', cleanup=%s)".' % (path, encoding, path, detected, cleanup))
    finally:
        fp.close()
Exemplo n.º 9
0
def editFile(path, cleanup=False):
    """Import file contents into the Jython Shell input field.
    
    Args:
        path: Required string value that represents a path to a file. The string
              is validated with expandpath, so paths like "~/test.py" will work.
              
        cleanup: Optional boolean value that defaults to False. If set to True,
                 calls to removeAllData() and removeAllLayers() are added to the 
                 beginning of the Jython Shell input text field.
    """
    fp = open(expandpath(path), 'r')
    try:
        shell = getStaticMcv().getJythonManager().getShell()
        lines = ''
        if cleanup:
            lines += '# removeAllData and removeAllLayers were added because editFile was called with "cleanup" set to True.\nremoveAllData()\nremoveAllLayers()\n\n'
        for line in fp:
            lines += line
        shell.setMultilineText(lines)
    finally:
        fp.close()
Exemplo n.º 10
0
def enableTruncation():
    """Enable Jython Shell truncation."""
    store = JythonObjectStore.newInstance(getStaticMcv())
    store.putBoolean(PROP_JYTHON_SHELL_TRUNCATE, True)
    store = None
Exemplo n.º 11
0
def truncation():
    """Return Jython Shell truncation status."""
    store = JythonObjectStore.newInstance(getStaticMcv())
    value = store.getBoolean(PROP_JYTHON_SHELL_TRUNCATE, True)
    store = None
    return value
Exemplo n.º 12
0
def getMouseEarthLocation():
    """Return position of the mouse pointer as a lat/lon tuple."""
    display = getStaticMcv().getVMManager().getLastActiveViewManager()
    master = display.getMaster()
    visadLat, visadLon = master.getCursorLatitude(), master.getCursorLongitude()
    return visadLat.getValue(), visadLon.getValue()
Exemplo n.º 13
0
def makeLocalADDEEntry(dataset, mask, format, imageType=None, save=False):
    """Creates a local ADDE entry in the server table.
    
    Required Args:
        dataset: Name of the group associated with the created dataset.
        imageType: Image type name for local server entry. The image type name is limited to twelve characters or less. (default=format_dataset)
        mask: Directory containing the files used by the created dataset.
        save: True saves entry into the server table. False will cause the entry to be removed at the end of this McIDAS-V session. (default=False)
        format: Data format of the files within the dataset. Either the Full Name or Short Name can be used as valid options:
            
            =========================================================  ============
            Full Name                                                  Short Name  
            =========================================================  ============
            "AMSR-E Rain Product"                                      "AMRR"
            "AMSR-E L 1b"                                              "AMSR"
            "LRIT GOES-9"                                              "FSDX_G9"
            "LRIT GOES-10"                                             "FSDX_G10"
            "LRIT GOES-11"                                             "FSDX_G11"
            "LRIT GOES-12"                                             "FSDX_G12"
            "LRIT MET-5"                                               "FSDX_M5"
            "LRIT MET-7"                                               "FSDX_M7"
            "LRIT MTSAT-1R"                                            "FSDX_MT"
            "McIDAS Area"                                              "AREA"
            "Meteosat OpenMTP"                                         "OMTP"
            "Metop AVHRR L 1b"                                         "LV1B_METOP"
            "MODIS MOD 02 - Level-1B Calibrated Geolocated Radiances"  "MODS"
            "MODIS MOD 04 - Aerosol Product"                           "MOD4"
            "MODIS MOD 06 - Cloud Product"                             "MODX_06"
            "MODIS MOD 07 - Atmospheric Profiles"                      "MODX_07"
            "MODIS MOD 28 - Sea Surface Temperature"                   "MOD8"
            "MODIS MOD 35 - Cloud Mask"                                "MODX_35"
            "MODIS MOD R - Corrected Reflectance"                      "MODR"
            "MSG HRIT FD"                                              "MSGT_FD"
            "MSG HRIT HRV"                                             "MSGT_HRV"
            "MTSAT HRIT"                                               "MTST"
            "NOAA AVHRR L 1b"                                          "LV1B_NOAA"
            "SSMI"                                                     "SMIN"
            "TRMM"                                                     "TMIN"
            "GINI"                                                     "GINI"
            =========================================================  ============
                    
    Returns:
        The newly created local ADDE dataset.
    """

    if len(dataset) > 8 or not dataset.isupper() or any(c in dataset
                                                        for c in "/. []%"):
        raise AddeJythonInvalidDatasetError("Dataset '%s' is not valid." %
                                            (dataset))

    convertedFormat = _formats.get(format, AddeFormat.INVALID)

    if convertedFormat is AddeFormat.INVALID:
        raise AddeJythonError("Unknown format '%s' specified." % (format))

    if not imageType:
        imageType = "%s_%s" % (format, dataset)

    localEntry = LocalAddeEntry.Builder(imageType, dataset, mask,
                                        convertedFormat).status(
                                            EntryStatus.ENABLED).temporary(
                                                (not save)).build()
    getStaticMcv().getServerManager().addEntry(localEntry)
    return localEntry
Exemplo n.º 14
0
def load(path):
    return getStaticMcv().makeOneDataSource(path, None, None)
Exemplo n.º 15
0
def getUserPath():
    """Return path to the user's McIDAS-V directory."""
    return getStaticMcv().getStore().getUserDirectory().getPath()
Exemplo n.º 16
0
def load(path):
    """Simplistic file loading function.
    
    Please use loadGrid instead.
    """
    return getStaticMcv().makeOneDataSource(path, None, None)
Exemplo n.º 17
0
def sandwich(imgIR, imgVIS, minIR=180, maxIR=280, colorTable='Sandwich', useNaN=True):
    """McIDAS-V implementation of Martin Setvak's "sandwich" imagery.
    
    Args:
        imgIR: IR image being displayed.
        imgVIS: VIS image being displayed.
        minIR, maxIR: outside these bounds, no IR layer will be visible.
        colorTable: Name of chosen enhancement table for IR image.
        useNaN: if True, the VIS image won't be visible outside of minIR/maxIR.
        usePlugin: if True, use sandwich_speedup.jar plugin for optimization.
        
    Returns:
       rgbImg: An RGB "sandwich".
    """
    if imgIR.isFlatField():
        imgIR = imgIR
    else:
        imgIR = imgIR[0]
        
    if imgIR.isFlatField():
        imgVIS = imgVIS
    else:
        imgVIS = imgVIS[0]
        
    if useNaN:
        noIRContribution = float('nan')
    else:
        noIRContribution = 1
        
    ct = getStaticMcv().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]
    
    t0 = time.clock()
    sandwichSpeedup(
        scaledFloats,
        floatsIR,
        rFloats,
        gFloats,
        bFloats,
        rTable,
        gTable,
        bTable,
        minIR,
        maxIR,
        nCols,
        noIRContribution,
    )
    t1 = time.clock()
    # print('Sandwich: time spent in for loop [s]: {}'.format(t1 - t0))
    
    # 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
    gOutput = imgVIS * gIR
    bOutput = imgVIS * bIR
    
    rgbImg = mycombineRGB(rOutput, gOutput, bOutput)
    return rgbImg
Exemplo n.º 18
0
def sandwich(imgIR,
             imgVIS,
             minIR=180,
             maxIR=280,
             colorTable='Sandwich',
             useNaN=True):
    """McIDAS-V implementation of Martin Setvak's "sandwich" imagery.
    
    Args:
        imgIR: IR image being displayed.
        imgVIS: VIS image being displayed.
        minIR, maxIR: outside these bounds, no IR layer will be visible.
        colorTable: Name of chosen enhancement table for IR image.
        useNaN: if True, the VIS image won't be visible outside of minIR/maxIR.
        usePlugin: if True, use sandwich_speedup.jar plugin for optimization.
        
    Returns:
       rgbImg: An RGB "sandwich".
    """
    if imgIR.isFlatField():
        imgIR = imgIR
    else:
        imgIR = imgIR[0]

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

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

    ct = getStaticMcv().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]

    t0 = time.clock()
    sandwichSpeedup(
        scaledFloats,
        floatsIR,
        rFloats,
        gFloats,
        bFloats,
        rTable,
        gTable,
        bTable,
        minIR,
        maxIR,
        nCols,
        noIRContribution,
    )
    t1 = time.clock()
    # print('Sandwich: time spent in for loop [s]: {}'.format(t1 - t0))

    # 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
    gOutput = imgVIS * gIR
    bOutput = imgVIS * bIR

    rgbImg = mycombineRGB(rOutput, gOutput, bOutput)
    return rgbImg
Exemplo n.º 19
0
def load(path):
    """Simplistic file loading function.
    
    Please use loadGrid instead.
    """
    return getStaticMcv().makeOneDataSource(path, None, None)
Exemplo n.º 20
0
def getMouseEarthLocation():
    display = getStaticMcv().getVMManager().getLastActiveViewManager()
    master = display.getMaster()
    visadLat, visadLon = master.getCursorLatitude(), master.getCursorLongitude()
    return visadLat.getValue(), visadLon.getValue()
Exemplo n.º 21
0
def load(path):
    return getStaticMcv().makeOneDataSource(path, None, None)
Exemplo n.º 22
0
def getMouseEarthLocation():
    display = getStaticMcv().getVMManager().getLastActiveViewManager()
    master = display.getMaster()
    visadLat, visadLon = master.getCursorLatitude(), master.getCursorLongitude()
    return visadLat.getValue(), visadLon.getValue()