From 73a77c3876b00f1c890aac2a800a81db5df3418a Mon Sep 17 00:00:00 2001 From: Kenn Cartier Date: Mon, 4 Nov 2024 17:24:22 -0800 Subject: [PATCH 1/5] Edited link for ERA5 setup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56ae15e..4af03c1 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ To run the module, 1. You need access to Google Earth Engine 2. Install - 3. If you want to use the ERA5 layer, you need to install the [Climate Data Store (CDS) Application Program Interface (API)](https://cds.climate.copernicus.eu/api-how-to) + 3. If you want to use the ERA5 layer, you need to install the [Climate Data Store (CDS) Application Program Interface (API)](https://cds.climate.copernicus.eu/how-to-api) ### Interactive development From 193d85418e1797168a2d5e221e97ab8602ca3a76 Mon Sep 17 00:00:00 2001 From: Kenn Cartier Date: Wed, 18 Dec 2024 22:20:19 -0800 Subject: [PATCH 2/5] partial undo of last PR --- city_metrix/layers/layer.py | 3 ++- city_metrix/layers/nasa_dem.py | 26 ++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/city_metrix/layers/layer.py b/city_metrix/layers/layer.py index 3d2829f..91e6316 100644 --- a/city_metrix/layers/layer.py +++ b/city_metrix/layers/layer.py @@ -2,6 +2,7 @@ from abc import abstractmethod from typing import Union, Tuple from uuid import uuid4 +from osgeo import gdal import ee import boto3 @@ -393,4 +394,4 @@ def offset_meters_to_geographic_degrees(decimal_latitude, length_m): lon_degree_offset = abs((length_m / (earth_radius_m * math.cos(math.pi*decimal_latitude/180))) * rad) lat_degree_offset = abs((length_m / earth_radius_m) * rad) - return lon_degree_offset, lat_degree_offset + return lon_degree_offset, lat_degree_offset \ No newline at end of file diff --git a/city_metrix/layers/nasa_dem.py b/city_metrix/layers/nasa_dem.py index d3840d3..d937129 100644 --- a/city_metrix/layers/nasa_dem.py +++ b/city_metrix/layers/nasa_dem.py @@ -1,4 +1,6 @@ import ee +import xee +import xarray as xr from .layer import Layer, get_image_collection @@ -14,20 +16,12 @@ def __init__(self, spatial_resolution=30, **kwargs): self.spatial_resolution = spatial_resolution def get_data(self, bbox): - nasa_dem = ee.Image("NASA/NASADEM_HGT/001") + dataset = ee.Image("NASA/NASADEM_HGT/001") + nasa_dem = ee.ImageCollection(ee.ImageCollection(dataset) + .filterBounds(ee.Geometry.BBox(*bbox)) + .select('elevation') + .mean() + ) + data = get_image_collection(nasa_dem, bbox, self.spatial_resolution, "NASA DEM").elevation - nasa_dem_elev = (ee.ImageCollection(nasa_dem) - .filterBounds(ee.Geometry.BBox(*bbox)) - .select('elevation') - .mean() - ) - - nasa_dem_elev_ic = ee.ImageCollection(nasa_dem_elev) - data = get_image_collection( - nasa_dem_elev_ic, - bbox, - self.spatial_resolution, - "NASA DEM" - ).elevation - - return data + return data \ No newline at end of file From 86cda0c1c7009e7fda2ae36e811aa4c3bd6983bf Mon Sep 17 00:00:00 2001 From: Kenn Cartier Date: Wed, 18 Dec 2024 23:04:54 -0800 Subject: [PATCH 3/5] further testing processing error --- city_metrix/layers/nasa_dem.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/city_metrix/layers/nasa_dem.py b/city_metrix/layers/nasa_dem.py index d937129..72623a9 100644 --- a/city_metrix/layers/nasa_dem.py +++ b/city_metrix/layers/nasa_dem.py @@ -1,6 +1,4 @@ import ee -import xee -import xarray as xr from .layer import Layer, get_image_collection @@ -16,12 +14,20 @@ def __init__(self, spatial_resolution=30, **kwargs): self.spatial_resolution = spatial_resolution def get_data(self, bbox): - dataset = ee.Image("NASA/NASADEM_HGT/001") - nasa_dem = ee.ImageCollection(ee.ImageCollection(dataset) - .filterBounds(ee.Geometry.BBox(*bbox)) - .select('elevation') - .mean() - ) - data = get_image_collection(nasa_dem, bbox, self.spatial_resolution, "NASA DEM").elevation - - return data \ No newline at end of file + nasa_dem = ee.Image("NASA/NASADEM_HGT/001") + + nasa_dem_elev = (ee.ImageCollection(nasa_dem) + .filterBounds(ee.Geometry.BBox(*bbox)) + .select('elevation') + .mean() + ) + + nasa_dem_elev_ic = ee.ImageCollection(nasa_dem_elev) + data = get_image_collection( + nasa_dem_elev_ic, + bbox, + self.spatial_resolution, + "NASA DEM" + ).elevation + + return data From 21b3d15ce2f1bc71f67050bfd743babe5acbba5a Mon Sep 17 00:00:00 2001 From: Kenn Cartier Date: Wed, 18 Dec 2024 23:38:45 -0800 Subject: [PATCH 4/5] re-added imports --- city_metrix/layers/albedo.py | 5 ++++- city_metrix/layers/alos_dsm.py | 3 +++ city_metrix/layers/average_net_building_height.py | 5 ++++- city_metrix/layers/built_up_height.py | 5 ++++- city_metrix/layers/esa_world_cover.py | 6 ++++-- city_metrix/layers/glad_lulc.py | 2 +- city_metrix/layers/high_land_surface_temperature.py | 8 ++++---- city_metrix/layers/impervious_surface.py | 5 ++++- city_metrix/layers/land_surface_temperature.py | 6 ++++-- city_metrix/layers/layer.py | 1 + city_metrix/layers/nasa_dem.py | 2 ++ city_metrix/layers/natural_areas.py | 1 + city_metrix/layers/smart_surface_lulc.py | 2 ++ city_metrix/layers/tree_canopy_height.py | 4 ++++ city_metrix/layers/tree_cover.py | 4 ++++ city_metrix/layers/urban_land_use.py | 3 +++ city_metrix/layers/world_pop.py | 3 +++ 17 files changed, 52 insertions(+), 13 deletions(-) diff --git a/city_metrix/layers/albedo.py b/city_metrix/layers/albedo.py index dc1780a..ea7ae6e 100644 --- a/city_metrix/layers/albedo.py +++ b/city_metrix/layers/albedo.py @@ -1,6 +1,9 @@ import ee +import xarray +from dask.diagnostics import ProgressBar + +from .layer import Layer, get_utm_zone_epsg, get_image_collection -from .layer import Layer, get_image_collection class Albedo(Layer): """ diff --git a/city_metrix/layers/alos_dsm.py b/city_metrix/layers/alos_dsm.py index c22df82..0fc470b 100644 --- a/city_metrix/layers/alos_dsm.py +++ b/city_metrix/layers/alos_dsm.py @@ -1,4 +1,7 @@ import ee +import xee +import xarray as xr + from .layer import Layer, get_image_collection diff --git a/city_metrix/layers/average_net_building_height.py b/city_metrix/layers/average_net_building_height.py index 11799cc..2e26018 100644 --- a/city_metrix/layers/average_net_building_height.py +++ b/city_metrix/layers/average_net_building_height.py @@ -1,6 +1,9 @@ +from dask.diagnostics import ProgressBar +import xarray as xr +import xee import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_utm_zone_epsg, get_image_collection class AverageNetBuildingHeight(Layer): diff --git a/city_metrix/layers/built_up_height.py b/city_metrix/layers/built_up_height.py index aef268e..b04399d 100644 --- a/city_metrix/layers/built_up_height.py +++ b/city_metrix/layers/built_up_height.py @@ -1,6 +1,9 @@ +from dask.diagnostics import ProgressBar +import xarray as xr +import xee import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_utm_zone_epsg, get_image_collection class BuiltUpHeight(Layer): diff --git a/city_metrix/layers/esa_world_cover.py b/city_metrix/layers/esa_world_cover.py index c214781..7e20c31 100644 --- a/city_metrix/layers/esa_world_cover.py +++ b/city_metrix/layers/esa_world_cover.py @@ -1,7 +1,9 @@ +from dask.diagnostics import ProgressBar +from enum import Enum +import xarray as xr import ee -from enum import Enum -from .layer import Layer, get_image_collection +from .layer import Layer, get_utm_zone_epsg, get_image_collection class EsaWorldCoverClass(Enum): diff --git a/city_metrix/layers/glad_lulc.py b/city_metrix/layers/glad_lulc.py index 11afe31..da29076 100644 --- a/city_metrix/layers/glad_lulc.py +++ b/city_metrix/layers/glad_lulc.py @@ -1,7 +1,7 @@ import xarray as xr import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_utm_zone_epsg, get_image_collection class LandCoverGlad(Layer): diff --git a/city_metrix/layers/high_land_surface_temperature.py b/city_metrix/layers/high_land_surface_temperature.py index 9cbf5ea..670db62 100644 --- a/city_metrix/layers/high_land_surface_temperature.py +++ b/city_metrix/layers/high_land_surface_temperature.py @@ -1,9 +1,9 @@ -import datetime -import ee - -from shapely.geometry import box +from .landsat_collection_2 import LandsatCollection2 from .land_surface_temperature import LandSurfaceTemperature from .layer import Layer +from shapely.geometry import box +import datetime +import ee class HighLandSurfaceTemperature(Layer): """ diff --git a/city_metrix/layers/impervious_surface.py b/city_metrix/layers/impervious_surface.py index 9cf017d..da45159 100644 --- a/city_metrix/layers/impervious_surface.py +++ b/city_metrix/layers/impervious_surface.py @@ -1,6 +1,9 @@ +from dask.diagnostics import ProgressBar +import xarray as xr +import xee import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_utm_zone_epsg, get_image_collection class ImperviousSurface(Layer): diff --git a/city_metrix/layers/land_surface_temperature.py b/city_metrix/layers/land_surface_temperature.py index 93888ce..48a66e6 100644 --- a/city_metrix/layers/land_surface_temperature.py +++ b/city_metrix/layers/land_surface_temperature.py @@ -1,6 +1,8 @@ +from .landsat_collection_2 import LandsatCollection2 +from .layer import Layer, get_utm_zone_epsg, get_image_collection +from dask.diagnostics import ProgressBar import ee - -from .layer import Layer, get_image_collection +import xarray class LandSurfaceTemperature(Layer): """ diff --git a/city_metrix/layers/layer.py b/city_metrix/layers/layer.py index 91e6316..211ecac 100644 --- a/city_metrix/layers/layer.py +++ b/city_metrix/layers/layer.py @@ -2,6 +2,7 @@ from abc import abstractmethod from typing import Union, Tuple from uuid import uuid4 +# This osgeo import is essential for proper functioning. Do not remove. from osgeo import gdal import ee diff --git a/city_metrix/layers/nasa_dem.py b/city_metrix/layers/nasa_dem.py index 72623a9..4f08d4e 100644 --- a/city_metrix/layers/nasa_dem.py +++ b/city_metrix/layers/nasa_dem.py @@ -1,4 +1,6 @@ import ee +import xee +import xarray as xr from .layer import Layer, get_image_collection diff --git a/city_metrix/layers/natural_areas.py b/city_metrix/layers/natural_areas.py index fdf499b..092a30c 100644 --- a/city_metrix/layers/natural_areas.py +++ b/city_metrix/layers/natural_areas.py @@ -1,3 +1,4 @@ +import xarray as xr from xrspatial.classify import reclassify from .layer import Layer diff --git a/city_metrix/layers/smart_surface_lulc.py b/city_metrix/layers/smart_surface_lulc.py index 2e0f083..c8e0582 100644 --- a/city_metrix/layers/smart_surface_lulc.py +++ b/city_metrix/layers/smart_surface_lulc.py @@ -1,7 +1,9 @@ import xarray as xr import numpy as np import pandas as pd +import geopandas as gpd from shapely.geometry import CAP_STYLE, JOIN_STYLE +from shapely.geometry import box from exactextract import exact_extract from geocube.api.core import make_geocube import warnings diff --git a/city_metrix/layers/tree_canopy_height.py b/city_metrix/layers/tree_canopy_height.py index f499552..2acca4a 100644 --- a/city_metrix/layers/tree_canopy_height.py +++ b/city_metrix/layers/tree_canopy_height.py @@ -1,3 +1,7 @@ +from .layer import Layer, get_utm_zone_epsg, get_image_collection +from dask.diagnostics import ProgressBar +import xarray as xr +import xee import ee from .layer import Layer, get_image_collection diff --git a/city_metrix/layers/tree_cover.py b/city_metrix/layers/tree_cover.py index 52fc8d6..1b58cf3 100644 --- a/city_metrix/layers/tree_cover.py +++ b/city_metrix/layers/tree_cover.py @@ -1,3 +1,7 @@ +from .layer import Layer, get_utm_zone_epsg, get_image_collection +from dask.diagnostics import ProgressBar +import xarray as xr +import xee import ee from .layer import Layer, get_image_collection diff --git a/city_metrix/layers/urban_land_use.py b/city_metrix/layers/urban_land_use.py index 02c737c..708ba32 100644 --- a/city_metrix/layers/urban_land_use.py +++ b/city_metrix/layers/urban_land_use.py @@ -1,3 +1,6 @@ +from dask.diagnostics import ProgressBar +import xarray as xr +import xee import ee from .layer import Layer, get_image_collection diff --git a/city_metrix/layers/world_pop.py b/city_metrix/layers/world_pop.py index 700010a..b177ab1 100644 --- a/city_metrix/layers/world_pop.py +++ b/city_metrix/layers/world_pop.py @@ -1,3 +1,6 @@ +from dask.diagnostics import ProgressBar +import xarray as xr +import xee import ee from .layer import Layer, get_image_collection From eabbbe741367e024da3d03f43ef29804e708e38e Mon Sep 17 00:00:00 2001 From: Kenn Cartier Date: Thu, 19 Dec 2024 10:54:59 -0800 Subject: [PATCH 5/5] additional changes to imports to restore to prior state --- city_metrix/layers/tree_canopy_height.py | 3 +-- city_metrix/layers/tree_cover.py | 2 +- city_metrix/layers/urban_land_use.py | 2 +- city_metrix/layers/world_pop.py | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/city_metrix/layers/tree_canopy_height.py b/city_metrix/layers/tree_canopy_height.py index 2acca4a..9dbeb52 100644 --- a/city_metrix/layers/tree_canopy_height.py +++ b/city_metrix/layers/tree_canopy_height.py @@ -1,11 +1,10 @@ from .layer import Layer, get_utm_zone_epsg, get_image_collection + from dask.diagnostics import ProgressBar import xarray as xr import xee import ee -from .layer import Layer, get_image_collection - class TreeCanopyHeight(Layer): """ Attributes: diff --git a/city_metrix/layers/tree_cover.py b/city_metrix/layers/tree_cover.py index 1b58cf3..4c1a16e 100644 --- a/city_metrix/layers/tree_cover.py +++ b/city_metrix/layers/tree_cover.py @@ -1,10 +1,10 @@ from .layer import Layer, get_utm_zone_epsg, get_image_collection + from dask.diagnostics import ProgressBar import xarray as xr import xee import ee -from .layer import Layer, get_image_collection class TreeCover(Layer): """ diff --git a/city_metrix/layers/urban_land_use.py b/city_metrix/layers/urban_land_use.py index 708ba32..1c81d39 100644 --- a/city_metrix/layers/urban_land_use.py +++ b/city_metrix/layers/urban_land_use.py @@ -3,7 +3,7 @@ import xee import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_utm_zone_epsg, get_image_collection class UrbanLandUse(Layer): diff --git a/city_metrix/layers/world_pop.py b/city_metrix/layers/world_pop.py index b177ab1..88a5ad0 100644 --- a/city_metrix/layers/world_pop.py +++ b/city_metrix/layers/world_pop.py @@ -3,7 +3,7 @@ import xee import ee -from .layer import Layer, get_image_collection +from .layer import Layer, get_utm_zone_epsg, get_image_collection class WorldPop(Layer):