lisaml02 commited on
Commit
163c4f4
1 Parent(s): c09cddf

Upload 8 files

Browse files
GLOBEMeasurementData-21686.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7f258731131a927a8a2e4195df230a8da8e7cb598a3a38e206757eefacbde41
3
+ size 6159945
GO_LandCover.csv ADDED
The diff for this file is too large to render. See raw diff
 
adoptapixelf24.Rproj ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Version: 1.0
2
+
3
+ RestoreWorkspace: Default
4
+ SaveWorkspace: Default
5
+ AlwaysSaveHistory: Default
6
+
7
+ EnableCodeIndexing: Yes
8
+ UseSpacesForTab: Yes
9
+ NumSpacesForTab: 2
10
+ Encoding: UTF-8
11
+
12
+ RnwWeave: Sweave
13
+ LaTeX: pdfLaTeX
eda.Rmd ADDED
@@ -0,0 +1,592 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: "eda"
3
+ output: html_document
4
+ date: "2024-09-29"
5
+ ---
6
+
7
+ ```{r setup, include=FALSE}
8
+ knitr::opts_chunk$set(echo = TRUE)
9
+ ```
10
+
11
+ ```{r loading packages and data}
12
+ library(tidyverse)
13
+ library(dplyr)
14
+
15
+ globe <- read_csv("./GLOBE_data.csv")
16
+ ```
17
+
18
+ # Cleaning
19
+
20
+ ```{r rename columns}
21
+ globe <- globe %>%
22
+ rename(landcover_id = `land covers:land cover id`) %>%
23
+ rename(data_source = `land covers:data source`) %>%
24
+ rename(measured_at = `land covers:measured at`) %>%
25
+ rename(muc_code = `land covers:muc code`) %>%
26
+ rename(muc_description = `land covers:muc description`) %>%
27
+ rename(north_photo_url = `land covers:north photo url`) %>%
28
+ rename(east_photo_url = `land covers:east photo url`) %>%
29
+ rename(south_photo_url = `land covers:south photo url`) %>%
30
+ rename(west_photo_url = `land covers:west photo url`) %>%
31
+ rename(upward_photo_url = `land covers:upward photo url`) %>%
32
+ rename(downward_photo_url = `land covers:downward photo url`) %>%
33
+ rename(measure_lat = `land covers:measurement latitude`) %>%
34
+ rename(measure_long = `land covers:measurement longitude`) %>%
35
+ rename(measure_elev = `land covers:measurement elevation`) %>%
36
+ rename(loc_method = `land covers:location method`) %>%
37
+ rename(loc_accuracy = `land covers:location accuracy (m)`) %>%
38
+ rename(snow_ice = `land covers:snow ice`) %>%
39
+ rename(standing_water = `land covers:standing water`) %>%
40
+ rename(muddy = `land covers:muddy`) %>%
41
+ rename(dry_ground = `land covers:dry ground`) %>%
42
+ rename(leaves_on_trees = `land covers:leaves on trees`) %>%
43
+ rename(raining_snowing = `land covers:raining snowing`)
44
+ ```
45
+
46
+ ```{r select columns and format}
47
+ library(dplyr)
48
+
49
+ globe_c <- globe %>%
50
+ select(
51
+ organization_id, org_name, site_id, site_name, latitude, longitude, elevation, measured_on,
52
+ landcover_id, data_source, measured_at, muc_code, muc_description, north_photo_url,
53
+ east_photo_url, south_photo_url, west_photo_url, upward_photo_url, downward_photo_url,
54
+ measure_lat, measure_long, measure_elev, loc_method, loc_accuracy, snow_ice, standing_water,
55
+ muddy, dry_ground, leaves_on_trees, raining_snowing
56
+ ) %>%
57
+ mutate(
58
+ snow_ice = ifelse(!is.na(snow_ice), 0, 1),
59
+ standing_water = ifelse(!is.na(standing_water), 0, 1),
60
+ muddy = ifelse(!is.na(muddy), 0, 1),
61
+ dry_ground = ifelse(!is.na(dry_ground), 0, 1),
62
+ leaves_on_trees = ifelse(!is.na(leaves_on_trees), 0, 1),
63
+ raining_snowing = ifelse(!is.na(raining_snowing), 0, 1)
64
+ ) %>%
65
+ filter(if_all(everything(), ~ !is.na(.)))
66
+
67
+ globe_c
68
+
69
+ ```
70
+
71
+ ```{r correctly formatting columns and rounding decimal points}
72
+ globe_c$measured_on <- as.POSIXct(as.character(globe_c$measured_on), format = "%Y-%m-%d")
73
+
74
+ globe_c <- globe_c %>%
75
+ mutate(
76
+ organization_id = as.numeric(organization_id),
77
+ site_id = as.numeric(site_id),
78
+ latitude = round(as.numeric(latitude), 6),
79
+ longitude = round(as.numeric(longitude), 6),
80
+ elevation = round(as.numeric(elevation), 6),
81
+ measure_lat = round(as.numeric(measure_lat), 6),
82
+ measure_long = round(as.numeric(measure_long), 6),
83
+ measure_elev = round(as.numeric(measure_elev), 6)
84
+ )
85
+ globe_c
86
+ ```
87
+
88
+ # Metadata Info
89
+
90
+ ```{r}
91
+ # install.packages("cld2")
92
+ library(cld2)
93
+
94
+ # Check languages in the text_column of globe_c
95
+ language_counts <- table(cld2::detect_language(globe_c$org_name, plain_text = TRUE))
96
+
97
+ # Display the language counts
98
+ print(language_counts)
99
+
100
+ ```
101
+
102
+ # Date/Time/Location
103
+
104
+ ```{r}
105
+ min(globe_c$measured_at)
106
+ max(globe_c$measured_at)
107
+
108
+ min(globe_c$latitude)
109
+ min(globe_c$longitude)
110
+ min(globe_c$measure_lat)
111
+ min(globe_c$measure_long)
112
+
113
+ max(globe_c$latitude)
114
+ max(globe_c$longitude)
115
+ max(globe_c$measure_lat)
116
+ max(globe_c$measure_long)
117
+ ```
118
+
119
+ ```{r checking if measured_at = measured_on}
120
+ library(dplyr)
121
+
122
+ globe_c <- globe_c %>%
123
+ mutate(
124
+ are_equal = measured_at == measured_on
125
+ )
126
+
127
+ # Display rows where the columns are not equal
128
+ globe_c_not_equal <- globe_c %>% filter(are_equal)
129
+ globe_c_not_equal
130
+ ```
131
+
132
+ Date range where they are equal: 2018-09-30 to 2019-07-18
133
+
134
+ ```{r calculating local time}
135
+ library(dplyr)
136
+ library(lubridate)
137
+
138
+ globe_c <- globe_c %>%
139
+ mutate(
140
+ # Calculate the time zone offset (round to the nearest hour)
141
+ timezone_offset = round(measure_long / 15),
142
+
143
+ # Calculate the local time by adding the offset to measured_on
144
+ local_time = measured_on + hours(timezone_offset)
145
+ )
146
+
147
+ globe_c
148
+ ```
149
+
150
+ ```{r converting location accuracy column into standardized units}
151
+ library(dplyr)
152
+
153
+ # Convert loc_accuracy from meters to degrees of latitude and longitude
154
+ globe_c <- globe_c %>%
155
+ mutate(
156
+ # Convert latitude offset: distance in meters divided by meters per degree of latitude
157
+ latitude_offset_deg = loc_accuracy / 111320,
158
+
159
+ # Convert longitude offset: accounts for latitude's effect on longitude distance
160
+ longitude_offset_deg = loc_accuracy / (111320 * cos(measure_lat * pi / 180))
161
+ )
162
+
163
+ globe_c
164
+ ```
165
+
166
+ ```{r site_ids with 10 observations or 1 observations}
167
+
168
+ # Assuming globe_c is your dataframe
169
+ site_id_counts <- globe_c %>%
170
+ group_by(site_id) %>%
171
+ summarise(count = n())
172
+
173
+ # Find site IDs with exactly 10 observations
174
+ site_ids_with_10_obs <- site_id_counts %>%
175
+ filter(count == 10)
176
+
177
+ # Find site IDs with exactly 1 observation
178
+ site_ids_with_1_obs <- site_id_counts %>%
179
+ filter(count == 1)
180
+
181
+ # Display results
182
+ site_ids_with_10_obs
183
+ site_ids_with_1_obs
184
+
185
+ ```
186
+
187
+ ```{r aggregating lat and long}
188
+ library(dplyr)
189
+
190
+ # Calculate the average of the latitude and longitude columns
191
+ globe_aggregated <- globe_c %>%
192
+ summarise(
193
+ avg_latitude = mean(latitude, na.rm = TRUE),
194
+ avg_longitude = mean(longitude, na.rm = TRUE),
195
+ avg_measure_lat = mean(measure_lat, na.rm = TRUE),
196
+ avg_measure_long = mean(measure_long, na.rm = TRUE)
197
+ )
198
+
199
+ # Display the results
200
+ globe_aggregated
201
+
202
+ ```
203
+
204
+ ```{r aggregating by degree blocks}
205
+ library(dplyr)
206
+
207
+ # Aggregate by degree blocks (round to the nearest whole number)
208
+ globe_block_aggregated <- globe_c %>%
209
+ mutate(
210
+ lat_block = floor(latitude), # Find the latitude degree block
211
+ long_block = floor(longitude), # Find the longitude degree block
212
+ measure_lat_block = floor(measure_lat), # Measured latitude block
213
+ measure_long_block = floor(measure_long) # Measured longitude block
214
+ ) %>%
215
+ group_by(lat_block, long_block) %>% # Group by the original lat/long blocks
216
+ summarise(
217
+ avg_latitude = mean(latitude, na.rm = TRUE),
218
+ avg_longitude = mean(longitude, na.rm = TRUE),
219
+ avg_measure_lat = mean(measure_lat, na.rm = TRUE),
220
+ avg_measure_long = mean(measure_long, na.rm = TRUE),
221
+ count = n() # Count of observations in each block
222
+ )
223
+
224
+ # Display the results
225
+ globe_block_aggregated
226
+
227
+
228
+ library(dplyr)
229
+
230
+ # Count unique latitude blocks and their frequencies
231
+ lat_block_counts <- globe_block_aggregated %>%
232
+ count(lat_block, name = "frequency_lat_block")
233
+
234
+ # Count unique longitude blocks and their frequencies
235
+ long_block_counts <- globe_block_aggregated %>%
236
+ count(long_block, name = "frequency_long_block")
237
+
238
+ # Display the total number of unique latitude and longitude blocks
239
+ num_lat_blocks <- n_distinct(globe_block_aggregated$lat_block)
240
+ num_long_blocks <- n_distinct(globe_block_aggregated$long_block)
241
+
242
+ print(paste("Total unique latitude blocks:", num_lat_blocks))
243
+ print(paste("Total unique longitude blocks:", num_long_blocks))
244
+
245
+ # Display the frequency tables for latitude and longitude blocks
246
+ lat_block_counts
247
+ long_block_counts
248
+
249
+ ```
250
+
251
+ ```{r adding season column}
252
+ library(dplyr)
253
+ library(lubridate)
254
+
255
+ # Add the season column based on the local_time
256
+ globe_c <- globe_c %>%
257
+ mutate(
258
+ # Extract the month and day for classification
259
+ month_day = format(local_time, "%m-%d"),
260
+
261
+ # Determine the season based on the local_time date
262
+ season = case_when(
263
+ month_day >= "03-20" & month_day <= "06-20" ~ "Spring",
264
+ month_day >= "06-21" & month_day <= "09-22" ~ "Summer",
265
+ month_day >= "09-23" & month_day <= "12-20" ~ "Fall",
266
+ TRUE ~ "Winter" # Remaining dates are considered Winter
267
+ )
268
+ )
269
+
270
+ # View the updated dataset with the season column
271
+ head(globe_c)
272
+
273
+ ```
274
+
275
+ ```{r day of year}
276
+ library(dplyr)
277
+ library(lubridate)
278
+
279
+ # Add a column that represents the day of the year
280
+ globe_c <- globe_c %>%
281
+ mutate(
282
+ day_of_year = yday(local_time) # yday() accounts for leap years
283
+ )
284
+
285
+ # View the updated dataset with the day_of_year column
286
+ head(globe_c)
287
+
288
+ ```
289
+
290
+ ```{r}
291
+ write_csv(globe_c, "globe_cv2.csv")
292
+ ```
293
+
294
+ ## Outlier Analyses
295
+
296
+ ```{r finding lat values that fall outside -90-90}
297
+ library(dplyr)
298
+
299
+ # Find rows where latitude or measured latitude falls outside the -90 to 90 range
300
+ invalid_latitudes <- globe_c %>%
301
+ filter(latitude < -90 | latitude > 90 | measure_lat < -90 | measure_lat > 90)
302
+
303
+ # Display the rows with invalid latitude values
304
+ invalid_latitudes
305
+
306
+ ```
307
+
308
+ ```{r outlier analysis for location}
309
+ library(dplyr)
310
+
311
+ # Function to identify outliers using the IQR method
312
+ find_outliers <- function(x) {
313
+ Q1 <- quantile(x, 0.25, na.rm = TRUE)
314
+ Q3 <- quantile(x, 0.75, na.rm = TRUE)
315
+ IQR_value <- IQR(x, na.rm = TRUE)
316
+ lower_bound <- Q1 - 1.5 * IQR_value
317
+ upper_bound <- Q3 + 1.5 * IQR_value
318
+ return(x < lower_bound | x > upper_bound)
319
+ }
320
+
321
+ # Apply outlier analysis to latitude and longitude columns
322
+ globe_c_outliers <- globe_c %>%
323
+ mutate(
324
+ lat_outlier = find_outliers(latitude),
325
+ long_outlier = find_outliers(longitude),
326
+ measure_lat_outlier = find_outliers(measure_lat),
327
+ measure_long_outlier = find_outliers(measure_long)
328
+ )
329
+
330
+ # Display rows where any of the latitude or longitude values are outliers
331
+ globe_c_outliers %>%
332
+ filter(lat_outlier | long_outlier | measure_lat_outlier | measure_long_outlier)
333
+
334
+ ```
335
+
336
+ ```{r}
337
+ library(dplyr)
338
+
339
+ # Function to identify outliers using the IQR method
340
+ find_date_outliers <- function(day_of_year) {
341
+ Q1 <- quantile(day_of_year, 0.25, na.rm = TRUE)
342
+ Q3 <- quantile(day_of_year, 0.75, na.rm = TRUE)
343
+ IQR_value <- IQR(day_of_year, na.rm = TRUE)
344
+ lower_bound <- Q1 - 1.5 * IQR_value
345
+ upper_bound <- Q3 + 1.5 * IQR_value
346
+ return(day_of_year < lower_bound | day_of_year > upper_bound)
347
+ }
348
+
349
+ # Apply the outlier analysis to the day_of_year column
350
+ globe_c <- globe_c %>%
351
+ mutate(
352
+ date_outlier = find_date_outliers(day_of_year)
353
+ )
354
+
355
+ # Display rows where the date is considered an outlier
356
+ date_outliers <- globe_c %>%
357
+ filter(date_outlier)
358
+
359
+ # View the date outliers
360
+ date_outliers
361
+
362
+ ```
363
+
364
+ ```{r}
365
+ library(dplyr)
366
+
367
+ # Calculate the IQR bounds for the loc_accuracy column
368
+ loc_accuracy_stats <- globe_c %>%
369
+ summarise(
370
+ Q1 = quantile(loc_accuracy, 0.25, na.rm = TRUE),
371
+ Q3 = quantile(loc_accuracy, 0.75, na.rm = TRUE),
372
+ IQR_value = IQR(loc_accuracy, na.rm = TRUE)
373
+ )
374
+
375
+ # Calculate the lower and upper bounds for outliers
376
+ lower_bound <- loc_accuracy_stats$Q1 - 1.5 * loc_accuracy_stats$IQR_value
377
+ upper_bound <- loc_accuracy_stats$Q3 + 1.5 * loc_accuracy_stats$IQR_value
378
+
379
+ # Identify outliers in the loc_accuracy column
380
+ globe_c <- globe_c %>%
381
+ mutate(
382
+ loc_accuracy_outlier = loc_accuracy < lower_bound | loc_accuracy > upper_bound
383
+ )
384
+
385
+ # Display rows where loc_accuracy is an outlier
386
+ loc_accuracy_outliers <- globe_c %>%
387
+ filter(loc_accuracy_outlier)
388
+
389
+ # View the outliers
390
+ loc_accuracy_outliers
391
+
392
+ ```
393
+
394
+ ## Graphs:
395
+
396
+ ```{r graphing lat and long}
397
+ library(ggplot2)
398
+
399
+ # Assuming 'globe_c' is your dataframe
400
+ ggplot(globe_c) +
401
+ # Plot measured latitude and longitude
402
+ geom_point(aes(x = measure_long, y = measure_lat), color = 'blue', alpha = 0.6, size = 2) +
403
+ # Plot latitude and longitude
404
+ geom_point(aes(x = longitude, y = latitude), color = 'red', alpha = 0.6, size = 2, shape = 4) +
405
+ labs(
406
+ title = 'Latitude and Longitude Scatter Plot',
407
+ x = 'Longitude',
408
+ y = 'Latitude'
409
+ ) +
410
+ theme_minimal() +
411
+ scale_color_manual(
412
+ name = 'Coordinates',
413
+ values = c('blue' = 'Measured Coordinates', 'red' = 'Original Coordinates')
414
+ ) +
415
+ theme(legend.position = 'top')
416
+
417
+ ```
418
+
419
+ ```{r distribution of time}
420
+ library(ggplot2)
421
+ library(lubridate)
422
+ library(dplyr)
423
+
424
+ # Extract hour, month, and year from local_time
425
+ globe_c <- globe_c %>%
426
+ mutate(
427
+ hour_of_day = hour(local_time),
428
+ month_of_year = month(local_time, label = TRUE, abbr = TRUE), # Label with month names
429
+ year = year(local_time)
430
+ )
431
+
432
+ # Plot 1: Distribution of Hour of the Day
433
+ plot_hour <- ggplot(globe_c, aes(x = hour_of_day)) +
434
+ geom_histogram(binwidth = 1, fill = 'blue', color = 'black', alpha = 0.7) +
435
+ labs(
436
+ title = 'Distribution of Time (Hour of Day)',
437
+ x = 'Hour of Day',
438
+ y = 'Frequency'
439
+ ) +
440
+ theme_minimal()
441
+
442
+ # Plot 2: Distribution of Month of the Year
443
+ plot_month <- ggplot(globe_c, aes(x = month_of_year)) +
444
+ geom_bar(fill = 'green', color = 'black', alpha = 0.7) +
445
+ labs(
446
+ title = 'Distribution of Time (Month of Year)',
447
+ x = 'Month of Year',
448
+ y = 'Frequency'
449
+ ) +
450
+ theme_minimal()
451
+
452
+ # Plot 3: Distribution of Years
453
+ plot_year <- ggplot(globe_c, aes(x = year)) +
454
+ geom_bar(fill = 'purple', color = 'black', alpha = 0.7) +
455
+ labs(
456
+ title = 'Distribution of Time (Years)',
457
+ x = 'Year',
458
+ y = 'Frequency'
459
+ ) +
460
+ theme_minimal()
461
+
462
+ # Display the plots
463
+ plot_hour
464
+ plot_month
465
+ plot_year
466
+
467
+ ```
468
+
469
+ ```{r location accuracy distribution with outliers}
470
+ library(ggplot2)
471
+
472
+ # Boxplot for location accuracy
473
+ ggplot(globe_c, aes(x = loc_accuracy)) +
474
+ geom_boxplot(fill = 'skyblue', color = 'black', outlier.colour = 'red', outlier.shape = 16, outlier.size = 2) +
475
+ labs(
476
+ title = 'Boxplot of Location Accuracy',
477
+ x = 'Location Accuracy (meters)'
478
+ ) +
479
+ theme_minimal()
480
+
481
+ ```
482
+
483
+ ```{r accuracy distribution without outliers}
484
+ library(ggplot2)
485
+ library(dplyr)
486
+
487
+ # Calculate the IQR bounds for loc_accuracy
488
+ loc_accuracy_stats <- globe_c %>%
489
+ summarise(
490
+ Q1 = quantile(loc_accuracy, 0.25, na.rm = TRUE),
491
+ Q3 = quantile(loc_accuracy, 0.75, na.rm = TRUE),
492
+ IQR_value = IQR(loc_accuracy, na.rm = TRUE)
493
+ )
494
+
495
+ # Calculate the lower and upper bounds for outliers
496
+ lower_bound <- loc_accuracy_stats$Q1 - 1.5 * loc_accuracy_stats$IQR_value
497
+ upper_bound <- loc_accuracy_stats$Q3 + 1.5 * loc_accuracy_stats$IQR_value
498
+
499
+ # Remove outliers from the data
500
+ globe_c_filtered <- globe_c %>%
501
+ filter(loc_accuracy >= lower_bound & loc_accuracy <= upper_bound)
502
+
503
+ # Plot the boxplot without outliers
504
+ ggplot(globe_c_filtered, aes(x = loc_accuracy)) +
505
+ geom_boxplot(fill = 'skyblue', color = 'black') +
506
+ labs(
507
+ title = 'Boxplot of Location Accuracy (Outliers Removed)',
508
+ x = 'Location Accuracy (meters)'
509
+ ) +
510
+ theme_minimal()
511
+
512
+ ```
513
+
514
+ # Notes:
515
+
516
+ check if measured at and measured on are equivalent
517
+
518
+ what is the date range where they are equal
519
+
520
+ measured at is reported from mobile device –\> reference to Greenwich mean time (could be 8 hours from when someone actually took it)
521
+
522
+ calculating local time could be useful
523
+
524
+ what to do with lat/long/elev
525
+
526
+ the only way to calculate local time is using lat/long at that date –\> ex. sun angle in Alaska in september vs december is different
527
+
528
+ remember: just because you can calculate it doesn't mean it has value
529
+
530
+ we should always have six digits in the lat/long measurement, even when rounded
531
+
532
+ time measurement should not go beyond seconds
533
+
534
+ we do have a bit of false accuracy –\> call people out on this in the future
535
+
536
+ each one of the decimal points in the lat/long measurement tells us more specifics of where we are on earth
537
+
538
+ measured lat and long actually come from the devices –\> start with these
539
+
540
+ they come from location services from a mobile device
541
+
542
+ we don't necessarily believe it until we find more info
543
+
544
+ if its an iphone, it will only get to 5 m within the coords bc of privacy reasons –\> androids go to 3m
545
+
546
+ location accuracy column: lat/long exist in degrees which are angular units, the accuracy field is in a distance measure (meters) so technically they don't really make sense but there are mathematical conversions are out there
547
+
548
+ for our purposes, we want to map the accuracy distribution –\> dont need to get rid of ones w a high value, we can interrogate them more –\> sort of like a measure of error
549
+
550
+ we can graph this, which is technically what a map is (lat = x and long = y)
551
+
552
+ get mins and maxs of lats and longs
553
+
554
+ nonmeasured lats and longs:
555
+
556
+ we have a global grid
557
+
558
+ we have cartesian coords that we put over places on the earth –\> origins have to be in diff places because the earth is not flat
559
+
560
+ the lat and long is in reference to that global grid –\> it is the south-west corner of the square
561
+
562
+ this is a way of grouping close things together
563
+
564
+ site-id : things are grouped together based on location and time
565
+
566
+ we are interested in location over time
567
+
568
+ find a count of which ones have 10 obs for that location? which ones have only 1? 1 isnt really as useful to us, but that's where most of it will be
569
+
570
+ at what level do we wanna agregate? essentially we wanna go back to the whole number (whats within the 45/46 degree lat range and the 129-130 long range) –\> this is called a degree block
571
+
572
+ look for lat measurements that fall outside -90 to 90 range –\> 0 is equator
573
+
574
+ if we average that range of values, are we getting participants north or south of the equator?
575
+
576
+ for the photos: what is the megabite size vs the image resolution? calculate this and plot it along a timeline
577
+
578
+ examine size more
579
+
580
+ order by lat/long
581
+
582
+ think about collaging these images into one image first –\> this emphasizes them
583
+
584
+ can use small.jpg 255 x 255
585
+
586
+ thumb.jpg is 64 x 64 –\> mosaic them into a 255 or 148 and then send that into a classifier
587
+
588
+ get distribution of time
589
+
590
+ grouping together based on seasons
591
+
592
+ calculate day of year: what day of year ? –\> ex. what day of the year is december 3rd of some year? like out of 365/366? what is the frequency of when we're getting our observations
globe_c.csv CHANGED
The diff for this file is too large to render. See raw diff
 
globe_cv2.csv ADDED
The diff for this file is too large to render. See raw diff
 
image_collage.Rmd ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: "image_collage"
3
+ output: html_document
4
+ date: "2024-10-03"
5
+ ---
6
+
7
+ ```{r setup, include=FALSE}
8
+ knitr::opts_chunk$set(echo = TRUE)
9
+ ```
10
+
11
+ ```{r importing data and packages}
12
+ library(tidyverse)
13
+ library(dplyr)
14
+
15
+ globe_c <- read_csv("./globe_cv2.csv")
16
+ ```
17
+
18
+ ```{r}
19
+
20
+ # Define the URL columns in your dataframe
21
+ urls <- c("north_photo_url", "east_photo_url", "south_photo_url",
22
+ "west_photo_url", "upward_photo_url", "downward_photo_url")
23
+
24
+
25
+ # Remove rows where any URL column contains the word "rejected"
26
+ globe_c <- globe_c[!apply(globe_c[urls], 1, function(row) any(grepl("rejected", row, ignore.case = TRUE))), ]
27
+
28
+ # Ensure URL columns are characters and trimmed
29
+ globe_c[urls] <- lapply(globe_c[urls], as.character)
30
+ globe_c[urls] <- lapply(globe_c[urls], trimws)
31
+
32
+ get_image_info <- function(url) {
33
+ # Ensure URL is not empty or malformed
34
+ if (is.na(url) || url == "" || !grepl("^https?://", url)) {
35
+ print(paste("Skipping invalid URL:", url))
36
+ return(NULL)
37
+ }
38
+
39
+ tryCatch({
40
+ print(paste("Processing URL:", url)) # Debugging statement
41
+ response <- GET(url)
42
+
43
+ # Check if the response status is successful
44
+ if (status_code(response) == 200) {
45
+ img <- image_read(content(response, "raw"))
46
+ size_mb <- length(content(response, "raw")) / (1024 * 1024)
47
+ info <- image_info(img)
48
+ width <- info$width
49
+ height <- info$height
50
+ return(data.frame(url = url, size_mb = size_mb, width = width, height = height))
51
+ } else {
52
+ print(paste("Failed to fetch image. Status code:", status_code(response))) # Debugging statement
53
+ return(NULL)
54
+ }
55
+ }, error = function(e) {
56
+ print(paste("Error processing URL:", url, "Error:", e)) # Debugging statement
57
+ return(NULL)
58
+ })
59
+ }
60
+
61
+ ```
62
+
63
+ ```{r}
64
+ library(httr)
65
+ library(magick)
66
+
67
+ # Function to apply get_image_info to each URL column in a row
68
+ process_row <- function(row) {
69
+ result_list <- lapply(row[urls], get_image_info)
70
+ result_df <- do.call(rbind, result_list)
71
+ return(result_df)
72
+ }
73
+
74
+ # Apply to a subset of rows in the dataframe (using the first 500 rows as an example)
75
+ image_info_list <- lapply(1:500, function(i) process_row(globe_c[i, ]))
76
+
77
+ # Remove NULL elements from the list
78
+ image_info_list <- Filter(Negate(is.null), image_info_list)
79
+
80
+ # Combine into a single dataframe
81
+ image_info_df <- do.call(rbind, image_info_list)
82
+
83
+ ```
84
+
85
+ ```{r}
86
+ # Check the resulting dataframe
87
+ print(image_info_df)
88
+
89
+ ```
90
+
91
+ ```{r}
92
+ library(ggplot2)
93
+
94
+ ggplot(image_info_df, aes(x = width * height, y = size_mb)) +
95
+ geom_point() +
96
+ labs(x = "Resolution (width x height)", y = "Size (MB)", title = "Image Size vs. Resolution")
97
+
98
+ ```
99
+
100
+ ```{r}
101
+ library(magick)
102
+
103
+ # Gather URLs from image_info_df (use all rows)
104
+ urls_to_process <- image_info_df$url
105
+
106
+ # Function to download and resize image
107
+ download_and_resize <- function(url, size = "255x255") {
108
+ tryCatch({
109
+ img <- image_read(url)
110
+ img_resized <- image_resize(img, size)
111
+ return(img_resized)
112
+ }, error = function(e) {
113
+ print(paste("Error processing URL:", url, "Error:", e))
114
+ return(NULL)
115
+ })
116
+ }
117
+
118
+ # Download and resize images to 255x255
119
+ images_resized <- lapply(urls_to_process, download_and_resize, size = "255x255")
120
+ images_resized <- Filter(Negate(is.null), images_resized) # Remove any NULLs from failed downloads
121
+
122
+ # Print the number of successfully processed images
123
+ print(paste("Number of successfully processed images:", length(images_resized)))
124
+
125
+ # Create a collage without borders
126
+ if (length(images_resized) > 0) {
127
+ # Ensure images are arranged in rows for the collage
128
+ rows <- split(images_resized, ceiling(seq_along(images_resized) / 10)) # Adjust to set the number of images per row
129
+
130
+ # Create a montage row by row, then stack them vertically
131
+ collage_rows <- lapply(rows, function(row) image_append(do.call(c, row), stack = FALSE))
132
+ collage_255 <- image_append(do.call(c, collage_rows), stack = TRUE)
133
+
134
+ # Save the final collage
135
+ image_write(collage_255, path = "collage_255_no_border.jpg", format = "jpg")
136
+ }
137
+
138
+ ```
139
+
140
+ ```{r}
141
+ library(magick)
142
+
143
+ # Gather URLs from image_info_df (use all rows)
144
+ urls_to_process <- image_info_df$url
145
+
146
+ # Function to download and resize image
147
+ download_and_resize <- function(url, size = "64x64") {
148
+ tryCatch({
149
+ img <- image_read(url)
150
+ img_resized <- image_resize(img, size)
151
+ return(img_resized)
152
+ }, error = function(e) {
153
+ print(paste("Error processing URL:", url, "Error:", e))
154
+ return(NULL)
155
+ })
156
+ }
157
+
158
+ # Download and resize images to 64x64
159
+ images_thumbnails <- lapply(urls_to_process, download_and_resize, size = "64x64")
160
+ images_thumbnails <- Filter(Negate(is.null), images_thumbnails) # Remove any NULLs from failed downloads
161
+
162
+ # Print the number of successfully processed thumbnail images
163
+ print(paste("Number of successfully processed thumbnail images:", length(images_thumbnails)))
164
+
165
+ # Create a collage without borders using thumbnails
166
+ if (length(images_thumbnails) > 0) {
167
+ # Ensure images are arranged in rows for the collage
168
+ rows <- split(images_thumbnails, ceiling(seq_along(images_thumbnails) / 20)) # Adjust to set the number of images per row
169
+
170
+ # Create a montage row by row, then stack them vertically
171
+ collage_rows <- lapply(rows, function(row) image_append(do.call(c, row), stack = FALSE))
172
+ collage_thumbnails <- image_append(do.call(c, collage_rows), stack = TRUE)
173
+
174
+ # Save the final thumbnail collage
175
+ image_write(collage_thumbnails, path = "collage_thumbnails_no_border.jpg", format = "jpg")
176
+ }
177
+
178
+ ```
179
+
180
+ # Notes
181
+
182
+ for the photos: what is the megabite size vs the image resolution? calculate this and plot it along a timeline
183
+
184
+ examine size more
185
+
186
+ order by lat/long
187
+
188
+ think about collaging these images into one image first –\> this emphasizes them
189
+
190
+ can use small.jpg 255 x 255
191
+
192
+ thumb.jpg is 64 x 64 –\> mosaic them into a 255 or 148 and then send that into a classifier