Spaces:
Sleeping
Sleeping
Commit
·
0d67bf1
1
Parent(s):
2f3810a
Upload run.py
Browse files
run.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import ee
|
| 3 |
+
import geemap.foliumap as geemap
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="TPL MAPPING",layout="wide")
|
| 9 |
+
|
| 10 |
+
st.markdown("<h1 style='text-align: center;'>Lake Distribution map of Tibet Plateau based on OTOP</h1>", unsafe_allow_html=True)
|
| 11 |
+
|
| 12 |
+
# geemap.set_proxy(33210)
|
| 13 |
+
|
| 14 |
+
row1_col1, row1_col2 = st.columns([4, 1])
|
| 15 |
+
|
| 16 |
+
Map = geemap.Map()
|
| 17 |
+
|
| 18 |
+
# 设置区域
|
| 19 |
+
region = ee.FeatureCollection("projects/useful-tempest-341103/assets/water/TPBoundary")
|
| 20 |
+
|
| 21 |
+
# 获取遥感影像
|
| 22 |
+
datastart='2021-06-01'
|
| 23 |
+
dataend='2021-10-15'
|
| 24 |
+
|
| 25 |
+
def rmCloudByQA(image):
|
| 26 |
+
qa = image.select('QA60')
|
| 27 |
+
cloudBitMask = 1 << 10
|
| 28 |
+
cirrusBitMask = 1 << 11
|
| 29 |
+
mask =qa.bitwiseAnd(cloudBitMask).eq(0)and(qa.bitwiseAnd(cirrusBitMask).eq(0))
|
| 30 |
+
return image.updateMask(mask);
|
| 31 |
+
|
| 32 |
+
S2 = (ee.ImageCollection('COPERNICUS/S2_SR')
|
| 33 |
+
.filterDate(datastart,dataend)
|
| 34 |
+
.filterBounds(region)
|
| 35 |
+
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 50))
|
| 36 |
+
.map(rmCloudByQA)
|
| 37 |
+
.select('B.*')
|
| 38 |
+
.median()
|
| 39 |
+
.clip(region))
|
| 40 |
+
|
| 41 |
+
pred = ee.Image("projects/useful-tempest-341103/assets/TPlake/pred");
|
| 42 |
+
|
| 43 |
+
# 对分类数据进行mask处理
|
| 44 |
+
def pred_mask(pred,threshold):
|
| 45 |
+
mask=pred.where(pred.lt(threshold),0).where(pred.gte(threshold),1).toInt()
|
| 46 |
+
mask=mask.setDefaultProjection('epsg:4326',None,10)
|
| 47 |
+
water=mask.updateMask(mask.gt(0.5))
|
| 48 |
+
return water
|
| 49 |
+
|
| 50 |
+
with row1_col2:
|
| 51 |
+
# 选择底图模块
|
| 52 |
+
basemaps = ['HYBRID', 'SATELLITE', 'TERRAIN']
|
| 53 |
+
basemap = st.selectbox("Basemap", basemaps,index=basemaps.index('HYBRID'))
|
| 54 |
+
Map.add_basemap(basemap)
|
| 55 |
+
|
| 56 |
+
# 选择典型湖泊
|
| 57 |
+
Typicallakes = ["Typical Lakes", "Qinghai Lake", "Selincuo", "Zhaling Lake", "Eling Lake", "Zhuonai Lake", "Margai Chaka", "Kokexili Lake"]
|
| 58 |
+
lakeword = st.selectbox("Typical Lakes", Typicallakes)
|
| 59 |
+
if lakeword == "Qinghai Lake":
|
| 60 |
+
Map.setCenter(100.192956,36.936857, zoom=9)
|
| 61 |
+
elif lakeword == "Selincuo":
|
| 62 |
+
Map.setCenter(88.955657,31.810172, zoom=10)
|
| 63 |
+
elif lakeword == "Zhaling Lake":
|
| 64 |
+
Map.setCenter(97.294221,34.938479, zoom=11)
|
| 65 |
+
elif lakeword == "Eling Lake":
|
| 66 |
+
Map.setCenter(97.70816,34.91575, zoom=11)
|
| 67 |
+
elif lakeword == "Zhuonai Lake":
|
| 68 |
+
Map.setCenter(91.944098,35.555848, zoom=11)
|
| 69 |
+
elif lakeword == "Margai Chaka":
|
| 70 |
+
Map.setCenter(86.768704,35.133507, zoom=12)
|
| 71 |
+
elif lakeword == "Kokexili Lake":
|
| 72 |
+
Map.setCenter(91.129067,35.595563, zoom=11)
|
| 73 |
+
else:
|
| 74 |
+
Map.setCenter(87.745,33.092, zoom=6)
|
| 75 |
+
|
| 76 |
+
# 自定义设置阈值
|
| 77 |
+
Threshold = st.slider('Threshold', 0, 255, 128)
|
| 78 |
+
water=pred_mask(pred,Threshold)
|
| 79 |
+
|
| 80 |
+
# 选择是否分屏查看
|
| 81 |
+
split = st.checkbox("Split View")
|
| 82 |
+
if split:
|
| 83 |
+
left_layer = geemap.ee_tile_layer(water, {'min': 0, 'max':1, 'palette': '0905ff'}, name='water',opacity=0.7)
|
| 84 |
+
right_layer = geemap.ee_tile_layer(S2, {'min': 0, 'max':3000, 'bands': ['B4', 'B3', 'B2']},name='Image',shown=False)
|
| 85 |
+
Map.split_map(left_layer, right_layer)
|
| 86 |
+
else:
|
| 87 |
+
Map.addLayer(water, {'min': 0, 'max':1, 'palette': '0905ff'}, name='water',opacity=0.7)
|
| 88 |
+
|
| 89 |
+
st.sidebar.title("About")
|
| 90 |
+
st.sidebar.info(
|
| 91 |
+
"""
|
| 92 |
+
This web [app]() is maintained by [Junchuan Yu](https://junchuanyu.netlify.app/posts/). You can follow me on social media:
|
| 93 |
+
[GitHub](https://github.com/JunchuanYu) | [Zhihu](https://twitter.com/giswqs) .
|
| 94 |
+
|
| 95 |
+
Sentinel-2 is used as the data, and 8-band images are used as training data (B4, B3, B2, B8, B11, B12, MNDWI, SDWI). The model uses a multi-scale deep neural network model based on transfer learning, and is implemented using otop technology
|
| 96 |
+
"""
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
with row1_col1:
|
| 100 |
+
Map.to_streamlit(height=750)
|
| 101 |
+
|
| 102 |
+
st.markdown("<h5 style='text-align: center;'>you can follow the WeChat public account [45度科研人] and leave me a message!</h5>", unsafe_allow_html=True)
|
| 103 |
+
|
| 104 |
+
row2_col1, row2_col2,row2_col3,row2_col4 = st.columns([2,1,1,2])
|
| 105 |
+
with row2_col2:
|
| 106 |
+
st.markdown("<img src='https://dunazo.oss-cn-beijing.aliyuncs.com/blog/wechat-simple.png' style='margin-right:25px;width:200px;height:200px;'>", unsafe_allow_html=True)
|
| 107 |
+
with row2_col3:
|
| 108 |
+
st.markdown("<img src='https://dunazo.oss-cn-beijing.aliyuncs.com/blog/shoukuanma222.png' style='margin-right:25px;width:170px;height:190px;'>", unsafe_allow_html=True)
|
| 109 |
+
|