SHARE
TWEET

Untitled

a guest Jun 16th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #%%
  2. import numpy as np, pandas as pd
  3. import matplotlib.pyplot as plt
  4. import matplotlib.colors as colors
  5. import matplotlib.colorbar as colorbar
  6. import ee; ee.Initialize()
  7.  
  8.  
  9. sampleslist = ee.FeatureCollection(
  10.         [ee.Feature(
  11.             ee.Geometry.Point([-90.42115355993224, 44.65267001216058]),
  12.             {
  13.               "num": 1,
  14.               "system:index": "0"
  15.             }),
  16.         ee.Feature(
  17.             ee.Geometry.Point([-90.41875030065489, 44.65297530265321]),
  18.             {
  19.               "num": 2,
  20.               "system:index": "1"
  21.             }),
  22.         ee.Feature(
  23.             ee.Geometry.Point([-90.42132522130919, 44.65034975189679]),
  24.             {
  25.               "num": 3,
  26.               "system:index": "2"
  27.             }),
  28.         ee.Feature(
  29.             ee.Geometry.Point([-90.41866446996642, 44.65068558478559]),
  30.             {
  31.               "num": 4,
  32.               "system:index": "3"
  33.             }),
  34.         ee.Feature(
  35.             ee.Geometry.Point([-90.41935111547423, 44.64860949578218]),
  36.             {
  37.               "num": 5,
  38.               "system:index": "4"
  39.             })]);
  40.  
  41. def maskS2clouds(image):
  42.     qa = image.select('QA60')
  43.     cloudBitMask = 1 << 10;
  44.     cirrusBitMask = 1 << 11;
  45.     mask = qa.bitwiseAnd(cloudBitMask).eq(0).And(qa.bitwiseAnd(cirrusBitMask).eq(0))
  46.     return image.updateMask(mask).divide(10000)\
  47. .select("B.*")\
  48. .copyProperties(image, ["system:time_start"])
  49.  
  50. series = ee.ImageCollection('COPERNICUS/S2')\
  51. .filterDate('2018-05-15', '2018-10-31')\
  52. .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))\
  53. .filterBounds(westernRegions)\
  54. .map(maskS2clouds)\
  55. .map(lambda image: image.addBands(image.normalizedDifference(['B8', 'B4'])).select('nd'))
  56.  
  57. stat = series.map(lambda image:
  58.             image.reduceRegions(**{
  59.             'collection': sampleslist,
  60.             'reducer': 'mean',
  61.             'scale': 30
  62.         }).map(lambda f: f.set('doy', image.date().format("D")).set('date', image.date().format("MMM-dd")).set('year', image.date().format("YYYY"))))
  63. # print(stat.size().getInfo())
  64. features = ee.FeatureCollection(ee.FeatureCollection(stat).flatten()).getInfo()['features']
  65. df = pd.DataFrame([ft['properties'] for ft in features])
  66.  
  67. #%%
  68. fig, ax = plt.subplots(figsize=(8,6))
  69. for i, (label, d) in enumerate(df[['date', 'mean', 'num']].groupby('num'),1):
  70.     d.rename(columns={'mean':'pt{}'.format(i)}).plot(ax=ax, x='date', y='pt{}'.format(i))
  71.     # break
  72. plt.legend();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top