def createScatterPlot(id, parameter):
    with ResultsStorage.ResultsRetrieval() as storage:
        params, stats, data = storage.retrieveResults(id)

    primary = params["primary"]
    secondary = params["matchup"][0]

    x, y, z = createScatterTable(data, secondary, parameter)

    plot = renderAsync(x, y, z, primary, secondary, parameter)

    r = DomsScatterPlotQueryResults(x=x,
                                    y=y,
                                    z=z,
                                    parameter=parameter,
                                    primary=primary,
                                    secondary=secondary,
                                    args=params,
                                    details=stats,
                                    bounds=None,
                                    count=None,
                                    computeOptions=None,
                                    executionId=id,
                                    plot=plot)
    return r
示例#2
0
    def calc(self, computeOptions, **args):
        id = computeOptions.get_argument("id", None)

        retrieval = ResultsStorage.ResultsRetrieval()

        params, stats, data = retrieval.retrieveResults(id)

        return BaseDomsHandler.DomsQueryResults(results=data,
                                                args=params,
                                                details=stats,
                                                bounds=None,
                                                count=None,
                                                computeOptions=None,
                                                executionId=id)
    def calc(self, computeOptions, **args):
        execution_id = computeOptions.get_argument("id", None)

        try:
            execution_id = uuid.UUID(execution_id)
        except:
            raise NexusProcessingException(reason="'id' argument must be a valid uuid", code=400)

        simple_results = computeOptions.get_boolean_arg("simpleResults", default=False)

        with ResultsStorage.ResultsRetrieval() as storage:
            params, stats, data = storage.retrieveResults(execution_id, trim_data=simple_results)

        return BaseDomsHandler.DomsQueryResults(results=data, args=params, details=stats, bounds=None, count=None,
                                                computeOptions=None, executionId=execution_id)
示例#4
0
    def calc(self, computeOptions, **args):
        id = computeOptions.get_argument("id", None)

        retrieval = ResultsStorage.ResultsRetrieval()

        params, stats, data = retrieval.retrieveResults(id)

        plotType = computeOptions.get_argument("type", PlotTypes.SCATTER)

        if plotType == PlotTypes.SCATTER:
            return self.__createScatterPlot(id, params, stats, data)
        elif plotType == PlotTypes.MAP:
            return self.__createMapPlot(id, params, stats, data)
        else:
            raise Exception("Unsupported plot type '%s' specified." % plotType)
def createHistogramPlot(id, parameter, norm_and_curve=False):
    with ResultsStorage.ResultsRetrieval() as storage:
        params, stats, data = storage.retrieveResults(id)

    primary = params["primary"]
    secondary = params["matchup"][0]

    x = createHistTable(data, secondary, parameter)

    plot = renderAsync(x, primary, secondary, parameter, norm_and_curve)

    r = DomsHistogramPlotQueryResults(x=x, parameter=parameter, primary=primary, secondary=secondary,
                                      args=params, details=stats,
                                      bounds=None, count=None, computeOptions=None, executionId=id, plot=plot)
    return r
示例#6
0
文件: mapplot.py 项目: lfcma/nexus
def createMapPlot(id, parameter):

    with ResultsStorage.ResultsRetrieval() as storage:
        params, stats, data = storage.retrieveResults(id)

    primary = params["primary"]
    secondary = params["matchup"][0]

    lats = []
    lons = []
    z = []

    field = PARAMETER_TO_FIELD[
        parameter] if parameter in PARAMETER_TO_FIELD else PARAMETER_TO_FIELD[
            "sst"]

    for entry in data:
        for match in entry["matches"]:
            if match["source"] == secondary:

                if field in entry and field in match:
                    a = entry[field]
                    b = match[field]
                    z.append((a - b))
                    z.append((a - b))
                else:
                    z.append(1.0)
                    z.append(1.0)
                lats.append(entry["y"])
                lons.append(entry["x"])
                lats.append(match["y"])
                lons.append(match["x"])

    plot = renderAsync(lats, lons, z, primary, secondary, parameter)
    r = DomsMapPlotQueryResults(lats=lats,
                                lons=lons,
                                z=z,
                                parameter=parameter,
                                primary=primary,
                                secondary=secondary,
                                args=params,
                                details=stats,
                                bounds=None,
                                count=None,
                                computeOptions=None,
                                executionId=id,
                                plot=plot)
    return r
示例#7
0
    def calc(self, computeOptions, **args):
        primary = computeOptions.get_argument("primary", None)
        matchup = computeOptions.get_argument("matchup", None)
        startTime = computeOptions.get_argument("s", None)
        endTime = computeOptions.get_argument("e", None)
        bbox = computeOptions.get_argument("b", None)
        timeTolerance = computeOptions.get_float_arg("tt")
        depth_min = computeOptions.get_float_arg("depthMin", default=None)
        depth_max = computeOptions.get_float_arg("depthMax", default=None)
        radiusTolerance = computeOptions.get_float_arg("rt")
        platforms = computeOptions.get_argument("platforms", None)

        if primary is None or len(primary) == 0:
            raise Exception("No primary dataset specified")

        if matchup is None or len(matchup) == 0:
            raise Exception("No matchup datasets specified")

        start = self._now()

        primarySpec = self.getDataSourceByName(primary)
        if primarySpec is None:
            raise Exception("Specified primary dataset not found using identifier '%s'" % primary)

        primaryData, bounds = self.fetchData([primarySpec], startTime, endTime, bbox, depth_min, depth_max, platforms)

        primaryContext = MatchupContext(primaryData)

        matchupIds = matchup.split(",")

        for matchupId in matchupIds:
            matchupSpec = self.getDataSourceByName(matchupId)

            if matchupSpec is not None:  # Then it's in the in-situ configuration
                proc = InsituDatasetProcessor(primaryContext, matchupSpec, startTime, endTime, bbox, depth_min, depth_max,
                                              platforms, timeTolerance, radiusTolerance)
                proc.start()
            else:  # We assume it to be a Nexus tiled dataset

                '''
                Single Threaded at the moment...
                '''
                daysinrange = self._tile_service.find_days_in_range_asc(bounds.south, bounds.north, bounds.west,
                                                                        bounds.east, matchupId,
                                                                        self.__parseDatetime(startTime) / 1000,
                                                                        self.__parseDatetime(endTime) / 1000)

                tilesByDay = {}
                for dayTimestamp in daysinrange:
                    ds1_nexus_tiles = self._tile_service.get_tiles_bounded_by_box_at_time(bounds.south, bounds.north,
                                                                                          bounds.west, bounds.east,
                                                                                          matchupId, dayTimestamp)

                    # print "***", type(ds1_nexus_tiles)
                    # print ds1_nexus_tiles[0].__dict__
                    tilesByDay[dayTimestamp] = ds1_nexus_tiles

                primaryContext.processGridded(tilesByDay, matchupId, radiusTolerance, timeTolerance)

        matches, numMatches = primaryContext.getFinal(len(matchupIds))

        end = self._now()

        args = {
            "primary": primary,
            "matchup": matchupIds,
            "startTime": startTime,
            "endTime": endTime,
            "bbox": bbox,
            "timeTolerance": timeTolerance,
            "depthMin": depth_min,
            "depthMax": depth_max,
            "radiusTolerance": radiusTolerance,
            "platforms": platforms
        }

        details = {
            "timeToComplete": (end - start),
            "numInSituRecords": primaryContext.insituCount,
            "numInSituMatched": primaryContext.insituMatches,
            "numGriddedChecked": primaryContext.griddedCount,
            "numGriddedMatched": primaryContext.griddedMatched
        }

        with ResultsStorage.ResultsStorage() as resultsStorage:
            execution_id = resultsStorage.insertResults(results=matches, params=args, stats=details, startTime=start,
                                                        completeTime=end, userEmail="")

        return BaseDomsHandler.DomsQueryResults(results=matches, args=args, details=details, bounds=None, count=None,
                                                computeOptions=None, executionId=execution_id)