// Author: Frederico Brandão // Date and location: November 2018, Belém, Brazil // Specifications: Calmaria II settlement (PA) in Moju/Tailândia // Enjoy!! //====================================================================================================== // Defining the sample for analysis // Can be done straight in the script using collected points or through designing polygons in GEE // In this case I ran points of surveyed smallholders collected on the ground in QGIS and with support of Planet image (2018) I was able to build polygons of smallholder oil palm plots // Given landsat resolution (30) I reduced manually the plot size in order to avoid border effects // Polygons have in general around 4 to 8 hectares while oil palm plot range between 6 and 10 hectares // sets geometries for analysis: more than 30 oil palm plots in principle planted after 2014, 30 planted around 2006 and 10 forest polygon to compare with // sets calmaria as research area under the variable 'geometry' var bio1 = /* color: #ff99ff */ee.Geometry.Polygon( [[[-48.815351480386255, -2.49711483627039], [-48.815372938058374, -2.494456608844165], [-48.81672477140188, -2.4942851101159884], [-48.81653165235281, -2.4959786590766626]]]), bio2 = /* color: #ffff99 */ee.Geometry.Polygon( [[[-48.82166003598928, -2.4906621942598015], [-48.82146691694021, -2.493749176446296], [-48.8202223719573, -2.4937920511479037], [-48.82013654126882, -2.4902977583851618]]]), bio3 = /* color: #99ffff */ee.Geometry.Polygon( [[[-48.81893491163015, -2.4934061787831183], [-48.81816243543386, -2.493020306305156], [-48.81779765500784, -2.491433940485022], [-48.81741141690969, -2.489247325005995], [-48.81869887723684, -2.489268762430257]]]), bio4 = /* color: #ff9999 */ee.Geometry.Polygon( [[[-48.84231490377573, -2.4799569716139884], [-48.842701141873874, -2.48132897572009], [-48.839224998990574, -2.481714851618446], [-48.83931082967905, -2.480342847912675]]]), bio5 = /* color: #99ff99 */ee.Geometry.Polygon( [[[-48.82738036701153, -2.4832792684888387], [-48.824741073340874, -2.4835579562376884], [-48.824741073340874, -2.4825075174929387], [-48.826200195044976, -2.481778641138547], [-48.82755202838848, -2.4832792684888387]]]), bio6 = /* color: #00ffff */ee.Geometry.Polygon( [[[-48.79736351121403, -2.459678150466405], [-48.79740642655827, -2.460921548234643], [-48.794488183150065, -2.46057854206955], [-48.79435943711735, -2.4595923988534545]]]), bio7 = /* color: #ff00ff */ee.Geometry.Polygon( [[[-48.82418905379018, -2.46879382531189], [-48.82114206434926, -2.4693512068449337], [-48.820798741595354, -2.467764812636721], [-48.82371698500356, -2.4672074304384326]]]), bio8 = /* color: #ff0000 */ee.Geometry.Polygon( [[[-48.85077969981569, -2.439357711516751], [-48.85153071833986, -2.4409870158424933], [-48.851123022569595, -2.4421875546082275], [-48.85022180034059, -2.4426591945441163], [-48.85005013896364, -2.4436882265566133], [-48.84884850932497, -2.4438597318153588], [-48.848419355882584, -2.4430450816412184], [-48.84921328975099, -2.442594880017157], [-48.84882705165285, -2.4416515999346355], [-48.848912882341324, -2.439786476004416]]]), bio9 = /* color: #99ffff */ee.Geometry.Polygon( [[[-48.82130496476884, -2.476310686467466], [-48.8216912029045, -2.477039565904621], [-48.82023208105869, -2.477811320165608], [-48.82023208105869, -2.4750244276591045], [-48.820940184030405, -2.475067302983401]]]), bio10 = /* color: #ff0000 */ee.Geometry.Polygon( [[[-48.89370927357328, -2.4668515781810667], [-48.893773646589636, -2.468588037801237], [-48.8922716095413, -2.4684165357174863], [-48.89194974445951, -2.4665728869197396]]]), bio11 = /* color: #ff9999 */ee.Geometry.Polygon( [[[-48.823717623409436, -2.4088761641245333], [-48.82234433239381, -2.4093478156768255], [-48.821786432918714, -2.406689413884794], [-48.823245554622815, -2.4057889862957462]]]), bio12 = /* color: #0000ff */ee.Geometry.Polygon( [[[-48.79835401655873, -2.4736816246319577], [-48.79736696364125, -2.473124244917021], [-48.7986544239684, -2.471194851788026], [-48.799770222918596, -2.4718379831426933]]]), bio13 = /* color: #999900 */ee.Geometry.Polygon( [[[-48.79539285780629, -2.4714521043672835], [-48.79462038161, -2.472952743419167], [-48.79174505354604, -2.4715378552159595], [-48.79234586836537, -2.469908588144143], [-48.79414831282338, -2.4709375991589355]]]), bio14 = /* color: #d63000 */ee.Geometry.Polygon( [[[-48.763831014719756, -2.431204072686925], [-48.761856908884795, -2.429724825205336], [-48.7627581311138, -2.428224137698529], [-48.76496827134207, -2.429489002993262]]]), bio15 = /* color: #009999 */ee.Geometry.Polygon( [[[-48.79015718580922, -2.4708947237159027], [-48.78947054030141, -2.4705945955759314], [-48.789084302203264, -2.4722667372060014], [-48.78818307997426, -2.4721381110015543], [-48.78959928633412, -2.4694798333193466], [-48.79062925459584, -2.4698228371902546]]]), bio16 = /* color: #98ff00 */ee.Geometry.Polygon( [[[-48.763299511824755, -2.4379348062921373], [-48.76244120493999, -2.4384922006890486], [-48.76164727107158, -2.436455566196547], [-48.76201205149761, -2.4364984427439325]]]), bio17 = /* color: #ff99ff */ee.Geometry.Polygon( [[[-48.77076184281424, -2.4288672896913197], [-48.77022540101126, -2.4298105787267845], [-48.763079996195586, -2.4252227576855545], [-48.764067049113066, -2.4241937115763306]]]), bio18 = /* color: #99ff99 */ee.Geometry.Polygon( [[[-48.81719449108522, -2.411105788205057], [-48.814748316463636, -2.411791825648839], [-48.814533739742444, -2.4077184732582797], [-48.81663659161012, -2.407589840879091]]]), bio19 = /* color: #0b4a8b */ee.Geometry.Polygon( [[[-48.767131419341354, -2.4494113997707747], [-48.76592978970268, -2.4479964865872366], [-48.766852469603805, -2.4474605342336555], [-48.76775369183281, -2.4490469525785]]]), bio20 = /* color: #ffff99 */ee.Geometry.Polygon( [[[-48.80577113905696, -2.429660510060662], [-48.8062646655157, -2.4309896890943783], [-48.80216625014094, -2.4321902367738586], [-48.80175855437068, -2.431279106936261]]]), bio21 = /* color: #99ffff */ee.Geometry.Polygon( [[[-48.79561688526974, -2.4336373240744575], [-48.79611041172848, -2.4353309502015335], [-48.792677184189415, -2.436488617468453], [-48.79205491169796, -2.434687801290026]]]), bio22 = /* color: #9999ff */ee.Geometry.Polygon( [[[-48.821035414394544, -2.409069112506573], [-48.821228533443616, -2.4103554343548743], [-48.818245917019055, -2.4109557174681133], [-48.81816008633058, -2.4096693961870197]]]), bio23 = /* color: #999900 */ee.Geometry.Polygon( [[[-48.866157862290834, -2.4048613405417867], [-48.86452707920978, -2.404604075232181], [-48.86607203160236, -2.399887535964711], [-48.86748823796222, -2.4003591906242403]]]), bio24 = /* color: #bf04c2 */ee.Geometry.Polygon( [[[-48.85369794322389, -2.4217996886159945], [-48.85256068660158, -2.4204276234947684], [-48.85376231624025, -2.419012679883881], [-48.85522143794435, -2.41989166017952]]]), bio25 = /* color: #98ff00 */ee.Geometry.Polygon( [[[-48.85992394401251, -2.4164472541205546], [-48.85863648368536, -2.41588985063302], [-48.860481843487605, -2.4110875957311872], [-48.8615976424378, -2.4113448598165848]]]), bio26 = /* color: #d63000 */ee.Geometry.Polygon( [[[-48.88140307380377, -2.4233075859797073], [-48.877991303936824, -2.422235661415694], [-48.87859211875616, -2.4211208589692257], [-48.87985812141119, -2.421463875204298], [-48.87992249442755, -2.4207778426473237], [-48.88078080131231, -2.4209279122988328], [-48.88090954734503, -2.421678260307125], [-48.88174639655767, -2.4222142229157555]]]), bio27 = /* color: #00ffff */ee.Geometry.Polygon( [[[-48.84953843070684, -2.4152466924785156], [-48.844989404217586, -2.4159756050306225], [-48.844002351300105, -2.415718341821595], [-48.84460316611944, -2.414474902291134], [-48.846491441265925, -2.413102829764635], [-48.8511692137879, -2.414303393301076]]]), bio28 = /* color: #ff00ff */ee.Geometry.Polygon( [[[-48.845356074150345, -2.404052738454031], [-48.845613566215775, -2.406025105384827], [-48.84372529106929, -2.405467697628276], [-48.844369021232865, -2.402680655429488], [-48.84617146569087, -2.4028950434929786]]]), bio29 = /* color: #0000ff */ee.Geometry.Polygon( [[[-48.87379679356525, -2.4031891151624323], [-48.8730672327132, -2.405375871015443], [-48.87177977238605, -2.4049042180886677], [-48.872595163926576, -2.4023315628912183], [-48.87332472477863, -2.4026317062473956]]]), bio30 = /* color: #ffc82d */ee.Geometry.Polygon( [[[-48.84863720847784, -2.418633988668989], [-48.84786473228155, -2.4179479546801925], [-48.84687767936407, -2.4179479546801925], [-48.84554730369268, -2.4171332888679773], [-48.849967584149226, -2.4162757453795343], [-48.85065422965704, -2.417176166028192]]]), bio31 = /* color: #0b4a8b */ee.Geometry.Polygon( [[[-48.845289811627254, -2.4223642924081736], [-48.84468899680792, -2.4232218320458174], [-48.841985330120906, -2.422021276401083], [-48.84005413963018, -2.4215925062700707], [-48.83945332481085, -2.4200060556056378], [-48.83971081687628, -2.41811946320991], [-48.8421999068421, -2.418248094592974], [-48.842757806317195, -2.420477703294447], [-48.844474420086726, -2.4211208589692257]]]), bio32 = /* color: #ffc82d */ee.Geometry.Polygon( [[[-48.807985058913005, -2.451360218370596], [-48.80768465150334, -2.45217486349114], [-48.80678342927433, -2.4515960367459666], [-48.80592512238957, -2.4476085568126678], [-48.80710529435612, -2.4472869853331627]]]), bio33 = /* color: #9999ff */ee.Geometry.Polygon( [[[-48.82064265796612, -2.4838366439277357], [-48.820234962195855, -2.481778641138547], [-48.82128638812969, -2.481371327706632], [-48.82203740665386, -2.4831292058304912]]]), bio34 = /* color: #009999 */ee.Geometry.Polygon( [[[-48.8495617778857, -2.3962918757038447], [-48.84668644982173, -2.395605830469459], [-48.84715851860835, -2.3939335937711212], [-48.84973343926265, -2.3945767619735574]]]), bio35 = /* color: #00ff00 */ee.Geometry.Polygon( [[[-48.86192357289707, -2.472685343629118], [-48.86270677792942, -2.4740251987612063], [-48.86083996045505, -2.4748291111907], [-48.8601640437833, -2.473660758299278]]]), bio36 = /* color: #d63000 */ee.Geometry.Polygon( [[[-48.8595269770783, -2.41755705798791], [-48.85763870193182, -2.4196151595064777], [-48.856994971768245, -2.418843371802944], [-48.85892616225897, -2.4168281462848205]]]), forest1 = /* color: #d63000 */ee.Geometry.Polygon( [[[-48.77578519987037, -2.4343317468059626], [-48.77432607547928, -2.4343317461335], [-48.77351068191223, -2.4323165396345625], [-48.77509855260763, -2.4319306487842804]]]), forest2 = /* color: #98ff00 */ee.Geometry.Polygon( [[[-48.774626483105635, -2.421361506231614], [-48.77278112330339, -2.420975612931896], [-48.77295278468034, -2.4185316194826227], [-48.7754847899904, -2.4185316194826227]]]), forest3 = /* color: #0b4a8b */ee.Geometry.Polygon( [[[-48.81936572947404, -2.4150371299732614], [-48.82013820567033, -2.4170952353130493], [-48.817820777081465, -2.4180385325510247], [-48.817348708294844, -2.4164735163204965]]]), forest4 = /* color: #ffc82d */ee.Geometry.Polygon( [[[-48.87904512941077, -2.408426408443283], [-48.87780058442786, -2.411556457631996], [-48.87574064790442, -2.4099271178564656], [-48.87737143098548, -2.4072258397223343]]]), forest5 = /* color: #00ffff */ee.Geometry.Polygon( [[[-48.81738796643151, -2.483759957699163], [-48.81515636853112, -2.483459832474628], [-48.814298061646355, -2.480844452632894], [-48.81489887646569, -2.4800298250681085]]]), forest6 = /* color: #bf04c2 */ee.Geometry.Polygon( [[[-48.8875708319506, -2.4536871775020614], [-48.88349387424796, -2.45471620104469], [-48.88272139805167, -2.4516291280412985], [-48.8855538107714, -2.451457623776667]]]), forest7 = /* color: #ff0000 */ee.Geometry.Polygon( [[[-48.855307623618216, -2.4367812233544477], [-48.8531618564063, -2.439096554398557], [-48.8517027347022, -2.4373814947483603], [-48.85389141725835, -2.4357521860565816]]]), forest8 = /* color: #00ff00 */ee.Geometry.Polygon( [[[-48.79350926367641, -2.429501057065105], [-48.79290844885708, -2.4317306472219724], [-48.79007603613735, -2.4293295499774517], [-48.79179264990688, -2.4276144779031816]]]), forest9 = /* color: #0000ff */ee.Geometry.Polygon( [[[-48.84180638639202, -2.4132097374826764], [-48.84180638639202, -2.416511284395592], [-48.84013268796673, -2.4166399159310683], [-48.839746449868585, -2.414453178170859], [-48.840776418130304, -2.4127380872689392]]]), forest10 = /* color: #999900 */ee.Geometry.Polygon( [[[-48.80607378289017, -2.483747025920699], [-48.80500089928421, -2.486576774711668], [-48.801396010368194, -2.4854620259120734], [-48.804142592399444, -2.482332149251468]]]), geometry = /* color: #bf04c2 */ee.Geometry.Polygon( [[[-49.070884888212845, -2.3481698074006556], [-49.05852526907222, -2.555346812523112], [-48.53118151907222, -2.5265360561793084], [-48.590233032744095, -2.282305651997937]]]), ag1 = /* color: #d63000 */ee.Geometry.Polygon( [[[-48.802018763497585, -2.446487079134353], [-48.801267744973416, -2.446680022146421], [-48.80040943808865, -2.4429497856622917], [-48.80098879523587, -2.4427782802873286]]]), ag2 = /* color: #99ffff */ee.Geometry.Polygon( [[[-48.799250723794216, -2.4444075804650423], [-48.79834950156521, -2.4444718949051727], [-48.797319533303494, -2.441084663533831], [-48.79834950156521, -2.440977472528237]]]), ag3 = /* color: #ff99ff */ee.Geometry.Polygon( [[[-48.801010252907986, -2.446808650805709], [-48.80032360740017, -2.4470873461918465], [-48.79914343543362, -2.442713965766069], [-48.79985153861355, -2.442628213066272]]]), ag4 = /* color: #98ff00 */ee.Geometry.Polygon( [[[-48.80489547172317, -2.437148764723429], [-48.80498130241165, -2.4382635539374924], [-48.803307603986354, -2.438520812855748], [-48.80292136588821, -2.437234517772667]]]), ag5 = /* color: #ffff99 */ee.Geometry.Polygon( [[[-48.79813492484402, -2.444986410315264], [-48.797534110024685, -2.4450507247276474], [-48.796289565041775, -2.4405487084203683], [-48.79674017615628, -2.4405058320020627]]]), ag6 = /* color: #ffc82d */ee.Geometry.Polygon( [[[-48.80375440705359, -2.433530242505135], [-48.80394752610266, -2.4344306516687078], [-48.80169447053015, -2.4343877750555105], [-48.80147989380896, -2.433744625693866]]]), ag7 = /* color: #0b4a8b */ee.Geometry.Polygon( [[[-48.80420882621536, -2.4353050728436445], [-48.80244929710159, -2.4353050728436445], [-48.80244929710159, -2.434811992029475], [-48.80408008018264, -2.4347691154284017]]]), ag8 = /* color: #00ffff */ee.Geometry.Polygon( [[[-48.80277412280361, -2.4230321871705094], [-48.80285995349209, -2.4240826726335745], [-48.799941710083885, -2.4245114419760383], [-48.79987733706753, -2.4235681492433185]]]), ag9 = /* color: #9999ff */ee.Geometry.Polygon( [[[-48.784390566831576, -2.4490393969725277], [-48.78398287106131, -2.449618224823084], [-48.78203022289847, -2.4468312736166324], [-48.78248083401297, -2.4460166252465028]]]), ag10 = /* color: #99ff99 */ee.Geometry.Polygon( [[[-48.7773524503765, -2.4537557647624655], [-48.775635836606966, -2.4565427015477477], [-48.77512085247611, -2.456113942420691], [-48.77696621227835, -2.453670012769223]]]), ag11 = /* color: #00ff00 */ee.Geometry.Polygon( [[[-48.81077517796405, -2.497562123174207], [-48.809788125046566, -2.4972191265058177], [-48.81021727848895, -2.4947752726522725], [-48.81077517796405, -2.494732397982712]]]), ag12 = /* color: #ff9999 */ee.Geometry.Polygon( [[[-48.79769536170795, -2.4773971352370308], [-48.79743786964252, -2.476754006578774], [-48.79906865272358, -2.4751676212201876], [-48.799626552198674, -2.475424873028962]]]), ag13 = /* color: #ff00ff */ee.Geometry.Polygon( [[[-48.79948844242938, -2.497562123174207], [-48.79875888157733, -2.496447383674554], [-48.800089257248715, -2.495075395300049], [-48.800818818100765, -2.495761389666297]]]), ag14 = /* color: #009999 */ee.Geometry.Polygon( [[[-48.80240668583758, -2.4974763740155], [-48.80137671757586, -2.498119492569287], [-48.80000342656024, -2.497947994319072], [-48.8014196329201, -2.4963187598252827], [-48.80240668583758, -2.496876129747889]]]), ag15 = /* color: #999900 */ee.Geometry.Polygon( [[[-48.803093331345394, -2.4961901359634284], [-48.802063363083676, -2.4955041418209007], [-48.802835839279965, -2.4943465258937696], [-48.803822892197445, -2.495032520640272]]]), ag16 = /* color: #0000ff */ee.Geometry.Polygon( [[[-48.80914439488299, -2.4970047535426083], [-48.80841483403094, -2.496876129747889], [-48.80850066471942, -2.4943894005759124], [-48.80953063298114, -2.4943465258937696]]]), ag17 = /* color: #ff0000 */ee.Geometry.Polygon( [[[-48.814594643601254, -2.49709050273209], [-48.81416549015887, -2.496447383674554], [-48.81335009861834, -2.496447383674554], [-48.81343592930682, -2.4951611446154045], [-48.81476630497821, -2.4951611446154045]]]), ag18 = /* color: #00ffff */ee.Geometry.Polygon( [[[-48.823855143466176, -2.4930880270230302], [-48.82248185245055, -2.4934738994811205], [-48.82248185245055, -2.4911586630356513], [-48.82351182071227, -2.4910729134594773]]]), ag19 = /* color: #ffc82d */ee.Geometry.Polygon( [[[-48.826387170820794, -2.492187657514142], [-48.82501387980517, -2.492745029187517], [-48.82492804911669, -2.491415911730663], [-48.82630134013232, -2.4910300386693103]]]), ag20 = /* color: #0b4a8b */ee.Geometry.Polygon( [[[-48.83449817088183, -2.492230532266626], [-48.83355403330859, -2.4925735302362315], [-48.833382371931634, -2.4900439181100107], [-48.83449817088183, -2.490429791460259]]]), ag21 = /* color: #98ff00 */ee.Geometry.Polygon( [[[-48.83943343546923, -2.4898295439777054], [-48.83947635081347, -2.4912872873894356], [-48.83677268412646, -2.4917589099125], [-48.836643938093744, -2.490429791460259]]]), ag22 = /* color: #d63000 */ee.Geometry.Polygon( [[[-48.84514117625292, -2.4940741453021142], [-48.84355330851611, -2.4926164049761454], [-48.844111207991205, -2.491844659444006], [-48.84518409159716, -2.492745029187517]]]), ag23 = /* color: #009999 */ee.Geometry.Polygon( [[[-48.82053321588842, -2.4658896166681323], [-48.82070487726537, -2.4669615063657857], [-48.81890243280736, -2.467390262002972], [-48.81843036402074, -2.46614687027434]]]), ag24 = /* color: #ff00ff */ee.Geometry.Polygon( [[[-48.817572057135976, -2.466189745870536], [-48.816327512153066, -2.466747128495362], [-48.81568378198949, -2.4651607311804216], [-48.81705707300512, -2.4645175965950488]]]), ag25 = /* color: #ff9999 */ee.Geometry.Polygon( [[[-48.81821578729955, -2.4679905196627536], [-48.81654208887426, -2.4685050260125516], [-48.81615585077611, -2.467390262002972], [-48.81774371851293, -2.467004381935723]]]), ag26 = /* color: #9999ff */ee.Geometry.Polygon( [[[-48.8231760805628, -2.473424967107637], [-48.821631128170225, -2.4737679699590758], [-48.82124489007208, -2.4724388334156746], [-48.82278984246466, -2.472138705624814]]]), ag27 = /* color: #99ff99 */ee.Geometry.Polygon( [[[-48.82248943505499, -2.4716670761020607], [-48.82128780541632, -2.4716670761020607], [-48.82094448266241, -2.4712383218450316], [-48.8202578371546, -2.4708953183397218], [-48.81991451440069, -2.470123560128797], [-48.82145946679327, -2.4697805563355457]]]), ag28 = /* color: #bf04c2 */ee.Geometry.Polygon( [[[-48.82242269509294, -2.479437567527947], [-48.822766017846845, -2.4802093203157844], [-48.82010526650407, -2.481109697999181], [-48.819761943750166, -2.4805523214103102]]]), ag29 = /* color: #ff99ff */ee.Geometry.Polygon( [[[-48.85295176890429, -2.4899152936348057], [-48.851621393232904, -2.490815664697471], [-48.851363901167474, -2.4889720470997445], [-48.85196471598681, -2.4888434225199245]]]); //====================================================================================================== // Sets general parameters including the cloud cover which is very important for this region // Tried many different combinations and this one seems to work ok though there are years with low quality imagery such as 2012 which was removed from the analysis // There is also the problem of L7 stripes which is partly solved through the use of medians var params = { t0: '2000-01-01', t1: '2018-12-30', roi: geometry, cloud: 75, }; // Sets band names var options = { 'L5': { 'bandNames': ['B1', 'B2', 'B3', 'B4', 'B5', 'B7'], 'newNames': ['blue', 'green', 'red', 'nir', 'swir1', 'swir2'], }, 'L7': { 'bandNames': ['B1', 'B2', 'B3', 'B4', 'B5', 'B7'], 'newNames': ['blue', 'green', 'red', 'nir', 'swir1', 'swir2'], }, 'L8': { 'bandNames': ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'], 'newNames': ['blue', 'green', 'red', 'nir', 'swir1', 'swir2'], } }; //====================================================================================================== // Sets cloud mask functions function cloudMaskL8(image) { var qa = image.select('pixel_qa'); var cloudShadowBitMask = (1 << 3); var cloudsBitMask = (1 << 5); var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and(qa.bitwiseAnd(cloudsBitMask).eq(0)); return image.updateMask(mask); } function cloudMaskL7 (image) { var qa = image.select('pixel_qa'); var cloud = qa.bitwiseAnd(1 << 5).and(qa.bitwiseAnd(1 << 7)).or(qa.bitwiseAnd(1 << 3)); var mask2 = image.mask().reduce(ee.Reducer.min()); return image.updateMask(cloud.not()).updateMask(mask2); } function cloudMaskL5 (image) { var qa = image.select('pixel_qa'); var cloud = qa.bitwiseAnd(1 << 5).and(qa.bitwiseAnd(1 << 7)).or(qa.bitwiseAnd(1 << 3)); var mask2 = image.mask().reduce(ee.Reducer.min()); return image.updateMask(cloud.not()).updateMask(mask2); } //====================================================================================================== // Sets other functions // This one to make a collection of images for the parameters defined above function getCollection(sr, t0, t1, roi, cloud){ var collection = null; if(sr == 'L5'){ collection = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR').filterDate(t0, t1).filterBounds(roi) .filterMetadata('CLOUD_COVER','less_than', cloud) .map(cloudMaskL5); }else if(sr == 'L7'){ collection = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR').filterDate(t0, t1).filterBounds(roi) .filterMetadata('CLOUD_COVER','less_than', cloud) .map(cloudMaskL7); }else if(sr == 'L8'){ collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterDate(t0, t1).filterBounds(roi) .filterMetadata('CLOUD_COVER','less_than', cloud) .map(cloudMaskL8); } return collection; } // This one combines everything as a collection // There are normally problems of band names given the differences between L8 and the others that's why I rename to facilitate function getCombineCollection(t0, t1, roi, cloud){ var L5 = getCollection('L5', t0, t1, roi, cloud) .select(options.L5.bandNames, options.L5.newNames); var L7 = getCollection('L7', t0, t1, roi, cloud) .select(options.L7.bandNames, options.L7.newNames) /*.map(function(img){ var filled1b = img.focal_mean(1, 'circle', 'pixels', 8); return filled1b.blend(img) }); // I tried this function in order to correct stripes problems and gaps but it didn't work well */ // I leave it here just in case something better comes up var L8 = getCollection('L8', t0, t1, roi, cloud) .select(options.L8.bandNames, options.L8.newNames); return ee.ImageCollection(L5.merge(L7).merge(L8)); } // improves the image quality by emilinating residues function edgeRemoval (image) { var edgeSize = -5500.0; image = image.clip( image.geometry() .buffer(edgeSize) .simplify(1) ); return image; } // function to simply clip the ares of interest function cut(img){ return img.clip(params.roi); } //====================================================================================================== // Creates vegetation indexes and add them as bands // In addition to the original bands each image would include 3 extra bands with names set below between '(...)' // This one for NDVI function addNdvi(img){ return img.addBands(img.normalizedDifference(['nir','red']).rename('ndvi')); } // Another option with EVI function addEvi(img){ var evi = img.expression('(2.5 * float(nir - red)/(nir + 2.4 * red + 1))',{ 'nir': img.select(['nir']), 'red': img.select(['red']), }); return img.addBands(evi.rename('evi')); } // And this one for WDRVI which is being increasingly used function addWdrvi(img){ var wdrvi= img.expression('(0.1 * (nir - red))/(0.1 *(nir + red))',{ 'nir': img.select(['nir']), 'red': img.select(['red']), }) .rename('WDRVI'); return img.addBands(wdrvi.rename('wdrvi')); }; // Differences between indexes are not so relevant though... // At least in this case //====================================================================================================== function imageYear(collection, s, e){ var list = ee.List([]); // Here this creates an empty list for (var i = s; i <= e; i++){ var imagem = collection.filterDate(i+'-01-01', i+'-12-30').median() .set('system:time_start', ee.Date(i+'-01-01').millis()); list = list.add(imagem); } return ee.ImageCollection(list); } // here we apply a filter per date and then the median which means that we will create one image per year which is the result of the median of the pixels for the selected period // I tried different combinations for example reducing the time interval to capture only the dry season but no significant changes //====================================================================================================== // Now finally a collection of images with all the functions introduced above var collection = getCombineCollection(params.t0, params.t1, params.roi, params.cloud) .map(edgeRemoval) .map(cut).map(addNdvi).map(addEvi).map(addWdrvi) var collection2000 = (imageYear(collection, 2000, 2000)); var collection2001 = (imageYear(collection, 2001, 2001)); var collection2002 = (imageYear(collection, 2002, 2002)); var collection2003 = (imageYear(collection, 2003, 2003)); var collection2004 = (imageYear(collection, 2004, 2004)); var collection2005 = (imageYear(collection, 2005, 2005)); var collection2006 = (imageYear(collection, 2006, 2006)); var collection2007 = (imageYear(collection, 2007, 2007)); var collection2008 = (imageYear(collection, 2008, 2008)); var collection2009 = (imageYear(collection, 2009, 2009)); var collection2010 = (imageYear(collection, 2010, 2010)); var collection2011 = (imageYear(collection, 2011, 2011)); var collection2012 = (imageYear(collection, 2012, 2012)); var collection2013 = (imageYear(collection, 2013, 2013)); var collection2014 = (imageYear(collection, 2014, 2014)); var collection2015 = (imageYear(collection, 2015, 2015)); var collection2016 = (imageYear(collection, 2016, 2016)); var collection2017 = (imageYear(collection, 2017, 2017)); var collection2018 = (imageYear(collection, 2018, 2018)); var collectionAnnual = (imageYear(collection, 2000, 2018)); // Created variables with one image per year just for vizualization purposes and the code below displays the images in GEE // Through this I am able to check which images are good // You can use /* (...) */ in order to unselect codes for faster vizualization of selected years /* Map.addLayer(collection2000, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2000') Map.addLayer(collection2001, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2001') */ // for example like above GEE doesn't read the codes (which turn green) // But in this case I ask GEE to display every image /* Map.addLayer(collection2000, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2000') Map.addLayer(collection2001, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2001') Map.addLayer(collection2002, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2002') Map.addLayer(collection2003, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2003') Map.addLayer(collection2004, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2004') Map.addLayer(collection2005, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2005') Map.addLayer(collection2006, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2006') Map.addLayer(collection2007, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2007') Map.addLayer(collection2008, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2008') Map.addLayer(collection2009, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2009') Map.addLayer(collection2010, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2010') Map.addLayer(collection2011, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2011') Map.addLayer(collection2012, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2012') Map.addLayer(collection2013, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2013') Map.addLayer(collection2014, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2014') Map.addLayer(collection2015, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2015') Map.addLayer(collection2016, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2016') Map.addLayer(collection2017, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2017') */ Map.addLayer(collection2018, { "bands": 'swir1,nir,red', "gain": '0.08,0.06,0.2', "gamma": '0.5', }, '2018') //====================================================================================================== // Sets the research area in the center of the screen for vizualization purposes Map.centerObject(geometry) //====================================================================================================== // Sets a collection with the polygons to run the analysis and creates labels var regions = ee.FeatureCollection([ ee.Feature(bio1, {label: 'bio 1'}), ee.Feature(bio2, {label: 'bio 2'}), ee.Feature(bio3, {label: 'bio 3'}), ee.Feature(bio4, {label: 'bio 4'}), ee.Feature(bio5, {label: 'bio 5'}), ee.Feature(bio6, {label: 'bio 6'}), ee.Feature(bio7, {label: 'bio 7'}), ee.Feature(bio8, {label: 'bio 8'}), ee.Feature(bio9, {label: 'bio 9'}), ee.Feature(bio10, {label: 'bio 10'}), ee.Feature(bio11, {label: 'bio 11'}), ee.Feature(bio12, {label: 'bio 12'}), ee.Feature(bio13, {label: 'bio 13'}), ee.Feature(bio14, {label: 'bio 14'}), ee.Feature(bio15, {label: 'bio 15'}), ee.Feature(bio16, {label: 'bio 16'}), ee.Feature(bio17, {label: 'bio 17'}), ee.Feature(bio18, {label: 'bio 18'}), ee.Feature(bio19, {label: 'bio 19'}), ee.Feature(bio20, {label: 'bio 20'}), ee.Feature(bio21, {label: 'bio 21'}), ee.Feature(bio22, {label: 'bio 22'}), ee.Feature(bio23, {label: 'bio 23'}), ee.Feature(bio24, {label: 'bio 24'}), ee.Feature(bio25, {label: 'bio 25'}), ee.Feature(bio26, {label: 'bio 26'}), ee.Feature(bio27, {label: 'bio 27'}), ee.Feature(bio28, {label: 'bio 28'}), ee.Feature(bio29, {label: 'bio 29'}), ee.Feature(bio30, {label: 'bio 30'}), ee.Feature(bio31, {label: 'bio 31'}), ee.Feature(bio32, {label: 'bio 32'}), ee.Feature(bio33, {label: 'bio 33'}), ee.Feature(bio34, {label: 'bio 34'}), ee.Feature(bio35, {label: 'bio 35'}), ee.Feature(bio36, {label: 'bio 36'}), ee.Feature(forest1, {label: 'forest1'}), ee.Feature(forest2, {label: 'forest2'}), ee.Feature(forest3, {label: 'forest3'}), ee.Feature(forest4, {label: 'forest4'}), ee.Feature(forest5, {label: 'forest5'}), ee.Feature(forest6, {label: 'forest6'}), ee.Feature(forest7, {label: 'forest7'}), ee.Feature(forest8, {label: 'forest8'}), ee.Feature(forest9, {label: 'forest9'}), ee.Feature(forest10, {label: 'forest10'}), ee.Feature(ag1, {label: 'ag 1'}), ee.Feature(ag2, {label: 'ag 2'}), ee.Feature(ag3, {label: 'ag 3'}), ee.Feature(ag4, {label: 'ag 4'}), ee.Feature(ag5, {label: 'ag 5'}), ee.Feature(ag6, {label: 'ag 6'}), ee.Feature(ag7, {label: 'ag 7'}), ee.Feature(ag8, {label: 'ag 8'}), ee.Feature(ag9, {label: 'ag 9'}), ee.Feature(ag10, {label: 'ag 10'}), ee.Feature(ag11, {label: 'ag 11'}), ee.Feature(ag12, {label: 'ag 12'}), ee.Feature(ag13, {label: 'ag 13'}), ee.Feature(ag14, {label: 'ag 14'}), ee.Feature(ag15, {label: 'ag 15'}), ee.Feature(ag16, {label: 'ag 16'}), ee.Feature(ag17, {label: 'ag 17'}), ee.Feature(ag18, {label: 'ag 18'}), ee.Feature(ag19, {label: 'ag 19'}), ee.Feature(ag20, {label: 'ag 20'}), ee.Feature(ag21, {label: 'ag 21'}), ee.Feature(ag22, {label: 'ag 22'}), ee.Feature(ag23, {label: 'ag 23'}), ee.Feature(ag24, {label: 'ag 24'}), ee.Feature(ag25, {label: 'ag 25'}), ee.Feature(ag26, {label: 'ag 26'}), ee.Feature(ag27, {label: 'ag 27'}), ee.Feature(ag28, {label: 'ag 28'}), ee.Feature(ag29, {label: 'ag 29'}), ]) // this is to set vizualization options for charts var opt = { title: 'NDVI variance', vAxis: {title: 'NDVI'}, lineWidth: 1, pointSize: 4 }; var opt1 = { title: 'EVI variance', vAxis: {title: 'EVI'}, lineWidth: 1, pointSize: 4, } var opt2 = { title: 'WDRVI variance', vAxis: {title: 'WDRVI'}, lineWidth: 1, pointSize: 4, } // And finally this is to launch the charts // You can see I selected the mean so it will give the mean value of the polygon // You can try different options with max or min but in this case works well with mean var chart = ui.Chart.image.seriesByRegion(collectionAnnual, regions, ee.Reducer.mean(), 'ndvi', 30, 'system:time_start', 'label') .setChartType('LineChart') .setOptions(opt); print(chart) var chart = ui.Chart.image.seriesByRegion(collectionAnnual, regions, ee.Reducer.mean(), 'evi', 30, 'system:time_start', 'label') .setChartType('LineChart') .setOptions(opt1); print(chart) var chart = ui.Chart.image.seriesByRegion(collectionAnnual, regions, ee.Reducer.mean(), 'wdrvi', 30, 'system:time_start', 'label') .setChartType('LineChart') .setOptions(opt2); print(chart) // You can download the data as csv, open in excel and click on the conditional formating option in the home tab // Select one of the color scales et voilá // If you want to download the images just use this, select bands and vizualization options // default option is TIF /* var Calmaria2000 = collection2000 .median() .visualize({bands: ['swir1', 'nir', 'red'], min: 300, max: 4350, gamma: [0.5]}); Export.image.toDrive({ image: Calmaria2000, description: 'Calmaria2000', scale: 30, region: geometry, maxPixels: 1e12 }); */