Skip to content
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

Fix JS-PY conversion bugs #1890

Merged
merged 3 commits into from Jan 24, 2024
Merged

Fix JS-PY conversion bugs #1890

merged 3 commits into from Jan 24, 2024

Conversation

giswqs
Copy link
Member

@giswqs giswqs commented Jan 24, 2024

This PR fixes two bugs reported in #1887 and #1888 @spatialthoughts

JS example:

snippet = """
var geometry = ee.Geometry.Point([77.60412933051538, 12.952912912328241]);
var s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED');

var rgbVis = {'min': 0.0, 'max': 3000, 'bands': ['B4', 'B3', 'B2']};

var filtered = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30)) 
  .filter(ee.Filter.date('2019-01-01', '2020-01-01')) 
  .filter(ee.Filter.bounds(geometry));

var medianComposite = filtered.median();

Map.centerObject(geometry, 10);
Map.addLayer(medianComposite, rgbVis, 'Median Composite');
"""
lines = geemap.js_snippet_to_py(
    snippet, add_new_cell=False,
    import_ee=True, import_geemap=True, show_map=True)
for line in lines:
    print(line.rstrip())

Output:

import ee
import geemap

m = geemap.Map()

geometry = ee.Geometry.Point([77.60412933051538, 12.952912912328241])
s2 = ee.ImageCollection('COPERNICUS/S2_HARMONIZED')

rgbVis = {'min': 0.0, 'max': 3000, 'bands': ['B4', 'B3', 'B2']}

filtered = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30)) \
  .filter(ee.Filter.date('2019-01-01', '2020-01-01')) \
  .filter(ee.Filter.bounds(geometry))

medianComposite = filtered.median()

m.centerObject(geometry, 10)
m.addLayer(medianComposite, rgbVis, 'Median Composite')
m

Copy link

@github-actions github-actions bot temporarily deployed to pull request January 24, 2024 15:32 Inactive
@giswqs giswqs merged commit 2c46ef1 into master Jan 24, 2024
14 checks passed
@giswqs giswqs deleted the jspy branch January 24, 2024 15:33
@giswqs
Copy link
Member Author

giswqs commented Jan 24, 2024

@spatialthoughts run geemap.update_package() and restart the kernel to take effect.

@spatialthoughts
Copy link

Amazing. Tested and works well. Looking forward to the next release when this is available by default.

@giswqs
Copy link
Member Author

giswqs commented Feb 17, 2024

It should be available in v0.31.0 now

@spatialthoughts
Copy link

Thanks. I was just working in Colab and the default there is 0.30.4.

@giswqs
Copy link
Member Author

giswqs commented Feb 17, 2024

Colab's geemap version is usually behind for a few weeks. I guess v0.31.0 will be available there in a week a or two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants