def _map()

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


    def _map(self, tile_in):
        print('Started tile %s' % tile_in.section_spec)
        print('tile lats = ', tile_in.latitudes)
        print('tile lons = ', tile_in.longitudes)
        print('tile = ', tile_in.data)
        sys.stdout.flush()
        lats = tile_in.latitudes
        lons = tile_in.longitudes
        if len(lats > 0) and len(lons > 0):
            min_lat = np.ma.min(lats)
            max_lat = np.ma.max(lats)
            min_lon = np.ma.min(lons)
            max_lon = np.ma.max(lons)
            good_inds_lat = np.where(lats.mask == False)
            good_inds_lon = np.where(lons.mask == False)
            min_y = np.min(good_inds_lat)
            max_y = np.max(good_inds_lat)
            min_x = np.min(good_inds_lon)
            max_x = np.max(good_inds_lon)
            tile_inbounds_shape = (max_y - min_y + 1, max_x - min_x + 1)
            days_at_a_time = 90
            t_incr = 86400 * days_at_a_time
            avg_tile = np.ma.array(np.zeros(tile_inbounds_shape,
                                            dtype=np.float64))
            cnt_tile = np.ma.array(np.zeros(tile_inbounds_shape,
                                            dtype=np.uint32))
            t_start = self._startTime
            while t_start <= self._endTime:
                t_end = min(t_start + t_incr, self._endTime)
                t1 = time()
                print('nexus call start at time %f' % t1)
                sys.stdout.flush()
                nexus_tiles = self._get_tile_service().get_tiles_bounded_by_box(min_lat - self._latRes / 2,
                                                                          max_lat + self._latRes / 2,
                                                                          min_lon - self._lonRes / 2,
                                                                          max_lon + self._lonRes / 2, ds=self._ds,
                                                                          start_time=t_start, end_time=t_end)
                t2 = time()
                print('nexus call end at time %f' % t2)
                print('secs in nexus call: ', t2 - t1)
                sys.stdout.flush()
                self._prune_tiles(nexus_tiles)
                print('t %d to %d - Got %d tiles' % (t_start, t_end,
                                                     len(nexus_tiles)))
                sys.stdout.flush()
                for tile in nexus_tiles:
                    tile.data.data[:, :] = np.nan_to_num(tile.data.data)
                    avg_tile.data[:, :] += tile.data[0,
                                           min_y:max_y + 1,
                                           min_x:max_x + 1]
                    cnt_tile.data[:, :] += (~tile.data.mask[0,
                                             min_y:max_y + 1,
                                             min_x:max_x + 1]).astype(np.uint8)
                t_start = t_end + 1

            print('cnt_tile = ', cnt_tile)
            cnt_tile.mask = ~(cnt_tile.data.astype(bool))
            avg_tile.mask = cnt_tile.mask
            avg_tile /= cnt_tile
            print('Finished tile %s' % tile_in.section_spec)
            print('Tile avg = ', avg_tile)
            sys.stdout.flush()
        else:
            avg_tile = None
            min_lat = None
            max_lat = None
            min_lon = None
            max_lon = None
            print('Tile %s outside of bounding box' % tile_in.section_spec)
            sys.stdout.flush()
        return (avg_tile, min_lat, max_lat, min_lon, max_lon)