Exemple #1
0
def doFinal(execution: WPSExecution, to, transaction: Transaction):
    log.info('Fimex Transfermation ordered ' + execution.statusLocation)

    status = check_process_status(execution)

    transaction.set_status(status)

    # TODO: React based on status
    config = confuse.Configuration('Basket', __name__)
    solr_client = SolrClient(config['solr']['endpoint'].get(), "basket")
    solr_client.update(transaction.toSolrDocument())

    # send email to user
    send_email(to)
Exemple #2
0
def send_email(to):
    config = confuse.Configuration('Basket', __name__)
    message = MIMEMultipart("alternative")
    message["Subject"] = config['mail']['subject'].get()
    message["From"] = config['mail']['from'].get()
    message["To"] = to

    text = config['mail']['body']['content'].get()
    part1 = MIMEText(text, "plain")

    message.attach(part1)

    # Create secure connection with server and send email
    # context = ssl.create_default_context()
    try:
        server = smtplib.SMTP(config['mail']['smtp']['host'].get(),
                              config['mail']['smtp']['port'].get())
        server.sendmail(config['mail']['from'].get(), to, message.as_string())
    except:
        log.info('something wrong ......')
    finally:
        server.quit()
Exemple #3
0
def submitFeatureWeightedGridStatistics(geoType, dataSetURI, varID, startTime, endTime, attribute, value, gmlIDs,
                                        verbose, coverage, delim, stat, grpby, timeStep, summAttr, weighted, WFS_URL):
    """
    Makes a featureWeightedGridStatistics algorithm call. 
    The web service interface implemented is summarized here: 
    https://my.usgs.gov/confluence/display/GeoDataPortal/Generating+Area+Weighted+Statistics+Of+A+Gridded+Dataset+For+A+Set+Of+Vector+Polygon+Features
    
    Note that varID and stat can be a list of strings.
    
    """
    # test for dods:
    dataSetURI = _execute_request.dodsReplace(dataSetURI)
    
    log.info('Generating feature collection.')
    
    featureCollection = _get_geotype._getFeatureCollectionGeoType(geoType, attribute, value, gmlIDs, WFS_URL)
    if featureCollection is None:
        return
    
    processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
    if weighted==False:
        processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureGridStatisticsAlgorithm'
    
    solo_inputs = [("FEATURE_ATTRIBUTE_NAME",attribute), 
              ("DATASET_URI", dataSetURI),  
              ("TIME_START",startTime),
              ("TIME_END",endTime), 
              ("REQUIRE_FULL_COVERAGE",str(coverage).lower()), 
              ("DELIMITER",delim), 
              ("GROUP_BY", grpby),
              ("SUMMARIZE_TIMESTEP", str(timeStep).lower()), 
              ("SUMMARIZE_FEATURE_ATTRIBUTE",str(summAttr).lower()), 
              ("FEATURE_COLLECTION", featureCollection)]
              
    if isinstance(stat, list):
        num_stats=len(stat)
        if num_stats > 7:
            raise Exception('Too many statistics were submitted.')
    else:
        num_stats=1
              
    if isinstance(varID, list):
        num_varIDs=len(varID)
    else:
        num_varIDs=1
    
    inputs = [('','')]*(len(solo_inputs)+num_varIDs+num_stats)
    
    count=0
    rmvCnt=0
    
    for solo_input in solo_inputs:
                    if solo_input[1]!=None:
                            inputs[count] = solo_input
                            count+=1
                    else: 
                            rmvCnt+=1
            
    del inputs[count:count+rmvCnt]
                    
    if num_stats > 1:
        for stat_in in stat:
            if stat_in not in ["MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM", "COUNT"]:
                raise Exception('The statistic %s is not in the allowed list: "MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM", "COUNT"' % stat_in)
            inputs[count] = ("STATISTICS",stat_in)
            count+=1
    elif num_stats == 1:
        if stat not in ["MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM", "COUNT"]:
            raise Exception('The statistic %s is not in the allowed list: "MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM", "COUNT"' % stat)
        inputs[count] = ("STATISTICS",stat)
        count+=1
             
    if num_varIDs > 1:
        for var in varID:
            inputs[count] = ("DATASET_ID",var)
            count+=1
    elif num_varIDs == 1:
        inputs[count] = ("DATASET_ID",varID)
    
    output = "OUTPUT"
    
    return _execute_request._executeRequest(processid, inputs, output, verbose)
Exemple #4
0
def submitFeatureWeightedGridStatistics(geoType, dataSetURI, varID, startTime,
                                        endTime, attribute, value, gmlIDs,
                                        verbose, coverage, delim, stat, grpby,
                                        timeStep, summAttr, weighted, WFS_URL,
                                        outputfname, sleepSecs):
    """
    Makes a featureWeightedGridStatistics algorithm call. 
    The web service interface implemented is summarized here: 
    https://my.usgs.gov/confluence/display/GeoDataPortal/Generating+Area+Weighted+Statistics+Of+A+Gridded+Dataset+For+A+Set+Of+Vector+Polygon+Features
    
    Note that varID and stat can be a list of strings.
    
    """
    # test for dods:
    dataSetURI = _execute_request.dodsReplace(dataSetURI)

    log.info('Generating feature collection.')

    featureCollection = _get_geotype._getFeatureCollectionGeoType(
        geoType, attribute, value, gmlIDs, WFS_URL)
    if featureCollection is None:
        return

    processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
    if weighted == False:
        processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureGridStatisticsAlgorithm'

    solo_inputs = [("FEATURE_ATTRIBUTE_NAME", attribute),
                   ("DATASET_URI", dataSetURI), ("TIME_START", startTime),
                   ("TIME_END", endTime),
                   ("REQUIRE_FULL_COVERAGE", str(coverage).lower()),
                   ("DELIMITER", delim), ("GROUP_BY", grpby),
                   ("SUMMARIZE_TIMESTEP", str(timeStep).lower()),
                   ("SUMMARIZE_FEATURE_ATTRIBUTE", str(summAttr).lower()),
                   ("FEATURE_COLLECTION", featureCollection)]

    if isinstance(stat, list):
        num_stats = len(stat)
        if num_stats > 7:
            raise Exception('Too many statistics were submitted.')
    else:
        num_stats = 1

    if isinstance(varID, list):
        num_varIDs = len(varID)
    else:
        num_varIDs = 1

    inputs = [('', '')] * (len(solo_inputs) + num_varIDs + num_stats)

    count = 0
    rmvCnt = 0

    for solo_input in solo_inputs:
        if solo_input[1] != None:
            inputs[count] = solo_input
            count += 1
        else:
            rmvCnt += 1

    del inputs[count:count + rmvCnt]

    if num_stats > 1:
        for stat_in in stat:
            if stat_in not in [
                    "MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM",
                    "COUNT"
            ]:
                raise Exception(
                    'The statistic %s is not in the allowed list: "MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM", "COUNT"'
                    % stat_in)
            inputs[count] = ("STATISTICS", stat_in)
            count += 1
    elif num_stats == 1:
        if stat not in [
                "MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM",
                "COUNT"
        ]:
            raise Exception(
                'The statistic %s is not in the allowed list: "MEAN", "MINIMUM", "MAXIMUM", "VARIANCE", "STD_DEV", "SUM", "COUNT"'
                % stat)
        inputs[count] = ("STATISTICS", stat)
        count += 1

    if num_varIDs > 1:
        for var in varID:
            inputs[count] = ("DATASET_ID", var)
            count += 1
    elif num_varIDs == 1:
        inputs[count] = ("DATASET_ID", varID)

    output = "OUTPUT"

    return _execute_request._executeRequest(processid, inputs, output, verbose,
                                            outputfname, sleepSecs)
Exemple #5
0
def submitFeatureWeightedGridStatistics(geoType, dataSetURI, varID, startTime, endTime, attribute, value,
                                        gmlIDs, verbose, coverage, delim, stat, grpby, timeStep, summAttr,
                                        weighted, wfs_url, outputfname, sleepSecs, async=False):
    """
    Makes a featureWeightedGridStatistics algorithm call. 
    The web service interface implemented is summarized here: 
    https://my.usgs.gov/confluence/display/GeoDataPortal/Generating+Area+Weighted+Statistics+Of+A+Gridded+Dataset+For+A+Set+Of+Vector+Polygon+Features
    
    Note that varID and stat can be a list of strings.
    
    """
    # test for dods:
    dataSetURI = dodsReplace(dataSetURI)

    log.info('Generating feature collection.')

    featureCollection = _getFeatureCollectionGeoType(geoType, attribute, value, gmlIDs, wfs_url)

    if featureCollection is None:
        return

    processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureWeightedGridStatisticsAlgorithm'
    if not weighted:
        processid = 'gov.usgs.cida.gdp.wps.algorithm.FeatureGridStatisticsAlgorithm'

    solo_inputs = [("FEATURE_ATTRIBUTE_NAME", attribute),
                   ("DATASET_URI", dataSetURI),
                   ("TIME_START", startTime),
                   ("TIME_END", endTime),
                   ("REQUIRE_FULL_COVERAGE", str(coverage).lower()),