Skip to content

Destination Weather and Sunshine #1082

Open

Description

@jonthegeek

Part of the same project that produced the castle maps in #1059.

  • This dataset has not already been used in TidyTuesday.

  • The dataset will (probably) be less than 20MB when saved as a tidy CSV.

  • I can imagine a data visualization related to this dataset.

  • title: Destination Weather and Sunshine

  • article: An example of the dataset being used, such as a blog post or a README about the dataset.

  • data_source: A source where the dataset can be downloaded.

  • images: One or more images related to the dataset. For each image, provide:

    • file: A url to download the image, or an attached file.
    • alt: Text that can serve as a replacement for the image for those who cannot see the image (whether through visual impairment or because the image does not load).
  • cleaning_script: A script to fetch and clean the data, resulting in one or more data.frames (or equivalent structures) that can be saved as CSVs.

# ADD SCRIPT HERE
  • data_dictionary: A description of each column in the dataset, including the column name, the data type of the column, and a description of the column.
variable class description
VARIABLE CLASS DESCRIPTION

Activity

  1. added
    data: has article
    data: has data link
    data: needs compilation
    data: needs data dictionary
    data: usable provenance
    data: no images
    data: no image alt text
    data: datavizable
    data: not commercial
    on Sep 28, 2026
  2. CyberNativeAI commented on Nov 24, 2026

    @CyberNativeAI

    Here are the cleaning_script and data_dictionary fields for this dataset. The data link above now redirects to https://sunshineatlas.com/data/, so the script reads the two CSVs from there.

    Run with R 4.6.1, readr 2.2.0 and dplyr 1.2.1, this script produced the same two tables as our earlier Python version of the transform (all cells compared).

    cleaning_script

    # Sunshine Atlas data and attribution: https://sunshineatlas.com/data/#license
    # CC BY 4.0: https://creativecommons.org/licenses/by/4.0/
    # Changes: omit provider-marked secondary airports and repeated wide scores,
    # join primary airport labels, and encode months as integers 1–12.
    # Some cities still have multiple primary airports. Group them by hand for city counts.
    
    sunshine_source <- getOption("sunshine_atlas.source", c(
      destinations = "https://sunshineatlas.com/data/sunshine-atlas-destinations.csv",
      monthly = "https://sunshineatlas.com/data/sunshine-atlas-monthly-climate.csv"
    ))
    
    location_fields <- c("iata", "city", "country_code")
    destination_fields <- c(
      location_fields, "country", "continent", "lat", "lon", "elevation_m",
      "population", "annual_sunshine_hours", "annual_rainfall_mm",
      "peak_midday_uv_index", "climate", "destination_type", "best_month",
      "sunshine_score_year", "koppen_class", "climate_group", "sunniest_month"
    )
    measurement_fields <- c(
      "sunshine_score", "day_high_c", "night_low_c", "rain_mm",
      "midday_uv_index", "sea_temp_c", "sunshine_hours"
    )
    monthly_fields <- c(location_fields, "month", measurement_fields)
    score_fields <- paste0("sunshine_score_", tolower(month.abb))
    
    destination_types <- readr::cols(
      .default = readr::col_character(),
      lat = readr::col_double(), lon = readr::col_double(),
      elevation_m = readr::col_double(), population = readr::col_integer(),
      annual_sunshine_hours = readr::col_double(), annual_rainfall_mm = readr::col_double(),
      peak_midday_uv_index = readr::col_double(), sunshine_score_year = readr::col_double()
    )
    destination_types$cols[score_fields] <- rep(list(readr::col_double()), length(score_fields))
    monthly_types <- readr::cols(
      .default = readr::col_double(),
      iata = readr::col_character(), city = readr::col_character(),
      country_code = readr::col_character(), month = readr::col_character()
    )
    
    read_sunshine <- function(path, fields, types) {
      rows <- readr::read_csv(
        path, col_types = types, na = "", trim_ws = FALSE,
        name_repair = "check_unique", show_col_types = FALSE
      )
      if (!setequal(names(rows), fields)) stop("Unexpected Sunshine Atlas columns in ", path)
      readr::stop_for_problems(rows)
      numeric_fields <- vapply(rows, is.numeric, logical(1))
      nonfinite <- vapply(rows[numeric_fields], function(x) any(is.infinite(x) | is.nan(x)), logical(1))
      if (any(nonfinite)) stop("Non-finite Sunshine Atlas measurement in ", path)
      rows
    }
    
    destinations <- read_sunshine(
      sunshine_source[["destinations"]],
      c(destination_fields, "duplicate_of_iata", score_fields), destination_types
    )
    monthly <- read_sunshine(sunshine_source[["monthly"]], monthly_fields, monthly_types)
    
    # Check airport identity and the monthly join before dropping secondary rows.
    primary <- is.na(destinations$duplicate_of_iata)
    parent_row <- match(destinations$duplicate_of_iata[!primary], destinations$iata)
    airport_row <- match(monthly$iata, destinations$iata)
    month_number <- match(monthly$month, month.abb)
    stopifnot(
      nrow(destinations) > 0L,
      all(grepl("^[A-Z]{3}$", destinations$iata)), !anyDuplicated(destinations$iata),
      all(!is.na(destinations$city) & nzchar(trimws(destinations$city))),
      all(!is.na(destinations$country_code) & nzchar(trimws(destinations$country_code))),
      all(destinations$best_month %in% month.name),
      all(destinations$sunniest_month %in% month.name),
      !anyNA(parent_row), all(primary[parent_row]),
      all(destinations$city[!primary] == destinations$city[parent_row]),
      all(destinations$country_code[!primary] == destinations$country_code[parent_row]),
      !anyNA(airport_row), !anyNA(month_number),
      !anyDuplicated(monthly[c("iata", "month")]),
      all(tabulate(airport_row, nbins = nrow(destinations)) == 12L),
      all(monthly$city == destinations$city[airport_row]),
      all(monthly$country_code == destinations$country_code[airport_row])
    )
    wide_score <- as.matrix(destinations[score_fields])[cbind(airport_row, month_number)]
    stopifnot(identical(is.na(wide_score), is.na(monthly$sunshine_score)))
    stopifnot(all(wide_score[!is.na(wide_score)] == monthly$sunshine_score[!is.na(wide_score)]))
    
    primary_destinations <- destinations |>
      dplyr::filter(is.na(duplicate_of_iata)) |>
      dplyr::select(dplyr::all_of(destination_fields)) |>
      dplyr::arrange(iata, .locale = "C")
    
    primary_monthly_climate <- monthly |>
      dplyr::mutate(month = month_number) |>
      dplyr::select(-city, -country_code) |>
      dplyr::inner_join(
        dplyr::select(primary_destinations, dplyr::all_of(location_fields)), by = "iata"
      ) |>
      dplyr::select(dplyr::all_of(monthly_fields)) |>
      dplyr::arrange(iata, month, .locale = "C")

    primary_destinations

    One row per provider primary airport, keyed by iata. The provider’s duplicate_of_iata field marks nine secondary airports in the source edition used here. The script drops those records and retains each primary airport’s climate values.

    variable class description
    iata character Three-letter IATA code for the primary airport, used as the destination identifier.
    city character Provider label for the place served by the airport. It can name a city, town, metro, island or region.
    country_code character Two-letter country or territory code used by the provider.
    country character Provider's country or territory name.
    continent character Provider's continent label.
    lat numeric Latitude of the provider's destination coordinates in decimal degrees.
    lon numeric Longitude of the provider's destination coordinates in decimal degrees.
    elevation_m numeric Elevation of the destination coordinates in metres.
    population integer Provider's population figure for the named place. A blank means missing.
    annual_sunshine_hours numeric Modelled annual bright-sunshine duration in hours.
    annual_rainfall_mm numeric Sum of the 12 monthly precipitation normals in millimetres.
    peak_midday_uv_index numeric Highest of the 12 typical midday UV index values.
    climate character Climate description derived from the Köppen–Geiger class.
    destination_type character Provider-defined classification based on population, coast, elevation and sea temperature.
    best_month character Full English name of the month with the highest Sunshine Score.
    sunshine_score_year numeric Provider's annual Sunshine Score on a 0–100 scale.
    koppen_class character Köppen–Geiger class code derived from the monthly climate normals.
    climate_group character Provider's broader climate group used for filtering.
    sunniest_month character Full English name of the month with the most modelled sunshine hours.

    Six known cities have multiple primary airports.

    • Panama City (PTY, BLB, PAC)
    • Chengdu (CTU, TFU)
    • Phnom Penh (PNH, KTI)
    • Luanda (LAD, NBJ)
    • Nouméa (GEA, NOU)
    • Dazhou (DAX, DZH)

    Destin is a probable additional case (DSI, VPS). This list may be incomplete. For city counts, review airport-to-city assignments and group the relevant airports by hand.

    primary_monthly_climate

    One row per primary airport and calendar month, keyed by (iata, month). Join to primary_destinations on iata. Blank measurements are NA, and zero remains a numeric value.

    variable class description
    iata character Primary airport code, referencing primary_destinations.csv.
    city character Destination label joined from the primary destination table.
    country_code character Country or territory code joined from the primary destination table.
    month integer Calendar month, from 1 for January to 12 for December.
    sunshine_score numeric Provider's 0–100 index combining warmth, dryness and sunshine.
    day_high_c numeric Monthly average daytime high in degrees Celsius.
    night_low_c numeric Monthly average overnight low in degrees Celsius.
    rain_mm numeric Monthly precipitation normal in millimetres.
    midday_uv_index numeric Typical midday UV index for the month, on the WHO scale.
    sea_temp_c numeric Monthly sea-surface temperature normal in degrees Celsius, available for eligible coastal destinations. A blank means missing.
    sunshine_hours numeric Modelled bright-sunshine duration for the month in hours.

    Sunshine Atlas source fields, upstream credits and attribution · CC BY 4.0

    Prepared by CyberNative AI LLC, an AI-run company, using AI agents, which wrote the script and the dictionary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    data: datavizabledata: has articledata: has data linkdata: needs compilationdata: needs data dictionarydata: no image alt textdata: no imagesdata: not commercialdata: usable provenancedataset

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions