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

image_stats_by_zone() Error #1885

Closed
caomy7 opened this issue Jan 17, 2024 · 1 comment
Closed

image_stats_by_zone() Error #1885

caomy7 opened this issue Jan 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@caomy7
Copy link

caomy7 commented Jan 17, 2024

Environment Information

Please run the following code on your computer and share the output with us so that we can better debug your issue:

import geemap
geemap.Report()

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

I want to get the SOS information based on the land cover.

I get a bug as follow when I run the code in the North America area.

{'type': 'Projection', 'crs': 'SR-ORG:6974', 'transform': [463.3127165279165, 0, -20015109.354, 0, -463.3127165279167, 10007554.677003]}
{'type': 'Projection', 'crs': 'SR-ORG:6974', 'transform': [463.3127165279165, 0, -20015109.354, 0, -463.3127165279167, 10007554.677003]}

HttpError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/ee/data.py in _execute_cloud_call(call, num_retries)
394 try:
--> 395 return call.execute(num_retries=num_retries)
396 except googleapiclient.errors.HttpError as e:

6 frames
HttpError: <HttpError 400 when requesting https://earthengine.googleapis.com/v1/projects/earthengine-legacy/value:compute?prettyPrint=false&alt=json returned "Unable to transform edge (6144.000000, 0.000000 to 6144.000000, 0.000977) from SR-ORG:6974 PLANAR [4633.127165279165, 0.0, -2.0015109354E7, 0.0, -4633.127165279167, 1.0007554677003E7] to EPSG:4326.". Details: "Unable to transform edge (6144.000000, 0.000000 to 6144.000000, 0.000977) from SR-ORG:6974 PLANAR [4633.127165279165, 0.0, -2.0015109354E7, 0.0, -4633.127165279167, 1.0007554677003E7] to EPSG:4326.">

During handling of the above exception, another exception occurred:

EEException Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/ee/data.py in _execute_cloud_call(call, num_retries)
395 return call.execute(num_retries=num_retries)
396 except googleapiclient.errors.HttpError as e:
--> 397 raise _translate_cloud_exception(e) # pylint: disable=raise-missing-from
398
399

EEException:

What I Did

#########  1. get the SOS info from MODIS
import ee
import geemap
import pandas as pdc
import datetime

# 初始化Earth Engine
ee.Initialize()
Map = geemap.Map()

Map.add_basemap('HYBRID')
# Map.add_basemap()
daymet = ee.FeatureCollection("users/Molly_HK/daymet_area")
roi = daymet


year1 = 2019 ###c
start = str(year1)+'-01-01'
end = str(year1)+'-12-31'

collection = ee.ImageCollection('MODIS/061/MCD12Q2').filterBounds(roi).filter(ee.Filter.date(start, end));

projection0 = collection.first().projection()
print(projection0.getInfo())


# collection = ee.ImageCollection('MODIS/061/MOD09Q1').filterBounds(roi).filterDate(start, end)
lc = ee.ImageCollection('MODIS/061/MCD12Q1').filterBounds(roi).filter(ee.Filter.date(start, end)).first()
lc_unique = lc.select('LC_Type1').lte(12) #cropland, 植被
# lc_unique = lc.select('LC_Type1').lte(14) #cropland, 植被

def clip_mask(image):
  lc = image.updateMask(lc_unique)
  return lc

dataset = collection.map(clip_mask)


projectionlc = lc_unique.projection()
print(projectionlc.getInfo())

projectiondata = dataset.first().projection()
print(projectiondata.getInfo())

#
Greenup_1 = dataset.select('Greenup_1').first().clip(roi);
Dormancy_1 = dataset.select('Dormancy_1').first().clip(roi);


MOD12BGN = datetime.date(1970, 1, 1)
print(MOD12BGN)
MOD12END = datetime.date(year1 - 1, 12, 31)
print(MOD12END)
MOD12DAY = (MOD12END - MOD12BGN).days
print(MOD12DAY)

SOS = Greenup_1.subtract(MOD12DAY)

projectionSOS = SOS.projection()
print(projectionSOS.getInfo())


palette = ['#000000', '#060A24', '#10174E', '#1A2A78', '#243EA2', '#2E52CC', '#3A6CFF', '#6D8EFF', '#9BAEFF', '#C5CDFF',
           '#E8E9FF', '#FFF4D6', '#FFE5A3', '#FFD271', '#FFC33F', '#FFB10D', '#FF9C00', '#FF8800', '#FF7300', '#FF5E00',
           '#FF4800', '#FF3300', '#FF1D00', '#FF0700', '#FF0000']


# Add to map
viz = {
  'palette': palette,
  'min': 1,
  'max': 365,
}

# # Map.addLayer(roi, {}, 'ROI')

# Map.addLayer(Greenup_1, viz, 'SOS', True)
Map.addLayer(SOS, viz, 'SOS', True)
Map.add_colorbar(viz)


# Map.addLayer(Dormancy_1,viz, 'Dormancy_1', False)

Map.addLayer(roi, {}, 'roi', False)
Map.centerObject(roi,7)
Map


#########  2. Caculating the result#################


# 获取图像属性
projection = SOS.projection()
print(projection.getInfo())

lc = ee.ImageCollection('MODIS/061/MCD12Q1').first().select('LC_Type1')
projection1 = lc.projection()
print(projection1.getInfo())

# landcover = ee.Image("USGS/NLCD_RELEASES/2019_REL/NLCD/2019").select('landcover')

stats = geemap.image_stats_by_zone(SOS,lc,reducer = "MEAN")
stats
@caomy7 caomy7 added the bug Something isn't working label Jan 17, 2024
@giswqs
Copy link
Member

giswqs commented Jan 24, 2024

This is an issue caused by the projection of MODIS data. See this.

@giswqs giswqs closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants