var China = ee.FeatureCollection('users/yangjunting6/desert');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = ee.Number(2).pow(10).int();
var cirrusBitMask = ee.Number(2).pow(11).int();
print(cloudBitMask);
print(cirrusBitMask);
var addNDVI = function(image) {
var qa = image.select('QA60');
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.addBands(image.normalizedDifference(['B8', 'B4'])
.updateMask(mask)
)};
var collection = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(China)
.filterDate('2014-03-01', '2018-09-30')
.filter(ee.Filter.dayOfYear(90, 180))
.map(addNDVI);
var vizParams = {'bands': ['B4', 'B3', 'B2'], 'max': 4000, 'gamma': 1.6};
//print(collection);
//var newcollection = collection.sort('nd',false).limit(100);
Map.centerObject(China, 8);
var altgr = collection.qualityMosaic('nd').double().clip(China);
var altmean = collection.median().clip(China);
var maskwater = altmean.select('nd').gt(0.1);
var altgrmask = altgr.updateMask(maskwater);
var newcollection = ee.ImageCollection.fromImages([altgrmask,altmean]);
print(newcollection);
var altlast = newcollection.qualityMosaic('nd');
//Map.addLayer(altmean, vizParams);
//Map.addLayer(altgrmask, vizParams);
Map.addLayer(altlast, vizParams);
print(altlast);
var median = altlast;
var ss = ee.FeatureCollection('users/yangjunting6/somt')
.select('som');
var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3};
//Map.addLayer(median, visParams, 'median');
//Calculating variables
function radians(img) {
return img.toFloat().multiply(Math.PI).divide(180);
}
var terrain = ee.Algorithms.Terrain(ee.Image('CGIAR/SRTM90_V4')).clip(China);
var slope = radians(terrain.select('slope'));
var aspect = radians(terrain.select('aspect'));
//var sinImage = aspect.divide(180).multiply(Math.PI).sin();
Map.centerObject(China);// Center on the Grand Canyon.
var bands = [ 'B3', 'B4', 'B5', 'B6', 'B7'];
//Map.addLayer(somPoints);
var elevation = ee.Image('CGIAR/SRTM90_V4').clip(China).float();
print(elevation);
var pre = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
.filterDate('2017-01-01','2017-12-30')
.filterBounds(China);
var P = pre.filterBounds(China)
.select(['precipitation'], ['pree']);