APIs
Submodules
APIs.EarthEngine module
- class APIs.EarthEngine.EarthEngineManager(*args: Any, **kwargs: Any)[source]
Bases:
BaseModel
- aggregation_functions: ClassVar[dict] = {'first': <function EarthEngineManager.<lambda>>, 'max': <function EarthEngineManager.<lambda>>, 'mean': <function EarthEngineManager.<lambda>>, 'median': <function EarthEngineManager.<lambda>>, 'min': <function EarthEngineManager.<lambda>>, 'mode': <function EarthEngineManager.<lambda>>, 'sum': <function EarthEngineManager.<lambda>>}
- calculate_statistics(img, geometry, band)[source]
- Parameters:
img – The image on which to calculate the statistics.
geometry – The geometry within which to calculate the statistics.
band – The band of the image on which to calculate the statistics.
- Returns:
The calculated statistics as a dictionary.
This method calculates various statistics for a given image within a specified geometry and band. It uses the Earth Engine reducers to calculate mean, sum, maximum, minimum, standard * deviation, variance, and median.
The img parameter is the image object on which the statistics are calculated. The geometry parameter is the geometry object that defines the region within which the statistics are calculated. The band parameter is the name of the band on which the statistics are calculated.
The method returns the calculated statistics as a dictionary. The keys of the dictionary represent the statistic types (‘mean’, ‘sum’, ‘max’, ‘min’, ‘stdDev’, ‘variance’, ‘median’) and * the values represent the computed statistics for each type.
- convert_geojson_to_ee(geojson_obj)[source]
Converts a GeoJSON object to Earth Engine objects.
- Parameters:
geojson_obj – The GeoJSON object to be converted.
- Returns:
The converted Earth Engine object.
- Raises:
ValueError – If the GeoJSON type is not supported.
- determine_geometries_to_process(override_boundary_type=None, layer=None, column=None, dropdown_api=None, boundary_type=None, draw_features=None, userlayers=None, boundary_layer=None, output_folder_location=None)[source]
- Parameters:
override_boundary_type (str) – (optional) Type of boundary to override the default boundary type.
layer (str) – (optional) Name of the layer to use for processing features.
column (str) – (optional) Name of the column to use for processing features.
dropdown_api (str) – (optional) API to retrieve dropdown values.
boundary_type (str) – (optional) Type of boundary to process.
draw_features (list) – (optional) List of features drawn by the user.
userlayers (dict) – (optional) Dictionary of user uploaded layers.
boundary_layer (str) – (optional) Layer name for user defined boundary.
- Returns:
List of geometries to process.
- Return type:
list
- download_and_split(image, original_geometry, scale, split_count=1, params=None, band=None)[source]
- Parameters:
image – The image identifier.
original_geometry – The original geometry of the image.
scale – The scale of the image.
split_count – The number of splits to divide the image into (default is 1).
params – Additional parameters (default is None).
band – The band of the image (default is None).
- Returns:
A list of file names and a boolean indicating if the download was successful.
- download_feature_geometry(distinct_values, feature_type_prefix=None, column=None, layer=None, dropdown_api=None, output_folder_location=None)[source]
- Parameters:
distinct_values – A list of distinct values used to filter the features.
feature_type_prefix – Optional prefix for the feature type.
column – Optional column used for filtering the features.
layer – A layer object containing the features.
dropdown_api – Optional dropdown API type.
- Returns:
The geometry of the features or None if no valid geometries are found.
- static download_file_from_url(url, destination_path)[source]
Download a file from the given URL.
- Parameters:
url – The URL of the file to be downloaded.
destination_path – The path where the downloaded file will be saved.
- Returns:
None
- ee_dates: list = []
- ee_ensure_geometry(geometry)[source]
- Parameters:
geometry – The input geometry to ensure that it is a valid Earth Engine Geometry.
- Returns:
Return the valid Earth Engine Geometry.
Ensures that the input geometry is a valid Earth Engine Geometry. If the geometry is an instance of ee.Feature, it extracts the geometry from the feature and returns it. If the geometry is already an instance of ee.Geometry, it returns it directly. If the geometry is an instance of ee.FeatureCollection, it dissolves it into its outer boundary and returns the dissolved geometry. If the geometry is a dictionary, it assumes that it is a GeoJSON geometry and converts it to an Earth Engine Geometry before ensuring its validity. If the geometry is of any other type, it raises a ValueError with a specific error message indicating that the geometry type must be an Earth Engine Geometry, Feature, or FeatureCollection.
- ee_geometry_to_shapely(geometry)[source]
Converts an Earth Engine Geometry or Feature, or a GeoJSON dictionary, to a Shapely Geometry.
- Parameters:
geometry – An Earth Engine Geometry or Feature, or a GeoJSON dictionary.
- Returns:
A Shapely Geometry object.
Examples
# Convert an Earth Engine Geometry ee_geometry_to_shapely(ee_object)
# Convert a GeoJSON dictionary geo_json = {
“type”: “Point”, “coordinates”: [0, 0]
} ee_geometry_to_shapely(geo_json)
- generate_monthly_date_ranges(start_date, end_date)[source]
- Parameters:
start_date – The start date of the date ranges to generate. Should be a datetime.date object.
end_date – The end date of the date ranges to generate. Should be a datetime.date object.
- Returns:
A list of tuples, where each tuple represents a monthly date range. Each tuple contains the start date and end date of the respective month.
- generate_yearly_date_ranges(start_date, end_date)[source]
- Parameters:
start_date – The start date of the date range.
end_date – The end date of the date range.
- Returns:
A list of tuples, where each tuple represents the start and end dates for each year within the specified range.
- get_admin_units(level=0)[source]
- Parameters:
level – An integer representing the administrative level. Default is 0.
- Returns:
A list of unique administrative units at the specified level.
This method retrieves administrative units from a dataset based on the specified level. The dataset used is FAO/GAUL_SIMPLIFIED_500m/2015, which contains administrative boundary information *. The parameter ‘level’ specifies the desired administrative level.
If level is 0, the method returns a sorted list of unique country names found in the dataset.
If level is 1 or 2, the method creates a dictionary where each key represents a higher-level unit and its value is a list of lower-level units. The dictionary is returned as a Python * dictionary.
Note: This method utilizes the Earth Engine API to interact with geospatial data.
- Example usage:
my_object = MyClass() result = my_object.get_admin_units(level=1)
# Result may look like: {
‘Country A’: [‘Region 1’, ‘Region 2’], ‘Country B’: [‘Region 3’, ‘Region 4’], …
}
- get_image(multi_date: bool, aggregation_period: str | None = None, aggregation_method: str | None = None, start_date: str | None = None, end_date: str | None = None, date: str | None = None, create_sub_folder=None, scale=None, image_collection: str | None = None, add_to_map: bool | None = None, band: str | None = None, additional_filter=False, filter_argument=None, geometry=None, statistics_only=False)[source]
- Parameters:
multi_date – Boolean indicating whether multiple dates will be used for aggregation
aggregation_period – String indicating the period over which to aggregate the images
aggregation_method – String indicating the method of aggregation to be used
start_date – String indicating the start date of the image collection
end_date – String indicating the end date of the image collection
date – String indicating the date for which to retrieve the image
create_sub_folder – Boolean indicating whether to create a subfolder for the downloaded image
scale – Scale at which to retrieve the image. Default is None.
image_collection – String indicating the Earth Engine image collection to use
add_to_map – Boolean indicating whether to add the retrieved image to the map
band – String indicating the band to retrieve from the image collection
additional_filter – Boolean indicating whether to apply an additional filter to the image collection
filter_argument – Argument to be used for additional filtering. Default is None.
geometry – Geometry object representing the region of interest
statistics_only – Boolean indicating whether to only return additional statistics about the image
- Returns:
Tuple containing the retrieved image, the boundary of the region, and the nominal scale of the image
- get_image_collection_dates(collection: str, min_max_only: bool = False)[source]
- Parameters:
collection – The name of the image collection to retrieve dates from. It should be in the format ‘path/to/collection’.
min_max_only – A boolean value indicating whether to only return the minimum and maximum dates in the collection. Default is False.
- Returns:
A list of dates in the image collection. If min_max_only is True, it will return a list with two dates, representing the minimum and maximum dates in the collection. Otherwise
*, it will return a list of all dates in the collection.
- get_image_download_url(region, scale, img, format='GEO_TIFF', crs='EPSG:4326')[source]
- Parameters:
region – The region of interest for the image download. It can be either an ee.Feature or ee.Geometry object.
scale – The scale of the image. It can be either a numerical value or ‘default’ to use the default scale of the image.
img – The image to download.
format – The format of the downloaded image. Default is ‘GEO_TIFF’.
crs – The coordinate reference system of the downloaded image. Default is ‘EPSG:4326’.
- Returns:
The download URL for the image.
This method takes in a region of interest, scale, image, format, and coordinate reference system (CRS) as parameters and returns the URL to download the image. The region can be specified * as an ee.Feature or ee.Geometry object. The scale can be provided as a numerical value or ‘default’ to use the default scale of the image. The format parameter determines the format * in which the image will be downloaded, with the default being ‘GEO_TIFF’. The crs parameter specifies the CRS of the downloaded image, with the default being ‘EPSG:4326’.
- get_image_sum(img, geometry, scale, band='population')[source]
- Parameters:
img – The input image to calculate the sum.
geometry – The geometry to apply the calculation to.
scale – The scale to use for calculation.
band – The band to calculate the sum for. Defaults to ‘population’.
- Returns:
The sum value calculated for the specified band.
- img_min_max(img, scale, min_threshold=None, boundary=None, band=None)[source]
- Parameters:
img – The input image
scale – The scale at which to compute the min and max values
min_threshold – An optional threshold to exclude values below
boundary – An optional geometry to limit the computation to a specific area
band – The band to compute the min and max values for
- Returns:
The minimum and maximum values of the specified band as a tuple (min_value, max_value)
- plot_image(img, vis_params)[source]
Plot an image on a geemap.Map object.
- Parameters:
img – The image to be plotted.
vis_params – The visualization parameters for the image.
- Returns:
The geemap.Map object with the image plotted.
- process_drawn_features(drawn_features, layer, column)[source]
- Parameters:
drawn_features – A list of drawn features, each representing a geometry or a feature in Google Earth Engine.
layer – An Earth Engine asset layer to filter and retrieve distinct values from.
column – The column or property in the asset layer for which to retrieve distinct values.
- Returns:
A list of distinct values from the specified column
- process_geometry_collection(geometry_collection, all_geometries)[source]
Process a geometry collection and extract polygon and multipolygon geometries
- Parameters:
geometry_collection – The input geometry collection to be processed
all_geometries – List to store the extracted geometries
- Returns:
None
- process_images(start_date, end_date, image_collection, band, country, aggregation_type, function)[source]
Process images within a specified date range.
- Parameters:
start_date – The start date of the date range.
end_date – The end date of the date range.
image_collection – The collection of images to process.
band – The desired band of the images.
country – The country for which to process the images.
aggregation_type – The type of aggregation for the images (either “monthly” or “yearly”).
function – The function to apply to the images.
- Returns:
None
- split_and_sort_geometry(geometry, num_sections)[source]
- Parameters:
geometry – The geometry to be split and sorted.
num_sections – The number of sections to split the geometry into.
- Returns:
A list of sorted grid cells obtained by splitting the geometry.
This method takes a geometry and splits it into a grid of specified number of sections. The grid cells are then sorted based on their area in descending order.
Example usage: ``` geometry = ee.Geometry.Polygon(<coordinates>) num_sections = 4
sorted_grid = split_and_sort_geometry(geometry, num_sections) ```
- vis_params: ClassVar[dict] = {'NDVI': {'max': 1, 'min': 0, 'palette': ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901', '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01', '012E01', '011D01', '011301']}}
- year_ranges: list = []
- class APIs.EarthEngine.EarthEngineNotebookInterface(*args: Any, **kwargs: Any)[source]
Bases:
BaseModel
- class Config[source]
Bases:
object
This class represents a configuration object.
- extra
Specifies whether to allow extra fields in the configuration.
- Type:
Extra
- Enum:
- Extra:
allow: Allows extra fields in the configuration.
disallow: Disallows extra fields in the configuration.
- create_widgets_gee()[source]
:create_widgets_gee method creates and configures the GEE widgets used for searching layers, selecting layers, selecting bands, and setting processing options.
- Returns:
A list of the configured GEE widgets.
- gather_parameters()[source]
Gathers the parameters required for processing.
- Returns:
A dictionary containing the gathered parameters.
- on_gee_layer_selected(b)[source]
Method to handle the selection of a Google Earth Engine layer.
- Parameters:
b (object) – The event object triggered by the selection.
- Returns:
None
- Return type:
None
- on_gee_search_button_clicked(b)[source]
Handle the click event of the Google Earth Engine search button.
- Parameters:
b – The button object that was clicked.
- Returns:
None
APIs.GPWv4 module
- class APIs.GPWv4.GPWv4(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
object
Initialize the object.
- Parameters:
ee_manager (Optional[EarthEngineManager]) – An instance of the EarthEngineManager class. If not provided, a new instance will be created.
- data_type_options = [{'band': 'population_count', 'layer': 'CIESIN/GPWv411/GPW_Population_Count', 'name': 'Population Count'}, {'band': 'population_density', 'layer': 'CIESIN/GPWv411/GPW_Population_Density', 'name': 'Population Density'}, {'band': 'unwpp-adjusted_population_count', 'layer': 'CIESIN/GPWv411/GPW_UNWPP-Adjusted_Population_Count', 'name': 'UN-Adjusted Population Count'}]
- download_and_process_image(image: ee.Image, geometry: Any, scale: Any, gpwv4_params: Dict[str, Any], band: str) None [source]
Downloads and processes an image by splitting it into tiles and optionally mosaicing them.
- Parameters:
image – The image to download and process.
geometry – The geometry (region of interest) to download the image for.
scale – The scale to use for downloading the image.
gpwv4_params – Additional parameters for the download process.
band – The band of the image to download and process.
- Returns:
None
- process_api(geometry: Any, distinct_values: Any, index: Any, params: Dict[str, Any] | None = None, bbox=None, pbar=None) Any [source]
Perform API processing.
- Parameters:
geometry – The geometry to process.
distinct_values – The distinct values.
index – The index.
params – Additional parameters (optional).
bbox – The bounding box (optional).
- Returns:
The processed result.
- process_gpwv4_layer(geometry: Any, gpwv4_params: Dict[str, Any]) Any [source]
- Parameters:
geometry – The geometry object representing the area of interest for processing.
gpwv4_params – The dictionary containing all the parameters for processing the GPWv4 layer.
- Returns:
The processed image or dictionary of statistics, depending on the value of the ‘statistics_only’ parameter.
- validate_parameters(gpwv4_params: Dict[str, Any]) bool [source]
- Parameters:
gpwv4_params – A dictionary containing the parameters for GPWv4 processing. - ‘folder_output’: The selected output folder. - ‘year’: The selected year. - ‘datatype’: The selected data type.
- Returns:
Returns True if all parameters are valid, False otherwise.
- year_options = ['2000', '2005', '2010', '2015', '2020']
- class APIs.GPWv4.GPWv4NotebookInterface(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
GPWv4
GPWv4NotebookInterface is a class that extends the base class GPWv4 and provides a user interface for interacting with the GPWv4 API in a Jupyter notebook.
Usage:
Instantiate an instance of GPWv4NotebookInterface by providing an optional instance of EarthEngineManager as the ee_manager parameter. If no ee_manager is provided, the default Earth *EngineManager will be used.
Example
>>> interface = GPWv4NotebookInterface()
Methods:
- __init__(ee_manager: Optional[EarthEngineManager] = None)
Initializes a new instance of GPWv4NotebookInterface.
- param - ee_manager:
An optional instance of EarthEngineManager to use.
- type - ee_manager:
Optional[EarthEngineManager]
- create_widgets_for_gpwv4() -> List[widgets.Widget]
Creates the interactive widgets for the GPWv4 API.
- returns:
A list of Widget objects that represent the interactive widgets.
- rtype:
List[widgets.Widget]
- gather_parameters() -> Dict[str, Any]
Gathers the parameters from the interactive widgets.
- returns:
A dictionary of parameter name-value pairs.
- rtype:
Dict[str, Any]
- process_api(geometry: Any, distinct_values: Any, index: int, params=None, bbox=None) -> None
Processes the GPWv4 API using the provided parameters and displays the result.
- param - geometry:
The geometry to process.
- type - geometry:
Any
- param - distinct_values:
The distinct values to process.
- type - distinct_values:
Any
- param - index:
The index of the item to process.
- type - index:
int
- param - params:
An optional dictionary of parameter name-value pairs. If not provided, the parameters will be gathered from the interactive widgets.
- type - params:
Optional[Dict[str, Any]]
- param - bbox:
An optional bounding box to use for filtering the data. If not provided, no filtering will be applied.
- type - bbox:
Optional[Any]
- returns:
None
- create_widgets_for_gpwv4() List[ipywidgets.Widget] [source]
Returns a list of widgets for the GPWv4 data processing tool.
The create_widgets_for_gpwv4 method creates several widgets that are used in the GPWv4 data processing tool. These widgets allow the user to select options such as data type, year *, scale, file directory, and processing options.
The method initializes each widget with default values and settings. The gpwv4_data_type widget is a dropdown menu that displays available data types and their corresponding layers *. The gpwv4_year widget is also a dropdown menu that displays available years for the data.
The statistics_only_check widget is a checkbox that allows the user to select whether only image statistics should be generated, represented as a dictionary. The scale_input widget * is a text box where the user can input the desired scale for the processing.
The add_image_to_map and create_sub_folder widgets are checkboxes that give the user the option to add the processed image to the map and create a sub-folder, respectively. The ` *filechooser` widget is a file chooser dialog that allows the user to select the directory for the processed files.
The gee_end_of_container_options widget is an accordion container that holds the processing options checkboxes. It is configured with a two-by-two layout, with the statistics_only *_check widget in the top left corner, the add_image_to_map widget in the top right corner, and the create_sub_folder widget in the bottom right corner.
The method creates a list named widget_list which contains all the widgets created. Finally, the method returns this list.
- Returns:
A list of widgets used in the GPWv4 data processing tool.
- gather_parameters() Dict[str, Any] [source]
Gather the parameters for the method.
- Returns:
A dictionary containing the parameters.
- Return type:
Dict[str, Any]
- process_api(geometry: Any, distinct_values: Any, index: int, params=None, bbox=None, pbar=None) None [source]
Process the API for a given geometry.
- Parameters:
geometry (Any) – The geometry to process.
distinct_values (Any) – The distinct values.
index (int) – The index.
params (Any, optional) – The parameters.
bbox (Any, optional) – The bounding box.
- Returns:
None
APIs.GloFasAPI module
- class APIs.GloFasAPI.GloFasAPI(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
object
- download_glofas_data(bbox, params, index=None, distinct_values=None)[source]
- Parameters:
bbox – The bounding box of the area to download Glofas data for.
glofas_params – The parameters for downloading Glofas data.
index – The index of the Glofas data.
distinct_values – The distinct values for the Glofas data (optional).
- Returns:
The file path of the downloaded Glofas data.
- class APIs.GloFasAPI.GloFasAPINotebookInterface(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
GloFasAPI
- create_glofas_dropdown(dropdown_options, description, default_value)[source]
Creates a dropdown widget for the GLOFAS application.
- Parameters:
dropdown_options – A list of options for the dropdown.
description – The description label for the dropdown.
default_value – The default value for the dropdown.
- Returns:
A Dropdown widget for the GLOFAS application.
- create_widgets_for_glofas(glofas_option: str)[source]
Create widgets specific to GloFas Data Type 2
- Parameters:
glofas_option – The selected GloFas option
- Returns:
A list of widgets specific to the selected GloFas option
- gather_parameters(glofas_product: str)[source]
- Parameters:
glofas_product – The type of GloFAS product.
- Returns:
A dictionary containing the parameters required for the given GloFAS product.
The get_glofas_parameters method takes in the glofas_product parameter to determine the type of GloFAS product. It then collects the necessary parameters based on the type of product * and returns them in a dictionary.
Note: The returned dictionary may vary depending on the value of glofas_product.
Example usages: ``` parameters = get_glofas_parameters(‘cems-glofas-seasonal’) # Returns: # { # ‘system_version’: system_version, # ‘hydrological_model’: hydrological_model, # ‘leadtime_hour’: leadtime_hour, # ‘year’: year, # ‘month’: month, # ‘day’: day, #
- get_available_dates(glofas_option)[source]
Generate a list of available dates based on the selected GloFas option.
- on_glofas_option_change(change)[source]
Updates the glofas_stack based on the new value received in the change parameter.
- Parameters:
change – A dictionary containing the new value of the glofas option.
- Returns:
None
- on_single_or_date_range_change(change, glofas_option: str)[source]
Handles the change event when the option for single date or date range is changed.
- Parameters:
change – A dictionary containing information about the change event.
glofas_option – The selected Glofas option.
- Returns:
None
- process_api(geometry, distinct_values, index, bbox, params, pbar=None)[source]
Process the GLOFAS API data.
- update_date_dropdown(glofas_option)[source]
Update the date dropdown with available dates based on the selected GloFas option.
APIs.ModisNRT module
- class APIs.ModisNRT.ModisNRT(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
object
- Class:
ModisNRT
This class provides functions to interact with the MODIS NRT (Near Real-Time) data.
- Initialization Parameters:
None
- modis_tile_size
MODIS sinusoidal tile size in meters.
- Type:
float
- modis_download_token
Token for MODIS NRT download.
- Type:
str
- modis_nrt_api_root_url
Root URL for MODIS NRT API.
- Type:
str
- headers
Headers for API requests.
- Type:
dict
- nrt_band_options
Dictionary mapping MODIS band names to their index values.
- Type:
dict
- calculate_modis_tile_index(x, y)[source]
Calculate MODIS tile indices for given sinusoidal coordinates.
- get_modis_nrt_file_list(tiles, modis_nrt_params)[source]
Get a list of MODIS NRT files for the given tiles.
- process_hdf_file(hdf_file, subdataset_index, tif_list=None)[source]
Process an HDF file and convert it to a GeoTIFF.
- calculate_modis_tile_index(x: float, y: float) tuple[int, int] [source]
Calculate the MODIS tile index for the given coordinates.
- Parameters:
x – The X-coordinate of the location.
y – The Y-coordinate of the location.
- Returns:
A tuple containing the horizontal and vertical indices of the MODIS tile.
- calculate_population_in_flood_area(raster_path: str, year: int, population_data_type: str, population_data_source: str, folder_output: str) str [source]
- cleanup_files(tif_list: List[str], hdf_files_to_process: List[str], modis_nrt_params: Dict[str, Any]) None [source]
Removes files from the given lists if keep_individual_tiles parameter is False.
- Parameters:
tif_list – A list of TIFF file paths.
hdf_files_to_process – A list of HDF file paths.
modis_nrt_params – A dictionary of MODIS NRT parameters. - ‘keep_individual_tiles’: A boolean indicating whether to keep individual tiles or not.
- Returns:
None
- convert_to_date(date_string: str) datetime [source]
Converts a date string to a datetime object.
- Parameters:
date_string – The date string in the format “YYYYDDD”, where YYYY is the year and DDD is the day of the year.
- Returns:
The converted datetime object representing the given date.
Example
>>> convert_to_date("2020121") datetime.datetime(2020, 5, 1)
- date_type_options = ['Single Date', 'Date Range', 'All Available Images']
- download_and_process_files(matching_files: List[str], modis_nrt_params: Dict[str, Any])[source]
Download and process the given files.
- Parameters:
matching_files (List[str]) – List of files to be downloaded and processed.
modis_nrt_params (Dict[str, Any]) – Dictionary containing modis nrt parameters.
- Returns:
Tuple containing lists of hdf files to process and tif files.
- Return type:
Tuple[List[str], List[str]]
- download_and_process_modis_nrt(url: str, folder_path: str, hdf_files_to_process: List[str], subdataset: str, tif_list: List[str] | None = None) None [source]
- find_matching_files(tiles: List[Any], modis_nrt_params: Dict[str, Any]) List[str] [source]
Find matching files based on the given tiles and MODIS NRT parameters.
- Parameters:
tiles (List[Any]) – A list of tiles.
modis_nrt_params (Dict[str, Any]) – A dictionary of MODIS NRT parameters.
- Returns:
A list of matching file names.
- Return type:
List[str]
- get_modis_nrt_file_list(tiles: List[Tuple[int, int]], modis_nrt_params: Dict[str, datetime]) List[str] [source]
- Parameters:
tiles – List of tuples representing the tiles (integer values for h and v)
modis_nrt_params – Dictionary containing the necessary parameters for Modis NRT (date)
- Returns:
List of matching file URLs
This method takes in a list of tiles and Modis NRT parameters and returns a list of file URLs that match the specified criteria. It loops through each tile, constructs the base URL folder *, and generates a file pattern based on the year, day of year, and tile coordinates. It then sends a request to the base URL folder and parses the HTML content using BeautifulSoup. * It finds all the links in the HTML content and checks if they match the file pattern. If a link matches the pattern, it is added to the list of matching files. Finally, the method * prints a message and returns the list of matching file URLs.
- get_modis_tile(geometry: shapely.geometry.Point | list | pandas.DataFrame) Set[tuple[int, int]] [source]
- get_tiles(bbox: Any) List[Any] [source]
Get the tiles for the given bounding box.
- Parameters:
bbox (Any) – The bounding box.
- Returns:
The list of tiles.
- Return type:
List[Any]
- merge_files(tif_list: List[str], folder: str) str [source]
Merge the given list of TIFF files into a single merged file.
- Parameters:
tif_list – List of paths to TIFF files to be merged.
folder – Folder where the merged file will be saved.
- Returns:
Path to the merged TIFF file.
- Example Usage:
tif_list = [‘file1.tif’, ‘file2.tif’, ‘file3.tif’] folder = ‘/path/to/folder’ merged_file = merge_files(tif_list, folder)
- merge_tifs(tif_list: List[str], output_tif: str) None [source]
Merge a list of GeoTIFF files into a single GeoTIFF.
- Parameters:
tif_list – A list of GeoTIFF files to merge.
output_tif – The path to the output GeoTIFF file.
- Returns:
None
- modis_nrt_api_root_url = 'https://nrt3.modaps.eosdis.nasa.gov/api/v2/content/archives/allData/61/MCDWD_L3_NRT'
- modis_proj = '+proj=sinu +R=6371007.181 +nadgrids=@null +wktext'
- modis_tile_size = 1111950.5196666666
- nrt_band_options = {'Flood 1-Day 250m Grid_Water_Composite': 4, 'Flood 1-Day CS 250m Grid_Water_Composite': 5, 'Flood 2-Day 250m Grid_Water_Composite': 8, 'Flood 3-Day 250m Grid_Water_Composite': 11, 'Valid Counts 1-Day 250m Grid_Water_Composite': 2, 'Valid Counts 2-Day 250m Grid_Water_Composite': 7, 'Valid Counts 3-Day 250m Grid_Water_Composite': 10, 'Valid Counts CS 1-Day 250m Grid_Water_Composite': 3, 'Water Counts 1-Day 250m Grid_Water_Composite': 0, 'Water Counts 2-Day 250m Grid_Water_Composite': 6, 'Water Counts 3-Day 250m Grid_Water_Composite': 9, 'Water Counts CS 1-Day 250m Grid_Water_Composite': 1}
- population_source_options = ['WorldPop', 'GPWv4']
- population_source_variables = ['Residential Population', 'Age and Sex Structures']
- population_source_year_options = [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020]
- process_hdf_file(hdf_file: str, subdataset_index: int, tif_list: List[str] | None = None) None [source]
Process HDF file and convert the selected subdataset to GeoTIFF format.
- Parameters:
hdf_file – Path to the HDF file.
subdataset_index – Index of the subdataset to be converted.
tif_list – Optional list to store the paths of the converted GeoTIFF files.
- Returns:
None
- shapely_to_ee(geometry: shapely.geometry.base.BaseGeometry, crs: str = 'EPSG:4326') ee.Geometry [source]
- Parameters:
geometry (shapely.geometry.base.BaseGeometry) – The Shapely geometry object to be converted to Earth Engine Geometry.
crs (str) – The Coordinate Reference System (CRS) of the input geometry. Defaults to ‘EPSG:4326’.
- Returns:
The Earth Engine Geometry object created from the input Shapely geometry.
- Return type:
ee.Geometry
- class APIs.ModisNRT.ModisNRTNotebookInterface(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
ModisNRT
- create_widgets_for_modis_nrt() List[ipywidgets.Widget] [source]
Create widgets for MODIS NRT.
- Returns:
A list of widgets.
- gather_parameters() Dict[str, Any] [source]
- Returns:
A dictionary containing the parameters for the method.
The dictionary will have the following keys and values: - If single_or_date_range_modis_nrt is set to ‘Single Date’:
‘date’: The selected date from date_picker_modis_nrt
‘multi_date’: False
‘folder_path’: The selected folder path from filechooser
‘create_sub_folder’: The value of create_sub_folder
‘clip_to_geometry’: The value of clip_to_geometry
‘keep_individual_tiles’: The value of keep_individual_tiles
‘add_image_to_map’: The value of add_image_to_map
‘calculate_population’: The value of calculate_population
‘nrt_band’: The value of modis_nrt_band_selection
‘population_year’: The value of population_source_year
‘population_type’: The value of population_source_variable
‘population_data_type’: The value of population_source
- If single_or_date_range_modis_nrt is set to ‘Date Range’:
‘start_date’: The selected start date from date_picker_modis_nrt
‘end_date’: The selected end date from date_picker_modis_nrt
‘multi_date’: True
‘folder_path’: The selected folder path from filechooser
‘create_sub_folder’: The value of create_sub_folder
‘clip_to_geometry’: The value of clip_to_geometry
‘keep_individual_tiles’: The value of keep_individual_tiles
‘add_image_to_map’: The value of add_image_to_map
‘calculate_population’: The value of calculate_population
‘nrt_band’: The value of modis_nrt_band_selection
‘population_year’: The value of population_source_year
‘population_type’: The value of population_source_variable
‘population_data_type’: The value of population_source
If single_or_date_range_modis_nrt is neither ‘Single Date’ nor ‘Date Range’, returns None.
- get_modis_nrt_dates() List[date] [source]
Retrieves the MODIS NRT dates from the NASA API.
- Returns:
A list of datetime.date objects representing the MODIS NRT dates.
- on_population_source_change(change)[source]
- Parameters:
change – dictionary containing the new value of the population source
- Returns:
None
- on_single_or_date_range_change_modis_nrt(change: Dict[str, Any]) Any [source]
Handle the change event for the single or date range dropdown in the MODIS NRT widget.
- Parameters:
change (dict) – The change event.
- Returns:
The value of the single or date range dropdown.
- Return type:
any
- process_api(geometry: Any, distinct_values: Any, index: int, bbox, params=None, pbar=None) None [source]
Process API method to perform specific operations.
- Parameters:
geometry – The geometry for the operation.
distinct_values – The distinct values for the operation.
index – The index value for the operation.
bbox – The bounding box for the operation.
params – The optional parameters for the operation.
- Returns:
The path of the processed file.
APIs.WorldPop module
- class APIs.WorldPop.WorldPop(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
object
Class for processing WorldPop data.
- Parameters:
ee_manager (Optional[EarthEngineManager]) – An instance of EarthEngineManager (optional).
- data_type_options
List of valid data type options.
- Type:
list[str]
- year_options
List of valid year options.
- Type:
list[str]
- data_type_options = ['Residential Population', 'Age and Sex Structures']
- download_and_process_image(image: ee.Image, geometry: Any, scale: Any, params: Dict[str, Any], band: str) None [source]
Downloads and processes the given image.
- Parameters:
image – The Earth Engine image to be downloaded and processed.
geometry – The geometry to filter the image by.
scale – The scale of the image.
params – Additional parameters for the download and processing.
band – The specific band to be processed.
- Returns:
None
- get_image_dates() List[datetime] [source]
- Returns:
A list of datetime objects representing the dates of the images in the image collection.
- Return type:
List[datetime.datetime]
- process_age_and_sex_structures(geometry, params)[source]
Method to process age and sex structures for a given geometry.
- Parameters:
geometry – The geometry of interest.
params – A dictionary of parameters. - ‘statistics_only’: If True, calculate statistics only. If False, download and process image.
- Returns:
A dictionary containing the processed age and sex statistics. If ‘statistics_only’ is True, the dictionary will contain statistics for each band. If ‘statistics_only’ is False, the method returns None.
- process_api(geometry: Any, distinct_values: Any, index: Any, params: Dict[str, Any] | None = None, bbox=None, pbar=None) Any [source]
Process API method.
- Parameters:
geometry – The geometry to process.
distinct_values – The distinct values to process.
index – The index to process.
params – Additional parameters for processing (optional).
bbox – The bounding box for processing (optional).
- Returns:
The processed result.
- process_residential_population(geometry: Any, params: Dict[str, Any]) Any [source]
- Parameters:
geometry – The geometry representing the area of interest.
params – A dictionary containing parameters for processing the residential population. - “statistics_only”: A boolean indicating whether to only compute statistics or also download and process the image. - “year”: A string representing the year to filter the image collection.
- Returns:
If “statistics_only” is True, returns a dictionary containing statistics of the residential population. Otherwise, returns the processed image.
- validate_parameters(params: Dict[str, Any]) bool [source]
Validate the parameters passed to the method.
- Parameters:
params (dict[str, any]) – The parameters dictionary to validate.
- Returns:
True if all the parameters are valid, False otherwise.
- Return type:
bool
- year_options = ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020']
- class APIs.WorldPop.WorldPopNotebookInterface(ee_manager: mcimageprocessing.programmatic.APIs.EarthEngine.EarthEngineManager | None = None)[source]
Bases:
WorldPop
WorldPopNotebookInterface
is a subclass ofWorldPop
class and provides an interface for interacting with the WorldPop API in a Jupyter Notebook environment.Attributes:
ee_manager (
EarthEngineManager
, optional): An instance of the EarthEngineManager class. Defaults to None.
Methods:
- __init__(ee_manager: Optional[
EarthEngineManager
] = None) Initializes the WorldPopNotebookInterface class.
- create_widgets_for_worldpop() -> List[
Widget
] Creates and returns a list of widgets for configuring the WorldPop parameters.
- gather_parameters(**kwargs) -> Dict[str, Any]
Gathers user-selected parameters and returns them as a dictionary.
- process_api(geometry: Any, distinct_values: Any, index: int, params=None, bbox=None) -> None
Processes the WorldPop API with the provided parameters.
- create_widgets_for_worldpop() List[ipywidgets.Widget] [source]
Create and initialize widgets for configuring WorldPop data parameters.
- Returns:
A list of widget objects.
- gather_parameters(**kwargs) Dict[str, Any] [source]
- Parameters:
kwargs – Additional keyword arguments. No other parameters are required.
- Returns:
A dictionary containing the gathered parameters.
- process_api(geometry: Any, distinct_values: Any, index: int, params=None, bbox=None, pbar=None) None [source]
Process API.
- Parameters:
geometry – The geometry parameter.
distinct_values – The distinct_values parameter.
index – The index parameter.
params – The params parameter.
bbox – The bbox parameter.
- Returns:
None.