-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cif 197 core resolution option for layer downloads #68
Merged
kcartier-wri
merged 37 commits into
main
from
CIF-197-CORE-Resolution-option-for-layer-downloads
Sep 6, 2024
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
6c66430
Moved scale_meters argument into class definition
kcartier-wri 1648974
Renamed class property in compliance with stac standard. Implemented …
kcartier-wri cbea6ea
Merge branch 'main' into CIF-197-CORE-Resolution-option-for-layer-dow…
kcartier-wri c33c58c
renamed function and trying to resolve GH Action failure.
kcartier-wri c476aa1
Exposing parameters to understand Action failure
kcartier-wri b532b25
Handle other coordinate units
kcartier-wri fecab97
Fixed error in location of test tools
kcartier-wri c820296
Changed estimate of spatial resolution
kcartier-wri ea8cf88
Changed object definition
kcartier-wri 08e3d8b
Restructured tests to have individual test per layer
kcartier-wri ca2e23d
tweaked estimation of resolution.
kcartier-wri 58b2eba
improved method for getting crs
kcartier-wri 0da202a
corrected error in distance calculation
kcartier-wri 134e50b
changed determination of crs
kcartier-wri 8f1cbbe
reduced to natural areas
kcartier-wri 4fdc35c
enabled all tests
kcartier-wri 9f569c9
changed determination of crs_units
kcartier-wri 2168ef8
changed computation of coordinates
kcartier-wri 336a5a5
changed handling of 'm' unit
kcartier-wri 9760557
changed determination of crs_unit
kcartier-wri ac80767
forced to fail
kcartier-wri e7956cd
try to identify wkt projection
kcartier-wri 0aefba2
trying to isolate projection issue
kcartier-wri 34759aa
more attempts to isolate projection issue
kcartier-wri 6aab4c2
another attempts to isolate projection issue
kcartier-wri 7b2bbe6
Identified projection error as xee version
kcartier-wri 409e706
Cleaned up code and updated requirements
kcartier-wri e4ced61
Merge branch 'main' into CIF-197-CORE-Resolution-option-for-layer-dow…
kcartier-wri 85b02f4
Squashing commits related to understanding GH Actions
kcartier-wri f2f5b94
Merge branch 'CIF-197-CORE-Resolution-option-for-layer-downloads' of …
kcartier-wri 8e88425
Cleaned up and expanded resolution testing
kcartier-wri 8ff3340
Added docstring
kcartier-wri efeed2e
Added test of downsized image values
kcartier-wri 809c39d
Added missing packages
kcartier-wri ee0d8d1
Added test documentation and switch to quadratic interpolation for im…
kcartier-wri f20cd15
Merge branch 'main' into CIF-197-CORE-Resolution-option-for-layer-dow…
kcartier-wri 0108d98
Synched with main
kcartier-wri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,20 @@ | |
|
||
from .layer import Layer, get_utm_zone_epsg, get_image_collection | ||
|
||
|
||
class Albedo(Layer): | ||
def __init__(self, start_date="2021-01-01", end_date="2022-01-01", threshold=None, **kwargs): | ||
""" | ||
Attributes: | ||
start_date: starting date for data retrieval | ||
end_date: ending date for data retrieval | ||
spatial_resolution: raster resolution in meters (see https://github.com/stac-extensions/raster) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you added |
||
threshold: threshold value for filtering the retrieval | ||
""" | ||
|
||
def __init__(self, start_date="2021-01-01", end_date="2022-01-01", spatial_resolution=10, threshold=None, **kwargs): | ||
super().__init__(**kwargs) | ||
self.start_date = start_date | ||
self.end_date = end_date | ||
self.spatial_resolution = spatial_resolution | ||
self.threshold = threshold | ||
|
||
def get_data(self, bbox): | ||
|
@@ -30,7 +38,7 @@ def mask_and_count_clouds(s2wc, geom): | |
nb_cloudy_pixels = is_cloud.reduceRegion( | ||
reducer=ee.Reducer.sum().unweighted(), | ||
geometry=geom, | ||
scale=10, | ||
scale=self.spatial_resolution, | ||
maxPixels=1e9 | ||
) | ||
return s2wc.updateMask(is_cloud.eq(0)).set('nb_cloudy_pixels', | ||
|
@@ -88,7 +96,9 @@ def calc_s2_albedo(image): | |
s2_albedo = dataset.map(calc_s2_albedo) | ||
albedo_mean = s2_albedo.reduce(ee.Reducer.mean()) | ||
|
||
data = get_image_collection(ee.ImageCollection(albedo_mean), bbox, 10, "albedo").albedo_mean | ||
data = (get_image_collection( | ||
ee.ImageCollection(albedo_mean), bbox, self.spatial_resolution, "albedo") | ||
.albedo_mean) | ||
|
||
if self.threshold is not None: | ||
return data.where(data < self.threshold) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,18 @@ | |
class NdviSentinel2(Layer): | ||
"""" | ||
NDVI = Sentinel-2 Normalized Difference Vegetation Index | ||
param: year: The satellite imaging year. | ||
Attributes: | ||
year: The satellite imaging year. | ||
spatial_resolution: raster resolution in meters (see https://github.com/stac-extensions/raster) | ||
return: a rioxarray-format DataArray | ||
Author of associated Jupyter notebook: [email protected] | ||
Notebook: https://github.com/wri/cities-cities4forests-indicators/blob/dev-eric/scripts/extract-VegetationCover.ipynb | ||
Reference: https://en.wikipedia.org/wiki/Normalized_difference_vegetation_index | ||
""" | ||
def __init__(self, year=None, **kwargs): | ||
def __init__(self, year=None, spatial_resolution=10, **kwargs): | ||
super().__init__(**kwargs) | ||
self.year = year | ||
self.spatial_resolution = spatial_resolution | ||
|
||
def get_data(self, bbox): | ||
if self.year is None: | ||
|
@@ -39,8 +42,7 @@ def calculate_ndvi(image): | |
ndvi_mosaic = ndvi.qualityMosaic('NDVI') | ||
|
||
ic = ee.ImageCollection(ndvi_mosaic) | ||
ndvi_data = get_image_collection(ic, bbox, 10, "NDVI") | ||
ndvi_data = (get_image_collection(ic, bbox, self.spatial_resolution, "NDVI") | ||
.NDVI) | ||
|
||
xdata = ndvi_data.to_dataarray() | ||
|
||
return xdata | ||
return ndvi_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we using
scikit-image
for?