library(tidyverse)
# unzip("data/FM_service_contour_current.zip")
Source of data: https://www.fcc.gov/media/radio/fm-service-contour-data-points
this contour data is only generated once for each application ID number use https://www.fcc.gov/media/radio/fm-query to associate specific service contour records with the proper station or application data, match the application ID number or LMS application ID the record with the corresponding data in the LMS database.
<- read_delim(
raw_contour "data/FM_service_contour_current.txt",
delim = "|"
)# save(raw_contour,file="data/raw_contour.RData")
# load("data/raw_contour.RData")
%>%names
raw_contour# [1] "application_id" "service"
# [3] "lms_application_id" "dts_site_number"
# [5] "transmitter_site"
<- raw_contour |>
conv_contour select(-last_col()) |>
set_names(nm = c(
"application_id", "service", "lms_application_id", "dts_site_number", "transmitter_site",
::glue("deg_{0:360}")
glue
))
# save(conv_contour,file= "data/conv_contour.RData")
<- conv_contour |>
lng_lat separate(
transmitter_site, into = c("site_lat", "site_long"),
sep = " ,")
# save(lng_lat,file= "data/lng_lat.RData")
load("data/lng_lat.RData")
%>%count(site_lat,site_long,sort=T) lng_lat
<- lng_lat%>%
df_coords select(-dts_site_number) %>%
distinct() %>%
drop_na() %>%
mutate_all(trimws)%>%
mutate(application_id=as.numeric(application_id),
site_lat=as.numeric(site_lat),
site_long=as.numeric(site_long))
%>%count(service) df_coords
<- df_coords %>%
df_coords1 as.data.frame() %>%
#slice(1:30) %>%
arrange(service) %>%
filter(service=="FM")
%>%head() df_coords1
library(sf) # spatiotemporal
<- sf::st_as_sf(maps::map("world", plot = FALSE, fill = TRUE))
world <- sf::st_as_sf(maps::map("state", plot = FALSE, fill = TRUE))
states states
%>%
df_coords1 st_as_sf(coords=c(4,3),crs=4326)%>%
st_bbox()
ggplot(world) +
geom_sf(fill=NA) +
geom_point(data = df_coords1,
mapping = aes(site_long,site_lat),
shape=".",color="red",
inherit.aes = F) +
coord_sf(xlim = c(-171.73031,-25),ylim = c(10,71.29194))+
theme_classic() +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank())
<- lng_lat%>%
df_coords select(-dts_site_number) %>%
distinct() %>%
drop_na() %>%
mutate_all(trimws)%>%
mutate(application_id=as.numeric(application_id),
site_lat=as.numeric(site_lat),
site_long=as.numeric(site_long))
%>% count(service)
df_coords
<- df_coords %>%
df_coords1 as.data.frame() %>%
#slice(1:30) %>%
arrange(service) %>%
filter(service=="FM")
<- df_coords1 %>%
df_coords2 pivot_longer(cols = deg_0:deg_360,
names_to = "angle",
values_to = "values")
<- df_coords2 %>%
df_coords3 mutate(angle = str_remove(angle, "deg_"),
angle = as.integer(angle))
# lms_application_id
361,]
df_coords3[%>%
df_coords3filter(angle==360)%>%head
<- df_coords3 %>%
df_coords4 separate(values,
into = c("deg_lat", "deg_lng"),
sep = " ,")
<- df_coords4 %>%
df_coords5 mutate(deg_lat= ifelse(is.na(deg_lng),site_lat,deg_lat),
deg_lng= ifelse(is.na(deg_lng),site_long,deg_lng))
# save(df_coords5,file="rdata/df_coords5.RData")
%>%
df_coords5::profile_missing() DataExplorer
%>%dim # 4550766
df_coords5%>%head df_coords5
%>%count(application_id) df_coords5
<- df_coords5%>%
df_coords_750_2037197 filter(application_id%in%c(750,2037197)) # dim # 361
%>%count(application_id)
df_coords_750_2037197%>%
df_coords_750_2037197filter(application_id==750)
st_bbox(world)
ggplot() +
#geom_sf(fill=NA) +
geom_point(data = df_coords_750_2037197,
mapping = aes(deg_lng,deg_lat),
#shape=".",
color="red",
inherit.aes = F)
coord_sf(xlim = c(-180.00000,190.27084),ylim = c(-85.19218,83.59961))+
#coord_sf(xlim = c(-171.73031,-25),ylim = c(10,71.29194))+
theme_classic()
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank())
<- df_coords5%>%
df_coords_selected_id arrange(application_id) %>%
count(application_id) %>%
slice(1:10) %>%
select(-n) %>%
unlist()
<- df_coords5 %>%
df_coords5_selection filter(application_id%in%df_coords_selected_id) %>%
distinct() # dim # 361
%>%dim
df_coords5%>%names
df_coords5_selection
<- df_coords5_selection%>%
df_coords5_selection_sfst_as_sf(coords=c(8,7),crs=4326)
<- df_coords5%>%
df_coords51 st_as_sf(coords=c(8,7),crs=4326)
ggplot(world) +
geom_sf(fill=NA) +
geom_sf(data = df_coords51,
aes(color=application_id),
shape=21,stroke=0.01,
#shape=".",
alpha=0.2,
inherit.aes = F) +
coord_sf(xlim = c(-171.73031,-25),ylim = c(10,71.29194))+
theme_classic() +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank())
%>%count(application_id) df_coords5
<- df_coords5 %>%
df_coords5_all_sf st_as_sf(coords=c(7,6),crs=4326)
ggplot(world) +
geom_sf(fill=NA) +
geom_sf(data = df_coords5_all_sf,
#aes(color=application_id),
shape=21,stroke=0.01,
#shape=".",
alpha=0.2,
inherit.aes = F) +
coord_sf(xlim = c(-171.73031,-25),ylim = c(10,71.29194))+
theme_classic() +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank())
map
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-11-08/state_stations.csv') state_stations
%>%names state_stations
<- state_stations%>%
state_stations1 select(call_sign,frequency,state,city,format)
%>%head state_stations1
%>%DataExplorer::profile_missing() state_stations
%>%dim state_stations
<- tidytuesdayR::tt_load(2022, week = 45)
tuesdata <- tuesdata$station_info
station_info
%>%dim
station_info%>%DataExplorer::profile_missing() station_info
%>%count(service) station_info
<- station_info%>%
station_info1 select(call_sign,facility_id)
%>%head station_info1
%>%DataExplorer::profile_missing() station_info1
<- df_coords1 %>%
df_coords2 mutate(application_id=as.numeric(application_id))# 12604
%>% distinct() %>%dim # 2065
station_info1
<- state_stations1 %>% # 17186
join inner_join(station_info1,by="call_sign")
%>% # 17186
state_stations1 inner_join(station_info1,by="call_sign") %>% head # left 17186 # right 2065 # inner 2037 # full 17214
right_join(df_coords5,by=c("facility_id"="application_id")) %>%DataExplorer::profile_missing()
%>%distinct()%>%dim # 4551127
df_coords5%>%distinct()%>%dim # 2037
join setdiff(df_coords5$application_id,join$facility_id) %>%length() # 12551
setdiff(join$facility_id,df_coords5$application_id) %>%length() # 2049 # 2021
<-join %>%
full_joininner_join(df_coords5,by=c("facility_id"="application_id"))
%>% # dim # 5776
full_joinrelocate(call_sign,facility_id,lms_application_id)%>%
distinct()%>%dim # 5776
# DataExplorer::profile_missing()
%>%head full_join
%>%names full_join
%>%head full_join
<- full_join%>%
full_join1mutate(format=str_to_title(format)) # %>%
#filter(format=="Alternative Rock")
# count(format,sort=T)
%>%dim full_join1
%>%
full_join1group_by(state) %>%
mutate()
<- full_join1 %>%
full_join_sf st_as_sf(coords=c(13,12),crs=4326)
<- full_join1 %>%
full_join_sf_centr group_by(city,format)%>%
summarize(site_lat=mean(range(site_lat)),site_long=mean(range(site_long)),.groups="drop")%>%
ungroup() %>%
st_as_sf(coords=c(4,3),crs=4326)
ggplot(world) +
geom_sf(fill=NA) +
geom_sf_text(data = full_join_sf_centr,
aes(label=format),
#label.padding = unit(0.01, "lines"),
size=2,
inherit.aes = F) +
geom_sf(data = full_join_sf,
aes(color=factor(format)),
shape=21,stroke=0.01,
#shape=".",
alpha=0.2,
inherit.aes = F) +
coord_sf(xlim = c(-171.73031,-25),ylim = c(10,71.29194))+
theme_classic() +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank())
ggsave("test.png")