Invece di procedere in modo tradizionale come indicato nel post precedente si possono interrogare i dati GFS NOAA anche da Google Earth Engine con il vantaggi che i dati sono gia' scaricati e pronti all'elaborazione (con lo svantaggio che i risultati possono essere esportati in automatico solo su cloud e non sulla macchina locale)
=================================================
var palettes = require('users/gena/packages:palettes');
var palette = palettes.colorbrewer.RdYlGn[9];
var region = ee.Geometry(Map.getBounds(true))
// Strip time off current date/time
var today = ee.Date(new Date().toISOString().split('T')[0])
var image;
var collection = ee.ImageCollection('NOAA/GFS0P25')
.select('temperature_2m_above_ground')
.filterDate(today.advance(-1, 'day'), today.advance(1, 'day'))
.sort('system:time_start', false)
console.log(collection);
// per i successivi 3 giorni le previsioni sono orarie
// le previsioni vengono ricalcolate ogni 6 ore
var forecasts = ee.ImageCollection(
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23, 24,
25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,
49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,63,64,65,66,67,68,69,70,71].map(forecast)
//[12, 24, 36,48,60, 72].map(forecast)
)
Map.setCenter(11.8537, 46.4297, 12);
Map.setOptions('SATELLITE');
Map.setControlVisibility(false, false, true, true, true, false, false)
Map.addLayer(forecasts, {min: 0, max: 30,palette: palette,opacity: 0.5}, 'Temperature forecast', true)
var textStyle = {
color: 'grey',
fontName: 'arial',
fontSize: 10,
bold: true,
italic: false
}
var chart = ui.Chart.image.series({
imageCollection: forecasts,
region: geometry,
reducer: ee.Reducer.mean(),
scale: forecasts.first().projection().nominalScale(),
xProperty: 'date',
}).setChartType('LineChart').setOptions({title: 'Forecast 72h Temperature 2m above ground (C)',hAxis: {title: 'Date',textStyle: textStyle},vAxis: {title: 'Temperature'}});
//print(chart)
var panel_chart = ui.Panel({style: {width: '400px'}})
.add(ui.Label('NOAA/GFS0P25'))
.add(chart);
ui.root.add(panel_chart);
function forecast(hours) {
image = collection
.filterMetadata('forecast_hours', 'equals', hours)
// Since colleciton is sorted descending, if there are more than
// one forecast, first() will give the latest.
.first()
var date = image.date().advance(hours, 'hours')
return image
.set('date', date.format())
}
var panel = ui.Panel();
panel.style().set({
width: '400px',
position: 'bottom-right'
});
//Map.add(panel);
Map.onClick(function(coords) {
//panel_chart.clear();
console.log(collection);
//Map.add(panel);
var location = 'lon: ' + coords.lon.toFixed(4) + ' ' +
'lat: ' + coords.lat.toFixed(4);
var click_point = ee.Geometry.Point(coords.lon, coords.lat);
var valore = image.reduceRegion(ee.Reducer.first(), click_point, 90).evaluate(function(val){
//console.log(valore);
//var demText = 'Habitat suitability: ' + val.b1;
//toolPanel.widgets().set(2, ui.Label(demText));
});
panel.widgets().set(1, ui.Label(location));
// Edit: To be temporary, the "loading..." panel number has to be the same as the demText panel number (changed from 1 to 2).
//panel.widgets().set(2, ui.Label("loading..."));
Map.layers().set(1, ui.Map.Layer(click_point, {color: 'FF0000'}));
});