From 05f71d484d1044f49ef63f96830d00e358856bd9 Mon Sep 17 00:00:00 2001 From: dcarver1 Date: Thu, 12 Oct 2023 10:05:13 -0700 Subject: [PATCH 1/3] commit to pull --- .Rhistory | 1 + src/grabNAIPfromGEE.py | 0 2 files changed, 1 insertion(+) create mode 100644 src/grabNAIPfromGEE.py diff --git a/.Rhistory b/.Rhistory index 2ea3d8f9..c89a6293 100755 --- a/.Rhistory +++ b/.Rhistory @@ -30,3 +30,4 @@ image, mask, batch=True, foreground=True, erosion_kernel=(3, 3), mask_multiplier conda create -n gee python=3.10 conda activate gee reticulate::repl_python() +reticulate::repl_python() diff --git a/src/grabNAIPfromGEE.py b/src/grabNAIPfromGEE.py new file mode 100644 index 00000000..e69de29b From bbe9f03c62e5ae21633c8ed3c8c003987f44d519 Mon Sep 17 00:00:00 2001 From: dcarver1 Date: Thu, 12 Oct 2023 10:32:38 -0700 Subject: [PATCH 2/3] temp placement --- .Rhistory | 33 - .Rproj.user/290AA6C8/pcs/files-pane.pper | 9 + .Rproj.user/290AA6C8/pcs/source-pane.pper | 3 + .../290AA6C8/pcs/windowlayoutstate.pper | 14 + .Rproj.user/290AA6C8/pcs/workbench-pane.pper | 5 + .Rproj.user/290AA6C8/rmd-outputs | 5 + .Rproj.user/290AA6C8/saved_source_markers | 1 + .Rproj.user/290AA6C8/sources/prop/A9A6A1AE | 6 + .Rproj.user/290AA6C8/sources/prop/D7C9A909 | 6 + .Rproj.user/290AA6C8/sources/prop/EA6ADF66 | 8 + .Rproj.user/290AA6C8/sources/prop/INDEX | 3 + .../sources/session-21fbf5e5/26D9D65C | 34 + .../session-21fbf5e5/26D9D65C-contents | 0 .../sources/session-21fbf5e5/38A5B5F0 | 26 + .../session-21fbf5e5/38A5B5F0-contents | 16 + .../sources/session-21fbf5e5/652C3CBC | 28 + .../session-21fbf5e5/652C3CBC-contents | 122 +++ .../session-21fbf5e5/D4B089EF-contents | 42 ++ .../sources/session-21fbf5e5/E062E45A | 27 + .../session-21fbf5e5/E062E45A-contents | 47 ++ .../sources/session-21fbf5e5/lock_file | 0 .../290AA6C8/viewer-cache/D07B2148.Rdata | Bin 0 -> 3751 bytes .../1/290AA6C81fd36b85/chunks.json | 1 + .../notebooks/AEBFB6B3-tmp/1/s/chunks.json | 1 + .../AEBFB6B3-tmp/1/s/csetup_chunk/00000f.csv | 68 ++ .../shared/notebooks/patch-chunk-names | 0 .Rproj.user/shared/notebooks/paths | 0 .gitignore | 4 +- modeling/testingNAIPModel.R | 1 + .../treeSampling-checkpoint.ipynb | 652 +++------------- sampling/randonSampleWithinGrid.ipynb | 50 +- sampling/treeSampling.ipynb | 694 ++++-------------- .../testingDownloadFunction-checkpoint.ipynb | 106 +++ source/grabNAIPfromGEE.py | 15 + source/testingDownloadFunction.ipynb | 202 +++++ testing/aggregateImagery.R | 20 + testing/generateIndicies.R | 37 + testing/testingWorkflow.R | 106 +++ 38 files changed, 1199 insertions(+), 1193 deletions(-) delete mode 100755 .Rhistory create mode 100644 .Rproj.user/290AA6C8/pcs/files-pane.pper create mode 100644 .Rproj.user/290AA6C8/pcs/source-pane.pper create mode 100644 .Rproj.user/290AA6C8/pcs/windowlayoutstate.pper create mode 100644 .Rproj.user/290AA6C8/pcs/workbench-pane.pper create mode 100644 .Rproj.user/290AA6C8/rmd-outputs create mode 100644 .Rproj.user/290AA6C8/saved_source_markers create mode 100644 .Rproj.user/290AA6C8/sources/prop/A9A6A1AE create mode 100644 .Rproj.user/290AA6C8/sources/prop/D7C9A909 create mode 100644 .Rproj.user/290AA6C8/sources/prop/EA6ADF66 create mode 100644 .Rproj.user/290AA6C8/sources/prop/INDEX create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/26D9D65C create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/26D9D65C-contents create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0 create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0-contents create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC-contents create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/D4B089EF-contents create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A-contents create mode 100644 .Rproj.user/290AA6C8/sources/session-21fbf5e5/lock_file create mode 100644 .Rproj.user/290AA6C8/viewer-cache/D07B2148.Rdata create mode 100644 .Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/290AA6C81fd36b85/chunks.json create mode 100644 .Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/chunks.json create mode 100644 .Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/csetup_chunk/00000f.csv create mode 100644 .Rproj.user/shared/notebooks/patch-chunk-names create mode 100644 .Rproj.user/shared/notebooks/paths create mode 100644 source/.ipynb_checkpoints/testingDownloadFunction-checkpoint.ipynb create mode 100644 source/grabNAIPfromGEE.py create mode 100644 source/testingDownloadFunction.ipynb create mode 100644 testing/aggregateImagery.R create mode 100644 testing/generateIndicies.R create mode 100644 testing/testingWorkflow.R diff --git a/.Rhistory b/.Rhistory deleted file mode 100755 index c89a6293..00000000 --- a/.Rhistory +++ /dev/null @@ -1,33 +0,0 @@ -import os -import leafmap -from samgeo import SamGeo, tms_to_geotiff, get_basemaps -m = leafmap.Map(center=[29.676840, -95.369222], zoom=19) -m.add_basemap("SATELLITE") -m -import os -import leafmap -from samgeo import SamGeo, tms_to_geotiff, get_basemaps -m = leafmap.Map(center=[29.676840, -95.369222], zoom=19) -m.add_basemap("SATELLITE") -m -if m.user_roi_bounds() is not None: -bbox = m.user_roi_bounds() -else: -bbox = [-95.3704, 29.6762, -95.368, 29.6775] -image = "satellite.tif" -tms_to_geotiff(output=image, bbox=bbox, zoom=20, source="Satellite", overwrite=True) -) -sam = SamGeo( -model_type="vit_h", -checkpoint="sam_vit_h_4b8939.pth", -sam_kwargs=None, -) -sam -mask = "segment.tif" -sam.generate( -image, mask, batch=True, foreground=True, erosion_kernel=(3, 3), mask_multiplier=255 -) -conda create -n gee python=3.10 -conda activate gee -reticulate::repl_python() -reticulate::repl_python() diff --git a/.Rproj.user/290AA6C8/pcs/files-pane.pper b/.Rproj.user/290AA6C8/pcs/files-pane.pper new file mode 100644 index 00000000..02eac815 --- /dev/null +++ b/.Rproj.user/290AA6C8/pcs/files-pane.pper @@ -0,0 +1,9 @@ +{ + "sortOrder": [ + { + "columnIndex": 2, + "ascending": true + } + ], + "path": "C:/Users/carverd/Desktop/Agroforestry/modeling" +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/pcs/source-pane.pper b/.Rproj.user/290AA6C8/pcs/source-pane.pper new file mode 100644 index 00000000..28a3c2ee --- /dev/null +++ b/.Rproj.user/290AA6C8/pcs/source-pane.pper @@ -0,0 +1,3 @@ +{ + "activeTab": 3 +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/pcs/windowlayoutstate.pper b/.Rproj.user/290AA6C8/pcs/windowlayoutstate.pper new file mode 100644 index 00000000..e56a5a96 --- /dev/null +++ b/.Rproj.user/290AA6C8/pcs/windowlayoutstate.pper @@ -0,0 +1,14 @@ +{ + "left": { + "splitterpos": 316, + "topwindowstate": "NORMAL", + "panelheight": 760, + "windowheight": 798 + }, + "right": { + "splitterpos": 475, + "topwindowstate": "NORMAL", + "panelheight": 760, + "windowheight": 798 + } +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/pcs/workbench-pane.pper b/.Rproj.user/290AA6C8/pcs/workbench-pane.pper new file mode 100644 index 00000000..d3c76342 --- /dev/null +++ b/.Rproj.user/290AA6C8/pcs/workbench-pane.pper @@ -0,0 +1,5 @@ +{ + "TabSet1": 0, + "TabSet2": 1, + "TabZoom": {} +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/rmd-outputs b/.Rproj.user/290AA6C8/rmd-outputs new file mode 100644 index 00000000..3f2ff2d6 --- /dev/null +++ b/.Rproj.user/290AA6C8/rmd-outputs @@ -0,0 +1,5 @@ + + + + + diff --git a/.Rproj.user/290AA6C8/saved_source_markers b/.Rproj.user/290AA6C8/saved_source_markers new file mode 100644 index 00000000..2b1bef11 --- /dev/null +++ b/.Rproj.user/290AA6C8/saved_source_markers @@ -0,0 +1 @@ +{"active_set":"","sets":[]} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/prop/A9A6A1AE b/.Rproj.user/290AA6C8/sources/prop/A9A6A1AE new file mode 100644 index 00000000..01b8fef9 --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/prop/A9A6A1AE @@ -0,0 +1,6 @@ +{ + "source_window_id": "", + "Source": "Source", + "cursorPosition": "14,0", + "scrollLine": "0" +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/prop/D7C9A909 b/.Rproj.user/290AA6C8/sources/prop/D7C9A909 new file mode 100644 index 00000000..be693e64 --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/prop/D7C9A909 @@ -0,0 +1,6 @@ +{ + "source_window_id": "", + "Source": "Source", + "cursorPosition": "15,29", + "scrollLine": "0" +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/prop/EA6ADF66 b/.Rproj.user/290AA6C8/sources/prop/EA6ADF66 new file mode 100644 index 00000000..49a8f787 --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/prop/EA6ADF66 @@ -0,0 +1,8 @@ +{ + "tempName": "Untitled1", + "source_window_id": "", + "Source": "Source", + "cursorPosition": "98,2", + "scrollLine": "0", + "last_setup_crc32": "" +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/prop/INDEX b/.Rproj.user/290AA6C8/sources/prop/INDEX new file mode 100644 index 00000000..657317cf --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/prop/INDEX @@ -0,0 +1,3 @@ +C%3A%2FUsers%2Fcarverd%2FDesktop%2FAgroforestry%2Fmodeling%2FprocessCountyNAIP.R="D7C9A909" +C%3A%2FUsers%2Fcarverd%2FDesktop%2FAgroforestry%2Fmodeling%2FtestingNAIPModel.R="A9A6A1AE" +C%3A%2FUsers%2Fcarverd%2FDesktop%2Ftmp.rmd="EA6ADF66" diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/26D9D65C b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/26D9D65C new file mode 100644 index 00000000..8e7b05c2 --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/26D9D65C @@ -0,0 +1,34 @@ +{ + "id": "26D9D65C", + "path": null, + "project_path": null, + "type": "r_dataframe", + "hash": "0", + "contents": "", + "dirty": false, + "created": 1696452258051.0, + "source_on_save": false, + "relative_order": 3, + "properties": { + "expression": "year4", + "caption": "year4", + "totalObservations": 13, + "displayedObservations": 13, + "variables": 15, + "cacheKey": "D07B2148", + "object": "year4", + "environment": "", + "contentUrl": "grid_resource/gridviewer.html?env=&obj=year4&cache_key=D07B2148&max_display_columns=50", + "preview": 0, + "source_window_id": "", + "Source": "Source" + }, + "folds": "", + "lastKnownWriteTime": 8370073439636185705, + "encoding": "", + "collab_server": "", + "source_window": "", + "last_content_update": 1696452258051, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/26D9D65C-contents b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/26D9D65C-contents new file mode 100644 index 00000000..e69de29b diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0 b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0 new file mode 100644 index 00000000..02bf3ada --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0 @@ -0,0 +1,26 @@ +{ + "id": "38A5B5F0", + "path": "C:/Users/carverd/Desktop/Agroforestry/modeling/testingNAIPModel.R", + "project_path": "modeling/testingNAIPModel.R", + "type": "r_source", + "hash": "0", + "contents": "", + "dirty": true, + "created": 1696964484204.0, + "source_on_save": false, + "relative_order": 4, + "properties": { + "source_window_id": "", + "Source": "Source", + "cursorPosition": "14,0", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 1696958415, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1696964645591, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0-contents b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0-contents new file mode 100644 index 00000000..a3ea915a --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/38A5B5F0-contents @@ -0,0 +1,16 @@ +pacman::p_load(terra, here) + +here() +t1 <- rast("data/naip/m_4209864_nw_14_h_20160821_20161019.jp2") +t1 +plot(t1) +# rename to standard colors +names(t1) <- c("r","g","b","nr") +plotRGB(t1) + +# (NIR - R) / (NIR + R) +ndvi <- (t1$nr - t1$r)/(t1$nr + t1$r) +plot(ndvi) + + + diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC new file mode 100644 index 00000000..39375912 --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC @@ -0,0 +1,28 @@ +{ + "id": "652C3CBC", + "path": "C:/Users/carverd/Desktop/tmp.rmd", + "project_path": null, + "type": "r_markdown", + "hash": "0", + "contents": "", + "dirty": false, + "created": 1696452104482.0, + "source_on_save": false, + "relative_order": 2, + "properties": { + "tempName": "Untitled1", + "source_window_id": "", + "Source": "Source", + "cursorPosition": "98,2", + "scrollLine": "0", + "last_setup_crc32": "" + }, + "folds": "", + "lastKnownWriteTime": 1696460491, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1696460491428, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC-contents b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC-contents new file mode 100644 index 00000000..c852f5fb --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/652C3CBC-contents @@ -0,0 +1,122 @@ +--- + title: "try" +date: "`r Sys.Date()`" +output: + flexdashboard::flex_dashboard: + vertical_layout: fill +runtime: shiny +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set(echo=FALSE) +library(flexdashboard) +library(shiny) +library(tidyverse) +library(sf) +library(leaflet) + +pdf(NULL) + +nc <- st_read(system.file("shape/nc.shp", package="sf")) + +subset <- nc %>% filter(SID74 <=5) + +# Split data into multiple groups based on value of 'SID74' + +splitField <- "SID74" +years <- unique(subset[[splitField]]) +# assign these multiple groups to different 'sf' objects, namely 'year1', 'year2'... +for (i in 1:length(years)) { + tmp <- subset[subset[[splitField]] == years[i], ] + assign(paste0("year", i), tmp) +} + +``` + +Map +=========================================================== + + Row +----------------------------------------------------------- +### Map + +```{r} +renderLeaflet({ + + # Create custom colour palette + + colour6 <- tibble( + severity = c("0", "1", "2", "3", "4","5"), + Color = c("darkred", "#CC9966", "yellow", "#99CC33", "grey","black")) + + leaflet() %>% + setView(lng = -79.5, lat = 36,zoom =7) %>% + addTiles(group = "OSM (default)") %>% + for (i in 1:length(years)) { + dat_col <- merge( x = get(paste0("year",i)), y =colour6, by.x ="SID74", by.y="severity") + addPolygons(data =dat_col, + group = paste0("Year ",i), + fillColor = dat_col$Color, + opacity = 1, + color = NA, + fillOpacity = 0.7) } %>% + addLayersControl( + baseGroups = "OSM (default)", + options = layersControlOptions(collapsed = FALSE)) %>% + addLegend(colors = colour6$Color, labels = colour6$severity) +}) + +``` + + + +```{r} + + colour6 <- tibble( + severity = c("0", "1", "2", "3", "4","5"), + Color = c("darkred", "#CC9966", "yellow", "#99CC33", "grey","black")) + + m1 <- leaflet() %>% + setView(lng = -79.5, lat = 36,zoom =7) %>% + addTiles(group = "OSM (default)") + + + for(i in 1:length(years)){ + dat_col <- merge( x = get(paste0("year",i)), y =colour6, by.x ="SID74", by.y="severity") + + m1 <- m1 %>% + addPolygons(data =dat_col, + group = paste0("Year ",i), + fillColor = dat_col$Color, + opacity = 1, + color = NA, + fillOpacity = 0.7) } + m1 <- m1 %>% + addLayersControl( + baseGroups = "OSM (default)", + options = layersControlOptions(collapsed = FALSE)) %>% + addLegend(colors = colour6$Color, labels = colour6$severity) +m1 + +``` + + + +```{r} + leaflet() %>% + setView(lng = -79.5, lat = 36,zoom =7) %>% + addTiles(group = "OSM (default)") %>% + for(i in 1:length(years)){ + dat_col <- merge( x = get(paste0("year",i)), y =colour6, by.x ="SID74", by.y="severity") + addPolygons(data =dat_col, + group = paste0("Year ",i), + fillColor = dat_col$Color, + opacity = 1, + color = NA, + fillOpacity = 0.7) } %>% + addLayersControl( + baseGroups = "OSM (default)", + options = layersControlOptions(collapsed = FALSE)) %>% + addLegend(colors = colour6$Color, labels = colour6$severity) + +``` \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/D4B089EF-contents b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/D4B089EF-contents new file mode 100644 index 00000000..84ccb919 --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/D4B089EF-contents @@ -0,0 +1,42 @@ +pacman::p_load(terra, raster, glcm, purrr) + +path <- "C:/Users/carverd/Desktop/Agroforestry/data/naip/m_4209749_sw_14_h_20160821_20161019.jp2" +fileLocation <- "C:/Users/carverd/Desktop/Agroforestry/data/naip" + +bindNAIP <- function(fileLocation){ + f1 <- list.files(path = fileLocation, pattern = ".jp2", full.names = TRUE) + r1 <- map(.x = f1, .f = rast) + for(i in seq_along(r1)){ + if(i == 1){ + r2 <- r1[[i]] + }else{ + r2 <- terra::merge(r2, r1[[i]]) + } + } + r2 <- map(r1, terra::merge) + + +} + + + +processCountyNAIP <- (path){ + # read in features + t1 <- terra::rast(path) + + # calculate Brightness + ## mean of all four bands + t2 <- terra::mean(t1) + + # generate NDVI + ndvi <- (t) + # generate RBG + + # 1st level texture + ## focal window -- 3 by 3 standard devation of + + # texture calculation + ## https://cran.r-project.org/web/packages/glcm/glcm.pdf + t1 <- glcm::L5TSR_1986 + t2 <- glcm::glcm(x = t1[[1]]) + } \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A new file mode 100644 index 00000000..860c0f13 --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A @@ -0,0 +1,27 @@ +{ + "id": "E062E45A", + "path": null, + "project_path": null, + "type": "r_source", + "hash": "0", + "contents": "", + "dirty": true, + "created": 1696460698956.0, + "source_on_save": false, + "relative_order": 4, + "properties": { + "tempName": "Untitled1", + "source_window_id": "", + "Source": "Source", + "cursorPosition": "7,9", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 14431626988849, + "encoding": "", + "collab_server": "", + "source_window": "", + "last_content_update": 1696460955979, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A-contents b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A-contents new file mode 100644 index 00000000..8af7706c --- /dev/null +++ b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/E062E45A-contents @@ -0,0 +1,47 @@ + +library(flexdashboard) +library(shiny) +library(tidyverse) +library(sf) +library(leaflet) + +pdf(NULL) + +nc <- st_read(system.file("shape/nc.shp", package="sf")) + +subset <- nc %>% filter(SID74 <=5) + +# Split data into multiple groups based on value of 'SID74' + +splitField <- "SID74" +years <- unique(subset[[splitField]]) +# assign these multiple groups to different 'sf' objects, namely 'year1', 'year2'... +for (i in 1:length(years)) { + tmp <- subset[subset[[splitField]] == years[i], ] + assign(paste0("year", i), tmp) +} + +m1 <- leaflet() %>% + setView(lng = -79.5, lat = 36,zoom =7) %>% + addTiles(group = "OSM (default)") + + +for(i in 1:length(years)){ + dat_col <- merge( x = get(paste0("year",i)), y =colour6, by.x ="SID74", by.y="severity") + + m1 <- m1 %>% + addPolygons(data =dat_col, + group = paste0("Year ",i), + fillColor = dat_col$Color, + opacity = 1, + color = NA, + fillOpacity = 0.7) } + + +m1 <- m1 %>% + addLayersControl( + baseGroups = "OSM (default)", + overlayGroups = paste0("Year ",seq(1:length(years))), + options = layersControlOptions(collapsed = FALSE)) %>% + addLegend(colors = colour6$Color, labels = colour6$severity) +m1 diff --git a/.Rproj.user/290AA6C8/sources/session-21fbf5e5/lock_file b/.Rproj.user/290AA6C8/sources/session-21fbf5e5/lock_file new file mode 100644 index 00000000..e69de29b diff --git a/.Rproj.user/290AA6C8/viewer-cache/D07B2148.Rdata b/.Rproj.user/290AA6C8/viewer-cache/D07B2148.Rdata new file mode 100644 index 0000000000000000000000000000000000000000..e4d25232386da93236829d8fe0ef418f58ffd137 GIT binary patch literal 3751 zcmV;Y4p{LYiwFP!000002Gv@5RFhX0|5!z<*1cBHMsTfcVGF6+BtTe{O%fCZBmn}X zhQK62!4`H!CC4xJnw-DuqGbOMD@VLH?MKO(FNds}VBcGE;%lE_ zHAm-3PPy%M5svv@a`eF^_j5N?lGB;9EE;RRUyi)8_`xL)$-}L?zft^pR&vju{7CMk zjJtPiLyF`HNs}bG%m3<^9xM56F$pBO(=cfM)rbbE-C_BTQ|9H8M}Vqk4J#n}{dD9#1$7{Jk= z|8>58mVC6o&NI{ogGNuKo)HGMey&!h(=cfC&rpow~|Rd5a~$k%C^MYhqzHnbpHA6tuWkZtHdTUvm1hNaiW2}m!l z4XXuuPyp3adAu&$iqd%&g%z_q@>w{`*>DuKJQfV)e8 zWxjN&G+#dm-Hq0Kt5ndhhe5i09B>oeS6b>Kw2FiKS(p6zROJ`hun-??Zhk z+VK}fd&@f9%!;yOmWXD>Cf8zuF?ZKZhLtZZYuF7J{-c=%s@odwJIq^mqcl=LaF4Yj5aX zl~RHuB2_kdI=w$TWNLF!4$hvo!h&s`XigbAwb97o;B=r$`=pulRqvR@Xk}D}tz?+VDsFAZ_=K;e4agWM|xh3i|7!VP}|vV0R7BEJE?JP!KM zK9Hpw(3pw+fkSek9}+A;o_B$EXJB_()nbz$6}Nw4(~bTeyW#NUk8D8i_5vTdj6$6f z0-GmwEIfGag&2OD7UsJaT9A$f08rI%%HUZX&pcBF-hD{LL+H9+{tzS7B z1*lHL#B6B<5AoYO$~w$C&L)6O1e*}HrP&r|Ti)#gcy1?9;6cX(Hu1YCAj57c;B2!} zHjNZYDOZyMC?kFXP8moFp^O_w3ZztSCIwSYp9p?Z3wSdZNC_q{Aq7^Z4hB!{3VZs` zq>#$AyNH+a5BSfP!JhIP{E{nyvofHcWskTsR=|IHJ?t~G5r2jN>q_hkUi|mq#mxdv zjYXWObKpf@f?s3=9V$+QX<>^3UoXR{~n$#1YNQT zFQnHFU~duP^bG;_*Frxu3;x6Dd&h`+%nHA+J{e^xmuB z=jDoZc%OhA=miW)g+9=PJVBe_A0z;Zd@1%ozJQhB`=-!%t;pk3jd*@T!Sinf`W%Mc zi{=@>p59+8WamSWoj(`Y)Vqrf=EHU41{+{jd`zCu&5BQlkwH+L{kWFk`9$c?)lyt5 z4J6w-MlZR`Zd?5L(kH}&tL06n|20AtKb?! z=?)oBO?-YA`HBzt*FHld zey~Hl$Nf-vw!_&3vWaxMfc&={5bt6PXS1Fz8Z@vw8{}GseKO*vt7)8L!0gkA z|4J=z&Kcy@9YEatM&!eKrLu;4G~l2f@?kL=*Sr)3{_A1j>B-=o7=lI}pNfJX{|fqJ zZb0)AH2mnZuphb${ySq4|Ih-&J7|L3^k?uJz6by9`N+RF0t3=G9sC9*XS3ce8vI;$ zHaMRDJ0ubXUloDItZ_kMOY@Jfpif6XR}e*%Ba4e(aC!f*8$tZUse@K!&DzGOdS)J-Z&i9#c1E=FUg?}I-4 zDjGf|8}^umkmKKMAvldZ%SdGjI|T%1q(M$9hdm_=s1_n_E*&gWAh7T__=}#vzIrtH zYac;gFMz#lAM#h@Ayc+l2LG*GF~OQZ_`T5pxh@g@J0`-f<|^b}Em;4yNcdNO0J$m= zymfTIOWsEu<80(l^8r8gWyDGDqq3=67Xv?z>&Af}WmX1$LK>*_cOnf|`o0cyUridU z6!^kE;udhYJ?yTzWI&Y9uM`k`j=n_=nFhZ>7h&(e75qWxVfXk6=pTT1ev$CUI;65< zJdDYfZ$pDtGy%6H!Cv(v3Ri`PHCcH%u%aA=t{4D*B_6V56<@$!8G^=EzYENnf;>4h z(SV$}z(P7`SVtEP8PJ^#nZzIAV@P2X3-DB~SU4QGBo_LmZlu80lZx#?wj-@OlA+$S(ip{}{fN7;0Q~uj5vNEDx$rFHf;EVne-m>4Fyzgj23}r0 z^m+_}V$NaY(Y8Xyee#p||j(hV3A>qu35(JC5x@wj(P} z!d`U(epQ#jD{q5bQ38AUe2(BI6YOPw!$4F#g1wXu$~p=1E{g}RI39AbE9?tC1izrB z*5*FD7^o3kHx5*!S@FZSX!yexH0(hW8t}_5H00Msus;YwgMl|wK3i!Vj zAx_&I!c%hIKnHTeW~JkV7U&xhr_G3b4+9YA-m6lAKkWei_%`snX2kur1$nPuM84}E z!S9=N=&v+F|Me)UccA>ez#C%`@46rCH$S5|66^S<1cM%q4DeMV1MmA{9ii`-a0kntX&3N9|!%$1@POr9{jRs#4EdvbyU*9 zs(1ywN^(EEy$Sqs732*P*jK9%za#+uB^>N4PSSPTBmSa^kPB}kj%hsfx})&V*$X*` z=0RP$7}!x(5YAEj#^u9w7$6JMb6PBrL>d?hNx^sWbKz4Apr{;dftc$0+uy7pNKmJ(3*k6I{!;Q|LHt5y48un>}BMVrV zYyDu?vB>6iVXnHcUC+Pnc$1wL^t+EX95M_>x>4;rxj4nj!u&)Xm3H4m$m1eH6BNnr z#Om(ZOThnx$&`sPyeiLN$`QzNH3n^lS}zDwn+kFTLa~)*`H@FQN5w1RqQa8hLv?Dy z9F0I292Dg48RRbt_VW$$4)F972Y8D`!9n6+KcRoHIJn){@)IqOjZj7=#zrZV-E%c2 zgT~!cn3|djQhY*GjGSKx`NVvlHY3N~)3@DS78?;Qhi9fHo2T$rZ(pG(Akg1W>=!5$ ziv#@qS*TD&vPP%V<{R_0nQEP4iLA5#jC`;1?uHO~r^fcityXT77`lEsa&m6WCHhW0f=0SYRSVg)zri zS&W>$4(Df$ef`1mIyR1dIU+Pcu28glIfX| zF4BX)EZ+-zhQE4qc!wCwUzYDCSiVN$&tH}Um0vyg5`Rs8$~%(1F^j(Hm8mwVy|WB_ RA}oSy`xiY+RMdYa000HtJ3s&c literal 0 HcmV?d00001 diff --git a/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/290AA6C81fd36b85/chunks.json b/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/290AA6C81fd36b85/chunks.json new file mode 100644 index 00000000..350a1a5a --- /dev/null +++ b/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/290AA6C81fd36b85/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[{"row":33,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"setup","include":false},"document_id":"652C3CBC","chunk_id":"csetup_chunk","chunk_label":"setup"}],"doc_write_time":1696452191,"working_dir":null,"default_chunk_options":{"echo":false}} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/chunks.json b/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/chunks.json new file mode 100644 index 00000000..350a1a5a --- /dev/null +++ b/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[{"row":33,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"setup","include":false},"document_id":"652C3CBC","chunk_id":"csetup_chunk","chunk_label":"setup"}],"doc_write_time":1696452191,"working_dir":null,"default_chunk_options":{"echo":false}} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/csetup_chunk/00000f.csv b/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/csetup_chunk/00000f.csv new file mode 100644 index 00000000..9f6157dd --- /dev/null +++ b/.Rproj.user/shared/notebooks/AEBFB6B3-tmp/1/s/csetup_chunk/00000f.csv @@ -0,0 +1,68 @@ +"0","knitr::opts_chunk$set(echo=FALSE)" +"0","library(flexdashboard)" +"2","Warning: package β€˜flexdashboard’ was built under R version 4.2.3" +"0","library(shiny)" +"0","library(tidyverse)" +"2","Registered S3 methods overwritten by 'dbplyr': + method from + print.tbl_lazy + print.tbl_sql +" +"2","── Attaching packages ─────────────────────────────────────────────────────── tidyverse 1.3.2 ──" +"2","βœ” ggplot2 3.3.6 βœ” purrr  0.3.4 +βœ” tibble  3.1.8 βœ” dplyr  1.0.10 +βœ” tidyr  1.2.1 βœ” stringr 1.5.0 +βœ” readr  2.1.2 βœ” forcats 0.5.2 " +"2","── Conflicts ────────────────────────────────────────────────────────── tidyverse_conflicts() ── +βœ– dplyr::filter() masks stats::filter() +βœ– dplyr::lag() masks stats::lag()" +"0","library(sf)" +"2","Linking to GEOS 3.9.1, GDAL 3.4.3, PROJ 7.2.1; sf_use_s2() is TRUE +" +"0","library(leaflet)" +"2","Registered S3 method overwritten by 'htmlwidgets': + method from + print.htmlwidget tools:rstudio +" +"0","pdf(NULL)" +"0","" +"0","nc <- st_read(system.file(""shape/nc.shp"", package=""sf""))" +"1","Reading layer `" +"1","nc" +"1","' from data source " +"1"," +" +"1"," " +"1","`" +"1","C:\Users\carverd\AppData\Local\R\win-library\4.2\sf\shape\nc.shp" +"1","' " +"1","using driver `" +"1","ESRI Shapefile" +"1","'" +"1"," +" +"1","Simple feature collection with 100 features and 14 fields" +"1"," +" +"1","Geometry type: MULTIPOLYGON +" +"1","Dimension: XY +" +"1","Bounding box: " +"1","xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965" +"1"," +" +"1","Geodetic CRS: NAD27 +" +"0","subset <- nc %>% filter(SID74 <=5)" +"0","" +"0","# Split data into multiple groups based on value of 'SID74'" +"0","" +"0","splitField <- ""SID74""" +"0","years <- unique(subset[[splitField]])" +"0","# assign these multiple groups to different 'sf' objects, namely 'year1', 'year2'... " +"0","for (i in 1:length(years)) {" +"0"," tmp <- subset[subset[[splitField]] == years[i], ]" +"0"," assign(paste0(""year"", i), tmp)" +"0","}" +"0","" diff --git a/.Rproj.user/shared/notebooks/patch-chunk-names b/.Rproj.user/shared/notebooks/patch-chunk-names new file mode 100644 index 00000000..e69de29b diff --git a/.Rproj.user/shared/notebooks/paths b/.Rproj.user/shared/notebooks/paths new file mode 100644 index 00000000..e69de29b diff --git a/.gitignore b/.gitignore index 63d5a0c6..0283b5e4 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ -/agro_env + /agro-env -/agro_envv /data + .Rproj.user diff --git a/modeling/testingNAIPModel.R b/modeling/testingNAIPModel.R index 0bbbb390..df91ef57 100755 --- a/modeling/testingNAIPModel.R +++ b/modeling/testingNAIPModel.R @@ -11,3 +11,4 @@ plotRGB(t1) # (NIR - R) / (NIR + R) ndvi <- (t1$nr - t1$r)/(t1$nr + t1$r) plot(ndvi) + diff --git a/sampling/.ipynb_checkpoints/treeSampling-checkpoint.ipynb b/sampling/.ipynb_checkpoints/treeSampling-checkpoint.ipynb index b800a6e0..a2dcc302 100755 --- a/sampling/.ipynb_checkpoints/treeSampling-checkpoint.ipynb +++ b/sampling/.ipynb_checkpoints/treeSampling-checkpoint.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "2c92c063-ebff-4296-ae63-beb523b1bbaa", "metadata": {}, "outputs": [], @@ -14,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "id": "b175b238-75a3-4fb9-8cd5-9efc07db0382", "metadata": {}, "outputs": [], @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "id": "d78df8ca-3975-4f66-b61a-05d187d2462f", "metadata": {}, "outputs": [], @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "id": "af76cf3e-b4fa-400c-a73f-48453a542e51", "metadata": {}, "outputs": [ @@ -118,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "id": "cbd59220-b45a-4df9-a18b-e9b56d0b868a", "metadata": {}, "outputs": [ @@ -128,7 +128,7 @@ "" ] }, - "execution_count": 4, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" }, @@ -152,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "id": "a5c4b4f3-d9dd-4ce8-b5b5-499ac381a0b6", "metadata": {}, "outputs": [], @@ -166,178 +166,10 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 9, "id": "196fc88e-9233-4604-8945-b9e008a26792", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ee.Image({\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"ImageCollection.mosaic\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.filter\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.filter\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.filter\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"ImageCollection.load\",\n", - " \"arguments\": {\n", - " \"id\": {\n", - " \"constantValue\": \"USDA/NAIP/DOQQ\"\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"filter\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Filter.dateRangeContains\",\n", - " \"arguments\": {\n", - " \"leftValue\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"DateRange\",\n", - " \"arguments\": {\n", - " \"end\": {\n", - " \"constantValue\": \"2020-12-31\"\n", - " },\n", - " \"start\": {\n", - " \"constantValue\": \"2020-01-01\"\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"rightField\": {\n", - " \"constantValue\": \"system:time_start\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"filter\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Filter.listContains\",\n", - " \"arguments\": {\n", - " \"leftField\": {\n", - " \"constantValue\": \"system:band_names\"\n", - " },\n", - " \"rightValue\": {\n", - " \"constantValue\": \"N\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"filter\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Filter.intersects\",\n", - " \"arguments\": {\n", - " \"leftField\": {\n", - " \"constantValue\": \".all\"\n", - " },\n", - " \"rightValue\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Feature\",\n", - " \"arguments\": {\n", - " \"geometry\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.geometry\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection\",\n", - " \"arguments\": {\n", - " \"features\": {\n", - " \"arrayValue\": {\n", - " \"values\": [\n", - " {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Feature\",\n", - " \"arguments\": {\n", - " \"geometry\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"GeometryConstructors.MultiPolygon\",\n", - " \"arguments\": {\n", - " \"coordinates\": {\n", - " \"constantValue\": [\n", - " [\n", - " [\n", - " [\n", - " -100.575468431,\n", - " 42.608797389000074\n", - " ],\n", - " [\n", - " -100.40155538799996,\n", - " 42.608797389000074\n", - " ],\n", - " [\n", - " -100.40155538799996,\n", - " 42.782710432000044\n", - " ],\n", - " [\n", - " -100.575468431,\n", - " 42.782710432000044\n", - " ],\n", - " [\n", - " -100.575468431,\n", - " 42.608797389000074\n", - " ]\n", - " ]\n", - " ]\n", - " ]\n", - " },\n", - " \"geodesic\": {\n", - " \"constantValue\": true\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"metadata\": {\n", - " \"constantValue\": {\n", - " \"Unique_ID\": \"X12-677\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " ]\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - "})\n" - ] - } - ], + "outputs": [], "source": [ "# compile naip imagery \n", "# 2010, 2016, 2020 for sample time periods \n", @@ -349,7 +181,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 10, "id": "17490c65-09f6-4a6c-b627-23ad302bf166", "metadata": {}, "outputs": [], @@ -362,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "id": "d60b8033-6172-4a75-97b4-0587eae966dd", "metadata": {}, "outputs": [], @@ -375,22 +207,22 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 12, "id": "511b5176-27e2-4830-87c7-2c57fa4efea7", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "59d965fde2fc4d3cb70943c960f81639", + "model_id": "ac84664c240f469089c9fca932f6d182", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Map(bottom=6188773.0, center=[42.69574620931511, -100.48851190949973], controls=(WidgetControl(options=['posit…" + "Map(center=[42.69574620931511, -100.48851190949973], controls=(WidgetControl(options=['position', 'transparent…" ] }, - "execution_count": 15, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -398,45 +230,95 @@ "source": [ "# I'm not sure if we want all three naip images on at once or each map getting it's own. \n", "### 2020 tree sampling \n", - "Map2020 = Map \n", - "Map2020.addLayer(naip2020, visParamsTrue, name = \"rgb2020\")\n", - "Map2020.addLayer(naip2020, visParamsFalse, name = \"false2020\")\n", + "MapPresence = Map \n", + "MapPresence.addLayer(naip2020, visParamsTrue, name = \"rgb2020\")\n", + "MapPresence.addLayer(naip2020, visParamsFalse, name = \"false2020\")\n", "# testing the 2015 layer\n", - "Map2020.addLayer(naip2015, visParamsTrue, name = \"rgb2015\")\n", - "Map2020.addLayer(naip2010, visParamsTrue, name = \"rgb2010\")\n", + "MapPresence.addLayer(naip2015, visParamsTrue, name = \"rgb2015\")\n", + "MapPresence.addLayer(naip2010, visParamsTrue, name = \"rgb2010\")\n", "\n", - "Map2020" + "MapPresence" ] }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 42, "id": "e1863b67-79b3-4a5d-a711-546a75be29dc", "metadata": { "scrolled": true }, "outputs": [ { - "ename": "AttributeError", - "evalue": "'DataFrame' object has no attribute 'set_value'", + "ename": "TypeError", + "evalue": "'_iAtIndexer' object is not callable", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_7196\\3068110585.py\u001b[0m in \u001b[0;36m?\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;31m# extract objects\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;31m### feels like a single map will work for the sampling process\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mpresence2020\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mee\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mFeatureCollection\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mMap\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw_features\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m 6198\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mname\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_accessors\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6199\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6200\u001b[0m ):\n\u001b[0;32m 6201\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 6202\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'set_value'" + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[42], line 10\u001b[0m\n\u001b[0;32m 8\u001b[0m aoiID\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m\n\u001b[1;32m---> 10\u001b[0m \u001b[43mdf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43miat\u001b[49m\u001b[43m(\u001b[49m\u001b[43maoiID\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mpresence2020\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[1;31mTypeError\u001b[0m: '_iAtIndexer' object is not callable" ] } ], "source": [ - "# extract objects \n", - "### feels like a single map will work for the sampling process\n", - "\n", - "presence2020 = ee.FeatureCollection(Map.draw_features)\n", - "coords = presence2020.geometry()\n", + "# extract presence objects \n", + "presence = ee.FeatureCollection(MapPresence.draw_features)\n", + "coordsPresence = geemap.ee_to_geojson(presence)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "2802debf-aacc-48a3-ab04-bea8e25c5c03", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ac84664c240f469089c9fca932f6d182", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Map(bottom=96867.0, center=[42.69574620931511, -100.48851190949973], controls=(WidgetControl(options=['positio…" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "### 2020 absence sampling \n", + "MapAbsence = Map \n", + "MapAbsence.addLayer(naip2020, visParamsTrue, name = \"rgb2020\")\n", + "MapAbsence.addLayer(naip2020, visParamsFalse, name = \"false2020\")\n", + "# testing the 2015 layer\n", + "MapAbsence.addLayer(naip2015, visParamsTrue, name = \"rgb2015\")\n", + "MapAbsence.addLayer(naip2010, visParamsTrue, name = \"rgb2010\")\n", "\n", - "df.set_value(aoiID,'presence2020',coords)" + "MapAbsence" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "18a101d6-7ecd-4e33-a25a-3054eef87004", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'FeatureCollection', 'columns': {'system:index': 'String'}, 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.570233, 42.588334]}, 'id': '0', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.576069, 42.575695]}, 'id': '1', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.607309, 42.568363]}, 'id': '2', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.614862, 42.581256]}, 'id': '3', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.615892, 42.626743]}, 'id': '4', 'properties': {}}]}\n" + ] + } + ], + "source": [ + "# extract absence objects \n", + "absence = ee.FeatureCollection(MapAbsence.draw_features)\n", + "coordsAbsence = geemap.ee_to_geojson(absence)\n", + "print(coordsAbsence)" ] }, { @@ -777,365 +659,39 @@ } ], "source": [ + "# binding values to the \n", "df" ] }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 35, "id": "94f6ec86-031a-4b13-991e-8efbeb916051", "metadata": {}, "outputs": [ { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
IDpresence2010presence2015presence2020absencesampledBydateSampled
0X12-677NaNNaNNaNNaNNaNNaN
1X12-88NaNNaNNaNNaNNaNNaN
2X12-34NaNNaNNaNNaNNaNNaN
3X12-343NaNNaNNaNNaNNaNNaN
4X12-608NaNNaNNaNNaNNaNNaN
5X12-367NaNNaNNaNNaNNaNNaN
6X12-311NaNNaNNaNNaNNaNNaN
7X12-758NaNNaNNaNNaNNaNNaN
8X12-489NaNNaNNaNNaNNaNNaN
9X12-408NaNNaNNaNNaNNaNNaN
10X12-413NaNNaNNaNNaNNaNNaN
11X12-566NaNNaNNaNNaNNaNNaN
12X12-639NaNNaNNaNNaNNaNNaN
13X12-161NaNNaNNaNNaNNaNNaN
14X12-100NaNNaNNaNNaNNaNNaN
15X12-143NaNNaNNaNNaNNaNNaN
16X12-688NaNNaNNaNNaNNaNNaN
17X12-322NaNNaNNaNNaNNaNNaN
18X12-366NaNNaNNaNNaNNaNNaN
19X12-684NaNNaNNaNNaNNaNNaN
20X12-593NaNNaNNaNNaNNaNNaN
21X12-427NaNNaNNaNNaNNaNNaN
22X12-568NaNNaNNaNNaNNaNNaN
23X12-265NaNNaNNaNNaNNaNNaN
24X12-116NaNNaNNaNNaNNaNNaN
\n", - "
" - ], - "text/plain": [ - " ID presence2010 presence2015 presence2020 absence sampledBy \\\n", - "0 X12-677 NaN NaN NaN NaN NaN \n", - "1 X12-88 NaN NaN NaN NaN NaN \n", - "2 X12-34 NaN NaN NaN NaN NaN \n", - "3 X12-343 NaN NaN NaN NaN NaN \n", - "4 X12-608 NaN NaN NaN NaN NaN \n", - "5 X12-367 NaN NaN NaN NaN NaN \n", - "6 X12-311 NaN NaN NaN NaN NaN \n", - "7 X12-758 NaN NaN NaN NaN NaN \n", - "8 X12-489 NaN NaN NaN NaN NaN \n", - "9 X12-408 NaN NaN NaN NaN NaN \n", - "10 X12-413 NaN NaN NaN NaN NaN \n", - "11 X12-566 NaN NaN NaN NaN NaN \n", - "12 X12-639 NaN NaN NaN NaN NaN \n", - "13 X12-161 NaN NaN NaN NaN NaN \n", - "14 X12-100 NaN NaN NaN NaN NaN \n", - "15 X12-143 NaN NaN NaN NaN NaN \n", - "16 X12-688 NaN NaN NaN NaN NaN \n", - "17 X12-322 NaN NaN NaN NaN NaN \n", - "18 X12-366 NaN NaN NaN NaN NaN \n", - "19 X12-684 NaN NaN NaN NaN NaN \n", - "20 X12-593 NaN NaN NaN NaN NaN \n", - "21 X12-427 NaN NaN NaN NaN NaN \n", - "22 X12-568 NaN NaN NaN NaN NaN \n", - "23 X12-265 NaN NaN NaN NaN NaN \n", - "24 X12-116 NaN NaN NaN NaN NaN \n", - "\n", - " dateSampled \n", - "0 NaN \n", - "1 NaN \n", - "2 NaN \n", - "3 NaN \n", - "4 NaN \n", - "5 NaN \n", - "6 NaN \n", - "7 NaN \n", - "8 NaN \n", - "9 NaN \n", - "10 NaN \n", - "11 NaN \n", - "12 NaN \n", - "13 NaN \n", - "14 NaN \n", - "15 NaN \n", - "16 NaN \n", - "17 NaN \n", - "18 NaN \n", - "19 NaN \n", - "20 NaN \n", - "21 NaN \n", - "22 NaN \n", - "23 NaN \n", - "24 NaN " - ] - }, - "execution_count": 99, - "metadata": {}, - "output_type": "execute_result" + "ename": "ValueError", + "evalue": "No axis named X12-677 for object type DataFrame", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(cls, axis)\u001b[0m\n\u001b[0;32m 552\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_AXIS_TO_AXIS_NUMBER\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 553\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 554\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf\"No axis named {axis} for object type {cls.__name__}\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m: 'X12-677'", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_13752\\3341668906.py\u001b[0m in \u001b[0;36m?\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;31m# assign coords to the dataframe\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;31m# df.loc(\"ID\" == aoiID,\"presence2020\") # = coords\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0maoiID\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maoiID\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, axis)\u001b[0m\n\u001b[0;32m 718\u001b[0m \u001b[1;31m# we need to return a copy of ourselves\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 719\u001b[0m \u001b[0mnew_self\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 720\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 721\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0maxis\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 722\u001b[1;33m \u001b[0maxis_int_none\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_axis_number\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 723\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 724\u001b[0m \u001b[0maxis_int_none\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 725\u001b[0m \u001b[0mnew_self\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis_int_none\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(cls, axis)\u001b[0m\n\u001b[0;32m 550\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_get_axis_number\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mAxis\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[0mAxisInt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 551\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 552\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_AXIS_TO_AXIS_NUMBER\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 553\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 554\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf\"No axis named {axis} for object type {cls.__name__}\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mValueError\u001b[0m: No axis named X12-677 for object type DataFrame" + ] } ], "source": [ "# assign coords to the dataframe \n", - "# df[aoiID][\"presence2020\"] = coords\n", - "df" + "# df.loc(\"ID\" == aoiID,\"presence2020\") # = coords\n", + "aoiID\n", + "df.iloc(aoiID)" ] } ], diff --git a/sampling/randonSampleWithinGrid.ipynb b/sampling/randonSampleWithinGrid.ipynb index 52662f73..f9dd36e3 100755 --- a/sampling/randonSampleWithinGrid.ipynb +++ b/sampling/randonSampleWithinGrid.ipynb @@ -1,53 +1,5 @@ { "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "6d315d76", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c219d3f6", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "95409132", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "85567fbc", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "39237928", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1ab90dbe", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "code", "execution_count": null, @@ -113,7 +65,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.9.12" } }, "nbformat": 4, diff --git a/sampling/treeSampling.ipynb b/sampling/treeSampling.ipynb index b800a6e0..68d2f8ec 100755 --- a/sampling/treeSampling.ipynb +++ b/sampling/treeSampling.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "2c92c063-ebff-4296-ae63-beb523b1bbaa", "metadata": {}, "outputs": [], @@ -14,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 31, "id": "b175b238-75a3-4fb9-8cd5-9efc07db0382", "metadata": {}, "outputs": [], @@ -23,6 +23,8 @@ "import geemap\n", "import geopandas as gpd\n", "import pandas as pd\n", + "import numpy as np\n", + "from datetime import date\n", "import ee\n", "# ee.Authenticate()\n", "ee.Initialize()\n" @@ -30,19 +32,31 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 32, "id": "d78df8ca-3975-4f66-b61a-05d187d2462f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Today's date: 2023-10-11\n" + ] + } + ], "source": [ "### \n", "# set sample grid ID \n", - "aoiID = 'X12-677'" + "aoiID = 'X12-677'\n", + "# set some basic parameter for workflow \n", + "coordsAbsence = np.nan\n", + "coordsPresence = np.nan\n", + "today = date.today()" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "id": "af76cf3e-b4fa-400c-a73f-48453a542e51", "metadata": {}, "outputs": [ @@ -112,13 +126,12 @@ "# load the sampling reference grid 12kGrid\n", "grid = gpd.read_file(\"../data/griddedFeatures/twelve_mi_grid_uid.gpkg\")\n", "# load the sampling grid \n", - "df = pd.read_csv(\"../sampling/samplingReferenceSheet_12.csv\", index_col='ID')\n", - "print(df)" + "df = pd.read_csv(\"../sampling/samplingReferenceSheet_12.csv\", index_col='ID')" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "id": "cbd59220-b45a-4df9-a18b-e9b56d0b868a", "metadata": {}, "outputs": [ @@ -128,7 +141,7 @@ "" ] }, - "execution_count": 4, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" }, @@ -152,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "id": "a5c4b4f3-d9dd-4ce8-b5b5-499ac381a0b6", "metadata": {}, "outputs": [], @@ -166,178 +179,10 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 9, "id": "196fc88e-9233-4604-8945-b9e008a26792", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "ee.Image({\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"ImageCollection.mosaic\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.filter\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.filter\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.filter\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"ImageCollection.load\",\n", - " \"arguments\": {\n", - " \"id\": {\n", - " \"constantValue\": \"USDA/NAIP/DOQQ\"\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"filter\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Filter.dateRangeContains\",\n", - " \"arguments\": {\n", - " \"leftValue\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"DateRange\",\n", - " \"arguments\": {\n", - " \"end\": {\n", - " \"constantValue\": \"2020-12-31\"\n", - " },\n", - " \"start\": {\n", - " \"constantValue\": \"2020-01-01\"\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"rightField\": {\n", - " \"constantValue\": \"system:time_start\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"filter\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Filter.listContains\",\n", - " \"arguments\": {\n", - " \"leftField\": {\n", - " \"constantValue\": \"system:band_names\"\n", - " },\n", - " \"rightValue\": {\n", - " \"constantValue\": \"N\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"filter\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Filter.intersects\",\n", - " \"arguments\": {\n", - " \"leftField\": {\n", - " \"constantValue\": \".all\"\n", - " },\n", - " \"rightValue\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Feature\",\n", - " \"arguments\": {\n", - " \"geometry\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection.geometry\",\n", - " \"arguments\": {\n", - " \"collection\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Collection\",\n", - " \"arguments\": {\n", - " \"features\": {\n", - " \"arrayValue\": {\n", - " \"values\": [\n", - " {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"Feature\",\n", - " \"arguments\": {\n", - " \"geometry\": {\n", - " \"functionInvocationValue\": {\n", - " \"functionName\": \"GeometryConstructors.MultiPolygon\",\n", - " \"arguments\": {\n", - " \"coordinates\": {\n", - " \"constantValue\": [\n", - " [\n", - " [\n", - " [\n", - " -100.575468431,\n", - " 42.608797389000074\n", - " ],\n", - " [\n", - " -100.40155538799996,\n", - " 42.608797389000074\n", - " ],\n", - " [\n", - " -100.40155538799996,\n", - " 42.782710432000044\n", - " ],\n", - " [\n", - " -100.575468431,\n", - " 42.782710432000044\n", - " ],\n", - " [\n", - " -100.575468431,\n", - " 42.608797389000074\n", - " ]\n", - " ]\n", - " ]\n", - " ]\n", - " },\n", - " \"geodesic\": {\n", - " \"constantValue\": true\n", - " }\n", - " }\n", - " }\n", - " },\n", - " \"metadata\": {\n", - " \"constantValue\": {\n", - " \"Unique_ID\": \"X12-677\"\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " ]\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - " }\n", - "})\n" - ] - } - ], + "outputs": [], "source": [ "# compile naip imagery \n", "# 2010, 2016, 2020 for sample time periods \n", @@ -349,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 10, "id": "17490c65-09f6-4a6c-b627-23ad302bf166", "metadata": {}, "outputs": [], @@ -362,81 +207,131 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "id": "d60b8033-6172-4a75-97b4-0587eae966dd", "metadata": {}, "outputs": [], - "source": [ - "# generate the initial map object \n", - "Map = geemap.Map()\n", - "Map.add_basemap(\"SATELLITE\")\n", - "Map.centerObject(ee_object = aoi_ee, zoom = 10)" - ] + "source": [] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 26, "id": "511b5176-27e2-4830-87c7-2c57fa4efea7", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "59d965fde2fc4d3cb70943c960f81639", + "model_id": "1042bc85aa6d4cae940f67eef7e39bf9", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Map(bottom=6188773.0, center=[42.69574620931511, -100.48851190949973], controls=(WidgetControl(options=['posit…" + "Map(center=[42.69574620931511, -100.48851190949973], controls=(WidgetControl(options=['position', 'transparent…" ] }, - "execution_count": 15, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# I'm not sure if we want all three naip images on at once or each map getting it's own. \n", - "### 2020 tree sampling \n", - "Map2020 = Map \n", - "Map2020.addLayer(naip2020, visParamsTrue, name = \"rgb2020\")\n", - "Map2020.addLayer(naip2020, visParamsFalse, name = \"false2020\")\n", + "### Tree presence sampling \n", + "MapPresence = geemap.Map()\n", + "MapPresence.add_basemap(\"SATELLITE\")\n", + "MapPresence.centerObject(ee_object = aoi_ee, zoom = 10)\n", + "MapPresence.addLayer(naip2020, visParamsTrue, name = \"rgb2020\")\n", + "MapPresence.addLayer(naip2020, visParamsFalse, name = \"false2020\")\n", "# testing the 2015 layer\n", - "Map2020.addLayer(naip2015, visParamsTrue, name = \"rgb2015\")\n", - "Map2020.addLayer(naip2010, visParamsTrue, name = \"rgb2010\")\n", + "MapPresence.addLayer(naip2015, visParamsTrue, name = \"rgb2015\")\n", + "MapPresence.addLayer(naip2010, visParamsTrue, name = \"rgb2010\")\n", "\n", - "Map2020" + "MapPresence" ] }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 42, "id": "e1863b67-79b3-4a5d-a711-546a75be29dc", "metadata": { "scrolled": true }, "outputs": [ { - "ename": "AttributeError", - "evalue": "'DataFrame' object has no attribute 'set_value'", + "ename": "TypeError", + "evalue": "'_iAtIndexer' object is not callable", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_7196\\3068110585.py\u001b[0m in \u001b[0;36m?\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;31m# extract objects\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;31m### feels like a single map will work for the sampling process\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mpresence2020\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mee\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mFeatureCollection\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mMap\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw_features\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m 6198\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mname\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_accessors\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6199\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6200\u001b[0m ):\n\u001b[0;32m 6201\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 6202\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'set_value'" + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[42], line 10\u001b[0m\n\u001b[0;32m 8\u001b[0m aoiID\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m\n\u001b[1;32m---> 10\u001b[0m \u001b[43mdf\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43miat\u001b[49m\u001b[43m(\u001b[49m\u001b[43maoiID\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mpresence2020\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "\u001b[1;31mTypeError\u001b[0m: '_iAtIndexer' object is not callable" ] } ], "source": [ - "# extract objects \n", - "### feels like a single map will work for the sampling process\n", - "\n", - "presence2020 = ee.FeatureCollection(Map.draw_features)\n", - "coords = presence2020.geometry()\n", + "# extract presence objects \n", + "presence = ee.FeatureCollection(MapPresence.draw_features)\n", + "coordsPresence = geemap.ee_to_geojson(presence)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "2802debf-aacc-48a3-ab04-bea8e25c5c03", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "71bcf46055b9457897afc804416ba0c0", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Map(center=[42.69574620931511, -100.48851190949973], controls=(WidgetControl(options=['position', 'transparent…" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "### 2020 absence sampling \n", + "MapAbsence = geemap.Map()\n", + "MapAbsence.add_basemap(\"SATELLITE\")\n", + "MapAbsence.centerObject(ee_object = aoi_ee, zoom = 10)\n", + "MapAbsence.addLayer(naip2020, visParamsTrue, name = \"rgb2020\")\n", + "MapAbsence.addLayer(naip2020, visParamsFalse, name = \"false2020\")\n", + "# testing the 2015 layer\n", + "MapAbsence.addLayer(naip2015, visParamsTrue, name = \"rgb2015\")\n", + "MapAbsence.addLayer(naip2010, visParamsTrue, name = \"rgb2010\")\n", "\n", - "df.set_value(aoiID,'presence2020',coords)" + "MapAbsence" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "18a101d6-7ecd-4e33-a25a-3054eef87004", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'type': 'FeatureCollection', 'columns': {'system:index': 'String'}, 'features': [{'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.570233, 42.588334]}, 'id': '0', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.576069, 42.575695]}, 'id': '1', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.607309, 42.568363]}, 'id': '2', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.614862, 42.581256]}, 'id': '3', 'properties': {}}, {'type': 'Feature', 'geometry': {'type': 'Point', 'coordinates': [-100.615892, 42.626743]}, 'id': '4', 'properties': {}}]}\n" + ] + } + ], + "source": [ + "# extract absence objects \n", + "absence = ee.FeatureCollection(MapAbsence.draw_features)\n", + "coordsAbsence = geemap.ee_to_geojson(absence)\n", + "print(coordsAbsence)" ] }, { @@ -777,365 +672,42 @@ } ], "source": [ + "# binding values to the specific locations \n", + "if \n", + "\n", + "\n", "df" ] }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 35, "id": "94f6ec86-031a-4b13-991e-8efbeb916051", "metadata": {}, "outputs": [ { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
IDpresence2010presence2015presence2020absencesampledBydateSampled
0X12-677NaNNaNNaNNaNNaNNaN
1X12-88NaNNaNNaNNaNNaNNaN
2X12-34NaNNaNNaNNaNNaNNaN
3X12-343NaNNaNNaNNaNNaNNaN
4X12-608NaNNaNNaNNaNNaNNaN
5X12-367NaNNaNNaNNaNNaNNaN
6X12-311NaNNaNNaNNaNNaNNaN
7X12-758NaNNaNNaNNaNNaNNaN
8X12-489NaNNaNNaNNaNNaNNaN
9X12-408NaNNaNNaNNaNNaNNaN
10X12-413NaNNaNNaNNaNNaNNaN
11X12-566NaNNaNNaNNaNNaNNaN
12X12-639NaNNaNNaNNaNNaNNaN
13X12-161NaNNaNNaNNaNNaNNaN
14X12-100NaNNaNNaNNaNNaNNaN
15X12-143NaNNaNNaNNaNNaNNaN
16X12-688NaNNaNNaNNaNNaNNaN
17X12-322NaNNaNNaNNaNNaNNaN
18X12-366NaNNaNNaNNaNNaNNaN
19X12-684NaNNaNNaNNaNNaNNaN
20X12-593NaNNaNNaNNaNNaNNaN
21X12-427NaNNaNNaNNaNNaNNaN
22X12-568NaNNaNNaNNaNNaNNaN
23X12-265NaNNaNNaNNaNNaNNaN
24X12-116NaNNaNNaNNaNNaNNaN
\n", - "
" - ], - "text/plain": [ - " ID presence2010 presence2015 presence2020 absence sampledBy \\\n", - "0 X12-677 NaN NaN NaN NaN NaN \n", - "1 X12-88 NaN NaN NaN NaN NaN \n", - "2 X12-34 NaN NaN NaN NaN NaN \n", - "3 X12-343 NaN NaN NaN NaN NaN \n", - "4 X12-608 NaN NaN NaN NaN NaN \n", - "5 X12-367 NaN NaN NaN NaN NaN \n", - "6 X12-311 NaN NaN NaN NaN NaN \n", - "7 X12-758 NaN NaN NaN NaN NaN \n", - "8 X12-489 NaN NaN NaN NaN NaN \n", - "9 X12-408 NaN NaN NaN NaN NaN \n", - "10 X12-413 NaN NaN NaN NaN NaN \n", - "11 X12-566 NaN NaN NaN NaN NaN \n", - "12 X12-639 NaN NaN NaN NaN NaN \n", - "13 X12-161 NaN NaN NaN NaN NaN \n", - "14 X12-100 NaN NaN NaN NaN NaN \n", - "15 X12-143 NaN NaN NaN NaN NaN \n", - "16 X12-688 NaN NaN NaN NaN NaN \n", - "17 X12-322 NaN NaN NaN NaN NaN \n", - "18 X12-366 NaN NaN NaN NaN NaN \n", - "19 X12-684 NaN NaN NaN NaN NaN \n", - "20 X12-593 NaN NaN NaN NaN NaN \n", - "21 X12-427 NaN NaN NaN NaN NaN \n", - "22 X12-568 NaN NaN NaN NaN NaN \n", - "23 X12-265 NaN NaN NaN NaN NaN \n", - "24 X12-116 NaN NaN NaN NaN NaN \n", - "\n", - " dateSampled \n", - "0 NaN \n", - "1 NaN \n", - "2 NaN \n", - "3 NaN \n", - "4 NaN \n", - "5 NaN \n", - "6 NaN \n", - "7 NaN \n", - "8 NaN \n", - "9 NaN \n", - "10 NaN \n", - "11 NaN \n", - "12 NaN \n", - "13 NaN \n", - "14 NaN \n", - "15 NaN \n", - "16 NaN \n", - "17 NaN \n", - "18 NaN \n", - "19 NaN \n", - "20 NaN \n", - "21 NaN \n", - "22 NaN \n", - "23 NaN \n", - "24 NaN " - ] - }, - "execution_count": 99, - "metadata": {}, - "output_type": "execute_result" + "ename": "ValueError", + "evalue": "No axis named X12-677 for object type DataFrame", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(cls, axis)\u001b[0m\n\u001b[0;32m 552\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_AXIS_TO_AXIS_NUMBER\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 553\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 554\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf\"No axis named {axis} for object type {cls.__name__}\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m: 'X12-677'", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m~\\AppData\\Local\\Temp\\ipykernel_13752\\3341668906.py\u001b[0m in \u001b[0;36m?\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[1;31m# assign coords to the dataframe\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[1;31m# df.loc(\"ID\" == aoiID,\"presence2020\") # = coords\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0maoiID\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maoiID\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(self, axis)\u001b[0m\n\u001b[0;32m 718\u001b[0m \u001b[1;31m# we need to return a copy of ourselves\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 719\u001b[0m \u001b[0mnew_self\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 720\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 721\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0maxis\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 722\u001b[1;33m \u001b[0maxis_int_none\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_axis_number\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 723\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 724\u001b[0m \u001b[0maxis_int_none\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 725\u001b[0m \u001b[0mnew_self\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis_int_none\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m?\u001b[1;34m(cls, axis)\u001b[0m\n\u001b[0;32m 550\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_get_axis_number\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcls\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mAxis\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[0mAxisInt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 551\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 552\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_AXIS_TO_AXIS_NUMBER\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 553\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 554\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34mf\"No axis named {axis} for object type {cls.__name__}\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mValueError\u001b[0m: No axis named X12-677 for object type DataFrame" + ] } ], "source": [ "# assign coords to the dataframe \n", - "# df[aoiID][\"presence2020\"] = coords\n", - "df" + "# df.loc(\"ID\" == aoiID,\"presence2020\") # = coords\n", + "aoiID\n", + "df.iloc(aoiID)" ] } ], diff --git a/source/.ipynb_checkpoints/testingDownloadFunction-checkpoint.ipynb b/source/.ipynb_checkpoints/testingDownloadFunction-checkpoint.ipynb new file mode 100644 index 00000000..ba5dbdbf --- /dev/null +++ b/source/.ipynb_checkpoints/testingDownloadFunction-checkpoint.ipynb @@ -0,0 +1,106 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 10, + "id": "209c25d9-b9fc-4bfb-a4d3-21b4732b9d7c", + "metadata": {}, + "outputs": [], + "source": [ + "## developing the download function \n", + "\n", + "\n", + "import ee\n", + "import numpy as np\n", + "import geopandas as gpd\n", + "import itertools" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "351951e9-0b9d-4ceb-87f8-06d9f486ec30", + "metadata": {}, + "outputs": [], + "source": [ + "def make_grid(polygon, edge_size):\n", + " \"\"\"\n", + " polygon : shapely.geometry\n", + " edge_size : length of the grid cell\n", + " \"\"\"\n", + " from itertools import product\n", + " import numpy as np\n", + " import geopandas as gpd\n", + " \n", + " bounds = polygon.bounds\n", + " x_coords = np.arange(bounds[0] + edge_size/2, bounds[2], edge_size)\n", + " y_coords = np.arange(bounds[1] + edge_size/2, bounds[3], edge_size)\n", + " combinations = np.array(list(product(x_coords, y_coords)))\n", + " squares = gpd.points_from_xy(combinations[:, 0], combinations[:, 1]).buffer(edge_size / 2, cap_style=3)\n", + " return gpd.GeoSeries(squares[squares.intersects(polygon)])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fdb42858-ccaf-4284-85a5-9b0eb9521705", + "metadata": {}, + "outputs": [], + "source": [ + "# set sample grid ID \n", + "aoiID = 'X12-677'" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "3d6a32e2-42ad-446f-9e59-04a4924b303c", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "Input must be Index or array-like", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[26], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m d1 \u001b[38;5;241m=\u001b[39m gpd\u001b[38;5;241m.\u001b[39mread_file(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../data/griddedFeatures/twelve_mi_grid_uid.gpkg\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m----> 2\u001b[0m d2 \u001b[38;5;241m=\u001b[39m \u001b[43md1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfilter\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mUnique_ID\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m==\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mX12-1\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 3\u001b[0m poly \u001b[38;5;241m=\u001b[39m d1\u001b[38;5;241m.\u001b[39mloc[\u001b[38;5;241m0\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgeometry\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m 4\u001b[0m d2\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\generic.py:5706\u001b[0m, in \u001b[0;36mNDFrame.filter\u001b[1;34m(self, items, like, regex, axis)\u001b[0m\n\u001b[0;32m 5703\u001b[0m name \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_get_axis_name(axis)\n\u001b[0;32m 5704\u001b[0m \u001b[38;5;66;03m# error: Keywords must be strings\u001b[39;00m\n\u001b[0;32m 5705\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreindex( \u001b[38;5;66;03m# type: ignore[misc]\u001b[39;00m\n\u001b[1;32m-> 5706\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m{name: \u001b[43mlabels\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mintersection\u001b[49m\u001b[43m(\u001b[49m\u001b[43mitems\u001b[49m\u001b[43m)\u001b[49m}\n\u001b[0;32m 5707\u001b[0m )\n\u001b[0;32m 5708\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m like:\n\u001b[0;32m 5710\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mf\u001b[39m(x) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m bool_t:\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\indexes\\base.py:3459\u001b[0m, in \u001b[0;36mIndex.intersection\u001b[1;34m(self, other, sort)\u001b[0m\n\u001b[0;32m 3431\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 3432\u001b[0m \u001b[38;5;124;03mForm the intersection of two Index objects.\u001b[39;00m\n\u001b[0;32m 3433\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3456\u001b[0m \u001b[38;5;124;03mIndex([3, 4], dtype='int64')\u001b[39;00m\n\u001b[0;32m 3457\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 3458\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_validate_sort_keyword(sort)\n\u001b[1;32m-> 3459\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_assert_can_do_setop\u001b[49m\u001b[43m(\u001b[49m\u001b[43mother\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 3460\u001b[0m other, result_name \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_convert_can_do_setop(other)\n\u001b[0;32m 3462\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdtype \u001b[38;5;241m!=\u001b[39m other\u001b[38;5;241m.\u001b[39mdtype:\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\pandas\\core\\indexes\\base.py:3748\u001b[0m, in \u001b[0;36mIndex._assert_can_do_setop\u001b[1;34m(self, other)\u001b[0m\n\u001b[0;32m 3745\u001b[0m \u001b[38;5;129m@final\u001b[39m\n\u001b[0;32m 3746\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_assert_can_do_setop\u001b[39m(\u001b[38;5;28mself\u001b[39m, other) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mbool\u001b[39m:\n\u001b[0;32m 3747\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m is_list_like(other):\n\u001b[1;32m-> 3748\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInput must be Index or array-like\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 3749\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m\n", + "\u001b[1;31mTypeError\u001b[0m: Input must be Index or array-like" + ] + } + ], + "source": [ + "d1 = gpd.read_file(\"../data/griddedFeatures/twelve_mi_grid_uid.gpkg\")\n", + "d2 = d1.filter('Unique_ID'== \"X12-1\")\n", + "poly = d1.loc[0, 'geometry']\n", + "d2\n", + "\n", + "# d2 = make_grid(polygon = d1, edge_size = 5)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/source/grabNAIPfromGEE.py b/source/grabNAIPfromGEE.py new file mode 100644 index 00000000..7cbd35ca --- /dev/null +++ b/source/grabNAIPfromGEE.py @@ -0,0 +1,15 @@ +# import geemap +import ee + + + + ee.Initialize(opt_url='https://earthengine-highvolume.googleapis.com') + + items = getRequests() + + pool = multiprocessing.Pool(25) + pool.starmap(getResult, enumerate(items)) + pool.close() + pool.join() + + diff --git a/source/testingDownloadFunction.ipynb b/source/testingDownloadFunction.ipynb new file mode 100644 index 00000000..5b770530 --- /dev/null +++ b/source/testingDownloadFunction.ipynb @@ -0,0 +1,202 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 65, + "id": "209c25d9-b9fc-4bfb-a4d3-21b4732b9d7c", + "metadata": {}, + "outputs": [], + "source": [ + "## developing the download function \n", + "\n", + "\n", + "import ee\n", + "import numpy as np\n", + "import pandas as pd\n", + "import geopandas as gpd\n", + "import itertools\n", + "import geemap" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "id": "2ad4e122-0a3b-4fa9-a9fb-bac993f399d8", + "metadata": {}, + "outputs": [ + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[76], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# load the sampling reference grid 12kGrid\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m grid \u001b[38;5;241m=\u001b[39m \u001b[43mgpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread_file\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m../data/griddedFeatures/two_sq_grid.gpkg\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m# aoi = grid[0].geometry\u001b[39;00m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;66;03m# load the sampling grid \u001b[39;00m\n\u001b[0;32m 5\u001b[0m \u001b[38;5;66;03m# df = pd.read_csv(\"../sampling/samplingReferenceSheet_12.csv\", index_col='ID')\u001b[39;00m\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(aoi)\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\geopandas\\io\\file.py:297\u001b[0m, in \u001b[0;36m_read_file\u001b[1;34m(filename, bbox, mask, rows, engine, **kwargs)\u001b[0m\n\u001b[0;32m 294\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 295\u001b[0m path_or_bytes \u001b[38;5;241m=\u001b[39m filename\n\u001b[1;32m--> 297\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m _read_file_fiona(\n\u001b[0;32m 298\u001b[0m path_or_bytes, from_bytes, bbox\u001b[38;5;241m=\u001b[39mbbox, mask\u001b[38;5;241m=\u001b[39mmask, rows\u001b[38;5;241m=\u001b[39mrows, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs\n\u001b[0;32m 299\u001b[0m )\n\u001b[0;32m 301\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 302\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124munknown engine \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mengine\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\geopandas\\io\\file.py:395\u001b[0m, in \u001b[0;36m_read_file_fiona\u001b[1;34m(path_or_bytes, from_bytes, bbox, mask, rows, where, **kwargs)\u001b[0m\n\u001b[0;32m 391\u001b[0m df \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mDataFrame(\n\u001b[0;32m 392\u001b[0m [record[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproperties\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m record \u001b[38;5;129;01min\u001b[39;00m f_filt], columns\u001b[38;5;241m=\u001b[39mcolumns\n\u001b[0;32m 393\u001b[0m )\n\u001b[0;32m 394\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m--> 395\u001b[0m df \u001b[38;5;241m=\u001b[39m \u001b[43mGeoDataFrame\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_features\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 396\u001b[0m \u001b[43m \u001b[49m\u001b[43mf_filt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcrs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcrs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcolumns\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcolumns\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mgeometry\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[0;32m 397\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 398\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k \u001b[38;5;129;01min\u001b[39;00m datetime_fields:\n\u001b[0;32m 399\u001b[0m as_dt \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mto_datetime(df[k], errors\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mignore\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\geopandas\\geodataframe.py:641\u001b[0m, in \u001b[0;36mGeoDataFrame.from_features\u001b[1;34m(cls, features, crs, columns)\u001b[0m\n\u001b[0;32m 638\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(feature, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__geo_interface__\u001b[39m\u001b[38;5;124m\"\u001b[39m):\n\u001b[0;32m 639\u001b[0m feature \u001b[38;5;241m=\u001b[39m feature\u001b[38;5;241m.\u001b[39m__geo_interface__\n\u001b[0;32m 640\u001b[0m row \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m--> 641\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgeometry\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[43mshape\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfeature\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mgeometry\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mif\u001b[39;00m feature[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgeometry\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 642\u001b[0m }\n\u001b[0;32m 643\u001b[0m \u001b[38;5;66;03m# load properties\u001b[39;00m\n\u001b[0;32m 644\u001b[0m properties \u001b[38;5;241m=\u001b[39m feature[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mproperties\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\shapely\\geometry\\geo.py:108\u001b[0m, in \u001b[0;36mshape\u001b[1;34m(context)\u001b[0m\n\u001b[0;32m 106\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m MultiLineString(ob[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcoordinates\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[0;32m 107\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m geom_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmultipolygon\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m--> 108\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mMultiPolygon\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43m[\u001b[49m\u001b[43mc\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mc\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mc\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mob\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcoordinates\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 109\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m geom_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgeometrycollection\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m 110\u001b[0m geoms \u001b[38;5;241m=\u001b[39m [shape(g) \u001b[38;5;28;01mfor\u001b[39;00m g \u001b[38;5;129;01min\u001b[39;00m ob\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgeometries\u001b[39m\u001b[38;5;124m\"\u001b[39m, [])]\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\shapely\\geometry\\multipolygon.py:81\u001b[0m, in \u001b[0;36mMultiPolygon.__new__\u001b[1;34m(self, polygons)\u001b[0m\n\u001b[0;32m 79\u001b[0m shell \u001b[38;5;241m=\u001b[39m ob[\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m 80\u001b[0m holes \u001b[38;5;241m=\u001b[39m ob[\u001b[38;5;241m1\u001b[39m]\n\u001b[1;32m---> 81\u001b[0m p \u001b[38;5;241m=\u001b[39m \u001b[43mpolygon\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mPolygon\u001b[49m\u001b[43m(\u001b[49m\u001b[43mshell\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mholes\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 82\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 83\u001b[0m p \u001b[38;5;241m=\u001b[39m polygon\u001b[38;5;241m.\u001b[39mPolygon(ob)\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\shapely\\geometry\\polygon.py:230\u001b[0m, in \u001b[0;36mPolygon.__new__\u001b[1;34m(self, shell, holes)\u001b[0m\n\u001b[0;32m 228\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m shell\n\u001b[0;32m 229\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m--> 230\u001b[0m shell \u001b[38;5;241m=\u001b[39m \u001b[43mLinearRing\u001b[49m\u001b[43m(\u001b[49m\u001b[43mshell\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 232\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m holes \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 233\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(holes) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m 234\u001b[0m \u001b[38;5;66;03m# shapely constructor cannot handle holes=[]\u001b[39;00m\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\shapely\\geometry\\polygon.py:104\u001b[0m, in \u001b[0;36mLinearRing.__new__\u001b[1;34m(self, coordinates)\u001b[0m\n\u001b[0;32m 99\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(coordinates) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[0;32m 100\u001b[0m \u001b[38;5;66;03m# empty geometry\u001b[39;00m\n\u001b[0;32m 101\u001b[0m \u001b[38;5;66;03m# TODO better constructor + should shapely.linearrings handle this?\u001b[39;00m\n\u001b[0;32m 102\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m shapely\u001b[38;5;241m.\u001b[39mfrom_wkt(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLINEARRING EMPTY\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 104\u001b[0m geom \u001b[38;5;241m=\u001b[39m \u001b[43mshapely\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlinearrings\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcoordinates\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 105\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(geom, LinearRing):\n\u001b[0;32m 106\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid values passed to LinearRing constructor\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\shapely\\decorators.py:77\u001b[0m, in \u001b[0;36mmultithreading_enabled..wrapped\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 75\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m arr \u001b[38;5;129;01min\u001b[39;00m array_args:\n\u001b[0;32m 76\u001b[0m arr\u001b[38;5;241m.\u001b[39mflags\u001b[38;5;241m.\u001b[39mwriteable \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m---> 77\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 78\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[0;32m 79\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m arr, old_flag \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(array_args, old_flags):\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\shapely\\creation.py:173\u001b[0m, in \u001b[0;36mlinearrings\u001b[1;34m(coords, y, z, indices, out, **kwargs)\u001b[0m\n\u001b[0;32m 171\u001b[0m coords \u001b[38;5;241m=\u001b[39m _xyz_to_coords(coords, y, z)\n\u001b[0;32m 172\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m indices \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m--> 173\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m lib\u001b[38;5;241m.\u001b[39mlinearrings(coords, out\u001b[38;5;241m=\u001b[39mout, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 174\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 175\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m simple_geometries_1d(coords, indices, GeometryType\u001b[38;5;241m.\u001b[39mLINEARRING, out\u001b[38;5;241m=\u001b[39mout)\n", + "\u001b[1;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "# load the sampling reference grid 12kGrid\n", + "grid = gpd.read_file(\"../data/griddedFeatures/two_sq_grid.gpkg\") # cant read this in \n", + "# aoi = grid[0].geometry\n", + "# load the sampling grid \n", + "# df = pd.read_csv(\"../sampling/samplingReferenceSheet_12.csv\", index_col='ID')\n", + "print(aoi)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "b4fc778b-1623-4a9f-a8ef-6558390c485f", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# init the ee object\n", + "ee.Initialize()\n", + " \n", + "# Define the roi\n", + "area = ee.Geometry.Polygon([[-98.62164242554545,41.15853811488826],\\\n", + " [-98.56671078492045,41.15853811488826],\\\n", + " [-98.56671078492045,41.204015639589095],\\\n", + " [-98.62164242554545,41.204015639589095],\\\n", + " [-98.62164242554545,41.15853811488826]])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "59d3c669-a1d5-4d27-935e-90c2dc445444", + "metadata": {}, + "outputs": [ + { + "ename": "EEException", + "evalue": "Computed value is too large.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mHttpError\u001b[0m Traceback (most recent call last)", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\ee\\data.py:352\u001b[0m, in \u001b[0;36m_execute_cloud_call\u001b[1;34m(call, num_retries)\u001b[0m\n\u001b[0;32m 351\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 352\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcall\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexecute\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnum_retries\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnum_retries\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 353\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m googleapiclient\u001b[38;5;241m.\u001b[39merrors\u001b[38;5;241m.\u001b[39mHttpError \u001b[38;5;28;01mas\u001b[39;00m e:\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\googleapiclient\\_helpers.py:130\u001b[0m, in \u001b[0;36mpositional..positional_decorator..positional_wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 129\u001b[0m logger\u001b[38;5;241m.\u001b[39mwarning(message)\n\u001b[1;32m--> 130\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m wrapped(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\googleapiclient\\http.py:938\u001b[0m, in \u001b[0;36mHttpRequest.execute\u001b[1;34m(self, http, num_retries)\u001b[0m\n\u001b[0;32m 937\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resp\u001b[38;5;241m.\u001b[39mstatus \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m300\u001b[39m:\n\u001b[1;32m--> 938\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HttpError(resp, content, uri\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39muri)\n\u001b[0;32m 939\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpostproc(resp, content)\n", + "\u001b[1;31mHttpError\u001b[0m: ", + "\nDuring handling of the above exception, another exception occurred:\n", + "\u001b[1;31mEEException\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[79], line 64\u001b[0m\n\u001b[0;32m 55\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m arr\n\u001b[0;32m 57\u001b[0m \u001b[38;5;66;03m# # map over the image collection\u001b[39;00m\n\u001b[0;32m 58\u001b[0m \u001b[38;5;66;03m# myCollection = collection.map(anyFunction)\u001b[39;00m\n\u001b[0;32m 59\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 62\u001b[0m \n\u001b[0;32m 63\u001b[0m \u001b[38;5;66;03m# # get the lon, lat and result as 1d array\u001b[39;00m\n\u001b[1;32m---> 64\u001b[0m lat, lon, data \u001b[38;5;241m=\u001b[39m \u001b[43mLatLonImg\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnaip2020\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 66\u001b[0m \u001b[38;5;66;03m# # 1d to 2d array\u001b[39;00m\n\u001b[0;32m 67\u001b[0m \u001b[38;5;66;03m# image = toImage(lat,lon,data)\u001b[39;00m\n\u001b[0;32m 68\u001b[0m \n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 71\u001b[0m \u001b[38;5;66;03m# plt.imshow(image)\u001b[39;00m\n\u001b[0;32m 72\u001b[0m \u001b[38;5;66;03m# plt.show()\u001b[39;00m\n", + "Cell \u001b[1;32mIn[79], line 24\u001b[0m, in \u001b[0;36mLatLonImg\u001b[1;34m(img)\u001b[0m\n\u001b[0;32m 17\u001b[0m img \u001b[38;5;241m=\u001b[39m img\u001b[38;5;241m.\u001b[39maddBands(ee\u001b[38;5;241m.\u001b[39mImage\u001b[38;5;241m.\u001b[39mpixelLonLat())\n\u001b[0;32m 19\u001b[0m img \u001b[38;5;241m=\u001b[39m img\u001b[38;5;241m.\u001b[39mreduceRegion(reducer\u001b[38;5;241m=\u001b[39mee\u001b[38;5;241m.\u001b[39mReducer\u001b[38;5;241m.\u001b[39mtoList(),\\\n\u001b[0;32m 20\u001b[0m geometry\u001b[38;5;241m=\u001b[39marea,\\\n\u001b[0;32m 21\u001b[0m maxPixels\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1e13\u001b[39m,\\\n\u001b[0;32m 22\u001b[0m scale\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m);\n\u001b[1;32m---> 24\u001b[0m data \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marray((\u001b[43mee\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mArray\u001b[49m\u001b[43m(\u001b[49m\u001b[43mimg\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mresult\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgetInfo\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m))\n\u001b[0;32m 25\u001b[0m lats \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marray((ee\u001b[38;5;241m.\u001b[39mArray(img\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlatitude\u001b[39m\u001b[38;5;124m\"\u001b[39m))\u001b[38;5;241m.\u001b[39mgetInfo()))\n\u001b[0;32m 26\u001b[0m lons \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39marray((ee\u001b[38;5;241m.\u001b[39mArray(img\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlongitude\u001b[39m\u001b[38;5;124m\"\u001b[39m))\u001b[38;5;241m.\u001b[39mgetInfo()))\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\ee\\computedobject.py:103\u001b[0m, in \u001b[0;36mComputedObject.getInfo\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 97\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mgetInfo\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Optional[Any]:\n\u001b[0;32m 98\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Fetch and return information about this object.\u001b[39;00m\n\u001b[0;32m 99\u001b[0m \n\u001b[0;32m 100\u001b[0m \u001b[38;5;124;03m Returns:\u001b[39;00m\n\u001b[0;32m 101\u001b[0m \u001b[38;5;124;03m The object can evaluate to anything.\u001b[39;00m\n\u001b[0;32m 102\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m--> 103\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mdata\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcomputeValue\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\ee\\data.py:971\u001b[0m, in \u001b[0;36mcomputeValue\u001b[1;34m(obj)\u001b[0m\n\u001b[0;32m 968\u001b[0m body \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mexpression\u001b[39m\u001b[38;5;124m'\u001b[39m: serializer\u001b[38;5;241m.\u001b[39mencode(obj, for_cloud_api\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)}\n\u001b[0;32m 969\u001b[0m _maybe_populate_workload_tag(body)\n\u001b[1;32m--> 971\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_execute_cloud_call\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 972\u001b[0m \u001b[43m \u001b[49m\u001b[43m_get_cloud_projects\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 973\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalue\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 974\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcompute\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbody\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mproject\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_get_projects_path\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mprettyPrint\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[0;32m 975\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mresult\u001b[39m\u001b[38;5;124m'\u001b[39m]\n", + "File \u001b[1;32m~\\Desktop\\Agroforestry\\agro-env\\lib\\site-packages\\ee\\data.py:354\u001b[0m, in \u001b[0;36m_execute_cloud_call\u001b[1;34m(call, num_retries)\u001b[0m\n\u001b[0;32m 352\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m call\u001b[38;5;241m.\u001b[39mexecute(num_retries\u001b[38;5;241m=\u001b[39mnum_retries)\n\u001b[0;32m 353\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m googleapiclient\u001b[38;5;241m.\u001b[39merrors\u001b[38;5;241m.\u001b[39mHttpError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m--> 354\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m _translate_cloud_exception(e)\n", + "\u001b[1;31mEEException\u001b[0m: Computed value is too large." + ] + } + ], + "source": [ + "# define the image\n", + "# collection = ee.ImageCollection(\"COPERNICUS/S2\").filterBounds(area)\\\n", + "# .filterDate(\"2018-01-01\",\"2019-01-10\")\\\n", + "# .filterMetadata(\"CLOUDY_PIXEL_PERCENTAGE\",\"less_than\",10)\\\n", + "# .select(['B8', 'B4'])\n", + "\n", + "naip2020 = geemap.get_annual_NAIP(2020).filterBounds(area).mosaic()\n", + "\n", + " \n", + "# # perform any calculation on the image collection here\n", + "# def anyFunction(img):\n", + "# ndvi = ee.Image(img.normalizedDifference(['B8', 'B4'])).rename([\"ndvi\"])\n", + "# return ndvi\n", + " \n", + "# export the latitude, longitude and array\n", + "def LatLonImg(img):\n", + " img = img.addBands(ee.Image.pixelLonLat())\n", + " \n", + " img = img.reduceRegion(reducer=ee.Reducer.toList(),\\\n", + " geometry=area,\\\n", + " maxPixels=1e13,\\\n", + " scale=1);\n", + " \n", + " data = np.array((ee.Array(img.get(\"result\")).getInfo()))\n", + " lats = np.array((ee.Array(img.get(\"latitude\")).getInfo()))\n", + " lons = np.array((ee.Array(img.get(\"longitude\")).getInfo()))\n", + " return lats, lons, data\n", + "\n", + "\n", + "# covert the lat, lon and array into an image\n", + "def toImage(lats,lons,data):\n", + " \n", + " # get the unique coordinates\n", + " uniqueLats = np.unique(lats)\n", + " uniqueLons = np.unique(lons)\n", + " \n", + " # get number of columns and rows from coordinates\n", + " ncols = len(uniqueLons)\n", + " nrows = len(uniqueLats)\n", + " \n", + " # determine pixelsizes\n", + " ys = uniqueLats[1] - uniqueLats[0]\n", + " xs = uniqueLons[1] - uniqueLons[0]\n", + " \n", + " # create an array with dimensions of image\n", + " arr = np.zeros([nrows, ncols], np.float32) #-9999\n", + " \n", + " # fill the array with values\n", + " counter =0\n", + " for y in range(0,len(arr),1):\n", + " for x in range(0,len(arr[0]),1):\n", + " if lats[counter] == uniqueLats[y] and lons[counter] == uniqueLons[x] and counter < len(lats)-1:\n", + " counter+=1\n", + " arr[len(uniqueLats)-1-y,x] = data[counter] # we start from lower left corner\n", + " return arr\n", + " \n", + "# # map over the image collection\n", + "# myCollection = collection.map(anyFunction)\n", + " \n", + "# # get the median\n", + "# result = ee.Image(myCollection.median()).rename(['result'])\n", + " \n", + "# # get the lon, lat and result as 1d array\n", + "lat, lon, data = LatLonImg(naip2020)\n", + " \n", + "# # 1d to 2d array\n", + "# image = toImage(lat,lon,data)\n", + " \n", + "# # in case you want to plot the image\n", + "# import matplotlib.pyplot as plt\n", + "# plt.imshow(image)\n", + "# plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/testing/aggregateImagery.R b/testing/aggregateImagery.R new file mode 100644 index 00000000..bcdcb6fc --- /dev/null +++ b/testing/aggregateImagery.R @@ -0,0 +1,20 @@ +raster <- n1 +scaleFactors <- c(2,3,4) +#' Upscale rasters +#' +#' @param raster +#' @param scaleFactors +#' +#' @return a list of rasters at values scaled levels +aggregateRasters <- function(raster, scaleFactors){ + # helper function to help order the inputs to the map call + ag <- function(scaleFactor, raster){ + v1 <- terra::aggregate(x = raster,fact = scaleFactor, fun = "mean") + names(v1) <- paste0(raster, "_", scaleFactor) + } + + m1 <- purrr::map(.x = scaleFactors,.f = ag, raster = raster) + +} + + diff --git a/testing/generateIndicies.R b/testing/generateIndicies.R new file mode 100644 index 00000000..c1aec287 --- /dev/null +++ b/testing/generateIndicies.R @@ -0,0 +1,37 @@ + +#' Generate NDVI values +#' +#' @param raster terra object with red and ndvi bands present +#' +#' @return single band raster with NDVI values +createNDVI <- function(raster){ + # (NIR - R) / (NIR + R) + r1 <- (raster$n - raster$r) / (raster$n + raster$r) + return(r1) +} + + + +#' Create GLCM indicies +#' +#' @param band single raster object +#' +#' @return three raster bands with basic on the input layer +createGLCM <- function(band){ + # grab the name of the input feature + name <- names(band) + # run the glcm function + ## currently the window and the statistics are hard coded. Need to be selective + ## about this so might want to move to the parameters + vals <- glcm(band, + window = c(3, 3), + statistics = + c("entropy", + "second_moment", + "correlation") + ) + # rename the values as these will be part of the stack of multiple indicies + names(vals) <- paste0(name,"_", names(vals)) + + return(vals) +} \ No newline at end of file diff --git a/testing/testingWorkflow.R b/testing/testingWorkflow.R new file mode 100644 index 00000000..0851353a --- /dev/null +++ b/testing/testingWorkflow.R @@ -0,0 +1,106 @@ +### temp doc for developing the work flow +pacman::p_load(dplyr,terra,sf, readr, stringr, tidyr, tmap, glcm, raster, furrr) +tmap_mode("view") + + +data <- list.files("data/testFeatures", all.files = TRUE, full.names = TRUE,recursive = TRUE) + +n1 <- rast(data[1]) |> + terra::project("epsg:4326") + +names(n1) <- c("r", "g","b","n") + + +# Source functions ------------------------------------------------------- + +source("testing/generateIndicies.R") + + + +# silly stuff to prep the test input data --------------------------------- +p1 <- read_csv(data[4]) |> + dplyr::select(WKT) |> + pull() |> + str_remove_all("POINT ")|> + str_remove_all("[()]") |> + str_replace_all(pattern = " ", replacement = ", ") |> + data.frame() + +names(p1) <- "vals" + +p1 <- p1 |> + tidyr::separate( col = "vals", sep = ", ", into = c("x", "y"))|> + mutate(x = as.numeric(x), + y = as.numeric(y)) + +p2 <- sf:: st_as_sf(x = p1, coords = c("x","y"), dim = "XY",) |> + mutate(presence = 1) +st_crs(p2)= 4326 + +qtm(p2) + +a1 <- read_csv(data[3])|> + dplyr::select(WKT) |> + pull() |> + str_remove_all("POINT ")|> + str_remove_all("[()]") |> + str_replace_all(pattern = " ", replacement = ", ") |> + data.frame() +names(a1) <- "vals" + +a1 <- a1 |> + tidyr::separate( col = "vals", sep = ", ", into = c("x", "y"))|> + mutate(x = as.numeric(x), + y = as.numeric(y)) + +a2 <- sf:: st_as_sf(x = a1, coords = c("x","y"), dim = "XY") |> + mutate(presence = 0) +st_crs(a2)= 4326 + +qtm(a2) + +points <- bind_rows(p2,a2) + + + +# generate indices ------------------------------------------------------ +ndvi <- createNDVI(n1) + + +names(ndvi) <- "ndvi" +# generate a multiband feature ------------------------------------------- +n2 <- c(n1, ndvi) +# original data is ~0.5 meters +111139 * res(n2) + +# extract values ---------------------------------------------------------- +v2 <- terra::extract(x = n2, y = points) + + +# resample raster data to high resultions -------------------------------- + +# factor of work is working 1 cell in all direction so the avergage of 9 cells +# works in parallel which I'd like to use if possilbe. +n2_3 <- terra::aggregate(x = n2, fact = 3, fun = "mean") # cell 1.5 meter +111139 * res(n2_3) + +n2_3_3 <-terra::aggregate(x = n2, fact = 6, fun = "mean") # cell 3 meter +111139 * res(n2_3_3) + + + +# generate GLMC on the high res features --------------------------------- +l1 <- list() + +for(i in 1:nlyr(n2_3_3)){ + l1[[i]] <- raster(n2_3_3[[i]]) +} + + +plan(multisession, workers = 5) +d2 <- furrr::future_map(.x = l1, createGLCM ) + +# convert back to +d3 <- map(d2, rast) |> rast() +d4 <- c(n2_3_3, d3) + From aa0b0212c51053805f855c78ceeb88eda5d71ae7 Mon Sep 17 00:00:00 2001 From: dcarver1 Date: Thu, 12 Oct 2023 10:34:52 -0700 Subject: [PATCH 3/3] adding to git ignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0283b5e4..d4beb6ed 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ - /agro-env /data - .Rproj.user