Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
894 changes: 894 additions & 0 deletions cog_transformation/cms-global-map-mangrove-canopy.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

16,010 changes: 16,010 additions & 0 deletions generating_statistics_for_validation/cms-global-map-mangrove/detailed_stats.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"Stats for raw tif files."
{"agb": {"min_value": 0.2844882905483246, "max_value": 910.4758911132812, "mean_value": 130.23778814734214, "std_value": 108.86896375862148}, "hmax95": {"min_value": 0.8485000133514404, "max_value": 62.78900146484375, "mean_value": 16.388412236876732, "std_value": 11.19070852893252}, "hba95": {"min_value": 0.5376999974250793, "max_value": 39.789798736572266, "mean_value": 10.46833660312674, "std_value": 7.126195837381929}}
"Stats for transformed COG files."
{"agb": {"min_value": 0.2844882905483246, "max_value": 910.4758911132812, "mean_value": 130.23778814734214, "std_value": 108.86896375862148}, "hmax95": {"min_value": 0.8485000133514404, "max_value": 62.78900146484375, "mean_value": 16.388412236876732, "std_value": 11.19070852893252}, "hba95": {"min_value": 0.5376999974250793, "max_value": 39.789798736572266, "mean_value": 10.46833660312674, "std_value": 7.126195837381929}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,826 changes: 2,826 additions & 0 deletions user_data_notebooks/cms-global-map-mangrove_User_Notebook.ipynb

Large diffs are not rendered by default.

42 changes: 19 additions & 23 deletions user_data_notebooks/ghgc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def raster_stats(item, geojson,**kwargs):
"""
Returns Raster API statistics for an item. Inputs: item, geojson, url = Raster API url, asset = asset name within item. Outputs: dictionary containing statistics over the bounding box and item's datetime information.
"""

try:
url = item["assets"][kwargs["asset"]]["href"]
except TypeError as err:
Expand All @@ -19,53 +18,53 @@ def raster_stats(item, geojson,**kwargs):
print('KeyError in raster_stats: Make sure you include \'url\' and \'asset\' as keyword arguments!')
sys.exit()

# Build parameters dictionary
params = {"url": url}

# Add nodata parameter if provided
if "nodata" in kwargs:
params["nodata"] = kwargs["nodata"]

# A POST request is made to submit the data associated with the item of interest (specific observation) within the boundaries of the polygon to compute its statistics
result = requests.post(

# Raster API Endpoint for computing statistics
f"{kwargs['url']}/cog/statistics",

# Pass the URL to the item, asset name, and raster identifier as parameters
params={"url": url},
params=params,

# Send the GeoJSON object (polygon) along with the request
json=geojson,

# Return the response in JSON format
).json()


# Print the result
##print(result)
# print(result)

# Return a dictionary containing the computed statistics along with the item's datetime information.
try:
return {
**result["properties"],
"datetime": item["properties"]["start_datetime"],
"datetime": item["properties"].get("start_datetime", item["properties"].get("datetime")),
}
except KeyError as err:
try:
return {
**result["features"][0]["properties"],
'datetime': item["properties"]["start_datetime"],
'datetime': item["properties"].get("start_datetime", item["properties"].get("datetime")),
}
except TypeError as err:
return {
**result["features"][0]["properties"],
"datetime": item.properties["start_datetime"]
"datetime": item.properties.get("start_datetime", item.properties.get("datetime"))
}
except TypeError as err:
try:
return {
**result["properties"],
"datetime": item.properties["start_datetime"]
}
except KeyError:
return {
**result["properties"],
"datetime": item.properties["datetime"]
}
return {
**result["properties"],
"datetime": item.properties.get("start_datetime", item.properties.get("datetime"))
}

def clean_stats(stats_json) -> pd.DataFrame:
"""
Expand Down Expand Up @@ -93,12 +92,9 @@ def generate_stats(items,geojson,**kwargs):
print('Generating stats...')
for item in items:
try:
date = item["properties"]["start_datetime"] # Get the associated date
except TypeError:
try:
date = item.properties["start_datetime"]
except KeyError:
date = item.properties["datetime"]
date = item["properties"].get("start_datetime", item["properties"].get("datetime")) # Get the associated date
except (TypeError, AttributeError):
date = item.properties.get("start_datetime", item.properties.get("datetime"))
year_month = date[:10].replace('-', '') # Convert datetime to year-month
stats[year_month] = raster_stats(item, geojson,**kwargs)
df = clean_stats(stats)
Expand Down