ecoscope.io.eetools =================== .. py:module:: ecoscope.io.eetools Module Contents --------------- .. py:data:: logger .. py:data:: ee_is_initialized :value: False .. py:data:: ee_initialization_expires .. py:data:: ee_initialization_ttl .. py:data:: colourPalettes .. py:function:: initialize_earthengine(key_dict) This takes a JSON key as a dict. :param key_dict: :return: a credentials object that can be used to initialize the earth engine library. .. py:function:: convert_millisecs_datetime(unix_time) .. py:function:: add_img_time(img) A function to add the date range of the image as one of its properties and the start and end values as new bands .. py:function:: label_gdf_with_img(gdf, img, region_reducer, scale = 500.0) .. py:function:: _match_gdf_to_img_coll_ids(gdf, time_col, img_coll, output_col_name = 'img_ids', n_before = 1, n_after = 1, n = 'images') A function that will add a column to a gdf (output_col_name) that contains the n_before -> n_after temporally closest image IDs from an image collection. :param gdf: The GeoDataFrame to add image IDs to :type gdf: geopandas.GeoDataFrame :param time_col: The name of the column within the given gdf containing the relevant timestamps :type time_col: str :param img_coll: The image collection to lookup image IDs from :type img_coll: ee.ImageCollection :param output_col_name: The name of the column to be added to the given gdf, default is 'img_ids' :type output_col_name: str, optional :param n_before: The number of n days/weeks/images before to grab image IDs for, default is 1 :type n_before: int, optional :param n_after: The number of n days/weeks/images after to grab image IDs for, default is 1 :type n_after: int, optional :param n: One of: 'images'(default), 'microseconds', 'milliseconds' 'seconds', 'minutes', 'hours', 'days' or 'weeks' If n is 'images', this appends n_before IDs + the temporally closest ID + n_after IDs Otherwise this appends image IDs between timestamp-n_before to timestamp+n_after where timestamp is a given row from the input gdf :type n: str, optional .. py:function:: label_gdf_with_temporal_image_collection_by_feature(gdf, img_coll, time_col_name, n_before = 1, n_after = 1, n = 'images', region_reducer = None, scale=500.0) .. py:function:: label_gdf_with_temporal_image_collection_by_timespan(gdf, img_coll, image_radius = 0, add_time = False, region_reducer='toList', df_chunk_size=25000, max_workers=1) .. py:function:: chunk_gdf(gdf, label_func, label_func_kwargs = None, df_chunk_size = 25000, max_workers = 1) A function that will process the input gdf in chunks and apply the input label_func function over the chunks. :param gdf: a geopandas dataframe. The 'geometry' column can be any type pf geometry (point/line/polygon). The gdf needs to have a column with the name of the image_collection and the column values are lists of the individual image IDs that need to be associated with each feature. This step will typically be run with the match_img_coll_ids_to_gdf() function beforehand. :param label_func: a function to run on the EE cloud that has the signature (feat, kwargs) :param label_func_kwargs: a dictionary of parameters to provide to the label_func :param df_chunk_size: how many features (rows) to process at once within EE :param max_workers: the number of chunks to process concurrently :return: a dataframe with the same index as the input gdf and where each pixel value (or reduced value) is a row .. py:function:: calculate_anomaly(gdf, img_coll, historical_start, start, end, scale = 5000.0) Compute anomalies by subtracting the historical_start mean from each image in a collection of start->end images. :param gdf: the input geodataframe :param img_coll: the input EE image collection :param historical_start: start time for calculating the mean reference :param start: end time for mean reference and the start time for the anomaly calculation :param end: end time for the anomaly calculation :param scale: the image scale :return: a dataframe with same index as input gdf with the img_dates and the anomaly calculation