Skip to content

Commit

Permalink
fix: drop some of ee_extra dependencies (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Dec 26, 2024
2 parents 059b173 + 6ead701 commit 8743cf1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
50 changes: 30 additions & 20 deletions geetools/ee_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ def toGrid(
) -> ee.FeatureCollection:
"""Convert an image to a grid of polygons.
Based on the size given by the user, the tool will build a grid of size*pixelSize x size * pixelSize cells. Each cell will be a polygon. Note that for images that have multiple scale depending on the band, we will use the first one or the one stated in the parameters.
Based on the size given by the user, the tool will build a grid of size*pixelSize x size * pixelSize cells.
Each cell will be a polygon. Note that for images that have multiple scale depending on the band,
we will use the first one or the one stated in the parameters.
Parameters:
size: The size of the grid. It will be size * pixelSize x size * pixelSize cells.
Expand All @@ -320,7 +322,8 @@ def toGrid(
The grid as a FeatureCollection.
Note:
The method has a known bug when the projection of the image is different than 3857. As we use a buffer, the grid cells can slightly overlap. Feel free to open a Issue and contribute if you feel it needs improvements.
The method has a known bug when the projection of the image is different than 3857. As we use a buffer,
the grid cells can slightly overlap. Feel free to open a Issue and contribute if you feel it needs improvements.
Examples:
.. code-block:: python
Expand Down Expand Up @@ -828,7 +831,10 @@ def index_list(cls) -> dict:
print(ind["formula"])
print(ind["reference"])
"""
return ee_extra.Spectral.core.indices()
url = "https://raw.githubusercontent.com/awesome-spectral-indices/awesome-spectral-indices/main/output/spectral-indices-dict.json"
response = requests.get(url)
response.raise_for_status()
return response.json()["SpectralIndices"]

def spectralIndices(
self,
Expand Down Expand Up @@ -998,14 +1004,14 @@ def getSTAC(self) -> dict:
STAC of the image.
Examples:
.. code-block:: python
.. jupyter-execute::
import ee
import geetools
import ee, geetools
from geetools.utils import initialize_documentation
ee.Initialize()
initialize_documentation()
ee.ImageCollection('COPERNICUS/S2_SR').first().getSTAC()
ee.ImageCollection('COPERNICUS/S2_SR').first().geetools.getSTAC()
"""
# extract the Asset id from the imagecollection
assetId = self._obj.get("system:id").getInfo()
Expand Down Expand Up @@ -1034,16 +1040,18 @@ def getDOI(self) -> str:
DOI of the ee.Image dataset.
Examples:
.. code-block:: python
.. jupyter-execute::
import ee
import geetools
import ee, geetools
from geetools.utils import initialize_documentation
ee.Initialize()
initialize_documentation()
ee.ImageCollection('NASA/GPM_L3/IMERG_V06').first().getDOI()
ee.ImageCollection('NASA/GPM_L3/IMERG_V06').first().geetools.getDOI()
"""
return ee_extra.STAC.core.getDOI(self._obj)
stac = self.getSTAC()
error_msg = "DOI not found in the STAC"
return stac["sci:doi"] if "sci:doi" in stac else error_msg

def getCitation(self) -> str:
"""Gets the citation of the image, if available.
Expand All @@ -1052,16 +1060,18 @@ def getCitation(self) -> str:
Citation of the ee.Image dataset.
Examples:
.. code-block:: python
.. jupyter-execute::
import ee
import geetools
import ee, geetools
from geetools.utils import initialize_documentation
ee.Initialize()
initialize_documentation()
ee.ImageCollection('NASA/GPM_L3/IMERG_V06').first().getCitation()
ee.ImageCollection('NASA/GPM_L3/IMERG_V06').first().geetools.getCitation()
"""
return ee_extra.STAC.core.getCitation(self._obj)
stac = self.getSTAC()
error_msg = "Citation not found in the STAC"
return stac["sci:citation"] if "sci:citation" in stac else error_msg

def panSharpen(self, method: str = "SFIM", qa: str = "", **kwargs) -> ee.Image:
"""Apply panchromatic sharpening to the Image.
Expand Down
2 changes: 1 addition & 1 deletion geetools/ee_image_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def preprocess(self, **kwargs) -> ee.ImageCollection:
return ee_extra.QA.pipelines.preprocess(self._obj, **kwargs)

def getSTAC(self) -> dict:
"""Gets the STAC of the image.
"""Gets the STAC of the imageCollection.
Returns:
STAC of the image.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class TestIndicexList:
def test_indices(self):
indices = ee.Image.geetools.index_list()
assert "NDVI" in indices.keys()
assert len(indices) == 228
assert len(indices) == 247


class TestSpectralIndices:
Expand Down

0 comments on commit 8743cf1

Please sign in to comment.