示例#1
0
def lc8CountObservations(path, row):

	ee.Initialize();

	filter = ee.Filter.And( ee.Filter.eq('WRS_PATH', path), ee.Filter.eq('WRS_ROW', row) );

	lc8array = utils.imageCollection2Array('LANDSAT/LC8', '2013-04-01', '2015-03-31', filter);

	result = { 
		'path': path, 
		'row': row, 
		'scenes': {
			'total': 0, 
			'months': {
				'2013-04': 0,
				'2013-05': 0,
				'2013-06': 0,
				'2013-07': 0,
				'2013-08': 0,
				'2013-09': 0,
				'2013-10': 0,
				'2013-11': 0,
				'2013-12': 0,
				'2014-01': 0,
				'2014-02': 0,
				'2014-03': 0,
				'2014-04': 0,
				'2014-05': 0,
				'2014-06': 0,
				'2014-07': 0,
				'2014-08': 0,
				'2014-09': 0,
				'2014-10': 0,
				'2014-11': 0,
				'2014-12': 0,
				'2015-01': 0,
				'2015-02': 0,
				'2015-03': 0
			}
		},
		'cloudCover': {
			'total':0,
			'months': {
					'2013-04': 0,
					'2013-05': 0,
					'2013-06': 0,
					'2013-07': 0,
					'2013-08': 0,
					'2013-09': 0,
					'2013-10': 0,
					'2013-11': 0,
					'2013-12': 0,
					'2014-01': 0,
					'2014-02': 0,
					'2014-03': 0,
					'2014-04': 0,
					'2014-05': 0,
					'2014-06': 0,
					'2014-07': 0,
					'2014-08': 0,
					'2014-09': 0,
					'2014-10': 0,
					'2014-11': 0,
					'2014-12': 0,
					'2015-01': 0,
					'2015-02': 0,
					'2015-03': 0
			},
			'days': {}
		}
	}

	print(len(lc8array))

	for i, lc8 in enumerate(lc8array):

		while True:
			try:
				img = lc8['img'];
				imgTime = img.get('system:time_start').getInfo();
				dt = datetime.datetime.utcfromtimestamp(imgTime/1000);
				month = str(dt.strftime('%Y-%m'));
				day = str(dt.strftime('%Y-%m-%d'));

				cloudCover = img.get('CLOUD_COVER').getInfo();
				break;

			except:
				print('error',i);
				traceback.print_exc();

		print(i, cloudCover, month, day);

		if month not in result['scenes']['months']:
			result['scenes']['months'][month] = 0;
			result['cloudCover']['months'][month] = 0;

		result['scenes']['months'][month] += 1;
		result['scenes']['total'] += 1;

		result['cloudCover']['total'] += cloudCover
		result['cloudCover']['days'][day] = cloudCover;
		result['cloudCover']['months'][month] += cloudCover

	if(result['scenes']['total'] > 0):
		result['cloudCover']['total'] = result['cloudCover']['total'] / result['scenes']['total'];

	for month in result['cloudCover']['months']:
		if result['scenes']['months'][month] > 0:
			result['cloudCover']['months'][month] = result['cloudCover']['months'][month] / result['scenes']['months'][month]

	return result;
collumns = [ 'scene', 'date', 'cloudCover', 'total', \
	'cloud', 	'maybe', \
	'cirrus', 'google_0', \
	'google_10', 'google_20', \
	'google_30', 'google_40', \
	'google_50', 'google_60', \
	'google_70', 'google_80', \
	'google_90', 'google_100', \
];

pixelWriter.writerow(collumns);
percentageWriter.writerow(collumns);

filter = ee.Filter.And( ee.Filter.eq('WRS_PATH', 227), ee.Filter.eq('WRS_ROW', 67) );

lc8array = utils.imageCollection2Array('LANDSAT/LC8', '2013-04-01', '2015-03-31', filter);

for lc8Obj in lc8array:

	ee.Initialize();

	lc8 = lc8Obj['img']

	imgTime = lc8.get('system:time_start').getInfo();
	dt = datetime.datetime.utcfromtimestamp(imgTime/1000);
	strDate = str(dt.strftime('%Y-%m-%d'));

	cloudCover = lc8.get('CLOUD_COVER').getInfo();

	bqa = lc8.select('BQA');