File:January Temperature Middle East 1.png

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file (2,031 × 1,973 pixels, file size: 2.62 MB, MIME type: image/png)

Captions

Captions

January Temperature of Middle East

Summary

[edit]
Description
English: January Temperature of Middle East
Date
Source Own work
Author Merikanto

This plotting is based on WorldClim 2.1

https://www.worldclim.org/data/worldclim21.html Fick, S.E. and R.J. Hijmans, 2017. WorldClim 2: new 1km spatial resolution climate surfaces for global land areas. International Journal of Climatology 37 (12): 4302-4315.

"R" source code. mus copr output file

  1. Asenna tarvittavat paketit vain, jos install_packages_yes on TRUE

install_packages_yes <- FALSE

if (install_packages_yes) {

 install.packages("terra")
 install.packages("ggplot2")
 install.packages("sf")
 install.packages("rnaturalearth")
 install.packages("rnaturalearthdata")
 install.packages("rayshader")
 install.packages("viridis")
 install.packages("ggtext")
 install.packages("metR")

}

  1. Lataa tarvittavat kirjastot

library(terra) library(ggplot2) library(sf) library(rnaturalearth) library(rnaturalearthdata) library(viridis) library(ggtext) library(metR) library(rayshader)

  1. Lataa ja prosessoi WorldClim-data
  2. Define the WorldClim data URL for the desired resolution (10 minutes)

url <- "https://geodata.ucdavis.edu/climate/worldclim/2_1/base/wc2.1_10m_tavg.zip"

  1. Define the local file path

temp_file <- tempfile(fileext = ".zip")

  1. Download the file

download.file(url, temp_file, mode = "wb")

  1. Unzip the file

temp_dir <- tempdir() unzip(temp_file, exdir = temp_dir)

  1. List the files in the unzipped directory

files <- list.files(temp_dir, pattern = "\\.tif$", full.names = TRUE)

  1. Load the raster files as a SpatRaster object

worldclim_raster <- rast(files)

  1. Define the extent for the Middle East region (approximate coordinates)

extent_me <- ext(30, 55, 25, 45)

  1. Lataa Lähi-idän rajaus

bbox <- ext(30, 55, 25, 45)

  1. Select January and July layers

jan_raster <- rast(file.path(temp_dir, "wc2.1_10m_tavg_01.tif")) jul_raster <- rast(file.path(temp_dir, "wc2.1_10m_tavg_07.tif"))

  1. Crop the layers to the Middle East region

jan_me_raster <- crop(jan_raster, extent_me) jul_me_raster <- crop(jul_raster, extent_me)

  1. Convert to data frames for ggplot2

jan_df <- as.data.frame(jan_me_raster, xy = TRUE) jul_df <- as.data.frame(jul_me_raster, xy = TRUE)

  1. Varmista, että sarakkeen nimi on 'layer'

names(jan_df)[3] <- "layer" names(jul_df)[3] <- "layer"

  1. Lataa DEM-data ja prosessoi se

dem_url <- "https://geodata.ucdavis.edu/climate/worldclim/2_1/base/wc2.1_10m_elev.zip" dem_temp_file <- tempfile(fileext = ".zip") download.file(dem_url, dem_temp_file, mode = "wb") unzip(dem_temp_file, exdir = temp_dir) dem_raster <- rast(file.path(temp_dir, "wc2.1_10m_elev.tif"))

  1. Crop the DEM layer to the Middle East region

dem_me_raster <- crop(dem_raster, extent_me)

  1. Convert DEM to a data frame for ggplot2

dem_df <- as.data.frame(dem_me_raster, xy = TRUE)

  1. Varmista, että DEM-sarakkeen nimi on 'layer'

names(dem_df)[3] <- "layer"

  1. Lataa luonnonmaan tiedot
  2. Load natural earth data for countries, rivers, and lakes
  3. world <- ne_countries(scale = "medium", returnclass = "sf")

rivers <- ne_download(scale = "medium", type = "rivers_lake_centerlines", category = "physical", returnclass = "sf") lakes <- ne_download(scale = "medium", type = "lakes", category = "physical", returnclass = "sf") coastlines <- ne_download(scale = "medium", type = "coastline", category = "physical", returnclass = "sf")

rivers_vect <- vect(rivers) middle_east_rivers <- crop(rivers_vect, bbox)

lakes_vect <- vect(lakes) middle_east_lakes <- crop(lakes_vect, bbox)

coastlines_vect <- vect(coastlines) middle_east_coastlines <- crop(coastlines_vect, bbox)

  1. ocean <- ne_download(scale = "medium", type = "ocean", category = "physical", returnclass = "sf")
  1. Define a base plot function with contours, transparency, and DEM overlay

base_plot <- function(data, title) {

 ggplot() +
  #geom_raster(data = dem_df, aes(x = x, y = y, fill = layer), alpha = 0.3) +
   scale_fill_gradient(low = "white", high = "black", name = "Elevation", guide = "none") +
   geom_raster(data = data, aes(x = x, y = y, fill = layer), alpha = 1.0, interpolate = TRUE) +
   #geom_raster(data = dem_df, aes(x = x, y = y, fill = layer), alpha = 0.1) +
   geom_contour(data = data, aes(x = x, y = y, z = layer), color = "#5f0000", linewidth=0.5, alpha=0.5, breaks = seq(-20, 50, by = 5)) +
  1. metR::geom_text_contour(aes(z = layer, label = after_stat(level))) +
   geom_text_contour(data = data, aes(x = x, y = y, z = layer), breaks = seq(-50, 50, by = 5), check_overlap = TRUE) +
   scale_fill_viridis(option = "turbo", name = "Temp (°C)") +
   #geom_sf(data = middle_east_world, fill = NA, color = "black") +
   #geom_sf(data = middle_east_rivers, color = "blue") +
   #geom_sf(data = middle_east_lakes, fill = "blue", color = "blue") +
   #geom_sf(data = middle_east_coastlines, fill = "blue", color = "blue") +
   geom_sf(data = rivers, color = "blue", alpha=0.5) +
   geom_sf(data = lakes, fill = "blue", color = "blue", alpha=0.5) +
   geom_sf(data = coastlines, fill = "blue", color = "blue", alpha=0.5) + 
  #geom_sf(data = ocean, fill = "blue", color = "blue") +
   coord_sf(xlim = c(30, 55), ylim = c(25, 45)) +
   theme_minimal() +
   labs(title = title, x = "Longitude", y = "Latitude")

}

  1. print("TEOUK")
  2. stop(-1)
  1. Plot January temperature

p1 <- base_plot(jan_df, "Average Temperature in January of Middle East ")

  1. Plot July temperature

p2 <- base_plot(jul_df, "Average Temperature in July of Middle East ")

  1. Print the plots

print(p1) print(p2)

  1. Tallenna kuvat PNG-tiedostoina

ggsave("January_Temperature_Middle_East.png", plot = p1, width = 10, height = 8, bg="white", dpi = 300) ggsave("July_Temperature_Middle_East.png", plot = p2, width = 10, height = 8, bg="white", dpi = 300)

Licensing

[edit]
I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution
This file is licensed under the Creative Commons Attribution 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current08:39, 21 July 2024Thumbnail for version as of 08:39, 21 July 20242,031 × 1,973 (2.62 MB)Merikanto (talk | contribs)Uploaded own work with UploadWizard

There are no pages that use this file.