diff --git a/DRAFT_Connectivity.Rmd b/DRAFT_Connectivity.Rmd
new file mode 100644
index 00000000..0bd88737
--- /dev/null
+++ b/DRAFT_Connectivity.Rmd
@@ -0,0 +1,266 @@
+---
+title: "Template for indicator documentation"
+output:
+ html_document
+---
+
+
+
+
+
+
+
+
+# Connectivity
+
+
+
+_Author and date:_
+Vegar Bakkestuen, October 2023_
+
+
+
+
+
+```{r setup, include=FALSE}
+library(knitr)
+knitr::opts_chunk$set(echo = TRUE)
+```
+
+
+
+```{r, echo=F}
+Ecosystem <- "Våtmark"
+Egenskap <- "Konnektivitet"
+ECT <- " Strukturell konnektivitet"
+Contact <- "Vegar Bakkestuen"
+```
+
+```{r, echo=F}
+metaData <- data.frame(Ecosystem,
+ "Økologisk egenskap" = Egenskap,
+ "ECT class" = ECT)
+knitr::kable(metaData)
+```
+
+
+
+
+
+
+
+
+
+
+## Introduction
+Loss of natural habitat and changes in landscape patterns are central issues in biogeography and conservation biology. The loss of connectivity (connections or linkages) between suitable habitats affects individuals, populations, and communities through various ecosystem interactions. In landscape ecology, connectivity is essentially defined as "the degree to which the landscape facilitates or impedes movement between patches of resources or suitable habitats." The concept of connectivity encompasses both structural connectivity, which involves the physical locations of suitable and unsuitable habitats or patches being analyzed, and functional connectivity, which focuses on the actual movement of individuals across suitable and unsuitable habitats and disturbance barriers. We have assessed that there is currently insufficient data available to start calculating functional connectivity on a national scale in relation to the assessment of ecological condition, as there is almost a total lack of relevant data for almost all species. Therefore, we have developed an index for structural connectivity based on physical interventions calculated using an infrastructure index (Erikstad et al. 2023) and a new wetland map for Norway (Bakkestuen et al. 2023, Bakkestuen et al. in prep).
+Here a general workflow for the calculation of the indicator.
+1. You must load the necessary libraries for geospatial analysis.
+2. You must load the infrastructure index and wetland data.
+3. You define the buffer distance (500 meters).
+4. You must create a function (calculateMeanDistance) to calculate the mean distance to infrastructure within a buffer around each wetland polygon.
+5. Then you filter the wetlands with more than 80% coverage.
+6. You have to apply the calculateMeanDistance function to these selected wetlands, both with and without infrastructure.
+7. You export the results as shapefiles for both scenarios.
+8. The reference values for the "Connectivity" indicator are determined by comparing two scenarios: one that includes the presence of infrastructure and one that excludes infrastructure. The reference value is calculated as the ratio of the mean distances between myrpolygon areas in these two scenarios.
+
+## About the underlying data
+The infrastructure index is one part of the connectivity index for wetlands. The infrastructure index was calculated for three time points: 2003, 2013, and 2023. This provides a temporal perspective for assessing changes over time. The data used included information on various types of infrastructure, such as roads and buildings. Additionally, a new wetland map for Norway has been developed. This map is based on Sentinel-2 and LiDAR data from the year 2020. The U-Net model, implemented through Google Earth Engine and TensorFlow, has been used for mapping wetlands in southern Norway. The model achieved a balanced accuracy rate of 90.9% when validated against ground-truth samples, significantly improving upon the accuracy rates achieved with manually digitized maps in Norway.
+
+### Representativity in time and space
+The data for the infrastructure index covers the entire country and was collected for three time points over a 20-year period. This provides a broad and representative dataset for assessing changes in connectivity in Norwegian landscapes. The wetland mapping was conducted using data from the year 2020, making it representative for that specific time frame. However, the model used in the mapping process can be applied to other time frames if necessary.
+### Original units
+The infrastructure index has no specific units as it is a measure of landscape fragmentation and disruption. It is expressed as a dimensionless index.
+
+### Temporal coverage
+The data covers three time points: 2003, 2013, and 2023. This provides a 20-year temporal perspective for assessing changes in connectivity over time. The wetland mapping provides information in the form of pixel values representing wetland presence or absence.
+
+### Aditional comments about the dataset
+It is important to note that infrastructure data are based on available map and geographical data sources. Sometimes, there may be variations and uncertainties in this data that can affect the accuracy of the infrastructure index.
+
+## Ecosystem characteristic
+In the context of the Norwegian standard, the "Connectivity" indicator aligns with the ecosystem characteristic known as "Biologisk mangfold" or "Biological diversity." This classification underscores the significance of the indicator in assessing its impact on biological diversity within ecosystems. It emphasizes how connectivity can influence biological diversity by facilitating or impeding the movement of species across habitats. Additionally, the indicator could also be relevant in the context of "funksjonelt viktige arter og strukturer," or "functionally important species and structures," particularly when assessing its effects on nutrient cycling, species recruitment, or other key ecosystem functions.
+UN Standard
+### SEEA EA (UN standard)
+In the framework of the United Nations System of Environmental-Economic Accounting (SEEA EA), the "Connectivity" indicator can be classified as a B1 "Compositional state characteristics" indicator. This classification within the SEEA EA framework highlights the indicator's role in assessing the compositional state of ecosystems. By examining how connectivity influences the arrangement and presence of species and structures within an ecosystem, it provides valuable insights into the overall composition and structure of ecosystems.
+
+## Collinearities with other indicators
+Connectivity is not thought to exhibit collinearity with any other indicator at the present.
+
+## Reference condition and values
+### Reference condition
+The reference condition for the "Connectivity" indicator is characterized as one with minimal negative human impact on the connectivity of ecosystems. In this reference condition, the landscape exhibits natural and undisturbed patterns of connectivity between suitable habitats. This state represents the optimal ecological condition for connectivity assessment.
+
+### Reference values, thresholds for defining _good ecological condition_, minimum and/or maximum values
+The reference values for the "Connectivity" indicator are determined by comparing two scenarios: one that includes the presence of infrastructure and one that excludes infrastructure. The reference value is calculated as the ratio of the mean distances between myrpolygon areas in these two scenarios. This ratio provides a value between 0 and 1, where 0 indicates a severe disruption of connectivity due to infrastructure, and 1 represents an undisturbed natural state of connectivity.
+Thresholds for defining "good ecological condition" can be established based on this reference value. For instance, a reference value close to 1 would indicate that connectivity is minimally affected by infrastructure, suggesting a state of good ecological condition. In contrast, a reference value closer to 0 would signify a significant negative impact on connectivity, indicating a less desirable ecological condition. The specific thresholds may vary based on the desired ecological quality standards and policy objectives.
+In the report «Vurdering av økologisk tilstand for fjell i Norge i 2021» (Framstad et al. 2021) the value of 0,8 was used as the threshold for good ecological condition.
+
+## Uncertainties
+Our wetland mapping model is a powerful tool for large-scale mapping but does come with certain uncertainties. While our U-Net model achieved an impressive balanced accuracy rate of 90.9% when validated against an independent ground-truth sample, it's essential to recognize that some level of uncertainty is inherent. The model's accuracy may vary across different wetland types and landscape conditions. The model's performance might vary in regions with distinct wetland characteristics that differ from our training data. It may not fully capture variations in wetland types or subtle differences in wetland boundaries. The accuracy of the wetland mapping model is influenced by the quality and representativeness of the training data. We made significant efforts to ensure the highest quality, but the inherent variability in ground-truth data may introduce some level of uncertainty.
+
+The infrastructure data sources used for this analysis might contain inaccuracies, errors, or omissions. These can arise from factors like inconsistent reporting and data collection methods. While infrastructure data is a valuable proxy for landscape barriers, it may not capture all potential barriers accurately. For instance, small-scale features or unreported structures could introduce uncertainties in connectivity assessments. The resolution of the infrastructure data might not capture all relevant features at a fine scale. This can affect the precision of connectivity assessments in areas with small, localized infrastructure.
+
+
+## References
+Bakkestuen, V.; Venter, Z.; Ganerød, A.J.; Framstad, E. Delineation of Wetland Areas in South Norway from Sentinel-2 Imagery and LiDAR Using TensorFlow, U-Net, and Google Earth Engine. Remote Sens. 2023, 15, 1203. https://doi.org/10.3390/rs15051203
+Bakkestuen, V. et al. in prep. Comprehensive Mapping of Wetland Areas in Norway: An Integration of Sentinel-2 Imagery, LiDAR, and Deep Learning Using TensorFlow and Google Earth Engine
+Erikstad, L.; Simensen, T.; Bakkestuen, V.; Halvorsen, R. Index Measuring Land Use Intensity—A Gradient-Based Approach. Geomatics 2023, 3, 188-204. https://doi.org/10.3390/geomatics3010010
+Framstad, E., Eide, N.E., Eide, W., Klanderud, K., Kolstad, A., Töpper, J. & Vandvik, V. 2022. Vurdering av økologisk tilstand for fjell i Norge i 2021. NINA Rapport 2050. Norsk institutt for naturforskning.
+
+
+## Analyses
+### Data sets
+Two main data sets were included. (A) The infrastructure index (Erikstad et al. 2023) and the wetland model (Bakkestuen et al. 2023) and Bakkestuen et al. In prep.
+
+
+#### Data set A
+The infrastructure index utilized in this analysis was derived from data sources available through Google Earth Engine (GEE). The index quantifies the presence and distribution of key infrastructure elements such as roads, buildings, and related human-made structures across Norway. The data were available for the years 2003, 2013, and 2023, facilitating an assessment of how infrastructure has evolved in terms of both magnitude and distribution over time. It is important to note that this data forms a fundamental component in the calculation of the connectivity indicator.
+
+#### Data set B
+The wetland model used in this study was developed based on the integration of Sentinel-2 satellite imagery and LiDAR data, utilizing deep learning techniques. The model provides high-resolution information regarding the distribution and extent of wetland areas within southern Norway, specifically for the year 2020. By fusing spectral and elevation data, this model offers significant improvements over conventional, manually-digitized land cover maps. The wetland model is a critical component of the connectivity analysis, as it aids in the identification of ecologically relevant areas. The data set B for South-Norway is already accessible here: Åpen våtmark i Sør-Norge basert på Natur i Norge (NiN) typologi - Kartkatalogen (geonorge.no)
+
+### Scaled indicator values
+The connectivity indicator was created by examining the interplay between infrastructure and wetland areas. We initially calculated the average distance between wetland patches using the wetland model, representing a baseline measure of natural connectivity in the absence of infrastructure (i.e., the reference condition). Subsequently, the infrastructure index was introduced, portraying the extent of human-made structural elements within the landscape.
+To assess the impact of infrastructure on connectivity, we conducted two scenarios: one considering connectivity with infrastructure and another without it. In both scenarios, we measured the average distance between wetland patches. This comparison enabled the quantification of changes in connectivity attributed to the presence of infrastructure. The results provide a clear depiction of how infrastructure influences connectivity between wetland areas, with reference values set according to the reference condition.
+
+### Uncertainty
+Wetland Model Uncertainties: The wetland model's accuracy is dependent on various factors, including the quality of Sentinel-2 imagery and the accuracy of LiDAR data. While we achieved a balanced accuracy rate of 90.9% when validating the model against an independent ground-truth sample, it's important to acknowledge that uncertainties may arise due to classification errors, misalignment between satellite imagery and LiDAR data, and variations in wetland characteristics. The accuracy rate of this model significantly surpasses traditional mapping methods but should be interpreted with awareness of these potential sources of uncertainty.
+Infrastructure Index Uncertainties: The infrastructure index is based on the availability and accuracy of infrastructure data sources. Variations in the quality of data and the ability to correctly identify and classify different infrastructure elements may introduce uncertainties in the index. While efforts have been made to minimize such uncertainties, it is important to recognize that the index's accuracy may vary depending on data sources and their completeness.
+
+
+## Prepare export
+You must run the whole code below. There is a maximum of 5000 wetland polygons for each export.
+
+
+
+### Eksport file (final product)
+Kode
+Koden er utviklet i JAVA for Google Earth Engine:
+// Senter kartet til en bestemt geografisk posisjon (bredde- og lengdegrad) og velg en zoomnivå
+Map.setCenter(11.0534047, 62.14137, 12);
+
+// Laste inn infrastrukturindeks og myr datasett fra Google Earth Engine (GEE). Datasettene er delt og fitt tilgjengelig for alle fra GEE
+
+Data
+var infrastruktur = ee.Image('users/vegar/NY_INFRA_IND');
+var myrpred2 = ee.ImageCollection('users/vegarbakkestuen/Myr153');
+var myrpred2 = ee.ImageCollection('users/vegarbakkestuen/Myr153');
+var myrpredNN = ee.ImageCollection('users/vegarbakkestuen/Myr168NN');
+
+var myrpredNN = myrpredNN.mean()
+var myrpred = myrpred2.mean()//.rename('DTM');
+
+
+// Legg til myrdata som et lag på kartet med tilpassede visningsparametere
+Map.addLayer(myr, {min: 0, max: 1, palette: ['white', 'green']}, 'myr');
+Map.addLayer(infrastruktur, {min: 0, max: 13, palette: ['blue', 'yellow', 'red']}, 'infrastruktur');
+
+// Definer en bufferavstand (i meter) som bestemmer området som blir analysert rundt hvert myrpolygon
+var bufferDistance = 500;
+
+// Funksjon for å beregne gjennomsnittlig avstand til infrastruktur
+var calculateMeanDistance = function(feature) {
+ // Beregn gjennomsnittlig avstand til infrastruktur ved å redusere regionen rundt hvert myrpolygon
+ var distance = infrastruktur.rename('infrastruktur').reduceRegion({
+ reducer: ee.Reducer.mean(),
+ geometry: feature.geometry().buffer(bufferDistance),
+ scale: 10, // Oppløsningen til datasettet (meters per piksel)
+ maxPixels: 1e13
+ }).get('infrastruktur');
+ return feature.set('mean_distance', distance);
+};
+
+// Velg områder med myr (myrinnhold > 80%) og bruk dette som geometri for analysen
+var omraderMedMyr = myr.gt(0.8).selfMask();
+
+// Hent geometriene for hvert område med myr
+var omraderGeometries = omraderMedMyr.reduceToVectors({
+ geometry: Map.getBounds(true),
+ scale: 10, // Oppløsningen til datasettet (meters per piksel)
+ maxPixels: 1e13
+});
+
+// Bruk funksjonen calculateMeanDistance for å beregne gjennomsnittlig avstand til infrastruktur for hvert område med myr
+
+// For scenariet "Konnektivitet med infrastruktur"
+var omraderMedGjennomsnittligAvstand = omraderGeometries.map(calculateMeanDistance);
+
+// Legg til lag som viser myrpolygonene og lag med gjennomsnittlig avstand til infrastruktur på kartet
+Map.addLayer(omraderMedMyr, {min: 0, max: 1, palette: ['white', 'green']}, 'Myrpolygoner');
+
+// Vis scenariet "Konnektivitet med infrastruktur" på kartet
+var visParams = {
+ min: 0,
+ max: 1, // Juster dette basert på din infrastrukturindeksens min og maks
+ palette: ['blue', 'yellow', 'red'],
+};
+Map.addLayer(omraderMedGjennomsnittligAvstand, visParams, 'Gjennomsnittlig avstand til infrastruktur');
+
+// Eksporter resultatene som en Shapefile til Google Drive
+Export.table.toDrive({
+ collection: omraderMedGjennomsnittligAvstand,
+ description:'Konnektivitet_med_infrastruktur', // Navnet på eksportfilen for scenariet "Konnektivitet med infrastruktur"
+ fileFormat: 'SHP' // Filformat for eksport (Shapefile)
+});
+
+// Skift til scenariet "Konnektivitet uten infrastruktur" ved å fjerne infrastrukturdataene
+infrastruktur = ee.Image(0); // Nullstiller infrastruktur til et tomt bilde
+var omraderMedGjennomsnittligAvstandUtenInfrastruktur = omraderGeometries.map(calculateMeanDistance);
+
+// Vis scenariet "Konnektivitet uten infrastruktur" på kartet
+Map.addLayer(omraderMedGjennomsnittligAvstandUtenInfrastruktur, visParams, 'Gjennomsnittlig avstand uten infrastruktur');
+
+// Eksporter resultatene som en Shapefile til Google Drive for scenariet "Konnektivitet uten infrastruktur"
+Export.table.toDrive({
+ collection: omraderMedGjennomsnittligAvstandUtenInfrastruktur,
+ description:'Konnektivitet_uten_infrastruktur', // Navnet på eksportfilen for scenariet "Konnektivitet uten infrastruktur"
+ fileFormat: 'SHP' // Filformat for eksport (Shapefile)
+});
+
+# Skift til scenariet "Konnektivitet uten infrastruktur" ved å fjerne infrastrukturdataene
+infrastruktur = ee.Image(0); // Nullstiller infrastruktur til et tomt bilde
+var omraderMedGjennomsnittligAvstandUtenInfrastruktur = omraderGeometries.map(calculateMeanDistance);
+
+// Vis scenariet "Konnektivitet uten infrastruktur" på kartet
+Map.addLayer(omraderMedGjennomsnittligAvstandUtenInfrastruktur, visParams, 'Gjennomsnittlig avstand uten infrastruktur');
+
+// Eksporter resultatene som en Shapefile til Google Drive for scenariet "Konnektivitet uten infrastruktur"
+Export.table.toDrive({
+ collection: omraderMedGjennomsnittligAvstandUtenInfrastruktur,
+ description:'Konnektivitet_uten_infrastruktur', // Navnet på eksportfilen for scenariet "Konnektivitet uten infrastruktur"
+ fileFormat: 'SHP' // Filformat for eksport (Shapefile)
+});
+
+// The "Connectivity" reference values is created by dividing the result without infrastructure by the result that includes infrastructure. This ratio will give you a value between 0 and 1, where 0 represents complete disruption of connectivity due to infrastructure, and 1 represents undisturbed natural connectivity.
+
+# Calculate the reference value for connectivity
+reference_value <- selected_wetlands_without_infrastructure$mean_distance / selected_wetlands_with_infrastructure$mean_distance
+
+
diff --git a/Konnetivitet.Rmd b/Konnetivitet.Rmd
new file mode 100644
index 00000000..a639d0fa
--- /dev/null
+++ b/Konnetivitet.Rmd
@@ -0,0 +1,99 @@
+Konnektivitet
+
+Kode
+Koden er utviklet i JAVA for Google Earth Engine:
+// Senter kartet til en bestemt geografisk posisjon (bredde- og lengdegrad) og velg en zoomnivå
+Map.setCenter(11.0534047, 62.14137, 12);
+
+// Laste inn infrastrukturindeks og myr datasett fra Google Earth Engine (GEE). Datasettene er delt og fitt tilgjengelig for alle fra GEE
+
+Data
+var infrastruktur = ee.Image('users/vegar/NY_INFRA_IND');
+var myrpred2 = ee.ImageCollection('users/vegarbakkestuen/Myr153');
+var myrpred2 = ee.ImageCollection('users/vegarbakkestuen/Myr153');
+var myrpredNN = ee.ImageCollection('users/vegarbakkestuen/Myr168NN');
+
+var myrpredNN = myrpredNN.mean()
+var myrpred = myrpred2.mean()//.rename('DTM');
+
+
+// Legg til myrdata som et lag på kartet med tilpassede visningsparametere
+Map.addLayer(myr, {min: 0, max: 1, palette: ['white', 'green']}, 'myr');
+Map.addLayer(infrastruktur, {min: 0, max: 13, palette: ['blue', 'yellow', 'red']}, 'infrastruktur');
+
+// Definer en bufferavstand (i meter) som bestemmer området som blir analysert rundt hvert myrpolygon
+var bufferDistance = 500;
+
+// Funksjon for å beregne gjennomsnittlig avstand til infrastruktur
+var calculateMeanDistance = function(feature) {
+ // Beregn gjennomsnittlig avstand til infrastruktur ved å redusere regionen rundt hvert myrpolygon
+ var distance = infrastruktur.rename('infrastruktur').reduceRegion({
+ reducer: ee.Reducer.mean(),
+ geometry: feature.geometry().buffer(bufferDistance),
+ scale: 10, // Oppløsningen til datasettet (meters per piksel)
+ maxPixels: 1e13
+ }).get('infrastruktur');
+ return feature.set('mean_distance', distance);
+};
+
+// Velg områder med myr (myrinnhold > 80%) og bruk dette som geometri for analysen
+var omraderMedMyr = myr.gt(0.8).selfMask();
+
+// Hent geometriene for hvert område med myr
+var omraderGeometries = omraderMedMyr.reduceToVectors({
+ geometry: Map.getBounds(true),
+ scale: 10, // Oppløsningen til datasettet (meters per piksel)
+ maxPixels: 1e13
+});
+
+// Bruk funksjonen calculateMeanDistance for å beregne gjennomsnittlig avstand til infrastruktur for hvert område med myr
+
+// For scenariet "Konnektivitet med infrastruktur"
+var omraderMedGjennomsnittligAvstand = omraderGeometries.map(calculateMeanDistance);
+
+// Legg til lag som viser myrpolygonene og lag med gjennomsnittlig avstand til infrastruktur på kartet
+Map.addLayer(omraderMedMyr, {min: 0, max: 1, palette: ['white', 'green']}, 'Myrpolygoner');
+
+// Vis scenariet "Konnektivitet med infrastruktur" på kartet
+var visParams = {
+ min: 0,
+ max: 1, // Juster dette basert på din infrastrukturindeksens min og maks
+ palette: ['blue', 'yellow', 'red'],
+};
+Map.addLayer(omraderMedGjennomsnittligAvstand, visParams, 'Gjennomsnittlig avstand til infrastruktur');
+
+// Eksporter resultatene som en Shapefile til Google Drive
+Export.table.toDrive({
+ collection: omraderMedGjennomsnittligAvstand,
+ description:'Konnektivitet_med_infrastruktur', // Navnet på eksportfilen for scenariet "Konnektivitet med infrastruktur"
+ fileFormat: 'SHP' // Filformat for eksport (Shapefile)
+});
+
+// Skift til scenariet "Konnektivitet uten infrastruktur" ved å fjerne infrastrukturdataene
+infrastruktur = ee.Image(0); // Nullstiller infrastruktur til et tomt bilde
+var omraderMedGjennomsnittligAvstandUtenInfrastruktur = omraderGeometries.map(calculateMeanDistance);
+
+// Vis scenariet "Konnektivitet uten infrastruktur" på kartet
+Map.addLayer(omraderMedGjennomsnittligAvstandUtenInfrastruktur, visParams, 'Gjennomsnittlig avstand uten infrastruktur');
+
+// Eksporter resultatene som en Shapefile til Google Drive for scenariet "Konnektivitet uten infrastruktur"
+Export.table.toDrive({
+ collection: omraderMedGjennomsnittligAvstandUtenInfrastruktur,
+ description:'Konnektivitet_uten_infrastruktur', // Navnet på eksportfilen for scenariet "Konnektivitet uten infrastruktur"
+ fileFormat: 'SHP' // Filformat for eksport (Shapefile)
+});
+
+# Skift til scenariet "Konnektivitet uten infrastruktur" ved å fjerne infrastrukturdataene
+infrastruktur = ee.Image(0); // Nullstiller infrastruktur til et tomt bilde
+var omraderMedGjennomsnittligAvstandUtenInfrastruktur = omraderGeometries.map(calculateMeanDistance);
+
+// Vis scenariet "Konnektivitet uten infrastruktur" på kartet
+Map.addLayer(omraderMedGjennomsnittligAvstandUtenInfrastruktur, visParams, 'Gjennomsnittlig avstand uten infrastruktur');
+
+// Eksporter resultatene som en Shapefile til Google Drive for scenariet "Konnektivitet uten infrastruktur"
+Export.table.toDrive({
+ collection: omraderMedGjennomsnittligAvstandUtenInfrastruktur,
+ description:'Konnektivitet_uten_infrastruktur', // Navnet på eksportfilen for scenariet "Konnektivitet uten infrastruktur"
+ fileFormat: 'SHP' // Filformat for eksport (Shapefile)
+});
+