<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:"Gill Sans MT";
panose-1:2 11 5 2 2 1 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Texto de bal\00E3o Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EstiloDeEmail17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.TextodebaloChar
{mso-style-name:"Texto de bal\00E3o Char";
mso-style-priority:99;
mso-style-link:"Texto de bal\00E3o";
font-family:"Tahoma","sans-serif";}
span.shorttext
{mso-style-name:short_text;}
span.hps
{mso-style-name:hps;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'>Hello,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'>I am using the bfast in my jobs. But, I am attempting run the bfastmonitor on a raster brick (time serie MODIS EVI), I not get.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'>I followed the script proposed by you in this forum. </span><span class=hps><span lang=EN style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'>But</span></span><span class=shorttext><span lang=EN style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'> </span></span><span class=hps><span lang=EN style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'>I did not succeed.<o:p></o:p></span></span></p><p class=MsoNormal><span class=hps><span lang=EN style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'><o:p> </o:p></span></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'>Following is the script used:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'>################################################################################<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Gill Sans MT","sans-serif"'><o:p> </o:p></span></p><p class=MsoNormal>## TUTORIAL for processing raster bricks (satellite image time series of 16-day NDVI images)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>file<- brick("MT_micro.tif", native, package="raster")<o:p></o:p></p><p class=MsoNormal>file<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>## helper function for the calc function <o:p></o:p></p><p class=MsoNormal>xbfast <- function(file) {<o:p></o:p></p><p class=MsoNormal> ndvi <- ts(file, frequency=23, start=c(2000,9))<o:p></o:p></p><p class=MsoNormal> result <- bfast(ndvi, season="harmonic", max.iter=1, breaks=2)<o:p></o:p></p><p class=MsoNormal> return(cbind(result$Magnitude,result$Time)) ## save magnitude and time of the biggest break <o:p></o:p></p><p class=MsoNormal> }<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>## apply on a single pixel for testing<o:p></o:p></p><p class=MsoNormal>pixel <- as.vector(file[50])<o:p></o:p></p><p class=MsoNormal>ndvi <- ts(pixel, frequency=23, start=c(2000,9))<o:p></o:p></p><p class=MsoNormal>plot(ndvi)<o:p></o:p></p><p class=MsoNormal>result <- bfast(ndvi, season="harmonic", max.iter=1, breaks=2)<o:p></o:p></p><p class=MsoNormal>plot(result)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>## apply on a single pixel using the xbfast function <o:p></o:p></p><p class=MsoNormal>output <- xbfast(pixel)<o:p></o:p></p><p class=MsoNormal>output<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>## optimise function that takes into account the percentage of NA's within a time series <o:p></o:p></p><p class=MsoNormal>bfastfun <- function(y) {<o:p></o:p></p><p class=MsoNormal> percNA <- apply(y, 1, FUN=function(x) (sum(is.na(x))/length(x)) ) ## checks the percentage of NA's with the time series<o:p></o:p></p><p class=MsoNormal> <span lang=PT-BR>i <- (percNA<0.2)<o:p></o:p></span></p><p class=MsoNormal><span lang=PT-BR> res <- matrix(NA, length(i), 2)<o:p></o:p></span></p><p class=MsoNormal><span lang=PT-BR> </span>if (sum(i) > 0) {<o:p></o:p></p><p class=MsoNormal> res[i,] <- t(apply(y[i,], 1, xbfast))<o:p></o:p></p><p class=MsoNormal> }<o:p></o:p></p><p class=MsoNormal> res<o:p></o:p></p><p class=MsoNormal> }<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>##apply on the full satellite image time series <o:p></o:p></p><p class=MsoNormal>magntime <- calc(data, fun=bfastfun)<o:p></o:p></p><p class=MsoNormal>layerNames(magntime) <- c("Magnitude", "Time of biggest Break")<o:p></o:p></p><p class=MsoNormal>plot(magntime)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>## two rasters are returned: i.e. the magnitude and time of the biggest break ## WARNING: this is requires some time :-).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>###############################################################################################<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-family:"Gill Sans MT","sans-serif";color:#595959'>Polyanne Aguiar dos Santos<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Gill Sans MT","sans-serif";color:#595959'>Master in Applied Ecology – UFLA<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Gill Sans MT","sans-serif";color:#595959'>Specialist in Environmental Management – UNISAM<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Gill Sans MT","sans-serif";color:#595959'>Biologist – ESFA<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Gill Sans MT","sans-serif";color:#595959'>Phone: +55 35 9178 3275<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Gill Sans MT","sans-serif";color:#595959'>Skype: polyanne.aguiar<o:p></o:p></span></p><p class=MsoNormal align=center style='text-align:center'><o:p> </o:p></p><p class=MsoNormal><img width=134 height=45 id="Imagem_x0020_1" src="cid:image001.png@01CE0DD5.FC599ED0" alt="cid:image001.png@01CDF3FB.781F9910"><span lang=PT-BR><o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>