Beispiel #1
0
    def latitude_time_hofmoeller_stats(tile_in_spark):

        (tile_id, index, min_lat, max_lat, min_lon, max_lon) = tile_in_spark

        tile_service = NexusTileService()
        try:
            # Load the dataset tile
            tile = tile_service.find_tile_by_id(tile_id)[0]
            # Mask it to the search domain
            tile = tile_service.mask_tiles_to_bbox(min_lat, max_lat, min_lon,
                                                   max_lon, [tile])[0]
        except IndexError:
            return None

        stat = {'sequence': index, 'time': np.ma.min(tile.times), 'lats': []}

        points = list(tile.nexus_point_generator())
        data = sorted(points, key=lambda p: p.latitude)
        points_by_lat = itertools.groupby(data, key=lambda p: p.latitude)

        for lat, points_at_lat in points_by_lat:
            values_at_lat = np.array(
                [point.data_val for point in points_at_lat])

            stat['lats'].append({
                'latitude': float(lat),
                'cnt': len(values_at_lat),
                'avg': np.mean(values_at_lat).item(),
                'max': np.max(values_at_lat).item(),
                'min': np.min(values_at_lat).item(),
                'std': np.std(values_at_lat).item()
            })

        return stat
Beispiel #2
0
    def hofmoeller_stats(tile_in_spark):

        (latlon, tile_id, index,
         min_lat, max_lat, min_lon, max_lon) = tile_in_spark

        tile_service = NexusTileService()
        try:
            # Load the dataset tile
            tile = tile_service.find_tile_by_id(tile_id)[0]
            # Mask it to the search domain
            tile = tile_service.mask_tiles_to_bbox(min_lat, max_lat,
                                                   min_lon, max_lon, [tile])[0]
        except IndexError:
            # return None
            return []
        t = np.ma.min(tile.times)
        stats = []

        points = list(tile.nexus_point_generator())
        if latlon == 0:
            # Latitude-Time Map (Average over longitudes)
            data = sorted(points, key=lambda p: p.latitude)
            points_by_coord = itertools.groupby(data, key=lambda p: p.latitude)
        else:
            # Longitude-Time Map (Average over latitudes)
            data = sorted(points, key=lambda p: p.longitude)
            points_by_coord = itertools.groupby(data, key=lambda p: p.longitude)

        for coord, points_at_coord in points_by_coord:
            values_at_coord = np.array([[p.data_val,
                                         np.cos(np.radians(p.latitude))]
                                        for p in points_at_coord])
            vals = np.nan_to_num(values_at_coord[:, 0])
            weights = values_at_coord[:, 1]
            coord_cnt = len(values_at_coord)
            if latlon == 0:
                # Latitude-Time Map (Average over longitudes)
                # In this case there is no weighting by cos(lat)
                weighted_sum = np.sum(vals).item()
                sum_of_weights = coord_cnt
            else:
                # Longitude-Time Map (Average over latitudes)
                # In this case we need to weight by cos(lat)
                weighted_sum = np.dot(vals, weights)
                sum_of_weights = np.sum(weights).item()

            stats.append(((t, float(coord)), (t, index, float(coord),
                                              coord_cnt,
                                              weighted_sum,
                                              sum_of_weights,
                                              np.max(vals).item(),
                                              np.min(vals).item(),
                                              np.var(vals).item())))
        return stats