Skip to content

Commit

Permalink
推导和整理photosynthesis,极简登场
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Oct 12, 2024
1 parent a4a759e commit 6a47867
Show file tree
Hide file tree
Showing 11 changed files with 407 additions and 404 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# BEPS.jl

[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://CUG-hydro.github.io/BEPS.jl/dev)
[![CI](https://github.com/CUG-hydro/BEPS.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/CUG-hydro/BEPS.jl/actions/workflows/CI.yml)
[![Codecov](https://codecov.io/gh/CUG-hydro/BEPS.jl/branch/master/graph/badge.svg)](https://app.codecov.io/gh/CUG-hydro/BEPS.jl/tree/master)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://jl-pkgs.github.io/BEPS.jl/dev)
[![CI](https://github.com/jl-pkgs/BEPS.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/jl-pkgs/BEPS.jl/actions/workflows/CI.yml)
[![Codecov](https://codecov.io/gh/jl-pkgs/BEPS.jl/branch/master/graph/badge.svg)](https://app.codecov.io/gh/jl-pkgs/BEPS.jl/tree/master)

Boreal Ecosystem Productivity Simulator in Julia

Expand All @@ -22,16 +22,16 @@ Boreal Ecosystem Productivity Simulator in Julia
- For developers

```bash
git clone https://github.com/CUG-hydro/BEPS.jl
git clone https://github.com/jl-pkgs/BEPS.jl
cd BEPS.jl/deps
git clone https://github.com/CUG-hydro/BEPS.c
git clone https://github.com/jl-pkgs/BEPS.c
```

- For users

```bash
# In Julia
] add https://github.com/CUG-hydro/BEPS.jl
] add https://github.com/jl-pkgs/BEPS.jl
```

## Usage
Expand Down
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
Binary file added docs/BEPS_光合作用_三次方程.pdf
Binary file not shown.
Binary file added docs/BEPS_光合作用_二次方程.pdf
Binary file not shown.
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 6a47867

Please sign in to comment.