def calc()

in analysis/webservice/algorithms/TimeAvgMap.py [0:0]


    def calc(self, computeOptions, **args):
        """

        :param computeOptions: StatsComputeOptions
        :param args: dict
        :return:
        """

        self._minLat = float(computeOptions.get_min_lat())
        self._maxLat = float(computeOptions.get_max_lat())
        self._minLon = float(computeOptions.get_min_lon())
        self._maxLon = float(computeOptions.get_max_lon())
        self._ds = computeOptions.get_dataset()[0]
        self._startTime = computeOptions.get_start_time()
        self._endTime = computeOptions.get_end_time()

        self._find_native_resolution()
        print('Using Native resolution: lat_res=%f, lon_res=%f' % (self._latRes, self._lonRes))
        self._minLatCent = self._minLat + self._latRes / 2
        self._minLonCent = self._minLon + self._lonRes / 2
        nlats = int((self._maxLat - self._minLatCent) / self._latRes) + 1
        nlons = int((self._maxLon - self._minLonCent) / self._lonRes) + 1
        self._maxLatCent = self._minLatCent + (nlats - 1) * self._latRes
        self._maxLonCent = self._minLonCent + (nlons - 1) * self._lonRes
        print('nlats=', nlats, 'nlons=', nlons)
        print('center lat range = %f to %f' % (self._minLatCent,
                                               self._maxLatCent))
        print('center lon range = %f to %f' % (self._minLonCent,
                                               self._maxLonCent))
        sys.stdout.flush()
        a = np.zeros((nlats, nlons), dtype=np.float64, order='C')

        nexus_tiles = self._find_global_tile_set()
        # print 'tiles:'
        # for tile in nexus_tiles:
        #     print tile.granule
        #     print tile.section_spec
        #     print 'lat:', tile.latitudes
        #     print 'lon:', tile.longitudes

        #                                                          nexus_tiles)
        if len(nexus_tiles) == 0:
            raise NoDataException(reason="No data found for selected timeframe")

        print('Initially found %d tiles' % len(nexus_tiles))
        sys.stdout.flush()
        self._prune_tiles(nexus_tiles)
        print('Pruned to %d tiles' % len(nexus_tiles))
        sys.stdout.flush()
        # for tile in nexus_tiles:
        #    print 'lats: ', tile.latitudes.compressed()
        #    print 'lons: ', tile.longitudes.compressed()

        avg_tiles = list(map(self._map, nexus_tiles))
        print('shape a = ', a.shape)
        sys.stdout.flush()
        # The tiles below are NOT Nexus objects.  They are tuples
        # with the time avg map data and lat-lon bounding box.
        for tile in avg_tiles:
            if tile is not None:
                (tile_data, tile_min_lat, tile_max_lat,
                 tile_min_lon, tile_max_lon) = tile
                print('shape tile_data = ', tile_data.shape)
                print('tile data mask = ', tile_data.mask)
                sys.stdout.flush()
                if np.any(np.logical_not(tile_data.mask)):
                    y0 = self._lat2ind(tile_min_lat)
                    y1 = self._lat2ind(tile_max_lat)
                    x0 = self._lon2ind(tile_min_lon)
                    x1 = self._lon2ind(tile_max_lon)
                    print('writing tile lat %f-%f, lon %f-%f, map y %d-%d, map x %d-%d' % \
                          (tile_min_lat, tile_max_lat,
                           tile_min_lon, tile_max_lon, y0, y1, x0, x1))
                    sys.stdout.flush()
                    a[y0:y1 + 1, x0:x1 + 1] = tile_data
                else:
                    print('All pixels masked in tile lat %f-%f, lon %f-%f, map y %d-%d, map x %d-%d' % \
                          (tile_min_lat, tile_max_lat,
                           tile_min_lon, tile_max_lon, y0, y1, x0, x1))
                    sys.stdout.flush()

        self._create_nc_file(a)

        return TimeAvgMapResults(results={}, meta={}, computeOptions=computeOptions)