Error in code #269
-
Hello Community ! Greetings, I converted my JavaScript code to python while I am running the python code it is showing error. How can i overcome that error? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Hard to tell from the screenshot. Please share your complete source code. |
Beta Was this translation helpful? Give feedback.
-
This code I tested in Google Colab. import ee
import geemap
Map = geemap.Map()
ee.Initialize()
Map.add_basemap(basemap='HYBRID')
L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
roi =ee.Geometry.Polygon(
[[
[78.36456276631178, 13.52224244688901],
[79.99053932881178, 13.564965726101205],
[79.81475807881178, 16.703679438038012],
[77.63946511006178, 16.324487178056735]
]]
)
def maskL8sr(image):
cloudShadowBitMask = ee.Number(2).pow(3).int()
cloudsBitMask = ee.Number(2).pow(5).int()
qa = image.select('pixel_qa')
mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).And(qa.bitwiseAnd(cloudsBitMask).eq(0))
return image.updateMask(mask).divide(10000).copyProperties(image, ["system:time_start"])
rgb_vis = {'min':0, 'max':0.3, 'gamma': 1.4, 'bands':['B5','B4','B3']}
filtered = L8.filterDate("2016-03-01", "2016-05-31").filterBounds(roi).map(maskL8sr)
median = filtered.median()
clipped = median.clip(roi)
#image = ee.Image(filtered.sum())
Pre_ndvi = clipped.expression(
"(NIR - RED) / (NIR + RED)",
{
'RED': clipped.select("B4"), # RED
'NIR': clipped.select("B5") # NIR
})
Pre_NBR = clipped.expression(
"(NIR - SWIR2)/(NIR + SWIR2)",
{
'NIR' : clipped.select("B5"), # NIR
'SWIR2' : clipped.select("B7") #SWIR2
})
Map.addLayer(clipped, rgb_vis, 'RGB', 0)
Map.addLayer(Pre_ndvi, {'min':-0.2, 'max':0.8}, 'Pre_NDVI', 0)
Map.addLayer(Pre_NBR, {'min':-0.5, 'max':1.3}, 'Pre_NBR', 0)
rgb_vis1 = {'min':0, 'max':0.3, 'gamma': 1.4, 'bands':['B5','B4','B3']}
# Post Monsoon dates
filtered_1 = L8.filterDate('2016-10-01', '2016-11-30').filterBounds(roi).map(maskL8sr)
median_1 = filtered_1.median()
post_clipped = median_1.clip(roi)
#image = ee.Image(filtered.sum())
# Calculating Post_NDVI
Post_ndvi = post_clipped.expression(
"(NIR - RED) / (NIR + RED)",
{
'RED': post_clipped.select("B4"), # RED
'NIR': post_clipped.select("B5"), # NIR
#BLUE: image.select("B2") # BLUE
})
# Calculating Post_NBR
Post_NBR = post_clipped.expression(
"(NIR - SWIR2)/(NIR + SWIR2)",
{
'NIR' : post_clipped.select("B5"), # NIR
'SWIR2' : post_clipped.select("B7"), #SWIR2
})
Map.addLayer(post_clipped, rgb_vis1, 'post_RGB', 0)
Map.addLayer(Post_ndvi, {'min':-0.2, 'max':0.8}, 'Post_NDVI', 0)
Map.addLayer(Post_NBR, {'min':-0.5, 'max':1.3}, 'Post_NBR', 0)
# Difference in NDVI
Dndvi = Pre_ndvi.subtract(Post_ndvi)
# Difference in NBR
dNBR = Pre_NBR.subtract(Post_NBR)
Map.addLayer(Dndvi,{'min':0, 'max':1},'DNDVI', 0)
Map.addLayer(dNBR, {'min':0, 'max':1}, 'dNBR', 0)
Map.centerObject(roi, zoom=10)
Map.add_layer_control()
Map |
Beta Was this translation helpful? Give feedback.
-
I Tried ee.Reducer.LinearFit() model but it is showing an error that Dndvi
is not found and I also tried to print the chart but it is showing earth
engine limit exceeded.
Please help me with this. Here is the code link
<https://code.earthengine.google.com/9644dd482b297a67d263eb57d9e7908b>.
…On Sun, 24 Jan 2021 at 01:03, ErikSeras ***@***.***> wrote:
Look at this example
<https://developers.google.com/earth-engine/guides/reducers_regression>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#269 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQC7HG6EGH55CUSICFYMNSLS3MQAHANCNFSM4WMHMFLQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip!
Also, please help me with linear regression in the code.
…On Mon, 25 Jan 2021 at 10:59, ErikSeras ***@***.***> wrote:
Try changing the scale from 30 to a larger number (400 or more) so that
Google Earth Engine can process it:
var chart = ui.Chart.image.regions(clipped, feature, ee.Reducer.mean(), 400, 'label')
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#269 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQC7HG5UE3GMKZ3ZDT4UNFTS3T6TRANCNFSM4WMHMFLQ>
.
|
Beta Was this translation helpful? Give feedback.
This code I tested in Google Colab.