├── .gitignore
├── www
├── logo-wur.png
├── logo-tribes.png
├── logo-ms-research.png
├── styles.css
├── logo-fapesp.svg
├── logo-unicamp.svg
└── logo-cnpq.svg
├── md
├── images
│ ├── tutorial-01.jpg
│ ├── tutorial-02.jpg
│ ├── tutorial-03.jpg
│ ├── tutorial-04.jpg
│ ├── tutorial-05.jpg
│ ├── tutorial-06.jpg
│ ├── tutorial-07.jpg
│ ├── tutorial-08.jpg
│ ├── tutorial-09.jpg
│ ├── tutorial-10.jpg
│ ├── tutorial-11.jpg
│ ├── tutorial-12.jpg
│ ├── tutorial-13.jpg
│ └── tutorial-14.jpg
├── tutorial.md
└── tutorial.Rmd
├── bfast-explorer.Rproj
├── .gitattributes
├── README.md
├── test.R
├── python
├── gee-px-ls-new.py
└── gee-px-ls.py
├── sandbox.R
├── global.R
├── ui.R
├── server.R
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .Ruserdata
5 | .DS_Store
6 |
--------------------------------------------------------------------------------
/www/logo-wur.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/www/logo-wur.png
--------------------------------------------------------------------------------
/www/logo-tribes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/www/logo-tribes.png
--------------------------------------------------------------------------------
/md/images/tutorial-01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-01.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-02.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-03.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-04.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-04.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-05.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-05.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-06.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-06.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-07.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-07.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-08.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-08.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-09.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-09.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-10.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-11.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-12.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-13.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-13.jpg
--------------------------------------------------------------------------------
/md/images/tutorial-14.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/md/images/tutorial-14.jpg
--------------------------------------------------------------------------------
/www/logo-ms-research.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/almeidaxan/bfast-explorer/HEAD/www/logo-ms-research.png
--------------------------------------------------------------------------------
/bfast-explorer.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: Yes
4 | SaveWorkspace: No
5 | AlwaysSaveHistory: Yes
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 3
10 | Encoding: UTF-8
11 |
12 | RnwWeave: Sweave
13 | LaTeX: pdfLaTeX
14 |
15 | AutoAppendNewline: Yes
16 | StripTrailingWhitespace: Yes
17 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/www/styles.css:
--------------------------------------------------------------------------------
1 | /* customize map toolbar style */
2 | #map-toolbar {
3 | padding: 15px 15px 15px 15px;
4 | cursor: move;
5 | /* fade out while not hovering */
6 | opacity: 0.7;
7 | /* make sure that the toolbar is high enough to be above the Leaflet map */
8 | z-index: 500;
9 | transition: opacity 500ms 0s;
10 | }
11 | #map-toolbar:hover {
12 | /* fade in while hovering */
13 | opacity: 0.9;
14 | transition-delay: 0;
15 | }
16 |
17 | /* customize leaflet map */
18 | #map-leaflet {
19 | position: fixed;
20 | top: 51px;
21 | bottom: 0;
22 | left: 0;
23 | right: 0;
24 | padding: 0;
25 | overflow: hidden;
26 | background-color: rgb(0,0,0);
27 | }
28 |
29 | /* change leaflet container background color */
30 | .leaflet-container {
31 | background-color: rgb(0,0,0);
32 | }
33 |
34 | /* define a custom color to highlight text */
35 | .text-highlight {
36 | color: rgb(86,175,56);
37 | }
38 |
39 | .text-heading {
40 | margin-top: 0px;
41 | }
42 |
43 | /* highlight images in About tab when hovered */
44 | .image-highlight {
45 | border: 0;
46 | }
47 | .image-highlight img:hover {
48 | opacity: .7;
49 | }
50 |
51 | /* change Shiny error text color to blue and center it */
52 | .shiny-output-error-validation {
53 | color: blue;
54 | text-align: center;
55 | margin-left: auto;
56 | margin-right: auto;
57 | }
58 |
59 | .hidden-n {
60 | /* fade out while not hovering */
61 | opacity: 0.0;
62 | transition: opacity 500ms 0s;
63 | cursor: default;
64 | }
65 | .hidden-n:hover {
66 | /* fade in while hovering */
67 | opacity: 1.0;
68 | transition-delay: 0;
69 | }
70 |
71 | /* tutorial tab images */
72 | img[alt="md"] {
73 | max-width: 100%;
74 | width: auto;
75 | height: auto;
76 | }
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BFAST Explorer v0.0.3
2 |
3 | ## Description
4 |
5 | **BFAST Explorer** is a [Shiny](https://shiny.rstudio.com/) app, developed using R and Python, designed for the analysis of *Landsat Surface Reflectance* time series pixel data.
6 |
7 | Three change detection algorithms - **bfastmonitor**, **bfast01** and **bfast** - are used in order to investigate temporal changes in trend and seasonal components, via breakpoint detection.
8 |
9 | If you encounter any bugs, please create an [issue](https://github.com/almeidaxan/bfast-explorer/issues).
10 |
11 | ## Usage
12 |
13 | Currently, this tool only supports UNIX-like systems (no Windows OS) due to the integration between R and Python.
14 |
15 | In order to successfully run this tool, apart from having R and Python installed, you need the following:
16 |
17 | * Request access to use GEE (https://earthengine.google.com/signup/)
18 | * Install and set up GEE Python API (https://developers.google.com/earth-engine/python_install)
19 |
20 | ## Citation
21 |
22 | To cite BFAST Explorer in publications, please use
23 |
24 | > Alexandre Almeida, Nathalia Menini, Jan Verbesselt, Ricardo Torres (2018). BFAST Explorer: An Effective Tool for Time Series Analysis. In: 2018 IEEE International Geoscience and Remote Sensing Symposium (IGARSS). 22-27 July 2018. Valencia, Spain. DOI: 10.1109/IGARSS.2018.8517877.
25 |
26 | or, alternatively, the corresponding BibTeX entry
27 |
28 | ```
29 | @inproceedings{,
30 | author = {Alexandre Almeida and Nathalia Menini and Jan Verbesselt and Ricardo Torres},
31 | title = {BFAST Explorer: An Effective Tool for Time Series Analysis},
32 | booktitle = {2018 IEEE International Geoscience and Remote Sensing Symposium (IGARSS)},
33 | location = {Valencia, Spain},
34 | eventdate = {2018-07-22/2018-07-27},
35 | doi = {10.1109/IGARSS.2018.8517877}
36 | }
37 | ```
38 |
--------------------------------------------------------------------------------
/test.R:
--------------------------------------------------------------------------------
1 | # BFAST01
2 |
3 | z <- rbind(serie[[1]], serie[[2]], serie[[3]]) # serie[, matchCol]
4 | z <- z[order(z$date), ]
5 | date <- z$date # serie$date
6 | z <- z$ndvi
7 |
8 | res <- ppBfast(x = z, date = date, h = 0.15)
9 |
10 | plot(
11 | res,
12 | regular = F
13 | )
14 |
15 | # -----
16 |
17 | ### nao incluir pois ja existe
18 | ylimCustom <- c(0,1)
19 | xAxisCustom <- seq(as.numeric(substr(range(date), 1, 4))[1] - 1,
20 | as.numeric(substr(range(date), 1, 4))[2] + 1,
21 | 1)
22 | yAxisStep <- 0.1
23 |
24 | # -----
25 |
26 | par(mar = c(4, 4, 0, 0) + 0.1)
27 | plot(y = z,
28 | x = date,
29 | col = "white",
30 | axes = F,
31 | ylim = ylimCustom, # ylimCustom
32 | ylab = "NDVI", # ylab
33 | xlab = "Time")
34 |
35 | # redraw axis
36 | axis(side = 1,
37 | at = date(paste0(xAxisCustom, "-01-01")),
38 | labels = xAxisCustom)
39 | axis(side = 2,
40 | at = seq(0, 1, 0.1))
41 | for(i in xAxisCustom) {
42 | abline(v = date(paste0(i, "-01-01")),
43 | col = rgb(.8, .8, .8),
44 | lty = 2)
45 | }
46 | for(i in seq(ylimCustom[1], ylimCustom[2], yAxisStep)) {
47 | if(i == 0) {
48 | # highlight a guide line at "0"
49 | abline(h = i,
50 | col = "black",
51 | lty = 3,
52 | lwd = 1.3)
53 | } else {
54 | abline(h = i,
55 | col = rgb(.8, .8, .8),
56 | lty = 2)
57 | }
58 | }
59 | box()
60 |
61 | lines(y = res$Yt, x = as.Date(time(res$Yt)), col = "gray", lwd = 2)
62 | lines(y = res$output[[1]]$Tt + res$output[[1]]$St, x = as.Date(time(res$Yt)), col = "blue", lwd = 2)
63 |
64 | if(!res$nobp$Vt & !is.na(res$output[[1]]$Vt.bp)[1]) {
65 | for(i in 1:length(res$output[[1]]$Vt.bp)) {
66 | abline(
67 | v = as.Date(time(res$Yt))[res$output[[1]]$Vt.bp[i]],
68 | lty = 2,
69 | lwd = 1.5,
70 | col = "red"
71 | )
72 | }
73 | }
74 | if(!res$nobp$Wt & !is.na(res$output[[1]]$Wt.bp)[1]) {
75 | for(i in 1:length(res$output[[1]]$Wt.bp)) {
76 | abline(
77 | v = as.Date(time(res$Yt))[res$output[[1]]$Wt.bp[i]],
78 | lty = 2,
79 | lwd = 1.5,
80 | col = "darkgreen"
81 | )
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/www/logo-fapesp.svg:
--------------------------------------------------------------------------------
1 |
2 | image/svg+xml
--------------------------------------------------------------------------------
/python/gee-px-ls-new.py:
--------------------------------------------------------------------------------
1 | import ee
2 | import numpy
3 | import ssl
4 | from datetime import datetime
5 |
6 | # Earth Engine API init
7 | ee.Initialize()
8 |
9 | # Convert YYYYMMDD format to YYYY-MM-DD
10 | def convertDate(s):
11 | return datetime.strptime(s, '%Y%m%d').strftime('%Y_%m_%d')
12 |
13 | # Function to calculate and add some spectral-band-based indexes (LS 4,5,7)
14 | def getVi(image):
15 | scalingFactor = 0.0001
16 | b1 = image.select(['B1']).multiply(scalingFactor)
17 | b2 = image.select(['B2']).multiply(scalingFactor)
18 | b3 = image.select(['B3']).multiply(scalingFactor)
19 | b4 = image.select(['B4']).multiply(scalingFactor)
20 | b5 = image.select(['B5']).multiply(scalingFactor)
21 | b7 = image.select(['B7']).multiply(scalingFactor)
22 | evi = image.expression('2.5*(NIR - R)/(NIR + 6.0*R - 7.5*B + 1)', {'R': b3, 'NIR': b4, 'B': b1})
23 | evi2 = image.expression('2.5*(NIR - R)/(NIR + 2.4*R + 1)', {'R': b3, 'NIR': b4})
24 | ndvi = image.normalizedDifference(['B4','B3'])
25 | ndmi = image.normalizedDifference(['B4','B5'])
26 | image2 = (
27 | image.select(['pixel_qa'])
28 | .addBands(b1.select([0],['b1']))
29 | .addBands(b2.select([0],['b2']))
30 | .addBands(b3.select([0],['b3']))
31 | .addBands(b4.select([0],['b4']))
32 | .addBands(b5.select([0],['b5']))
33 | .addBands(b7.select([0],['b7']))
34 | .addBands(evi.select([0],['evi']))
35 | .addBands(evi2.select([0],['evi2']))
36 | .addBands(ndvi.select([0],['ndvi']))
37 | .addBands(ndmi.select([0],['ndmi']))
38 | )
39 | return(image2)
40 |
41 | # Function to calculate and add some spectral-band-based indexes (LS 8)
42 | def getVi8(image):
43 | scalingFactor = 0.0001
44 | b1 = image.select(['B1']).multiply(scalingFactor)
45 | b2 = image.select(['B2']).multiply(scalingFactor)
46 | b3 = image.select(['B3']).multiply(scalingFactor)
47 | b4 = image.select(['B4']).multiply(scalingFactor)
48 | b5 = image.select(['B5']).multiply(scalingFactor)
49 | b7 = image.select(['B7']).multiply(scalingFactor)
50 | evi = image.expression('2.5*(NIR - R)/(NIR + 6.0*R - 7.5*B + 1)', {'R': b4, 'NIR': b5, 'B': b2})
51 | evi2 = image.expression('2.5*(NIR - R)/(NIR + 2.4*R + 1)', {'R': b4, 'NIR': b5})
52 | ndvi = image.normalizedDifference(['B5','B4'])
53 | ndmi = image.normalizedDifference(['B5','B6'])
54 | image2 = (
55 | image.select(['pixel_qa'])
56 | .addBands(b1.select([0],['b1']))
57 | .addBands(b2.select([0],['b2']))
58 | .addBands(b3.select([0],['b3']))
59 | .addBands(b4.select([0],['b4']))
60 | .addBands(b5.select([0],['b5']))
61 | .addBands(b7.select([0],['b7']))
62 | .addBands(evi.select([0],['evi']))
63 | .addBands(evi2.select([0],['evi2']))
64 | .addBands(ndvi.select([0],['ndvi']))
65 | .addBands(ndmi.select([0],['ndmi']))
66 | )
67 | return(image2)
68 |
69 | # Create a geometry point with provided coordinates
70 | longCen = float(coords[0])
71 | latCen = float(coords[1])
72 | bounds = ee.Geometry.Point([longCen, latCen])
73 |
74 | # Define the image collection
75 | imgCol = ee.ImageCollection('LANDSAT/' + satChoice)
76 |
77 | # Get time series from GEE
78 | if satChoice == 'LC08/C01/T1_SR':
79 | values = imgCol.filterBounds(bounds).map(getVi8).getRegion(bounds, 30)
80 | else:
81 | values = imgCol.filterBounds(bounds).map(getVi).getRegion(bounds, 30)
82 |
83 | # Get time series info and apply cfmask filter
84 | try:
85 | aux = values.getInfo()
86 | serie = []
87 | # for i in range(1, len(aux)):
88 | # print aux[i][4] == None
89 | for i in range(1, len(aux)):
90 | serie += [convertDate(str(aux[i][0])[12:20])] + \
91 | ['NA' if v is None else v for v in aux[i][5:15]]
92 | #numpy.round(aux[i][5:15], 4).tolist()
93 |
94 | # Additional variables to be used in R
95 | if len(aux) > 0:
96 | colNames = [u'date'] + aux[0][5:15]
97 | numCol = len(colNames)
98 | numRow = len(aux) - 1
99 | except ee.ee_exception.EEException:
100 | # No data available
101 | serie = []
102 |
--------------------------------------------------------------------------------
/python/gee-px-ls.py:
--------------------------------------------------------------------------------
1 | import ee
2 | import numpy
3 | import ssl
4 | from datetime import datetime
5 |
6 | # earth engine API init
7 | ee.Initialize()
8 |
9 | # convert Julian day to YYYY-MM-DD date
10 | def julianDayToDate(s):
11 | return datetime.strptime(s, '%Y%j').strftime('%Y_%m_%d')
12 |
13 | # function to calculate and add some spectral-bands-based indexes (LS 4,5,7)
14 | def getVi(image):
15 | scalingFactor = 0.0001
16 | b1 = image.select(['B1']).multiply(scalingFactor)
17 | b2 = image.select(['B2']).multiply(scalingFactor)
18 | b3 = image.select(['B3']).multiply(scalingFactor)
19 | b4 = image.select(['B4']).multiply(scalingFactor)
20 | b5 = image.select(['B5']).multiply(scalingFactor)
21 | b7 = image.select(['B7']).multiply(scalingFactor)
22 | evi = image.expression('2.5 * (NIR - R) / (NIR + 6.0*R - 7.5*B + 1)', {'R': b3, 'NIR': b4, 'B': b1})
23 | evi2 = image.expression('2.5 * (NIR - R) / (NIR + 2.4*R + 1)', {'R': b3, 'NIR': b4})
24 | ndvi = image.normalizedDifference(['B4','B3'])
25 | ndmi = image.normalizedDifference(['B4','B5'])
26 | image2 = (
27 | image.select(['cfmask'])
28 | .addBands(b1.select([0],['b1']))
29 | .addBands(b2.select([0],['b2']))
30 | .addBands(b3.select([0],['b3']))
31 | .addBands(b4.select([0],['b4']))
32 | .addBands(b5.select([0],['b5']))
33 | .addBands(b7.select([0],['b7']))
34 | .addBands(evi.select([0],['evi']))
35 | .addBands(evi2.select([0],['evi2']))
36 | .addBands(ndvi.select([0],['ndvi']))
37 | .addBands(ndmi.select([0],['ndmi']))
38 | )
39 | return(image2)
40 |
41 | # function to calculate and add some spectral-bands-based indexes (LS 8)
42 | def getVi8(image):
43 | scalingFactor = 0.0001
44 | b1 = image.select(['B1']).multiply(scalingFactor)
45 | b2 = image.select(['B2']).multiply(scalingFactor)
46 | b3 = image.select(['B3']).multiply(scalingFactor)
47 | b4 = image.select(['B4']).multiply(scalingFactor)
48 | b5 = image.select(['B5']).multiply(scalingFactor)
49 | # b6 = image.select(['B6']).multiply(scalingFactor)
50 | b7 = image.select(['B7']).multiply(scalingFactor)
51 | evi = image.expression('2.5 * (NIR - R) / (NIR + 6.0*R - 7.5*B + 1)', {'R': b4, 'NIR': b5, 'B': b2})
52 | evi2 = image.expression('2.5 * (NIR - R) / (NIR + 2.4*R + 1)', {'R': b4, 'NIR': b5})
53 | ndvi = image.normalizedDifference(['B5','B4'])
54 | ndmi = image.normalizedDifference(['B5','B6'])
55 | image2 = (
56 | image.select(['cfmask'])
57 | .addBands(b1.select([0],['b1']))
58 | .addBands(b2.select([0],['b2']))
59 | .addBands(b3.select([0],['b3']))
60 | .addBands(b4.select([0],['b4']))
61 | .addBands(b5.select([0],['b5']))
62 | # .addBands(b6.select([0],['b6']))
63 | .addBands(b7.select([0],['b7']))
64 | .addBands(evi.select([0],['evi']))
65 | .addBands(evi2.select([0],['evi2']))
66 | .addBands(ndvi.select([0],['ndvi']))
67 | .addBands(ndmi.select([0],['ndmi']))
68 | )
69 | return(image2)
70 |
71 | # create a geometry point with provided coordinates
72 | longCen = float(coords[0])
73 | latCen = float(coords[1])
74 | bounds = ee.Geometry.Point([longCen, latCen])
75 |
76 | # define image collection
77 | imgCol = ee.ImageCollection('LANDSAT/' + satChoice)
78 |
79 | # get time series from GEE
80 | if satChoice == 'LC8_SR':
81 | values = imgCol.filterBounds(bounds).map(getVi8).getRegion(bounds, 30)
82 | else:
83 | values = imgCol.filterBounds(bounds).map(getVi).getRegion(bounds, 30)
84 |
85 | # get time series info and apply cfmask filter
86 | try:
87 | aux = values.getInfo()
88 | serie = []
89 | for i in range(1, len(aux)):
90 | # filtering using cfmask (only clear pixels are kept [value = 0])
91 | if aux[i][4] == 0:
92 | serie += [julianDayToDate(str(aux[i][0])[9:16])] + \
93 | numpy.round(aux[i][5:15], 4).tolist()
94 |
95 | # additional variables to be used in R
96 | if len(aux) > 0:
97 | colNames = [u'date'] + aux[0][5:15]
98 | numCol = len(colNames)
99 | numRow = len(aux) - 1
100 | except ee.ee_exception.EEException:
101 | # no data available
102 | serie = []
103 |
--------------------------------------------------------------------------------
/sandbox.R:
--------------------------------------------------------------------------------
1 | # ------------------------------------------------------ TO-DO ADVANCES ----
2 |
3 | ## Dynamically set 'harmonic order' parameter for bfastmonitor
4 |
5 | # currently, error occurs when:
6 | # condition: ht = "ROC"; order > 9
7 | # error msg: history_roc > Error in if: missing value where TRUE/FALSE needed
8 | #
9 | # condition: ht = "BP"; order > 1
10 | # error msg: history_break -> Error in breakpoints.formula: minimum segment size must be smaller than half the number of observations
11 | #
12 | # condition: ht = "all"; order > 18
13 | # error msg: monitor -> Error in if: missing value where TRUE/FALSE needed
14 |
15 | library(strucchange)
16 | load("test.RData")
17 |
18 | x <- rbind(serie[[1]])
19 | x <- x[order(x$date), ]
20 |
21 | if(input$select_bfm_formula != "trend") {
22 | if(input$select_bfm_history == "ROC") {
23 | orderMaxBfm <- 0
24 | cond4 <- F
25 | while(!cond4) {
26 | orderMaxBfm <- orderMaxBfm + 1
27 | data <- bfastts(data = serieSel()[, matchCol],
28 | dates = serieSel()$date,
29 | type = "irregular")
30 | data_tspp <- bfastpp(data, order = orderMaxBfm, lag = NULL, slag = NULL)
31 | history_tspp <- subset(data_tspp, time < decimal_date(input$select_bfm_monitor))
32 | data_rev <- history_tspp[nrow(history_tspp):1,]
33 | data_rev$response <- ts(data_rev$response)
34 | suppressWarnings(
35 | y_rcus <- efp(bfm_formula, data = data_rev, type = "Rec-CUSUM")
36 | )
37 | cond4 <- is.na(y_rcus$process[1])
38 | }
39 | orderMaxBfm <- orderMaxBfm - 1
40 | updateSliderInput(
41 | session = session,
42 | inputId = "select_bfm_order",
43 | max = orderMaxBfm
44 | )
45 | }
46 | }
47 |
48 | # ----------------------------------------------------- DISCARDED CODE ----
49 |
50 | # discarded code which my be useful in the future
51 |
52 | ## map draw toolbar observer
53 | coordsDf <- reactive({
54 | # check if no markers are drawn on the map
55 | validate(
56 | need(!is.null(input$leaf_drawLayer_created$geometry$coordinates[[1]]),
57 | "Place at least one marker on the map")
58 | )
59 |
60 | # create a data.frame with marker's lng-lat coordinates
61 | coords <- input$leaf_drawLayer_features$features %>%
62 | sapply(function(x) {
63 | c(x$geometry$coordinates[[1]],
64 | x$geometry$coordinates[[2]])
65 | }) %>%
66 | t() %>%
67 | data.frame()
68 |
69 | # add names to dataframe columns
70 | if(ncol(coords) > 0) coords <- coords %>% setNames(c("lon", "lat"))
71 |
72 | # if at least one point is drawn and shown on map, show output list
73 | output$mapDraw <- renderPrint(coords)
74 |
75 | return(coords)
76 | })
77 |
78 | ## coords data.frame observer to update input$select_coords
79 | observe({
80 | coords <- coordsDf()
81 |
82 | if(ncol(coords) > 0) {
83 | # change the available choices of input$select_coords to 1:nrow(z)
84 | updateSelectInput(session,
85 | inputId = "select_coords",
86 | label = "Now, select a marker from the list below",
87 | choices = 1:nrow(coords))
88 | } else {
89 | # if all points are deleted after drawn, reset input$select_coords
90 | updateSelectInput(session,
91 | inputId = "select_coords",
92 | label = "Place at least one marker on the map",
93 | choices = "")
94 | }
95 | })
96 |
97 | ## overlaying custom Tiles on the map
98 | addTiles(
99 | map = m,
100 | urlTemplate = "https://earthengine.googleapis.com/map/47fdcba98ca0ee3bdd8c25059f8403f3/{z}/{x}/{y}?token=18335d5369c9a0ccebcd45458d1a1d79",
101 | options = list(
102 | minZoom = 3,
103 | maxZoom = 19,
104 | noWrap = T,
105 | unloadInvisibleTiles = T,
106 | updateWhenIdle = T,
107 | reuseTiles = T,
108 | opacity = 0.5
109 | )
110 | )
111 |
112 | ## save a fixed time series to easily debug the Analysis tab
113 |
114 | k <- c(-47.109375, -4.56547355071028)
115 | python.assign("coords", k)
116 |
117 | serieList <- list()
118 | for (i in 1:3) {
119 | # assign Python variables using Shiny inputs
120 | python.assign("satChoice", c("LT5_SR", "LE7_SR", "LC8_SR")[i])
121 |
122 | # execute Python download script
123 | python.load(paste0(getwd(), "/python/gee-px-ls.py"))
124 |
125 | # get Python output and show download message
126 | if (is.null(unlist(python.get("serie")))) {
127 | serieList[[i]] <- NA
128 | } else {
129 | serieList[[i]] <- unlist(python.get("serie"))
130 | }
131 | }
132 |
133 | # remove from serieList those satellites with no data
134 | # also keep track of the satellites names in satOrder
135 | satOrder <- c("LT5_SR", "LE7_SR", "LC8_SR")
136 | serieList[is.na(serieList)] <- NULL
137 | satOrder[-is.na(serieList)]
138 |
139 | # arrange each list element form serieList as a df
140 | serie <- lapply(serieList, function(x) {
141 | tmp <- data.frame(matrix(x,
142 | ncol = python.get("numCol"),
143 | byrow = T))
144 |
145 | # format data type and columns names
146 | tmp[, 1] <- as.Date(tmp[, 1], format = "%Y_%m_%d")
147 | tmp[, 2:ncol(tmp)] <- apply(tmp[, 2:ncol(tmp)],
148 | MARGIN = 2,
149 | as.numeric)
150 | colnames(tmp) <- python.get("colNames")
151 |
152 | # exclude saturated data
153 | filterWhich <- which(rowSums(tmp[, 2:ncol(tmp)] == 2) > 0)
154 | if (length(filterWhich) > 0) {
155 | tmp <- tmp[-filterWhich, ]
156 | }
157 |
158 | return(tmp)
159 | })
160 |
161 | # create new column for each list element with corresponding satellite
162 | # name, also include this info as an attribute of the list
163 | for (i in 1:length(serie)) {
164 | serie[[i]]$sat <- satOrder[i]
165 | }
166 | attributes(serie) <- list(satOrder = satOrder)
167 |
168 | save(file = "test.RData",
169 | list = "serie",
170 | envir = .GlobalEnv)
171 |
172 | # load the previously saved data
173 | load("test.RData")
174 |
--------------------------------------------------------------------------------
/www/logo-unicamp.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
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 |
--------------------------------------------------------------------------------
/md/tutorial.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | *This tutorial comprehends the BFAST Explorer v0.0.1. Notice that if you are using a newer version, some features might be different.*
4 |
5 | ***
6 |
7 | ## Description
8 |
9 | **BFAST Explorer** is a [Shiny](https://shiny.rstudio.com/) app, developed using R and Python, designed for the analysis of *Landsat Surface Reflectance* time series pixel data.
10 |
11 | Three change detection algorithms - **bfastmonitor**, **bfast01** and **bfast** - are used in order to investigate temporal changes in trend and seasonal components, via breakpoint detection.
12 |
13 | If you encounter any bugs, please send a message to almeida.xan@gmail.com, or create an issue on the [GitHub page](https://github.com/almeidaxan/bfast-explorer/).
14 |
15 | ## Tutorial
16 |
17 | Albeit very simple, please follow this short usage guide to learn how to
18 | properly use the tool.
19 |
20 | ### Map Tab
21 |
22 | This is the starting tab, which we first see when we run the tool. The
23 | tab is composed of an interactive map (rendered using Google Maps engine)
24 | and a navigation toolbar. Feel free to zoom and pan the map.
25 |
26 | 
27 |
28 | If we wish, we can also use the *search field* located on the top of the
29 | toolbar to search for a location. Then, the map
30 | automatically zooms to the desired location, similar to how Google Maps
31 | works. In the example, we searched for `unicamp campinas`, which is the
32 | University of Campinas.
33 |
34 | 
35 |
36 | Now, let's zoom out all the way back and place a marker at the north of
37 | Brazil, as shown. To *place* a marker, simply click on the map. If we want
38 | to, we can also place multiple markers.
39 |
40 | We may also wish to clear all the placed markers. To do that, click on the
41 | **[ Clear Markers]** red button on the left side
42 | of the toolbar.
43 |
44 | 
45 |
46 | After that, we need to *select* one of the markers in order download its
47 | Landsat pixel data. To do that, simply click on an already placer marker,
48 | and it will be highlighted. Only one marker may be selected at a time.
49 |
50 | By selecting a marker, we can now choose a combination of which satellites
51 | to download from using the drop-down menu, located on the bottom of the
52 | toolbar. For instance, let's choose all the available satellites products:
53 | Landsat 5, 7 and 8 SR.
54 |
55 | 
56 |
57 | Then, we press the **[ Get Data]** blue
58 | button, located on the right side of the toolbar. By pressing that button,
59 | the download will start. We can keep track of the download progress by
60 | looking to the lower right corner. All the historical data available are
61 | downloaded, which should take less than 10 seconds for the three products
62 | selected.
63 |
64 | Note: as of the writing of this guide, not all Surface Reflectance
65 | data are availble from GEE. So, depending on where we place our markers,
66 | we may face a message indicating that *'No data available for the chosen*
67 | *satellite(s) and/or region... Please change your query and try again.'*.
68 | Since we rely heavily on GEE to download the data, there's nothing we can
69 | do yet. We're sorry for that.
70 |
71 | 
72 |
73 | If the download is successful, we'll receive a message directing to the
74 | ** Analysis** tab.
75 |
76 | ### Analysis Tab
77 |
78 | In this tab, we can analyze the downloaded data and, then,
79 | locally save the results as files.
80 |
81 | 
82 |
83 | First, let's choose which satellite time series date to visualize. Note
84 | that, even though we downloaded data from Landsat 5, 7 and 8 SR, we're
85 | can still analyze them separately. However, let's proceed by choosing
86 | all of them.
87 |
88 | As we can see, the time series of the first spectral band
89 | (`b1`) is plotted for all satellites. A colored legend distinguishes the
90 | different sources.
91 |
92 | Note: be careful when comparing *spectral bands* data from
93 | different satellites, as they may not correspond to the same wavelength range! Read more about this [here](https://landsat.usgs.gov/what-are-band-designations-landsat-satellites).
94 |
95 | 
96 |
97 | Apart from the spectral bands, there are also four spectral-bands-derived
98 | indexes available: NDVI, NDMI, EVI and EVI2. Let's check, for example, the
99 | NDVI time series.
100 |
101 | 
102 |
103 | If we want to, we can also download *all* the time series data as a file.
104 | To do that, press the **[ Data]** blue
105 | button. All the data will be downloaded as a .CSV, ordered by the acquisiton
106 | date. Also, an additional column is included, in order to distinguish the
107 | satellite sources.
108 |
109 | 
110 |
111 | We may download the time series plot as an image, by pressing the
112 | **[ Plot]** blue button. A window will appear
113 | offering some raster (.JPEG, .PNG) and a vectorial (.SVG) image output
114 | formats.
115 |
116 | 
117 |
118 | Next, we select the *change detection algorithm*. Three options are available: **bfastmonitor**, **bfast01** and **bfast**. More information
119 | about these algorithms can be found [here](http://bfast.r-forge.r-project.org/).
120 |
121 | 
122 |
123 | By selecting **bfastmonitor**, we are able to tweak four parameters on the
124 | left side-bar: `formula`, `history period type`, `harmonic order`, and
125 | `start of monitoring`. These parameters have different impacts on the
126 | results, which can be verified on the right side plot. Here, we set the
127 | maximum value of the `harmonic order` to 9 to avoid some problems.
128 |
129 | Similar to the time series, we can also download the *results* of the change detection algorithms as .RDS data files, by clicking on the **[ Results]** blue button. If we wish to download the plot, we can press the **[ Plot]** blue button.
130 |
131 | For more information on how to load .RDS files on R, please check this [link](http://www.fromthebottomoftheheap.net/2012/04/01/saving-and-loading-r-objects/).
132 |
133 | 
134 |
135 | By selecting **bfast01**, we can tweak two parameters: `formula`, and `harmonic order`.
136 | Here, the maximum value of the `harmonic order` is dynamically set
137 | depending on the time series data length and the choice of the `formula`
138 | parameter.
139 |
140 | 
141 |
142 | Finally, by selecting **bfast**, we may tweak two parameters: `h` (minimal
143 | segment size), and `season type`. Please note that, since **bfast** can
144 | detect multiple breakpoints, it may take a couple of seconds to process,
145 | in comparison to the previous two algorithms.
146 |
147 | 
148 |
--------------------------------------------------------------------------------
/md/tutorial.Rmd:
--------------------------------------------------------------------------------
1 | ```{r setup, include = F, echo = F}
2 | htmltools::tagList(rmarkdown::html_dependency_font_awesome())
3 | ```
4 |
5 | *This tutorial comprehends the BFAST Explorer v0.0.1. Notice that if you are using a newer version, some features might be different.*
6 |
7 | ***
8 |
9 | ## Description
10 |
11 | **BFAST Explorer** is a [Shiny](https://shiny.rstudio.com/) app, developed using R and Python, designed for the analysis of *Landsat Surface Reflectance* time series pixel data.
12 |
13 | Three change detection algorithms - **bfastmonitor**, **bfast01** and **bfast** - are used in order to investigate temporal changes in trend and seasonal components, via breakpoint detection.
14 |
15 | If you encounter any bugs, please send a message to almeida.xan@gmail.com, or create an issue on the [GitHub page](https://github.com/almeidaxan/bfast-explorer/).
16 |
17 | ## Tutorial
18 |
19 | Albeit very simple, please follow this short usage guide to learn how to
20 | properly use the tool.
21 |
22 | ### Map Tab
23 |
24 | This is the starting tab, which we first see when we run the tool. The
25 | tab is composed of an interactive map (rendered using Google Maps engine)
26 | and a navigation toolbar. Feel free to zoom and pan the map.
27 |
28 | 
29 |
30 | If we wish, we can also use the *search field* located on the top of the
31 | toolbar to search for a location. Then, the map
32 | automatically zooms to the desired location, similar to how Google Maps
33 | works. In the example, we searched for `unicamp campinas`, which is the
34 | University of Campinas.
35 |
36 | 
37 |
38 | Now, let's zoom out all the way back and place a marker at the north of
39 | Brazil, as shown. To *place* a marker, simply click on the map. If we want
40 | to, we can also place multiple markers.
41 |
42 | We may also wish to clear all the placed markers. To do that, click on the
43 | **[ Clear Markers]** red button on the left side
44 | of the toolbar.
45 |
46 | 
47 |
48 | After that, we need to *select* one of the markers in order download its
49 | Landsat pixel data. To do that, simply click on an already placer marker,
50 | and it will be highlighted. Only one marker may be selected at a time.
51 |
52 | By selecting a marker, we can now choose a combination of which satellites
53 | to download from using the drop-down menu, located on the bottom of the
54 | toolbar. For instance, let's choose all the available satellites products:
55 | Landsat 5, 7 and 8 SR.
56 |
57 | 
58 |
59 | Then, we press the **[ Get Data]** blue
60 | button, located on the right side of the toolbar. By pressing that button,
61 | the download will start. We can keep track of the download progress by
62 | looking to the lower right corner. All the historical data available are
63 | downloaded, which should take less than 10 seconds for the three products
64 | selected.
65 |
66 | Note: as of the writing of this guide, not all Surface Reflectance
67 | data are availble from GEE. So, depending on where we place our markers,
68 | we may face a message indicating that *'No data available for the chosen*
69 | *satellite(s) and/or region... Please change your query and try again.'*.
70 | Since we rely heavily on GEE to download the data, there's nothing we can
71 | do yet. We're sorry for that.
72 |
73 | 
74 |
75 | If the download is successful, we'll receive a message directing to the
76 | ** Analysis** tab.
77 |
78 | ### Analysis Tab
79 |
80 | In this tab, we can analyze the downloaded data and, then,
81 | locally save the results as files.
82 |
83 | 
84 |
85 | First, let's choose which satellite time series date to visualize. Note
86 | that, even though we downloaded data from Landsat 5, 7 and 8 SR, we're
87 | can still analyze them separately. However, let's proceed by choosing
88 | all of them.
89 |
90 | As we can see, the time series of the first spectral band
91 | (`b1`) is plotted for all satellites. A colored legend distinguishes the
92 | different sources.
93 |
94 | Note: be careful when comparing *spectral bands* data from
95 | different satellites, as they may not correspond to the same wavelength range! Read more about this [here](https://landsat.usgs.gov/what-are-band-designations-landsat-satellites).
96 |
97 | 
98 |
99 | Apart from the spectral bands, there are also four spectral-bands-derived
100 | indexes available: NDVI, NDMI, EVI and EVI2. Let's check, for example, the
101 | NDVI time series.
102 |
103 | 
104 |
105 | If we want to, we can also download *all* the time series data as a file.
106 | To do that, press the **[ Data]** blue
107 | button. All the data will be downloaded as a .CSV, ordered by the acquisiton
108 | date. Also, an additional column is included, in order to distinguish the
109 | satellite sources.
110 |
111 | 
112 |
113 | We may download the time series plot as an image, by pressing the
114 | **[ Plot]** blue button. A window will appear
115 | offering some raster (.JPEG, .PNG) and a vectorial (.SVG) image output
116 | formats.
117 |
118 | 
119 |
120 | Next, we select the *change detection algorithm*. Three options are available: **bfastmonitor**, **bfast01** and **bfast**. More information
121 | about these algorithms can be found [here](http://bfast.r-forge.r-project.org/).
122 |
123 | 
124 |
125 | By selecting **bfastmonitor**, we are able to tweak four parameters on the
126 | left side-bar: `formula`, `history period type`, `harmonic order`, and
127 | `start of monitoring`. These parameters have different impacts on the
128 | results, which can be verified on the right side plot. Here, we set the
129 | maximum value of the `harmonic order` to 9 to avoid some problems.
130 |
131 | Similar to the time series, we can also download the *results* of the change detection algorithms as .RDS data files, by clicking on the **[ Results]** blue button. If we wish to download the plot, we can press the **[ Plot]** blue button.
132 |
133 | For more information on how to load .RDS files on R, please check this [link](http://www.fromthebottomoftheheap.net/2012/04/01/saving-and-loading-r-objects/).
134 |
135 | 
136 |
137 | By selecting **bfast01**, we can tweak two parameters: `formula`, and `harmonic order`.
138 | Here, the maximum value of the `harmonic order` is dynamically set
139 | depending on the time series data length and the choice of the `formula`
140 | parameter.
141 |
142 | 
143 |
144 | Finally, by selecting **bfast**, we may tweak two parameters: `h` (minimal
145 | segment size), and `season type`. Please note that, since **bfast** can
146 | detect multiple breakpoints, it may take a couple of seconds to process,
147 | in comparison to the previous two algorithms.
148 |
149 | 
150 |
--------------------------------------------------------------------------------
/global.R:
--------------------------------------------------------------------------------
1 | # --------------------------------------------------------------- LIBS ----
2 |
3 | options(shiny.sanitize.errors = FALSE)
4 |
5 | # this tool is still not compatible with Windows OS
6 | if(Sys.info()[["sysname"]] == "Windows") {
7 | stop("This tool is not yet compatible with Windows.\nPlease use a UNIX-like system.")
8 | }
9 |
10 | # load and install packages if needed
11 | if(!require("pacman")) {
12 | install.packages("pacman")
13 | require("pacman")
14 | }
15 |
16 | # CRAN
17 | packs <- c(
18 | "bfast",
19 | "devtools",
20 | "dplyr",
21 | "ggmap",
22 | "knitr",
23 | "leaflet",
24 | "lubridate",
25 | "markdown",
26 | "magrittr",
27 | "RColorBrewer",
28 | "raster",
29 | "rPython",
30 | "shiny",
31 | "shinyBS",
32 | "shinyjs",
33 | "strucchange",
34 | "tools",
35 | "zoo"
36 | )
37 |
38 | p_load(char = packs)
39 |
40 | # ---------------------------------------------------------- FUNCTIONS ----
41 |
42 | # preprocessing
43 | ppBfastmonitor <- function(x, date, ...) {
44 | tmpTs <- bfastts(data = x,
45 | dates = date,
46 | type = "irregular")
47 | tmp <- bfastmonitor(tmpTs, ...)
48 | return(tmp)
49 | }
50 |
51 | ppBfast01 <- function(x, date, ...) {
52 | tmpTs <- bfastts(data = x,
53 | dates = date,
54 | type = "irregular")
55 | tmp <- bfast01(tmpTs, ...)
56 | return(tmp)
57 | }
58 |
59 | ppBfast <- function(x, date, ...) {
60 | # bfast needs regularly spaced data. Here, we force the data regularity
61 | # with a monthly aggregation. Temporal gaps are linearly filled.
62 | timeYM <- strftime(date, "%Y-%m")
63 | x <- data.frame(time = timeYM, x)
64 | x <- aggregate(x = x$x,
65 | by = list(x$time),
66 | FUN = median)
67 | names(x)[1] <- "time"
68 |
69 | # create an empty continuous year-month df
70 | mYear <- as.numeric(substr(head(x$time, 1), 1, 4))
71 | MYear <- as.numeric(substr(tail(x$time, 1), 1, 4))
72 | mMonth <- as.numeric(substr(head(x$time, 1), 6, 7))
73 | MMonth <- as.numeric(substr(tail(x$time, 1), 6, 7))
74 | fullYear <- rep(mYear:MYear, each = 12)
75 | fullMonth <- rep(1:12, times = length(mYear:MYear))
76 |
77 | # correcting the first year
78 | if(mMonth > 1) {
79 | fullYear <- fullYear[-(1:(mMonth - 1))]
80 | fullMonth <- fullMonth[-(1:(mMonth - 1))]
81 | }
82 |
83 | # correcting the last year
84 | if (MMonth < 12) {
85 | fullYear <- fullYear[-((length(fullYear) - 12 + MMonth + 1):length(fullYear))]
86 | fullMonth <- fullMonth[-((length(fullMonth) - 12 + MMonth + 1):length(fullMonth))]
87 | }
88 | dfull <- data.frame(time = paste0(fullYear, "-", sprintf("%02d", fullMonth)))
89 |
90 | # merging x df with the full year-month df
91 | d <- merge(dfull, x, all = T)
92 | d$time <- NULL
93 |
94 | dts <- na.approx(
95 | ts(data = c(d)$x,
96 | start = c(mYear, mMonth),
97 | end = c(MYear, MMonth),
98 | frequency = 12),
99 | rule = 2
100 | )
101 |
102 | tmp <- bfast(dts, max.iter = 1, ...)
103 | return(tmp)
104 | }
105 |
106 | # plotting
107 | plotRaw <- function(serie, matchCol, xAxisCustom, ylimCustom, ylab, seriePar, coords) {
108 | # placeholder blank plot
109 | par(mar = c(4, 4, 0, 0) + 0.1)
110 | plot(y = serie[, matchCol],
111 | x = serie$date,
112 | axes = F,
113 | xlab = "Time",
114 | ylab = toupper(colnames(serie)[matchCol]),
115 | ylim = ylimCustom,
116 | col = "white")
117 |
118 | # redraw axis
119 | axis(side = 1,
120 | at = date(paste0(xAxisCustom, "-01-01")),
121 | labels = xAxisCustom)
122 | if(ylimCustom[1] == -1) {
123 | yAxisStep <- 0.2
124 | } else {
125 | yAxisStep <- 0.1
126 | }
127 | axis(side = 2,
128 | at = seq(ylimCustom[1], ylimCustom[2], yAxisStep))
129 |
130 | # draw a grid on both axis directions
131 | for(i in xAxisCustom) {
132 | abline(v = date(paste0(i, "-01-01")),
133 | col = rgb(.8, .8, .8),
134 | lty = 2)
135 | }
136 | for(i in seq(ylimCustom[1], ylimCustom[2], yAxisStep)) {
137 | if(i == 0) {
138 | # highlight a guide line at "0"
139 | abline(h = i,
140 | col = "black",
141 | lty = 3,
142 | lwd = 1.3)
143 | } else {
144 | abline(h = i,
145 | col = rgb(.8, .8, .8),
146 | lty = 2)
147 | }
148 | }
149 | box()
150 |
151 | # draw time series as points and lines
152 | lines(
153 | y = serie[, matchCol],
154 | x = serie$date,
155 | col = rgb(.1, .1, .1)
156 | )
157 | points(
158 | y = serie[, matchCol],
159 | x = serie$date,
160 | col = seriePar[, 1],
161 | pch = as.numeric(seriePar[, 2]),
162 | cex = 0.6
163 | )
164 |
165 | # if(mean(serie[, matchCol]) > (ylimCustom[1] + 0.5 * (diff(ylimCustom))))
166 | if(mean(serie[, matchCol], na.rm = TRUE) > (ylimCustom[1] + 0.5 * (diff(ylimCustom)))) {
167 | posText <- 0.1
168 | } else {
169 | posText <- 0.9
170 | }
171 |
172 | if(coords$show) {
173 | text(
174 | x = serie$date %>% year() %>% unique() %>% range() %>% mean() %>% sum(0.5) %>% date_decimal() %>% format("%Y-%m-%d") %>% as.Date(),
175 | y = ylimCustom[1] + posText * (diff(ylimCustom)),
176 | labels = paste0("LatLong = (", sprintf("%.5f", round(coords$lat, 5)), ", ", sprintf("%.5f", round(coords$lon, 5)), ")"),
177 | cex = 1.3
178 | )
179 | }
180 | }
181 | plotRawLegend <- function(satOrder, seriePar) {
182 | # placeholder blank plot
183 | par(mar = c(4, 0, 0, 0) + 0.1)
184 | plot(0,
185 | col = "white",
186 | axes = F,
187 | xlab = "",
188 | ylab = "")
189 |
190 | # first, draw lines
191 | legend(x = "center",
192 | lty = 1,
193 | x.intersp = 2,
194 | y.intersp = 1.5,
195 | legend = names(satOrder),
196 | text.col = "white",
197 | bty = "n",
198 | col = rgb(.1, .1, .1))
199 |
200 | serieParOrder <- unique(seriePar)
201 | serieParOrder <- rbind(serieParOrder[order(serieParOrder[, 2]), ])
202 |
203 | # then, draw points
204 | legend(x = "center",
205 | x.intersp = 2,
206 | y.intersp = 1.5,
207 | legend = names(satOrder),
208 | bty = "n",
209 | col = serieParOrder[, 1],
210 | pch = as.numeric(serieParOrder[, 2])
211 | )
212 | }
213 |
214 | plotBfm <- function(serie, matchCol, bfmOut, xAxisCustom, ylimCustom, ylab) {
215 | # define a vector with rounded dates to avoid strange rounding errors
216 | # to interfere with the conditions below
217 | dates <- round(decimal_date(serie$date), digits = 3)
218 |
219 | # conditions
220 | condHist <- dates >= round(bfmOut$history[1], digits = 3) & dates <= round(bfmOut$history[2], digits = 3)
221 | condMoni <- dates >= round(bfmOut$monitor[1], digits = 3)
222 | condStart <- dates <= round(bfmOut$history[2], digits = 3)
223 | condPred <- dates >= round(bfmOut$history[1], digits = 3)
224 |
225 | # background blank plot
226 | par(mar = c(4, 4, 0, 0) + 0.1)
227 | plot(y = serie[, matchCol],
228 | x = serie$date,
229 | col = "white",
230 | axes = F,
231 | ylim = ylimCustom,
232 | ylab = ylab,
233 | xlab = "Time")
234 |
235 | # redraw axis
236 | axis(side = 1,
237 | at = date(paste0(xAxisCustom, "-01-01")),
238 | labels = xAxisCustom)
239 | if(ylimCustom[1] == -1) {
240 | yAxisStep <- 0.2
241 | } else {
242 | yAxisStep <- 0.1
243 | }
244 | axis(side = 2,
245 | at = seq(ylimCustom[1], ylimCustom[2], yAxisStep))
246 | for(i in xAxisCustom) {
247 | abline(v = date(paste0(i, "-01-01")),
248 | col = rgb(.8, .8, .8),
249 | lty = 2)
250 | }
251 | for(i in seq(ylimCustom[1], ylimCustom[2], yAxisStep)) {
252 | if(i == 0) {
253 | # highlight a guide line at "0"
254 | abline(h = i,
255 | col = "black",
256 | lty = 3,
257 | lwd = 1.3)
258 | } else {
259 | abline(h = i,
260 | col = rgb(.8, .8, .8),
261 | lty = 2)
262 | }
263 | }
264 | box()
265 |
266 | # draw a guide line at "0"
267 | abline(h = 0,
268 | lty = 3,
269 | lwd = 1.3,
270 | col = "black")
271 |
272 | # draw historical data
273 | lines(y = serie[, matchCol][which(condStart)],
274 | x = serie$date[which(condStart)])
275 |
276 | # draw data of monitoring period
277 | lines(y = serie[, matchCol][which(condMoni)],
278 | x = serie$date[which(condMoni)],
279 | col = "red",
280 | type = "o",
281 | pch = 20)
282 |
283 | # draw stable history points
284 | points(y = serie[, matchCol][which(condHist)],
285 | x = serie$date[which(condHist)],
286 | pch = 20,
287 | col = "darkgreen")
288 |
289 | # draw fit based on stable history
290 | lines(y = bfmOut$tspp$prediction,
291 | x = serie$date[which(condPred)],
292 | col = "blue",
293 | lwd = 1.5)
294 |
295 | # draw line of start of the monitoring period
296 | abline(v = as.Date(date_decimal(bfmOut$monitor[1]), format = "YYYY-MM-DD"),
297 | lty = 2,
298 | lwd = 1.2)
299 |
300 | # draw line of time of detected break (if it exists)
301 | if(is.na(!bfmOut$mefp$breakpoint)) {
302 | abline(v = serie$date[c(which(condHist), which(condMoni))[bfmOut$mefp$breakpoint]-1],
303 | lty = 2,
304 | lwd = 2,
305 | col = "red")
306 | }
307 | }
308 | plotBfmLegend <- function() {
309 | # placeholder blank plot
310 | par(mar = c(4, 0, 0, 0) + 0.1)
311 | plot(0,
312 | col = "white",
313 | axes = F,
314 | xlab = "",
315 | ylab = "")
316 |
317 | legendText <- c(
318 | "Historical data",
319 | "Stable history",
320 | "New data",
321 | "Fit using stable history",
322 | "Start of monitoring",
323 | "Detected break"
324 | )
325 |
326 | # first, draw the lines
327 | legend(x = "center",
328 | x.intersp = 2,
329 | y.intersp = 1.5,
330 | legend = legendText,
331 | text.col = "white",
332 | bty = "n",
333 | lty = c(rep(1, 4), rep(2, 2)),
334 | lwd = c(rep(1, 2), 1.2, 1.5, .9, 2),
335 | col = c(rep("black", 2), "red", "blue", "black", "red"))
336 |
337 | # then, draw the points
338 | legend(x = "center",
339 | x.intersp = 2,
340 | y.intersp = 1.5,
341 | legend = legendText,
342 | bty = "n",
343 | col = c(rgb(0,0,0,0), "darkgreen", "red", rep(rgb(0,0,0,0), 3)),
344 | pch = 20)
345 | }
346 |
347 | plotBf01 <- function(serie, matchCol, bf01Out, xAxisCustom, ylimCustom, ylab) {
348 | # background blank plot
349 | par(mar = c(4, 4, 0, 0) + 0.1)
350 | plot(y = serie[, matchCol],
351 | x = serie$date,
352 | col = "white",
353 | axes = F,
354 | ylim = ylimCustom,
355 | ylab = ylab,
356 | xlab = "Time")
357 |
358 | # redraw axis
359 | axis(side = 1,
360 | at = date(paste0(xAxisCustom, "-01-01")),
361 | labels = xAxisCustom)
362 | if(ylimCustom[1] == -1) {
363 | yAxisStep <- 0.2
364 | } else {
365 | yAxisStep <- 0.1
366 | }
367 | axis(side = 2,
368 | at = seq(ylimCustom[1], ylimCustom[2], yAxisStep))
369 | for(i in xAxisCustom) {
370 | abline(v = date(paste0(i, "-01-01")),
371 | col = rgb(.8, .8, .8),
372 | lty = 2)
373 | }
374 | for(i in seq(ylimCustom[1], ylimCustom[2], yAxisStep)) {
375 | if(i == 0) {
376 | # highlight a guide line at "0"
377 | abline(h = i,
378 | col = "black",
379 | lty = 3,
380 | lwd = 1.3)
381 | } else {
382 | abline(h = i,
383 | col = rgb(.8, .8, .8),
384 | lty = 2)
385 | }
386 | }
387 | box()
388 |
389 | # draw a guide line at "0"
390 | abline(h = 0,
391 | lty = 3,
392 | lwd = 1.3,
393 | col = "black")
394 |
395 | lines(
396 | y = as.zoo(bf01Out)$response,
397 | x = serie$date,
398 | col = "black",
399 | lwd = 1
400 | )
401 | lines(
402 | y = as.zoo(bf01Out)$fitted,
403 | x = serie$date,
404 | col = "blue",
405 | lwd = 2
406 | )
407 |
408 | if(bf01Out$breaks == 1) {
409 | # bp
410 | abline(
411 | v = serie$date[bf01Out$confint[2]],
412 | lty = 2,
413 | lwd = 2,
414 | col = "red"
415 | )
416 | }
417 | }
418 | plotBf01Legend <- function() {
419 | # placeholder blank plot
420 | par(mar = c(4, 0, 0, 0) + 0.1)
421 | plot(0,
422 | col = "white",
423 | axes = F,
424 | xlab = "",
425 | ylab = "")
426 |
427 | legendText <- c(
428 | "Data",
429 | "Fitted model",
430 | "Detected break"
431 | )
432 |
433 | # draw the lines
434 | legend(x = "center",
435 | x.intersp = 2,
436 | y.intersp = 1.5,
437 | legend = legendText,
438 | bty = "n",
439 | lty = c(1, 1, 2),
440 | lwd = c(1, 1, 2),
441 | col = c("black", "blue", "red"))
442 | }
443 |
444 | plotBfast <- function(serie, matchCol, bfastOut, xAxisCustom, ylimCustom, ylab) {
445 | # background blank plot
446 | par(mar = c(4, 4, 0, 0) + 0.1)
447 | plot(y = serie[, matchCol],
448 | x = serie$date,
449 | col = "white",
450 | axes = F,
451 | ylim = ylimCustom,
452 | ylab = ylab,
453 | xlab = "Time")
454 |
455 | # redraw axis
456 | axis(side = 1,
457 | at = date(paste0(xAxisCustom, "-01-01")),
458 | labels = xAxisCustom)
459 | if(ylimCustom[1] == -1) {
460 | yAxisStep <- 0.2
461 | } else {
462 | yAxisStep <- 0.1
463 | }
464 | axis(side = 2,
465 | at = seq(ylimCustom[1], ylimCustom[2], yAxisStep))
466 | for(i in xAxisCustom) {
467 | abline(v = date(paste0(i, "-01-01")),
468 | col = rgb(.8, .8, .8),
469 | lty = 2)
470 | }
471 | for(i in seq(ylimCustom[1], ylimCustom[2], yAxisStep)) {
472 | if(i == 0) {
473 | # highlight a guide line at "0"
474 | abline(h = i,
475 | col = "black",
476 | lty = 3,
477 | lwd = 1.3)
478 | } else {
479 | abline(h = i,
480 | col = rgb(.8, .8, .8),
481 | lty = 2)
482 | }
483 | }
484 | box()
485 |
486 | # draw a guide line at "0"
487 | abline(h = 0,
488 | lty = 3,
489 | lwd = 1.3,
490 | col = "black")
491 |
492 | lines(y = bfastOut$Yt, x = as.Date(time(bfastOut$Yt)), col = "gray", lwd = 2)
493 | lines(y = bfastOut$output[[1]]$Tt + bfastOut$output[[1]]$St, x = as.Date(time(bfastOut$Yt)), col = "blue", lwd = 2)
494 |
495 | if(!bfastOut$nobp$Vt & !is.na(bfastOut$output[[1]]$Vt.bp)[1]) {
496 | for(i in 1:length(bfastOut$output[[1]]$Vt.bp)) {
497 | abline(
498 | v = as.Date(time(bfastOut$Yt))[bfastOut$output[[1]]$Vt.bp[i]],
499 | lty = 2,
500 | lwd = 1.5,
501 | col = "red"
502 | )
503 | }
504 | }
505 | if(!bfastOut$nobp$Wt & !is.na(bfastOut$output[[1]]$Wt.bp)[1]) {
506 | for(i in 1:length(bfastOut$output[[1]]$Wt.bp)) {
507 | abline(
508 | v = as.Date(time(bfastOut$Yt))[bfastOut$output[[1]]$Wt.bp[i]],
509 | lty = 2,
510 | lwd = 1.5,
511 | col = "darkgreen"
512 | )
513 | }
514 | }
515 | }
516 | plotBfastLegend <- function() {
517 | # placeholder blank plot
518 | par(mar = c(4, 0, 0, 0) + 0.1)
519 | plot(0,
520 | col = "white",
521 | axes = F,
522 | xlab = "",
523 | ylab = "")
524 |
525 | legendText <- c(
526 | "Data",
527 | "Fitted model",
528 | "Detected trend break",
529 | "Detected season break"
530 | )
531 |
532 | # draw the lines
533 | legend(x = "center",
534 | x.intersp = 2,
535 | y.intersp = 1.5,
536 | legend = legendText,
537 | bty = "n",
538 | lty = c(1, 1, 2, 2),
539 | lwd = c(1, 2, 2, 2),
540 | col = c("black", "blue", "red", "darkgreen"))
541 | }
542 |
543 | # --------------------------------------------------------------- DEFS ----
544 |
545 | # define custom AwesomeIcons markers
546 | iconSet <- awesomeIconList(
547 | # unselected marker
548 | marker = makeAwesomeIcon(
549 | icon = "circle",
550 | markerColor = "lightgray",
551 | iconColor = "white",
552 | library = "fa"
553 | ),
554 | # selected marker
555 | markerSel = makeAwesomeIcon(
556 | icon = "circle",
557 | markerColor = "blue",
558 | iconColor = "white",
559 | library = "fa"
560 | )
561 | )
562 |
563 | # define all available satellites the user can choose from:
564 | # LHS is the alias name; RHS is the name that GEE understands
565 | # satChoices <- c(
566 | # "Landsat 5 SR" = "LT5_SR",
567 | # "Landsat 7 SR" = "LE7_SR",
568 | # "Landsat 8 SR" = "LC8_SR"
569 | # )
570 | satChoices <- c(
571 | "Landsat 5 SR" = "LT05/C01/T1_SR",
572 | "Landsat 7 SR" = "LE07/C01/T1_SR",
573 | "Landsat 8 SR" = "LC08/C01/T1_SR"
574 | )
575 |
576 | # coordinates (long, lat, zoom) of the default fixed center
577 | viewCenter <- c(-5.98, 24.69, 3)
578 |
579 | # defining colors & pch for points from differente satellite sources
580 | # satPar <- function(x) {
581 | # customPalette <- brewer.pal(length(satChoices) + 1, "Dark2")
582 | # switch(
583 | # x,
584 | # "LT5_SR" = c(customPalette[1], 15),
585 | # "LE7_SR" = c(customPalette[2], 16),
586 | # "LC8_SR" = c(customPalette[3], 17),
587 | # "Mixed" = c(customPalette[4], 18)
588 | # )
589 | # }
590 | satPar <- function(x) {
591 | customPalette <- brewer.pal(length(satChoices) + 1, "Dark2")
592 | switch(
593 | x,
594 | "LT05/C01/T1_SR" = c(customPalette[1], 15),
595 | "LE07/C01/T1_SR" = c(customPalette[2], 16),
596 | "LC08/C01/T1_SR" = c(customPalette[3], 17),
597 | "Mixed" = c(customPalette[4], 18)
598 | )
599 | }
600 |
601 | # create a .md file from the following .Rmd, in order to be embedded into
602 | # the Shiny app
603 | knit(input = "./md/tutorial.Rmd", output = "md/tutorial.md", quiet = T)
604 |
605 | # longlat projection default CRS
606 | proj_ll <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
607 |
--------------------------------------------------------------------------------
/ui.R:
--------------------------------------------------------------------------------
1 | library(shiny)
2 |
3 | shinyUI(
4 | navbarPage(
5 | title = div(
6 | em(strong("BFAST Explorer")),
7 | HTML("by Alexandre E. Almeida ")
8 | ),
9 | windowTitle = "BFAST Explorer",
10 | id = "navbar",
11 | position = "fixed-top",
12 | collapsible = T,
13 | header = {
14 | # load styles.css file with custom styles
15 | tags$head(includeCSS("www/styles.css"))
16 | },
17 |
18 | # ---------------------------------------------------- MAP TAB ----
19 |
20 | tabPanel(
21 | title = "Map",
22 | icon = icon(name = "map-marker", lib = "font-awesome", class = "fa-lg"),
23 | # set up shinyjs
24 | useShinyjs(),
25 | div(
26 | id = "map-leaflet",
27 | # render a leaflet map on the background
28 | leafletOutput(
29 | outputId = "leaf",
30 | height = "100%"
31 | ),
32 | # create a toolbar on top of the map
33 | fixedPanel(
34 | id = "map-toolbar",
35 | class = "panel panel-default",
36 | top = 60,
37 | bottom = "auto",
38 | right = 250,
39 | left = 250,
40 | # map search query
41 | fluidRow(
42 | column(
43 | 4,
44 | HTML('
45 |
55 | '),
56 | # enable "Enter" key press on textInput to activate the search button
57 | tags$script('
58 | $(document).on("keyup", function (e) {
59 | if (e.keyCode == 13) {
60 | $("#action_search").click();
61 | }
62 | });
63 | ')
64 | ),
65 | # 'insert shape' button
66 | column(
67 | 4,
68 | div(
69 | HTML('
70 |
84 | '),
85 | bsTooltip(
86 | id = "help_insertShape",
87 | title = 'The shape must be compressed into a zip with, at least, the .shp , .shx , .dbf , and .prj files.
The zip file
must have the same name as its contents.
',
88 | placement = "bottom",
89 | trigger = "hover",
90 | options = list(container = "body")
91 | )
92 | )
93 | ),
94 | # 'clear all markers' button
95 | column(
96 | 4,
97 | bsButton(
98 | inputId = "action_clearMarkers",
99 | label = "Clear Markers",
100 | style = "danger",
101 | icon = icon(name = "trash", lib = "font-awesome"),
102 | width = "100%"
103 | )
104 | )
105 | ),
106 | fluidRow(
107 | # select which satellite products to download
108 | column(
109 | 6,
110 | selectInput(
111 | inputId = "select_satGet",
112 | label = NULL,
113 | width = "100%",
114 | choices = c(""),
115 | multiple = T
116 | )
117 | ),
118 | # 'get data' button
119 | column(
120 | 6,
121 | bsButton(
122 | inputId = "action_getTs",
123 | label = "Get Data",
124 | style = "success",
125 | icon = icon(name = "download", lib = "font-awesome"),
126 | width = "100%"
127 | ),
128 | # tooltip with data preprocessing description
129 | bsTooltip(
130 | id = "action_getTs",
131 | title = 'The Landsat "Surface Refle- ctance" (SR) product is, by construction, already atmosphe- rically corrected.
In addition, the downloaded data is also filtered for cloud effects by using the CFMask algorithm.
',
132 | placement = "bottom",
133 | trigger = "hover",
134 | options = list(container = "body")
135 | )
136 | )
137 | ),
138 | # output text with download results
139 | htmlOutput(outputId = "text_getTs")
140 | )
141 | )
142 | ),
143 |
144 | # ----------------------------------------------- ANALYSIS TAB ----
145 |
146 | tabPanel(
147 | title = "Analysis",
148 | icon = icon(name = "bar-chart", lib = "font-awesome", class = "fa-lg"),
149 | fluidPage(
150 | # ----------------------------------------- TIME SERIES ---
151 |
152 | fixedRow(
153 | style = "margin-top: 71px;",
154 | column(
155 | 3,
156 | h3(class = "text-heading", "Visualization"),
157 | # select which satellite products to plot
158 | selectInput(
159 | inputId = "select_satPlot",
160 | label = "Satellite product",
161 | width = "100%",
162 | choices = NULL,
163 | multiple = T
164 | ),
165 | # select which band/index to plot
166 | selectInput(
167 | inputId = "select_index",
168 | label = "Data",
169 | width = "100%",
170 | choices = NULL
171 | ),
172 | # add a tooltip to select_index warning about mixing bands from different satellites
173 | bsTooltip(
174 | id = "select_index",
175 | title = 'Be careful when comparing
bands from different satellites.
For more information about Landsat bands, please visit this link . ',
176 | placement = "right",
177 | trigger = "focus",
178 | options = list(container = "body")
179 | ),
180 | # select which change detection algorithm to run
181 | selectInput(
182 | inputId = "select_chgDet",
183 | label = "Change detection algorithm",
184 | width = "100%",
185 | choices = c("Select the change detection algorithm..." = "", "bfastmonitor", "bfast01", "bfast")
186 | ),
187 | # tooltip with brief explanations about the change detection algorithms
188 | bsTooltip(
189 | id = "select_chgDet",
190 | title = 'bfastmonitor
Monitoring for the first break at the end of the time series.
bfast01
Checking for one major break in the time series.
bfast
Time series decomposition and multiple breakpoint detection in trend and seasonal components.
For more information about these algorithms, please visit this link . ',
191 | placement = "right",
192 | trigger = "focus",
193 | options = list(container = "body")
194 | ),
195 | # buttons to download the data and the plot figures
196 | h5(style = "cursor:default;", strong("Download")),
197 | downloadButton(
198 | outputId = "action_downloadDataRaw",
199 | label = "Data",
200 | class = "btn-primary"
201 | ),
202 | bsButton(
203 | inputId = "action_downloadPlotRaw",
204 | label = "Plot",
205 | style = "primary",
206 | icon = icon(name = "download", lib = "font-awesome")
207 | ),
208 | # checkbox to show/hide latlong coordinates
209 | checkboxInput(
210 | inputId = "select_showCoords",
211 | label = "Show coordinates?",
212 | value = T,
213 | width = "100%"
214 | )
215 | ),
216 | # time series plot and its legend
217 | column(
218 | 9,
219 | splitLayout(
220 | cellWidths = c("75%", "25%"),
221 | plotOutput(outputId = "plot_raw", height = 300),
222 | plotOutput(outputId = "plot_raw_legend", height = 300)
223 | )
224 | )
225 | ),
226 |
227 | # ---------------------------------------- BFASTMONITOR ---
228 |
229 | conditionalPanel(
230 | condition = "input.select_chgDet == 'bfastmonitor' && input.select_satPlot != null",
231 | hr(),
232 | fluidRow(
233 | column(
234 | 3,
235 | h3(class = "text-heading", "bfastMonitor"),
236 | helpText("Based on", a("bfmApp", href = "https://github.com/loicdtx/bfmApp", target = "_blank"), "by Loïc Dutrieux"),
237 | fluidRow(
238 | # formula parameter
239 | column(
240 | 6,
241 | selectInput(
242 | inputId = "select_bfm_formula",
243 | label = "Formula",
244 | width = "100%",
245 | choices = c("trend + harmon", "trend", "harmon"),
246 | selected = "trend + harmon"
247 | )
248 | ),
249 | # history period type parameter
250 | column(
251 | 6,
252 | selectInput(
253 | inputId = "select_bfm_history",
254 | label = "History period type",
255 | width = "100%",
256 | choices = c("ROC", "BP", "all"),
257 | selected = "ROC"
258 | ),
259 | # tooltip with brief explanations about the history period type parameter
260 | bsTooltip(
261 | id = "select_bfm_history",
262 | title = 'ROC
Reverse-ordered CUSUM.
BP
Bai & Perron
breakpoint estimation.
all
All available observations.
',
263 | placement = "right",
264 | trigger = "focus",
265 | options = list(container = "body")
266 | )
267 | )
268 | ),
269 | fluidRow(
270 | # harmonic order parameter (only show if applicable)
271 | column(
272 | 6,
273 | conditionalPanel(
274 | condition = "input.select_bfm_formula == 'harmon' | input.select_bfm_formula == 'trend + harmon'",
275 | sliderInput(
276 | inputId = "select_bfm_order",
277 | label = "Harmonic order",
278 | width = "100%",
279 | value = 1,
280 | min = 1,
281 | max = 9,
282 | step = 1
283 | )
284 | )
285 | ),
286 | # start of monitoring period parameter
287 | column(
288 | 6,
289 | dateInput(
290 | inputId = "select_bfm_monitor",
291 | label = "Start of monitoring",
292 | width = "100%",
293 | format = "yyyy-mm",
294 | startview = "decade"
295 | ),
296 | # tooltip with brief explanations about the monitoring period default
297 | bsTooltip(
298 | id = "select_bfm_monitor",
299 | title = 'Defaults to the last 30% of the data.
',
300 | placement = "bottom",
301 | options = list(container = "body")
302 | )
303 | )
304 | ),
305 | # buttons to download the data and the plot figures
306 | h5(style = "cursor:default;", strong("Download")),
307 | downloadButton(
308 | outputId = "action_downloadDataBfm",
309 | label = "Results",
310 | class = "btn-primary"
311 | ),
312 | bsButton(
313 | inputId = "action_downloadPlotBfm",
314 | label = "Plot",
315 | style = "primary",
316 | icon = icon(name = "download", lib = "font-awesome")
317 | )
318 | ),
319 | # bfastmonitor plot and its legend
320 | column(
321 | 9,
322 | splitLayout(
323 | cellWidths = c("75%", "25%"),
324 | plotOutput(outputId = "plot_bfm", height = 300),
325 | plotOutput(outputId = "plot_bfm_legend", height = 300)
326 | )
327 | )
328 | )
329 | ),
330 |
331 | # --------------------------------------------- BFAST01 ---
332 |
333 | conditionalPanel(
334 | condition = "input.select_chgDet == 'bfast01' && input.select_satPlot != null",
335 | hr(),
336 | fluidRow(
337 | column(
338 | 3,
339 | h3(class = "text-heading", "bfast01"),
340 | fluidRow(
341 | # formula parameter
342 | column(
343 | 6,
344 | selectInput(
345 | inputId = "select_bf01_formula",
346 | label = "Formula",
347 | width = "100%",
348 | choices = c("trend + harmon", "trend", "harmon"),
349 | selected = "trend + harmon"
350 | )
351 | ),
352 | # harmonic order parameter (only show if applicable)
353 | column(
354 | 6,
355 | conditionalPanel(
356 | condition = "input.select_bf01_formula == 'harmon' | input.select_bf01_formula == 'trend + harmon'",
357 | sliderInput(
358 | inputId = "select_bf01_order",
359 | label = "Harmonic order",
360 | width = "100%",
361 | value = 1,
362 | min = 1,
363 | max = 1,
364 | step = 1
365 | )
366 | )
367 | )
368 | ),
369 | # buttons to download the data and the plot figures
370 | h5(style = "cursor:default;", strong("Download")),
371 | downloadButton(
372 | outputId = "action_downloadDataBf01",
373 | label = "Results",
374 | class = "btn-primary"
375 | ),
376 | bsButton(
377 | inputId = "action_downloadPlotBf01",
378 | label = "Plot",
379 | style = "primary",
380 | icon = icon(name = "download", lib = "font-awesome")
381 | )
382 | ),
383 | # bfast01 plot and its legend
384 | column(
385 | 9,
386 | splitLayout(
387 | cellWidths = c("75%", "25%"),
388 | plotOutput(outputId = "plot_bf01", height = 300),
389 | plotOutput(outputId = "plot_bf01_legend", height = 300)
390 | )
391 | )
392 | )
393 | ),
394 |
395 | # ----------------------------------------------- BFAST ---
396 |
397 | conditionalPanel(
398 | condition = "input.select_chgDet == 'bfast' && input.select_satPlot != null",
399 | hr(),
400 | fluidRow(
401 | column(
402 | 3,
403 | h3(class = "text-heading", "bfast"),
404 | fluidRow(
405 | # h parameter (minimal segment size)
406 | column(
407 | 6,
408 | sliderInput(
409 | inputId = "select_bfast_h",
410 | label = "h",
411 | width = "100%",
412 | value = 0.15,
413 | step = 0.01,
414 | min = 0.00,
415 | max = 0.50
416 | ),
417 | # explanation about what the h parameter means
418 | bsTooltip(
419 | id = "select_bfast_h",
420 | title = 'Minimal segment size between potentially detected breaks.
',
421 | placement = "right",
422 | options = list(container = "body")
423 | )
424 | ),
425 | # season type parameter
426 | column(
427 | 6,
428 | selectInput(
429 | inputId = "select_bfast_season",
430 | label = "Season type",
431 | width = "100%",
432 | choices = c("dummy", "harmonic", "none"),
433 | selected = "dummy"
434 | )
435 | )
436 | ),
437 | # buttons to download the data and the plot figures
438 | h5(style = "cursor:default;", strong("Download")),
439 | downloadButton(outputId = "action_downloadDataBfast",
440 | label = "Results",
441 | class = "btn-primary"),
442 | bsButton(
443 | inputId = "action_downloadPlotBfast",
444 | label = "Plot",
445 | style = "primary",
446 | icon = icon(name = "download", lib = "font-awesome")
447 | )
448 | ),
449 | # bfast plot and its legend
450 | column(
451 | 9,
452 | splitLayout(
453 | cellWidths = c("75%", "25%"),
454 | plotOutput(outputId = "plot_bfast", height = 300),
455 | plotOutput(outputId = "plot_bfast_legend", height = 300)
456 | )
457 | )
458 | )
459 | )
460 | )
461 | ),
462 |
463 | # ----------------------------------------------- TUTORIAL TAB ----
464 |
465 | tabPanel(
466 | title = "Tutorial",
467 | icon = icon(name = "question-circle", lib = "font-awesome", class = "fa-lg"),
468 | fluidPage(
469 | div(style = "max-width: 70%; margin-left: auto; margin-right: auto; margin-top: 71px;",
470 | align = "justify",
471 | includeMarkdown("./md/tutorial.md")
472 | )
473 | )
474 | ),
475 |
476 | # -------------------------------------------------- ABOUT TAB ----
477 |
478 | tabPanel(
479 | title = "About",
480 | icon = icon(name = "info-circle", lib = "font-awesome", class = "fa-lg"),
481 | fluidPage(
482 | div(
483 | style = "margin-left: auto; margin-right: auto; margin-top: 71px; width: 600px;",
484 | div(
485 | align = "center",
486 | HTML('BFAST Explorer v0.0.3 ')
487 | ),
488 | hr(),
489 | HTML(' Authors '),
490 | p(),
491 | div("MSc. Alexandre Esteves Almeida", a(icon("user", lib = "font-awesome"), href = "http://buscatextual.cnpq.br/buscatextual/visualizacv.do?id=K4672382A6", target = "_blank"), a(icon("envelope", lib = "font-awesome"), href = "mailto:almeida.xan@gmail.com")),
492 | div("Nathalia Menini, Master's Student", a(icon("user", lib = "font-awesome"), href = "http://buscatextual.cnpq.br/buscatextual/visualizacv.do?id=K8200531Y0", target = "_blank"), a(icon("envelope", lib = "font-awesome"), href = "mailto:nathmenini@gmail.com")),
493 | div("Prof. Dr. Jan Verbesselt", a(icon("user", lib = "font-awesome"), href = "https://www.wur.nl/en/Persons/Jan-Verbesselt.htm", target = "_blank")),
494 | div("Prof. Dr. Ricardo da Silva Torres", a(icon("user", lib = "font-awesome"), href = "http://buscatextual.cnpq.br/buscatextual/visualizacv.do?id=K4769295A9", target = "_blank")),
495 | hr(),
496 | HTML(' Citation '),
497 | p(),
498 | "To cite BFAST Explorer in publications, please use",
499 | pre('Alexandre Almeida, Nathalia Menini, Jan Verbesselt, Ricardo Torres (2018). BFAST Explorer: An Effective Tool for Time Series Analysis. In: 2018 IEEE International Geoscience and Remote Sensing Symposium (IGARSS). 22-27 July 2018. Valencia, Spain. DOI: 10.1109/IGARSS.2018.8517877.'),
500 | "or, alternatively, the corresponding BibTeX entry described",
501 | a("here", href = "https://github.com/almeidaxan/bfast-explorer#citation", target = "_blank"),
502 | hr(),
503 | HTML(' Development '),
504 | p(),
505 | div(
506 | align = "center",
507 | div(class = "image-highlight", a(img(src = "logo-tribes.png", height = "80px"), href = "http://www.e-tribes.com.br", target = "_blank")),
508 | p(),
509 | div(class = "image-highlight", a(img(src = "logo-unicamp.svg", height = "80px"), href = "http://www.unicamp.br/unicamp/english/", target = "_blank")),
510 | div(class = "image-highlight", a(img(src = "logo-wur.png", height = "120px"), href = "http://www.wur.nl/en.htm", target = "_blank"))
511 | ),
512 | p(),
513 | HTML('This work is a product of the Tribes project, developed within the University of Campinas (UNICAMP) Institute of Computing and the Wageningen University & Research (WUR) Laboratory of Geo-information Science and Remote Sensing .'),
514 | hr(),
515 | HTML(' Supporters '),
516 | p(),
517 | div(align = "center",
518 | div(class = "image-highlight", a(img(src = "logo-fapesp.svg", height = "40px"), href = "http://www.fapesp.br/en/", target = "_blank")),
519 | div(style = "display:inline;", HTML("  ")),
520 | div(class = "image-highlight", a(img(src = "logo-ms-research.png", height = "40px"), href = "http://www.fapesp.br/en/5392", target = "_blank")),
521 | div(style = "display:inline;", HTML("  ")),
522 | div(class = "image-highlight", a(img(src = "logo-cnpq.svg", height = "60px"), href = "http://cnpq.br/", target = "_blank"))
523 | )
524 | ),
525 | HTML('
526 |
527 |
528 | N
529 |
530 | ')
531 | )
532 | )
533 | )
534 | )
535 |
--------------------------------------------------------------------------------
/server.R:
--------------------------------------------------------------------------------
1 | library(shiny)
2 | source("global.R")
3 |
4 | shinyServer(function(input, output, session) {
5 | # ------------------------------------------------------------- SESSION ----
6 |
7 | # allow reconnection by a certain grace period
8 | session$allowReconnect(T)
9 |
10 | # ------------------------------------------------------------- SHARED ----
11 |
12 | # reactive values
13 | v <- reactiveValues(markerId = 1,
14 | # selected marker info
15 | markerSel = NULL,
16 | # downloaded marker info
17 | markerDown = NULL,
18 | # defaults view to the center of the atlantic ocean
19 | searchLoc = data.frame(lon = viewCenter[1],
20 | lat = viewCenter[2],
21 | zoom = viewCenter[3]))
22 |
23 | # ---------------------------------------------------------------- MAP ----
24 |
25 | # render leaflet map
26 | output$leaf <- renderLeaflet({
27 | m <- leaflet(options = list(attributionControl = F)) %>%
28 | addTiles(
29 | urlTemplate = "http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}",
30 | attribution = paste(
31 | "Map data ©",
32 | substr(Sys.Date(), 1, 4),
33 | " Google, Imagery ©",
34 | substr(Sys.Date(), 1, 4),
35 | " TerraMetrics"
36 | ),
37 | options = list(
38 | minZoom = 3,
39 | maxZoom = 19,
40 | noWrap = T,
41 | subdomains = c("mt0", "mt1", "mt2", "mt3")
42 | )
43 | ) %>%
44 | setMaxBounds(-180, -90, 180, 90)
45 | m
46 | })
47 |
48 | # update map view with v$searchLoc coordinates
49 | observeEvent(v$searchLoc, {
50 | leafletProxy("leaf") %>%
51 | setView(
52 | lng = v$searchLoc$lon,
53 | lat = v$searchLoc$lat,
54 | zoom = v$searchLoc$zoom
55 | )
56 | })
57 |
58 | # update map with input shapefile
59 | observeEvent(input$file_insertShape, {
60 | inFile <- input$file_insertShape
61 | inFolder <- substr(inFile$datapath, 1, nchar(inFile$datapath) - 5)
62 | unzip(inFile$datapath, exdir = inFolder)
63 | shpPath <- paste0(substr(inFile$name, 1, tools::file_path_sans_ext(inFile$name) %>% nchar), ".shp")
64 | shp <- shapefile(file.path(inFolder, shpPath))
65 | shp <- spTransform(shp, proj_ll)
66 | leafletProxy("leaf") %>%
67 | clearShapes() %>%
68 | addPolylines(
69 | data = shp,
70 | weight = 4,
71 | opacity = 0.9,
72 | color = rgb(1, 1, 0)
73 | ) %>%
74 | fitBounds(
75 | lng1 = extent(shp)[1],
76 | lng2 = extent(shp)[2],
77 | lat1 = extent(shp)[3],
78 | lat2 = extent(shp)[4]
79 | )
80 | })
81 |
82 | # draw markers by clicking on the map
83 | observeEvent(input$leaf_click, {
84 | id <- as.character(v$markerId)
85 | tmp <- input$leaf_click
86 | v$markerId <- v$markerId + 1
87 | leafletProxy("leaf") %>%
88 | addAwesomeMarkers(
89 | lng = tmp$lng,
90 | lat = tmp$lat,
91 | layerId = id,
92 | icon = iconSet$marker
93 | )
94 | })
95 |
96 | # select markers by clicking and show a 'Selected' label next to them
97 | observeEvent(input$leaf_marker_click, {
98 | tmp <- input$leaf_marker_click
99 |
100 | # if user clicks on an already 'Selected' marker, deselect it
101 | if (grepl("selected", tmp$id)) {
102 | leafletProxy("leaf") %>%
103 | addAwesomeMarkers(
104 | lng = tmp$lng,
105 | lat = tmp$lat,
106 | layerId = as.character(v$markerSel[3]),
107 | icon = iconSet$marker
108 | ) %>%
109 | removeMarker("selectedLabel") %>%
110 | removeMarker("selectedHighlight")
111 | updateSelectInput(
112 | session,
113 | inputId = "select_satGet",
114 | choices = c("")
115 | )
116 | v$markerSel <- NULL
117 | } else {
118 | # redraw selected marker without highlighting it
119 | if (length(v$markerSel) > 0) {
120 | leafletProxy("leaf") %>%
121 | addAwesomeMarkers(
122 | lng = as.numeric(v$markerSel[1]),
123 | lat = as.numeric(v$markerSel[2]),
124 | layerId = v$markerSel[3],
125 | icon = iconSet$marker
126 | )
127 | }
128 | leafletProxy("leaf") %>%
129 | removeMarker(tmp$id) %>%
130 | removeMarker("selectedLabel") %>%
131 | removeMarker("selectedHighlight") %>%
132 | addAwesomeMarkers(
133 | lng = tmp$lng,
134 | lat = tmp$lat,
135 | layerId = "selectedHighlight",
136 | icon = iconSet$markerSel
137 | ) %>%
138 | addLabelOnlyMarkers(
139 | lng = tmp$lng,
140 | lat = tmp$lat,
141 | layerId = "selectedLabel",
142 | label = "Selected",
143 | labelOptions = list(
144 | textsize = "12px",
145 | direction = "auto",
146 | noHide = T,
147 | offset = c(18,-40)
148 | ),
149 | options = list(keyboard = F)
150 | )
151 | v$markerSel <- c(tmp$lng, tmp$lat, tmp$id)
152 | }
153 | })
154 |
155 | observeEvent(input$select_showCoords, {
156 | if(input$select_showCoords) {
157 | v$markerDown$show <- T
158 | } else {
159 | v$markerDown$show <- F
160 | }
161 | })
162 |
163 | # ----------------------------------------------------- ACTION BUTTONS ----
164 |
165 | # update v$searchLoc with map search query
166 | observeEvent(input$action_search, {
167 | # evaluate geocode, but suppress messages and warnings
168 | options(warn = -1)
169 | gc <- suppressMessages(geocode(input$select_search))
170 | options(warn = 0)
171 | if (is.na(gc$lon)) {
172 | # defaults view to the center of the atlantic ocean
173 | v$searchLoc$lon <- viewCenter[1]
174 | v$searchLoc$lat <- viewCenter[2]
175 | v$searchLoc$zoom <- viewCenter[3]
176 | } else {
177 | # if user-selected region exists, center on it
178 | v$searchLoc$lon <- gc$lon
179 | v$searchLoc$lat <- gc$lat
180 | v$searchLoc$zoom <- 16
181 | }
182 | })
183 |
184 | # change the state of clearMarkers ab if at least a marker is drawn
185 | observeEvent(v$markerId, {
186 | shinyjs::toggleState(id = "action_clearMarkers",
187 | condition = v$markerId > 1,
188 | selector = NULL)
189 | })
190 |
191 | # select_satPlot observer
192 | observeEvent(input$select_satPlot, ignoreNULL = F, handlerExpr = {
193 | # change the state of time series download buttons
194 | shinyjs::toggleState(id = "action_downloadDataRaw",
195 | condition = !is.null(input$select_satPlot),
196 | selector = NULL)
197 | shinyjs::toggleState(id = "action_downloadPlotRaw",
198 | condition = !is.null(input$select_satPlot),
199 | selector = NULL)
200 | })
201 |
202 | # change of state of getTs ab if a marker is selected
203 | # also update select_satGet values
204 | observeEvent(length(v$markerSel), {
205 | shinyjs::toggleState(id = "action_getTs",
206 | condition = length(v$markerSel) > 0,
207 | selector = NULL)
208 | if (length(v$markerSel) > 0) {
209 | updateSelectInput(
210 | session = session,
211 | inputId = "select_satGet",
212 | choices = c("Select the satellite product(s)..." = "",
213 | satChoices)
214 | )
215 | }
216 | })
217 |
218 | # clears all markers currently drawn on the map
219 | observeEvent(input$action_clearMarkers, {
220 | leafletProxy("leaf") %>%
221 | clearMarkers()
222 | updateSelectInput(
223 | session,
224 | inputId = "select_satGet",
225 | choices = c("")
226 | )
227 | v$markerSel <- NULL
228 | v$markerId <- 1
229 | })
230 |
231 | # calling gee-px-ls.py to download satellite data
232 | event_getTs <- eventReactive(input$action_getTs, {
233 | withProgress(message = "Downloading satellite data...",
234 | value = 0,
235 | expr = {
236 | validate(need(
237 | input$select_satGet != "",
238 | "Please select a satellite from the list above."
239 | ))
240 |
241 | # store info about the downloaded marker
242 | v$markerDown$lat <- as.numeric(v$markerSel[2])
243 | v$markerDown$lon <- as.numeric(v$markerSel[1])
244 |
245 | # assign variable in Python with selected coordinates (lng,lat order)
246 | python.assign("coords", as.numeric(v$markerSel[1:2]))
247 |
248 | # call Python download script for each selected satellite
249 | serieList <- list()
250 | for(i in 1:length(input$select_satGet)) {
251 | # assign Python variables using Shiny inputs
252 | python.assign("satChoice", input$select_satGet[i])
253 |
254 | # execute Python download script
255 | # python.load(paste0(getwd(), "/python/gee-px-ls.py"))
256 | python.load(paste0(getwd(), "/python/gee-px-ls-new.py"))
257 |
258 | # update progress
259 | incProgress(amount = 1 / length(input$select_satGet))
260 |
261 | # get Python output and show download message
262 | if (is.null(unlist(python.get("serie")))) {
263 | showNotification(
264 | ui = paste(names(satChoices[satChoices == input$select_satGet[i]]),
265 | "- no data available."),
266 | type = "error",
267 | duration = 4,
268 | closeButton = F
269 | )
270 | serieList[[i]] <- NA
271 | } else {
272 | showNotification(
273 | ui = paste(names(satChoices[satChoices == input$select_satGet[i]]),
274 | "- data downloaded."),
275 | type = "message",
276 | duration = 4,
277 | closeButton = F
278 | )
279 | serieList[[i]] <- unlist(python.get("serie"))
280 | }
281 | }
282 |
283 | # check for data availability
284 | validate(
285 | need(
286 | prod(is.na(serieList)) == 0,
287 | "No data available for the chosen satellite(s) and/or region... Please change your query and try again."
288 | )
289 | )
290 |
291 | # remove from serieList those satellites with no data
292 | # also keep track of the satellites names in satOrder
293 | satOrder <- input$select_satGet[!is.na(serieList)]
294 | serieList[is.na(serieList)] <- NULL
295 |
296 | # arrange each list element form serieList as a df
297 | serie <- lapply(serieList, function(x) {
298 | tmp <- data.frame(matrix(x,
299 | ncol = python.get("numCol"),
300 | byrow = T))
301 |
302 | # format data type and columns names
303 | tmp[, 1] <- as.Date(tmp[, 1], format = "%Y_%m_%d")
304 | tmp[, 2:ncol(tmp)] <- apply(tmp[, 2:ncol(tmp)],
305 | MARGIN = 2,
306 | as.numeric)
307 | colnames(tmp) <- python.get("colNames")
308 |
309 | # exclude saturated data
310 | # filterWhich <- which(rowSums(tmp[, 2:ncol(tmp)] == 2) > 0)
311 | filterWhich <- which(rowSums(tmp[, 2:ncol(tmp)] == 2, na.rm = TRUE) > 0)
312 | if (length(filterWhich) > 0) {
313 | tmp <- tmp[-filterWhich, ]
314 | }
315 |
316 | return(tmp)
317 | })
318 |
319 | # create new column for each list element with corresponding satellite
320 | # name, also include this info as an attribute of the list
321 | for (i in 1:length(serie)) {
322 | serie[[i]]$sat <- satOrder[i]
323 | }
324 | attributes(serie) <- list(satOrder = satOrder)
325 |
326 | # update select_satPlot with all possible satellite choices to be
327 | # visualized
328 | updateSelectInput(
329 | session,
330 | inputId = "select_satPlot",
331 | choices = satChoices[which(satChoices %in% satOrder)]
332 | )
333 |
334 | # update select_index
335 | updateSelectInput(
336 | session = session,
337 | inputId = "select_index",
338 | choices = python.get("colNames")[-1]
339 | )
340 |
341 | python.assign("aux", NULL)
342 | python.assign("serie", NULL)
343 | python.assign("values", NULL)
344 | python.assign("numCol", NULL)
345 | python.assign("colNames", NULL)
346 |
347 | return(serie)
348 | })
349 | })
350 |
351 | # download plot modal
352 | observeEvent(input$action_downloadPlotRaw, {
353 | showModal(modalDownloadPlot(type = "Raw"))
354 | })
355 |
356 | observeEvent(input$action_downloadPlotBfm, {
357 | showModal(modalDownloadPlot(type = "Bfm"))
358 | })
359 |
360 | observeEvent(input$action_downloadPlotBf01, {
361 | showModal(modalDownloadPlot(type = "Bf01"))
362 | })
363 |
364 | observeEvent(input$action_downloadPlotBfast, {
365 | showModal(modalDownloadPlot(type = "Bfast"))
366 | })
367 |
368 | # ------------------------------------------------------------- MODALS ----
369 |
370 | modalDownloadPlot <- function(type = c("Raw", "Bfm", "Bf01", "Bfast")) {
371 | type = match.arg(type)
372 |
373 | modalDialog(
374 | title = "Please choose the output format",
375 | easyClose = T,
376 |
377 | div(align = "center",
378 | downloadButton(outputId = paste0("action_downloadPlot", type, "_jpg"),
379 | label = "JPEG",
380 | class = "btn-primary"),
381 | downloadButton(outputId = paste0("action_downloadPlot", type, "_png"),
382 | label = "PNG",
383 | class = "btn-primary"),
384 | downloadButton(outputId = paste0("action_downloadPlot", type, "_svg"),
385 | label = "SVG",
386 | class = "btn-primary")),
387 |
388 | footer = tagList(
389 | modalButton("Cancel")
390 | )
391 | )
392 | }
393 |
394 | # ----------------------------------------------------------- ANALYSIS ----
395 |
396 | # call to event_getTs in Map tab
397 | # display a message if the download is successful
398 | output$text_getTs <- renderText({
399 | event_getTs()
400 | return(
401 | as.character(div(
402 | align = "center",
403 | strong("Data succesfully downloaded!"),
404 | HTML('Please head to the Analysis tab.')
405 | ))
406 | )
407 | })
408 |
409 | # subset from serie using select_satPlot, and merge data in a single df
410 | serieSel <- eventReactive(input$select_satPlot, valueExpr = {
411 | serie <- event_getTs()
412 |
413 | # only show satellites selected in select_satPlot
414 | satOrder <- attr(serie, "satOrder")
415 | whichSel <- which(satOrder %in% input$select_satPlot)
416 | serie <- serie[whichSel]
417 |
418 | # join all data in a single df
419 | tmp <- NULL
420 | for (i in 1:length(whichSel)) {
421 | tmp <- rbind(tmp, serie[[i]])
422 | }
423 | serie <- tmp
424 |
425 | # sort data by date
426 | serie <- serie[order(serie$date), ]
427 |
428 | # removendo NAs
429 | serie <- na.omit(serie)
430 |
431 | # remove leap year additional day (29th Feb), if it exists
432 | leapDay <- grep("-02-29", serie$date)
433 | if(length(leapDay) > 0) {
434 | serie <- serie[-leapDay, ]
435 | }
436 |
437 | # group by date and satellite using median
438 | serie <- serie %>%
439 | group_by(date) %>%
440 | summarise_all(function(x) {
441 | if (typeof(x) == "character") {
442 | if (x %>% unique() %>% length() > 1) {
443 | "Mixed"
444 | } else {
445 | x[1]
446 | }
447 | } else {
448 | median(x)
449 | }
450 | }) %>%
451 | data.frame()
452 |
453 | return(serie)
454 | })
455 |
456 | observe({
457 | # subset the chosen index from the data
458 | matchCol <- which(input$select_index == colnames(serieSel()))
459 | satOrder <- satChoices[which(satChoices %in% input$select_satPlot)]
460 |
461 | # add "Mixed" to satOrder, if it exists in the data
462 | if("Mixed" %in% serieSel()$sat) {
463 | satOrder <- c(satOrder, "Mixed" = "Mixed")
464 | }
465 |
466 | # define a vector of graphical parameters (color and pch),
467 | # per satellite
468 | seriePar <- matrix(sapply(serieSel()$sat, satPar),
469 | ncol = 2,
470 | byrow = T)
471 |
472 | # custom ylim parameter
473 | ylimCustom <- c(0, 1)
474 | # if (sum(serieSel()[, matchCol] < 0) > 0) {
475 | # ylimCustom[1] <- -1
476 | # }
477 | # if (sum(serieSel()[, matchCol] > 1) > 0) {
478 | # ylimCustom[2] <- 1.5
479 | # }
480 |
481 | if (sum(serieSel()[, matchCol] < 0, na.rm = TRUE) > 0) {
482 | ylimCustom[1] <- -1
483 | }
484 | if (sum(serieSel()[, matchCol] > 1, na.rm = TRUE) > 0) {
485 | ylimCustom[2] <- 1.5
486 | }
487 |
488 | # custom x axis
489 | xAxisCustom <- seq(as.numeric(substr(range(serieSel()$date), 1, 4))[1] - 1,
490 | as.numeric(substr(range(serieSel()$date), 1, 4))[2] + 1,
491 | 1)
492 |
493 | # bfastmonitor line segment parameter
494 | h <- 0.25
495 |
496 | bfm_formula <- switch(
497 | input$select_bfm_formula,
498 | "trend + harmon" = response ~ trend + harmon,
499 | "harmon" = response ~ harmon,
500 | "trend" = response ~ trend
501 | )
502 |
503 | # conditions to check if few data is available for bfastmonitor
504 | cond1 <- switch(
505 | input$select_bfm_formula,
506 | "trend + harmon" = length(serieSel()[, matchCol]) > 4,
507 | "harmon" = length(serieSel()[, matchCol]) > 3,
508 | "trend" = length(serieSel()[, matchCol]) > 2
509 | )
510 | cond2 <- floor(h * length(serieSel()[, matchCol])) > 1
511 |
512 | # update input$select_bfm_monitor
513 | updateDateInput(
514 | session = session,
515 | inputId = "select_bfm_monitor",
516 | min = head(serieSel()$date, 1),
517 | max = tail(serieSel()$date, 1),
518 | value = tail(serieSel()$date,
519 | floor(length(serieSel()$date)*0.3))[1]
520 | )
521 |
522 | # update input$select_bf01_order
523 | if(input$select_bf01_formula != "trend") {
524 | if(input$select_bf01_formula == "harmon") {
525 | pars <- 1
526 | } else { # "trend + harmon"
527 | pars <- 2
528 | }
529 | orderMaxBf01 <- 0
530 | cond3 <- T
531 | while(cond3) {
532 | orderMaxBf01 <- orderMaxBf01 + 1
533 | cond3 <- (5 * (pars + 2 * orderMaxBf01)) < length(serieSel()[, matchCol]) / 2
534 | }
535 | orderMaxBf01 <- orderMaxBf01 - 1
536 | updateSliderInput(
537 | session = session,
538 | inputId = "select_bf01_order",
539 | max = orderMaxBf01
540 | )
541 | }
542 |
543 | # update select_bfm_order (WIP)
544 | # if(input$select_bfm_formula != "trend") {
545 | # if(input$select_bfm_history == "ROC") {
546 | # orderMaxBfm <- 0
547 | # cond4 <- F
548 | # while(!cond4) {
549 | # orderMaxBfm <- orderMaxBfm + 1
550 | # data <- bfastts(data = serieSel()[, matchCol],
551 | # dates = serieSel()$date,
552 | # type = "irregular")
553 | # data_tspp <- bfastpp(data, order = orderMaxBfm, lag = NULL, slag = NULL)
554 | # history_tspp <- subset(data_tspp, time < decimal_date(input$select_bfm_monitor))
555 | # data_rev <- history_tspp[nrow(history_tspp):1,]
556 | # data_rev$response <- ts(data_rev$response)
557 | # suppressWarnings(
558 | # y_rcus <- efp(bfm_formula, data = data_rev, type = "Rec-CUSUM")
559 | # )
560 | # cond4 <- is.na(y_rcus$process[1])
561 | # }
562 | # orderMaxBfm <- orderMaxBfm - 1
563 | # updateSliderInput(
564 | # session = session,
565 | # inputId = "select_bfm_order",
566 | # max = orderMaxBfm
567 | # )
568 | # }
569 | # }
570 |
571 | # raw time series plot
572 | output$plot_raw <- renderPlot({
573 | output$action_downloadDataRaw <- downloadHandler(
574 | filename = paste0("be-data-ts", ".csv"),
575 | content = {function(file) {
576 | if(v$markerDown$show) {
577 | header <- rep("", ncol(serieSel()))
578 | names(header) <- c("LatLong Coordinates", as.character(c(v$markerDown$lat, v$markerDown$lon)), rep("", ncol(serieSel()) - 3))
579 | write.table(x = t(header), file = file, sep = ",", row.names = F)
580 | options(warn = -1)
581 | write.table(x = serieSel(), file = file, sep = ",", row.names = F, append = T)
582 | options(warn = 0)
583 | } else {
584 | write.table(x = serieSel(), file = file, sep = ",", row.names = F)
585 | }
586 | }}
587 | )
588 |
589 | plotRawComb <- function() {
590 | plotRaw(
591 | serie = serieSel(),
592 | matchCol = matchCol,
593 | xAxisCustom = xAxisCustom,
594 | ylimCustom = ylimCustom,
595 | ylab = toupper(colnames(serieSel())[matchCol]),
596 | seriePar = seriePar,
597 | coords = v$markerDown
598 | )
599 | plotRawLegend(
600 | satOrder = satOrder,
601 | seriePar = seriePar
602 | )
603 | }
604 |
605 | output$action_downloadPlotRaw_jpg <- downloadHandler(
606 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-ts", ".jpg"),
607 | content = {function(file) {
608 | jpeg(file, width = 1080, height = 600)
609 | layout(mat = matrix(c(1, 2), ncol = 2),
610 | widths = c(1.5, 0.5))
611 | plotRawComb()
612 | dev.off()
613 | }}
614 | )
615 |
616 | output$action_downloadPlotRaw_png <- downloadHandler(
617 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-ts", ".png"),
618 | content = {function(file) {
619 | png(file, width = 1080, height = 600)
620 | layout(mat = matrix(c(1, 2), ncol = 2),
621 | widths = c(1.5, 0.5))
622 | plotRawComb()
623 | dev.off()
624 | }}
625 | )
626 |
627 | output$action_downloadPlotRaw_svg <- downloadHandler(
628 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-ts", ".svg"),
629 | content = {function(file) {
630 | svg(file, width = 16, height = 8)
631 | layout(mat = matrix(c(1, 2), ncol = 2),
632 | widths = c(1.5, 0.5))
633 | plotRawComb()
634 | dev.off()
635 | }}
636 | )
637 |
638 | plotRaw(
639 | serie = serieSel(),
640 | matchCol = matchCol,
641 | xAxisCustom = xAxisCustom,
642 | ylimCustom = ylimCustom,
643 | ylab = toupper(colnames(serieSel())[matchCol]),
644 | seriePar = seriePar,
645 | coords = v$markerDown
646 | )
647 | })
648 |
649 | # bfastmonitor results plot
650 | output$plot_bfm <- renderPlot({
651 | # if(input$select_bfm_formula != "trend") {
652 | # validate(
653 | # need(
654 | # input$select_bfm_order <= orderMaxBfm,
655 | # FALSE
656 | # )
657 | # )
658 | # }
659 | validate(
660 | need(
661 | cond1 & cond2,
662 | "The selected history period hasn't enough observations."
663 | )
664 | )
665 |
666 | # run bfastmonitor
667 | res <- ppBfastmonitor(
668 | x = serieSel()[, matchCol],
669 | date = serieSel()$date,
670 | formula = bfm_formula,
671 | order = input$select_bfm_order,
672 | start = decimal_date(input$select_bfm_monitor),
673 | history = input$select_bfm_history,
674 | h = h
675 | )
676 |
677 | output$action_downloadDataBfm <- downloadHandler(
678 | filename = paste0("be-", colnames(serieSel())[matchCol], "-results-bfastmonitor", ".rds"),
679 | content = {function(file) {
680 | saveRDS(object = res,
681 | file = file)
682 | }}
683 | )
684 |
685 | plotBfmComb <- function() {
686 | plotBfm(
687 | serie = serieSel(),
688 | matchCol = matchCol,
689 | bfmOut = res,
690 | xAxisCustom = xAxisCustom,
691 | ylimCustom = ylimCustom,
692 | ylab = toupper(colnames(serieSel())[matchCol])
693 | )
694 | plotBfmLegend()
695 | }
696 |
697 | output$action_downloadPlotBfm_jpg <- downloadHandler(
698 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfastmonitor", ".jpg"),
699 | content = {function(file) {
700 | jpeg(file, width = 1080, height = 600)
701 | layout(mat = matrix(c(1, 2), ncol = 2),
702 | widths = c(1.5, 0.5))
703 | plotBfmComb()
704 | dev.off()
705 | }}
706 | )
707 |
708 | output$action_downloadPlotBfm_png <- downloadHandler(
709 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfastmonitor", ".png"),
710 | content = {function(file) {
711 | png(file, width = 1080, height = 600)
712 | layout(mat = matrix(c(1, 2), ncol = 2),
713 | widths = c(1.5, 0.5))
714 | plotBfmComb()
715 | dev.off()
716 | }}
717 | )
718 |
719 | output$action_downloadPlotBfm_svg <- downloadHandler(
720 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfastmonitor", ".svg"),
721 | content = {function(file) {
722 | svg(file, width = 16, height = 8)
723 | layout(mat = matrix(c(1, 2), ncol = 2),
724 | widths = c(1.5, 0.5))
725 | plotBfmComb()
726 | dev.off()
727 | }}
728 | )
729 |
730 | # plot bfastmonitor results
731 | plotBfm(
732 | serie = serieSel(),
733 | matchCol = matchCol,
734 | bfmOut = res,
735 | xAxisCustom = xAxisCustom,
736 | ylimCustom = ylimCustom,
737 | ylab = toupper(colnames(serieSel())[matchCol])
738 | )
739 | })
740 |
741 | # bfast01 results plot
742 | output$plot_bf01 <- renderPlot({
743 | if(input$select_bf01_formula != "trend") {
744 | validate(
745 | need(
746 | input$select_bf01_order <= orderMaxBf01,
747 | FALSE
748 | )
749 | )
750 | }
751 |
752 | bf01_formula <- switch(
753 | input$select_bf01_formula,
754 | "trend + harmon" = response ~ trend + harmon,
755 | "harmon" = response ~ harmon,
756 | "trend" = response ~ trend
757 | )
758 |
759 | res <- ppBfast01(
760 | x = serieSel()[, matchCol],
761 | date = serieSel()$date,
762 | formula = bf01_formula,
763 | order = input$select_bf01_order
764 | )
765 |
766 | output$action_downloadDataBf01 <- downloadHandler(
767 | filename = paste0("be-", colnames(serieSel())[matchCol], "-results-bfast01", ".rds"),
768 | content = {function(file) {
769 | saveRDS(object = res,
770 | file = file)
771 | }}
772 | )
773 |
774 | plotBf01Comb <- function() {
775 | plotBf01(
776 | serie = serieSel(),
777 | matchCol = matchCol,
778 | bf01Out = res,
779 | xAxisCustom = xAxisCustom,
780 | ylimCustom = ylimCustom,
781 | ylab = toupper(colnames(serieSel())[matchCol])
782 | )
783 | plotBf01Legend()
784 | }
785 |
786 | output$action_downloadPlotBf01_jpg <- downloadHandler(
787 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfast01", ".jpg"),
788 | content = {function(file) {
789 | jpeg(file, width = 1080, height = 600)
790 | layout(mat = matrix(c(1, 2), ncol = 2),
791 | widths = c(1.5, 0.5))
792 | plotBf01Comb()
793 | dev.off()
794 | }}
795 | )
796 |
797 | output$action_downloadPlotBf01_png <- downloadHandler(
798 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfast01", ".png"),
799 | content = {function(file) {
800 | png(file, width = 1080, height = 600)
801 | layout(mat = matrix(c(1, 2), ncol = 2),
802 | widths = c(1.5, 0.5))
803 | plotBf01Comb()
804 | dev.off()
805 | }}
806 | )
807 |
808 | output$action_downloadPlotBf01_svg <- downloadHandler(
809 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfast01", ".svg"),
810 | content = {function(file) {
811 | svg(file, width = 16, height = 8)
812 | layout(mat = matrix(c(1, 2), ncol = 2),
813 | widths = c(1.5, 0.5))
814 | plotBf01Comb()
815 | dev.off()
816 | }}
817 | )
818 |
819 | plotBf01(
820 | serie = serieSel(),
821 | matchCol = matchCol,
822 | bf01Out = res,
823 | xAxisCustom = xAxisCustom,
824 | ylimCustom = ylimCustom,
825 | ylab = toupper(colnames(serieSel())[matchCol])
826 | )
827 | })
828 |
829 | # bfast results plot
830 | output$plot_bfast <- renderPlot({
831 | res <- ppBfast(
832 | x = serieSel()[, matchCol],
833 | date = serieSel()$date,
834 | h = input$select_bfast_h,
835 | season = input$select_bfast_season
836 | )
837 |
838 | output$action_downloadDataBfast <- downloadHandler(
839 | filename = paste0("be-", colnames(serieSel())[matchCol], "-results-bfast", ".rds"),
840 | content = {function(file) {
841 | saveRDS(object = res,
842 | file = file)
843 | }}
844 | )
845 |
846 | plotBfastComb <- function() {
847 | plotBfast(
848 | serie = serieSel(),
849 | matchCol = matchCol,
850 | bfastOut = res,
851 | xAxisCustom = xAxisCustom,
852 | ylimCustom = ylimCustom,
853 | ylab = toupper(colnames(serieSel())[matchCol])
854 | )
855 | plotBfastLegend()
856 | }
857 |
858 | output$action_downloadPlotBfast_jpg <- downloadHandler(
859 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfast", ".jpg"),
860 | content = {function(file) {
861 | jpeg(file, width = 1080, height = 600)
862 | layout(mat = matrix(c(1, 2), ncol = 2),
863 | widths = c(1.5, 0.5))
864 | plotBfastComb()
865 | dev.off()
866 | }}
867 | )
868 |
869 | output$action_downloadPlotBfast_png <- downloadHandler(
870 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfast", ".png"),
871 | content = {function(file) {
872 | png(file, width = 1080, height = 600)
873 | layout(mat = matrix(c(1, 2), ncol = 2),
874 | widths = c(1.5, 0.5))
875 | plotBfastComb()
876 | dev.off()
877 | }}
878 | )
879 |
880 | output$action_downloadPlotBfast_svg <- downloadHandler(
881 | filename = paste0("be-", colnames(serieSel())[matchCol], "-plot-bfast", ".svg"),
882 | content = {function(file) {
883 | svg(file, width = 16, height = 8)
884 | layout(mat = matrix(c(1, 2), ncol = 2),
885 | widths = c(1.5, 0.5))
886 | plotBfastComb()
887 | dev.off()
888 | }}
889 | )
890 |
891 | plotBfast(
892 | serie = serieSel(),
893 | matchCol = matchCol,
894 | bfastOut = res,
895 | xAxisCustom = xAxisCustom,
896 | ylimCustom = ylimCustom,
897 | ylab = toupper(colnames(serieSel())[matchCol])
898 | )
899 | })
900 |
901 | # raw time series legend
902 | output$plot_raw_legend <- renderPlot({
903 | plotRawLegend(
904 | satOrder = satOrder,
905 | seriePar = seriePar
906 | )
907 | })
908 |
909 | # bfastmonitor legend
910 | output$plot_bfm_legend <- renderPlot({
911 | plotBfmLegend()
912 | })
913 |
914 | # bfast01 legend
915 | output$plot_bf01_legend <- renderPlot({
916 | plotBf01Legend()
917 | })
918 |
919 | # bfast legend
920 | output$plot_bfast_legend <- renderPlot({
921 | plotBfastLegend()
922 | })
923 | })
924 | })
925 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/www/logo-cnpq.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
12 |
17 |
19 |
173 |
344 |
480 |
517 |
518 |
--------------------------------------------------------------------------------