Skip to content

Commit

Permalink
third
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Oct 12, 2024
1 parent c39dd01 commit fd66967
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 104 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ docs/reference
.ipynb_checkpoints

__pycache__
data
examples
74 changes: 74 additions & 0 deletions data/ee_extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import argparse
import ee
import pandas as pd

# Dongdong Kong
# js版本已经测试通过
# 这是GPT3.5自动翻译的代码,可能会存在bug。
# https://code.earthengine.google.com/027ef28c2f7f304be6c7ebed95f5e1cc?noload=1

# Initialize the Earth Engine library
ee.Initialize()


def image_extract_points(img, points, proj=None, set_date=False):
if proj == None:
proj = img.projection().getInfo()
options = {
'collection': points,
'reducer': 'first',
'crs': proj['crs'],
'crsTransform': proj['transform'],
'tileScale': 16
}
date = ee.Date(img.get('system:time_start')).format('yyyy-MM-dd')

def tidy_props(f):
f = ee.Feature(None).copyProperties(f)
if set_date:
f = f.set('date', date)
return f
return img.reduceRegions(**options).map(tidy_props)


def col_extract_points(col, task, points):
proj = col.first().select(0).projection().getInfo()
res = col.map(lambda img: image_extract_points(
img, points, proj, set_date=True)).flatten()

ee.batch.Export.table.toDrive(
collection=res,
description=task,
folder="gee",
fileNamePrefix=task,
fileFormat="GeoJSON"
).start()


def export_image(img, task, prefix=""):
task = prefix + task
proj = img.projection().getInfo()

# Export the image to Drive as a GeoTIFF file
ee.batch.Export.image.toDrive(
image=img,
description=task,
folder="gee",
crs=proj['crs'],
crsTransform=proj['transform'],
maxPixels=1e13,
fileNamePrefix=task,
fileFormat='GeoTIFF'
).start()


def shp2df(fc, outfile=None):
data = fc.getInfo().get('features')
props = [x["properties"] for x in data]
df = pd.DataFrame(props)
if None != outfile:
df.to_csv(outfile, index=False)
return df

def hello():
print("Hello, World!")
54 changes: 9 additions & 45 deletions data/ee_extractor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# %%
## add pwd to path
# import os
# import sys
# sys.path.append(os.getcwd())

from ee_extract import *


# %%
import argparse
import ee
Expand All @@ -13,23 +22,6 @@

# %%
# Define the function to extract points from an image (internal)
def image_extract_points(img, points, proj=None, set_date=False):
if proj == None: proj = img.projection().getInfo()
options = {
'collection': points,
'reducer': 'first',
'crs': proj['crs'],
'crsTransform': proj['transform'],
'tileScale': 16
}
date = ee.Date(img.get('system:time_start')).format('yyyy-MM-dd')

def tidy_props(f):
f = ee.Feature(None).copyProperties(f)
if set_date: f = f.set('date', date)
return f

return img.reduceRegions(**options).map(tidy_props)

def shp2df(fc, outfile=None):
data = fc.getInfo().get('features')
Expand Down Expand Up @@ -57,34 +49,6 @@ def shp2df(fc, outfile=None):

# %%
# Define the function to export an image to Drive
def export_image(img, task, prefix=""):
task = prefix + task
proj = img.projection().getInfo()

# Export the image to Drive as a GeoTIFF file
ee.batch.Export.image.toDrive(
image=img,
description=task,
folder="gee",
crs=proj['crs'],
crsTransform=proj['transform'],
maxPixels=1e13,
fileNamePrefix=task,
fileFormat='GeoTIFF'
).start()

# Define the function to extract points from an image collection
def col_extract_points(col, task, points):
proj = col.first().select(0).projection().getInfo()
res = col.map(lambda img: image_extract_points(img, points, proj, set_date=True)).flatten()

ee.batch.Export.table.toDrive(
collection=res,
description=task,
folder="gee",
fileNamePrefix=task,
fileFormat="GeoJSON"
).start()

def main():
parser = argparse.ArgumentParser(description="Google Earth Engine Command Line Tool")
Expand Down
2 changes: 1 addition & 1 deletion data/s1_GEE.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

```{julia}
using EarthEngine
# Initialize()
Initialize()
dem = EE.Image("USGS/SRTMGL1_003")
xy = Point(86.9250, 27.9881)
Expand Down
2 changes: 1 addition & 1 deletion src/DataType/Constant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const ekc::Float64 = 80500.0 # Activation energy for K of CO2; J mol-1
const eko::Float64 = 14500.0 # Activation energy for K of O2, J mol-1
const erd::Float64 = 38000.0 # activation energy for dark respiration, eg Q10=2
const ektau::Float64 = -29000.0 # J mol-1 (Jordan and Ogren, 1984)
const tk_25::Float64 = 298.16 # absolute temperature at 25 C
const TK25::Float64 = 298.16 # absolute temperature at 25 C
const toptvc::Float64 = 301.0 # optimum temperature for maximum carboxylation
const toptjm::Float64 = 301.0 # optimum temperature for maximum electron transport
const eabole::Float64 = 45162.0 # activation energy for bole respiration for Q10 = 2.02
Loading

0 comments on commit fd66967

Please sign in to comment.