Esempio n. 1
0
    def _centroids_creation(firms, centr_res_factor):
        """ Compute centroids for the firms dataset.
            The number of centroids is defined according to the data resolution.

        Parameters:
            firms (dataframe): dataset obtained from FIRMS data
            centr_res_factor (float): the factor applied to voluntarly decrease/increase
                the centroids resolution

        Returns:
            centroids (Centroids)
            res_data (float): data resolution (km)
        """

        LOGGER.info('Defining the resolution of the centroids.')
        # Resolution of the centroids depends on the data origin.
        # Resolution in km.
        if 'instrument' in firms.columns:
            if firms['instrument'].any() == 'MODIS':
                res_data = 1.0
            else:
                res_data = 0.375 # For VIIRS data
        else:
            res_data = RES_DATA # For undefined data origin, defined by user

        LOGGER.info('Computing centroids.')
        centroids = Centroids()
        dlat_km = abs(firms['latitude'].min() - firms['latitude'].max()) * ONE_LAT_KM
        dlon_km = abs(firms['longitude'].min() - firms['longitude'].max()) * ONE_LAT_KM* \
            np.cos(np.radians((abs(firms['latitude'].min() - firms['latitude'].max()))/2))
        nb_centr_lat = int(dlat_km/res_data * centr_res_factor)
        nb_centr_lon = int(dlon_km/res_data * centr_res_factor)
        coord = (np.mgrid[firms['latitude'].min() : firms['latitude'].max() : \
            complex(0, nb_centr_lat), firms['longitude'].min() : firms['longitude'].max() : \
            complex(0, nb_centr_lon)]).reshape(2, nb_centr_lat*nb_centr_lon).transpose()
        centroids.set_lat_lon(coord[:, 0], coord[:, 1])

#        centroids.set_raster_from_pnt_bounds((firms['longitude'].min(),
#        firms['latitude'].min(), firms['longitude'].max(), firms['latitude'].max()),
#        res=res_data/centr_res_factor)    ---> propagation works?

        # Calculate the area attributed to each centroid
        centroids.set_area_approx()
        # Calculate if the centroids is on land or not
        centroids.set_on_land()
        # Calculate to distance to coast
        centroids.set_dist_coast()
        # Create on land grid
        centroids.land = centroids.on_land.reshape((nb_centr_lat, nb_centr_lon)).astype(int)
        centroids.nb_centr_lat = nb_centr_lat
        centroids.nb_centr_lon = nb_centr_lon
        centroids.empty_geometry_points()
        return centroids, res_data