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

Unable to use ui.Chart.image.series() in jupyter lab #16232

Closed
elysiaforme opened this issue Apr 24, 2024 · 2 comments
Closed

Unable to use ui.Chart.image.series() in jupyter lab #16232

elysiaforme opened this issue Apr 24, 2024 · 2 comments
Labels
bug status:Needs Triage Applied to new issues that need triage

Comments

@elysiaforme
Copy link

Hello!

A mistake occured when extracting NDVI and plotting trendlines with Sentinel 2, running S2_chart = ui.Chart.image.series() gives an error saying ui. is not defined.
I'm using Windows, Python 3.12.3, ipygee-Version: 0.0.18, geetools-Version: 1.3.0, jupyeter lab extension manager is also active, lab-version3.0 and note book-version6.5.4. version6.5.4

Here is the mistake report:
2

Here is the entire codes:

import ee
import geemap
geemap.set_proxy(port='my port')
Map = geemap.Map(basemap = 'Esri.WorldImagery')
shp_path = r'E:\postgraduate study\GIS文件\祁阳市.shp'
shp_fc = geemap.shp_to_ee(shp_path)

geometry = shp_fc
Map.centerObject(geometry, 9)

colorizedVis = {
'min': -0.8,
'max': 0.8,
'palette': ['blue', 'white', 'green']
}

def maskS2clouds(image):
qa = image.select('QA60')
# Bits 10 and 11 are clouds and cirrus, respectively.
cloudBitMask = 1 << 10
cirrusBitMask = 1 << 11
# Both flags should be set to zero, indicating clear conditions.
mask = qa.bitwiseAnd(cloudBitMask).eq(0).And(qa.bitwiseAnd(cirrusBitMask).eq(0))
return image.updateMask(mask).divide(10000).set(image.toDictionary(image.propertyNames()))

def createNDVI(image):
ndvi = image.normalizedDifference(["B8", "B4"]).rename('NDVI')
return image.addBands(ndvi)

S2_COL = ee.ImageCollection("COPERNICUS/S2")
.filterDate("2021-01-01", "2021-12-31")
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.filterBounds(geometry)
.map(maskS2clouds)
.map(createNDVI)
.select('NDVI')

#The mistake occured here:
S2_chart = ui.Chart.image.series({
'imageCollection': S2_COL.select('NDVI'),
'region': geometry,
'reducer': ee.Reducer.mean(),
'scale': 500
}).setOptions({
'interpolateNulls': True,
'lineWidth': 2,
'title': 'NDVI Time Series',
'vAxis': {'title': 'NDVI'},
'hAxis': {'title': 'Date'},
'trendlines': {0: {'title': 'NDVI_trend', 'type': 'linear', 'showR2': True, 'color': 'red', 'visibleInLegend': True}}
})
print(S2_chart)

Thanks for your attention very much!

Copy link

welcome bot commented Apr 24, 2024

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Apr 24, 2024
@JasonWeill
Copy link
Contributor

Hi @elysiaforme , thanks for your contribution! Your code refers to a name ui, but you haven't imported or declared anything by that name. I'm not familiar with NDVI or Sentinel 2. Because this is not an issue with JupyterLab, I'm closing this issue. If you were following guidance about setting up Sentinel 2, I recommend following up in a community that is more familiar with that code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status:Needs Triage Applied to new issues that need triage
Projects
None yet
Development

No branches or pull requests

2 participants