Rather than change the values of the band, you can change how the values are stretched when displaying.
In the corner of the map, click the gear next to your layer. Where it says custom choose an option. Play with that until you have one you like, then you can copy those values into your script.
Here's what the above setting looks like. It's the 2 sigma stretch.
I removed the functions I created. I thought I had to create mask function and then use them with map()
. Instead, I apply the .where()
directly to the means that are computed.
var cou_t = ['Tompkins'];
var st_y = ['New York'];
var cobo = ee.FeatureCollection("TIGER/2016/Counties").filter(ee.Filter.inList('NAME', cou_t)).geometry();
var st_ny = ee.FeatureCollection("TIGER/2018/States").filter(ee.Filter.inList('NAME', st_y));
var tomp = cobo.intersection(st_ny);
// Played around with different dates, like January, March, July
var start_date = ee.Date('2012-01-01'); // <<<<----
var end_date = ee.Date('2012-01-02'); // <<<<----
var daymet = ee.ImageCollection("NASA/ORNL/DAYMET_V4")
.filterDate(start_date, end_date)
.map(function(im){return im.clip(tomp)});
var daymean = daymet.map(function (image) {
var dayx = image.select('tmax');
var dayn = image.select('tmin');
// Apply threshold
// Hot temp on max. temp.
var dayxt = dayx.where(dayx.lt(10.0),0).rename('hotmax');
// Low temp. on max. temp. (e.g. high temp on a very cold day)
var dayxt2 = dayxt.where(dayxt.gt(26.0),0).rename('lowmax');
// Low temp. on cold day
var daynt = dayxt2.where(dayn.lt(10.0),0).rename('coldlow');
// Calculate mean temp.
var tavg = dayx.add(dayn).divide(2).rename('avg');
var tavghc = tavg.where(dayx.lt(10.0),0).rename('meanhotcol');
var tavgcc = tavghc.where(dayx.gt(26.0),0).rename('meanhihot');
var tavgcc2 = tavgcc.where(dayn.lt(10.0),0).rename('meanfinal');
return image.addBands([dayxt,dayxt2,daynt,tavg,tavghc,tavgcc,tavgcc2]);
});
var start_date2 = ee.Date('2012-03-15'); // <<<<----
var end_date2 = ee.Date('2012-03-16'); // <<<<----
var daymet2 = ee.ImageCollection("NASA/ORNL/DAYMET_V4")
.filterDate(start_date2, end_date2)
.map(function(im){return im.clip(tomp)});
var daymean2 = daymet2.map(function (image) {
var dayx = image.select('tmax');
var dayn = image.select('tmin');
// Apply threshold
// Hot temp on max. temp.
var dayxt = dayx.where(dayx.lt(10.0),0).rename('hotmax');
// Low temp. on max. temp. (e.g. high temp on a very cold day)
var dayxt2 = dayxt.where(dayxt.gt(26.0),0).rename('lowmax');
// Low temp. on cold day
var daynt = dayxt2.where(dayn.lt(10.0),0).rename('coldlow');
// Calculate mean temp.
var tavg = dayx.add(dayn).divide(2).rename('avg');
var tavghc = tavg.where(dayx.lt(10.0),0).rename('meanhotcol');
var tavgcc = tavghc.where(dayx.gt(26.0),0).rename('meanhihot');
var tavgcc2 = tavgcc.where(dayn.lt(10.0),0).rename('meanfinal');
return image.addBands([dayxt,dayxt2,daynt,tavg,tavghc,tavgcc,tavgcc2]);
});
var start_date3 = ee.Date('2012-07-15'); // <<<<----
var end_date3 = ee.Date('2012-07-16'); // <<<<----
var daymet3 = ee.ImageCollection("NASA/ORNL/DAYMET_V4")
.filterDate(start_date3, end_date3)
.map(function(im){return im.clip(tomp)});
var daymean3 = daymet3.map(function (image) {
var dayx = image.select('tmax');
var dayn = image.select('tmin');
// Apply threshold
// Hot temp on max. temp.
var dayxt = dayx.where(dayx.lt(10.0),0).rename('hotmax');
// Low temp. on max. temp. (e.g. high temp on a very cold day)
var dayxt2 = dayxt.where(dayxt.gt(26.0),0).rename('lowmax');
// Low temp. on cold day
var daynt = dayxt2.where(dayn.lt(10.0),0).rename('coldlow');
// Calculate mean temp.
var tavg = dayx.add(dayn).divide(2).rename('avg');
var tavghc = tavg.where(dayx.lt(10.0),0).rename('meanhotcol');
var tavgcc = tavghc.where(dayx.gt(26.0),0).rename('meanhihot');
var tavgcc2 = tavgcc.where(dayn.lt(10.0),0).rename('meanfinal');
return image.addBands([dayxt,dayxt2,daynt,tavg,tavghc,tavgcc,tavgcc2]);
});
Map.setCenter(-76,42.4);
Map.setZoom(9);
Map.addLayer(daymean,null,"one");
Map.addLayer(daymean2,null,"two");
Map.addLayer(daymean3,null,"three");
The code environment: https://code.earthengine.google.com/44c7a3e19ea8dbdfd381efcde7296d40
Best Answer
The trick is to save what the previously selected image was so you can easily set the Image to transparent. For this I use the variable
current
. Then you can get the newly selected Image from the layer list and set the opacity to 1.