Josh-Lee1 / eBird-Fire-Index

BEES3041 Big Data Project
0 stars 0 forks source link

shapefile of fires #3

Closed wcornwell closed 4 years ago

wcornwell commented 4 years ago

map_figure_of_fires_and_temperature

wcornwell commented 4 years ago

code from frog project

get_species_fire_summary <- function(species_name) {

  message(paste0("Analyzing ", species_name))

  load(paste0("Data/range_maps/", gsub(" ", "_", species_name), ".RData"))

  range <- range_map %>%
    st_as_sf() %>%
    st_transform(crs=st_crs(hotspot_points))

  points_within_range <- range %>%
    st_join(hotspot_points)

  overlap_extent_area <- range %>%
    st_intersection(extent) %>%
    st_area() %>%
    sum() %>%
    as.numeric()

  range_area <- range %>%
    st_area() %>%
    sum() %>%
    as.numeric()

  overlap_percentage <- (overlap_extent_area/range_area)*100

  dat_summary <- points_within_range %>%
    dplyr::select(id, latitude, longitude, temp_kelvin,
                  power, confidence, datetime) %>%
    st_set_geometry(NULL) %>%
    mutate(extent_percent_burn=overlap_percentage) %>%
    mutate(species=species_name)

  return(dat_summary)

}
wcornwell commented 4 years ago

Psuedo-code steps: save all maps to a figures directory with informative names

  1. Load one ebird file
  2. Filter out (ie exclude) bad checklists
  3. Select only useful columns (exclude others)
  4. Select only distinct rows (exclude others)
  5. Spatial processing 5a. read in fire shapefile 5b. make map of fire shapefile 5c. Convert ebird checklists to sf object with CRS code from fire shapefile 5d. Make a map of the points using ggplot and geom_sf on the fire shapefile map 5e. add column for inside/outside using st_join 5f. make a map with points colored by inside/outside
  6. write output file as rds to a directory called processed_data
Josh-Lee1 commented 4 years ago

Hey @wcornwell and @coreytcallaghan, Just getting stuck on 5c. a bit. Do I have to assign a CRS to my ebird data before I make it a sf object? and should st_as_sf() do the trick for this transformation? Thanks, Josh

coreytcallaghan commented 4 years ago

Nah. Part of making it an sf object. In the st as sf function, should be able to set crs=st_crs(fire_object).

On Mon, Jun 15, 2020, 6:31 PM Josh-Lee1 notifications@github.com wrote:

Hey @wcornwell https://github.com/wcornwell and @coreytcallaghan https://github.com/coreytcallaghan, Just getting stuck on 5c. a bit. Do I have to assign a CRS to my ebird data before I make it a sf object? and should st_as_sf() do the trick for this transformation? Thanks, Josh

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Josh-Lee1/eBird-Fire-Index/issues/3#issuecomment-643984594, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGWSEJVIXDCKVCBXA54FDI3RWXL3TANCNFSM4N5VYICQ .

Josh-Lee1 commented 4 years ago

Yeah I think I understand that line of code but cant get the checklists into an sf object I bump into this error. Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) : no simple features geometry column present

coreytcallaghan commented 4 years ago

Can you flick me an RDS real quick via email and Ill have a go?

On Mon, Jun 15, 2020, 6:43 PM Josh-Lee1 notifications@github.com wrote:

Yeah I think I understand that line of code but cant get the checklists into an sf object I bump into this error. Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) : no simple features geometry column present

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Josh-Lee1/eBird-Fire-Index/issues/3#issuecomment-643990998, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGWSEJTKWWPHVLGWAEBM3M3RWXNJPANCNFSM4N5VYICQ .

Josh-Lee1 commented 4 years ago

Did that make it past your auto reply?

On Mon., 15 Jun. 2020, 18:45 Corey Callaghan, notifications@github.com wrote:

Can you flick me an RDS real quick via email and Ill have a go?

On Mon, Jun 15, 2020, 6:43 PM Josh-Lee1 notifications@github.com wrote:

Yeah I think I understand that line of code but cant get the checklists into an sf object I bump into this error. Error in st_sf(x, ..., agr = agr, sf_column_name = sf_column_name) : no simple features geometry column present

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/Josh-Lee1/eBird-Fire-Index/issues/3#issuecomment-643990998 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AGWSEJTKWWPHVLGWAEBM3M3RWXNJPANCNFSM4N5VYICQ

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Josh-Lee1/eBird-Fire-Index/issues/3#issuecomment-643991997, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOENO3WM7Z427ETCKL3S5IDRWXNQZANCNFSM4N5VYICQ .

coreytcallaghan commented 4 years ago

This should work:

ebird_points <- st_as_sf(data=baatrimmed, coords=c("LONGITUDE", "LATITUDE"), crs=st_crs(fireshape))

And it appears to work for me:

ggplot() + 
   geom_sf(data = fireshape, size = 0.1, color = "black", fill = "black") + 
   geom_sf(data=ebird_points, color="green")+
   ggtitle("Fire Boundary Plot") + 
   coord_sf()
Josh-Lee1 commented 4 years ago

I got this error. cant find Longitude? Error in lapply(x[coords], as.numeric) : argument "x" is missing, with no default

coreytcallaghan commented 4 years ago

Check the spelling and case of the word...?

On Mon, Jun 15, 2020, 8:26 PM Josh-Lee1 notifications@github.com wrote:

I got this error. cant find Longitude? Error in lapply(x[coords], as.numeric) : argument "x" is missing, with no default

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Josh-Lee1/eBird-Fire-Index/issues/3#issuecomment-644043897, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGWSEJXNDSD5GQTIWMJSU63RWXZL7ANCNFSM4N5VYICQ .

Josh-Lee1 commented 4 years ago

:/

coreytcallaghan commented 4 years ago

Still nothing? It just worked on my machine.

On Mon, Jun 15, 2020, 8:38 PM Josh-Lee1 notifications@github.com wrote:

:/

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Josh-Lee1/eBird-Fire-Index/issues/3#issuecomment-644049138, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGWSEJWSJMAXZ2MFANMP2HTRWX2XRANCNFSM4N5VYICQ .

Josh-Lee1 commented 4 years ago

Yeah no bingo. Could it have to do with needing to update R? I dont think im on the most recent version.

Josh-Lee1 commented 4 years ago

Did you change any code above that chunk?

coreytcallaghan commented 4 years ago

Sorry! Need to remove the 'data=' in that code.

coreytcallaghan commented 4 years ago

Here is everything from that .Rmd into a chunk:

baa <- read_delim("C:/Users/CTC/Desktop/baa", "\t", escape_double = FALSE, trim_ws = TRUE)

colnames(baa) <- gsub(" ", ".", colnames(baa))

library(dplyr)

baatrimmed<- baa %>% 
  filter(ALL.SPECIES.REPORTED==1, EFFORT.DISTANCE.KM<10, DURATION.MINUTES<300, DURATION.MINUTES>10) %>% 
  select(SAMPLING.EVENT.IDENTIFIER, LOCALITY.ID, LATITUDE, LONGITUDE, OBSERVATION.DATE) %>% 
  distinct()

library(sf)
fireshape<- st_read("National_Indicative_Aggregated_Fire_Extent_Dataset_v20200211/National_Indicative_Aggregated_Fire_Extent_Dataset_v20200211.shp")

library(ggplot2)
ggplot() + 
  geom_sf(data = fireshape, size = 0.1, color = "black", fill = "black") + 
  ggtitle("Fire Boundary Plot") + 
  coord_sf()

ebird_points <- st_as_sf(baatrimmed, coords=c("LONGITUDE", "LATITUDE"), crs=st_crs(fireshape))

ggplot() + 
  geom_sf(data = fireshape, size = 0.1, color = "black", fill = "black") + 
  geom_sf(data=ebird_points, color="green")+
  ggtitle("Fire Boundary Plot") + 
  coord_sf()
Josh-Lee1 commented 4 years ago

Haha ok sweet well I'll let you know how I go after I finish updating R.

coreytcallaghan commented 4 years ago

Oh the suspense!!

Josh-Lee1 commented 4 years ago

image

Yipee! Thanks heaps. I will carry on tomorrow.

Josh-Lee1 commented 4 years ago

So trying to figure out how st_join works, I have this line: st_join(ebird_points, fireshape) It adds another column but is full of N/As. Do I need another argument in the function to tell it inside= true or something? or is there another function to apply? Thanks

coreytcallaghan commented 4 years ago

I'd recommend looking around on google for different vignettes and/or tutorials.

e.g., https://cran.r-project.org/web/packages/sf/vignettes/sf4.html#Joining_two_feature_sets_based_on_geometries

Sometimes if I can't get something to work, I try to find some very simple play data and wrap my head around something that way first.

Josh-Lee1 commented 4 years ago

Ok thanks. Ill give that a go.

On Wed., 17 Jun. 2020, 18:17 Corey Callaghan, notifications@github.com wrote:

I'd recommend looking around on google for different vignettes and/or tutorials.

e.g., https://cran.r-project.org/web/packages/sf/vignettes/sf4.html#Joining_two_feature_sets_based_on_geometries

Sometimes if I can't get something to work, I try to find some very simple play data and wrap my head around something that way first.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Josh-Lee1/eBird-Fire-Index/issues/3#issuecomment-645227669, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOENO3TC5QUBEMCTFMCX6ADRXB3Z5ANCNFSM4N5VYICQ .