# define projections
longlat_crs <- "+proj=longlat +datum=WGS84 +no_defs"
#ortho_crs <-'+proj=ortho +lat_0=32.4279 +lon_0=53.688 +x_0=0 +y_0=0 +R=6371000 +units=m +no_defs +type=crs'
ortho_crs <-'+proj=ortho +lat_0=25.54 +lon_0=-103.44 +x_0=0 +y_0=0 +R=6371000 +units=m +no_defs +type=crs'
#Torreón -103.44 25.54
Poligono para hacer el crop
#a<-gisco_get_countries()
#a<-gisco_get_lau(year = "2016",epsg = "4326",cache = TRUE,update_cache = FALSE,cache_dir = NULL,verbose = FALSE,country = NULL,gisco_id = NULL)
#b<-subset(a,(a$CNTR_CODE %in% c("FR")))
#C<-as.data.frame(unique(a$CNTR_CODE))
paises<-c("MEX","CHL","BOL","BRA","COL","CAN","NIC","GRL")
#paises<-c("MEX")
get_flat_world_sf <- function() {
world <- giscoR::gisco_get_countries(
year = "2016",
epsg = "4326",
resolution = "60",
country=paises
) %>%
sf::st_transform(longlat_crs)
world_vect <- terra::vect(world)
return(world_vect)
}
world_vect <- get_flat_world_sf()
plot(world_vect)
names(world_vect)
## [1] "ISO3_CODE" "CNTR_NAME" "CNTR_ID" "NAME_ENGL" "FID"
library(swatches)
colpal<-read_palette("modis_lst.aco", use_names = TRUE, .verbose = FALSE)
aa<-data.frame(colpal)
colpal[1]<-"#FFFFFF"
#————- #https://neo.gsfc.nasa.gov/view.php?datasetId=MOD_LSTD_M&date=2022-11-01
#get_nasa_data <- function() {
#ras <- terra::rast("/vsicurl/https://eoimages.gsfc.nasa.gov/images/imagerecords/144000/144898/BlackMarble_2016_01deg_geo.tif")
ras <- terra::rast("MOD_LSTD_M_2022-11-01_rgb_3600x1800.TIFF")
names(ras)="calor"
plot(ras)
r <- ifel(is.na(ras),1, ras)
rascrop <- terra::crop(x = r, y = world_vect, mask=TRUE)
plot(rascrop)
#——————- https://neo.gsfc.nasa.gov/view.php?datasetId=MOD_LSTD_M&date=2022-11-01
#https://www.cyotek.com/downloads/info/setup-cyopaled-1.7.0.411.exe ### cambio de paletas aco, act... photoshop
#https://www.youtube.com/watch?v=NQZNpyEgVss
#https://dieghernan.github.io/202210_tidyterra-hillshade/
#https://eospso.nasa.gov/sites/default/files/atbd/atbd_mod11.pdf
#> install.packages("swatches")
#make_nighlights_globe <- function() {
base_text_size <- 15
tinf<--35
tsup<-55
colormax<-255
colormin<-1
#(calor+(tinf*(colormax-colormin)/(tsup-tinf)))/((colormax-colormin)/(tsup-tinf))
rascrop$escat<-(rascrop$calor+(tinf*(colormax-colormin)/(tsup-
tinf)))/((colormax-colormin)/(tsup-tinf))
colpal[257]<-"#000000"
library(ggnewscale)
crsLAEA <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +datum=WGS84 +units=m +no_defs"
plotg<-ggplot() +
geom_spatraster(data = rascrop$escat,maxcell =Inf+Inf,
alpha = 1) +
scale_fill_gradientn(name="ºC", colours =colpal,na.value = "black",
labels = scales::label_number(suffix = "º"))+
ggnewscale::new_scale_color() +
geom_spatvector(data=world_vect,fill=NA,color="#D1E1F1") +
theme_minimal() +
theme(
plot.background = element_rect("grey97", colour = NA),
plot.margin = margin(20, 20, 20, 20),
plot.caption = element_text(size = base_text_size * 0.5),
plot.title = element_text(face = "bold", size = base_text_size * 1.3),
plot.subtitle = element_text(
margin = margin(b = 10),
size = base_text_size
),
axis.text = element_text(size = base_text_size * 0.7),
legend.position = "bottom",
legend.title = element_text(size = base_text_size * 0.8),
legend.text = element_text(size = base_text_size * 0.8),
legend.key = element_rect("grey50"),
legend.spacing.x = unit(0, "pt")
)+
labs(
title = "Temperatura de la tierra recuperada durante el dÃa en Noviembre 2022",
subtitle = "en México, Chile, Bolivia, Brasil, Colombia, Canada,Nicaragua y Groelandia",
caption = paste0("Amarillo las más calientes(arriba de 45°C) azul lo más frÃo (abajo de -25°C).Negro sin datos","@guerreroclaudia"))+
coord_sf(crs =longlat_crs)
plotg
ggsave(
filename = "landtemperature.png",
width =900, height =900, units = "mm", bg="black",dpi = 600,limitsize = FALSE, device = "png", plotg
)