local globe = asset.require("../../earth")



local Name = "Temperature Anomaly: Yearly (NOAA) - 1880 - Present"
local Identifier = "noaa-sos-atmosphere-temp_anom"
local Description = [[This animation shows Earth's surface temperature from 1880 through
2019 compared to the 20th century average. Maps are based on data from NOAA's National
Climatic Data Center. In 2016, the combined land and ocean surface temperature was 1.69°F
(0.94°C) above the 20th century average, making the year the warmest since records began
in 1880. This is the third consecutive year a new global annual temperature record has
been set. The first eight months of 2016 set monthly temperatures records and the last
four months were ranked among the top five for each month's temperature records. To date,
all 16 years of the 21st century rank among the seventeen warmest on record (1998 is
currently the eighth warmest.) The five warmest years have all occurred since 2010. 2017
was the third warmest, slightly cooler than the previous two. 2018 was the fourth
warmest]]
local URL = "https://sos.noaa.gov/catalog/datasets/temperature-anomaly-yearly-noaa-1880-present/"


local syncedDirectory = asset.syncedResource({
  Name = Name,
  Type = "HttpSynchronization",
  Identifier = Identifier,
  Version = 1,
  UnzipFiles = true
})


local Layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "TemporalTileLayer",
  Mode = "Folder",
  Folder = {
    Folder = syncedDirectory .. "4096_new",
    -- See https://en.cppreference.com/w/cpp/io/manip/get_time for an explanation of the
    -- time formatting string
    Format = "ANOM.yearly.%Y.color.png"
  },
  Description = Description
}

local Colorbar = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "colorbar.png",
  FaceCamera = false,
  BackgroundColor = { 1.0, 1.0, 1.0, 1.0 },
  CartesianPosition = { 0.0, -0.5, -2.0 }
}


asset.onInitialize(function()
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", Layer)
  openspace.addScreenSpaceRenderable(Colorbar)
end)

asset.onDeinitialize(function()
  openspace.removeScreenSpaceRenderable(Colorbar)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", Layer)
end)

asset.export(Layer)
asset.export(Colorbar)



asset.meta = {
  Name = Name,
  Version = "1.0",
  Description = Description .. "Data provided by the National Oceanic and Atmospheric Administration",
  Author = "National Oceanic and Atmospheric Administration",
  URL = URL,
  License = "https://sos.noaa.gov/copyright/"
}
