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



local Name = "Human Climate Niche - 2020 and 2070"
local Identifier = "noaa-sos-atmosphere-climate_niche"
local Description = [[The human climate niche are areas on Earth where humans have
historically lived due to favorable climate conditions related to temperature and
precipitation. For the past 6000 years, humans have mostly lived in the same climate
conditions as they do now. In addition to humans, this climate niche is also where the
production of crops and livestock typically takes place. The optimal mean annual
temperature of this identified niche is around 52 °F to 59 °F (~11 °C to 15 °C). But as
the climate changes, the areas that fit within the human climate niche will change as
well. This dataset identifies the current human climate niche, with land shaded to show
which areas are more or less suitable for people, and then projects the future human
climate niche in 2070 based on the climate projection scenario of RCP 8.5. Also included
as an additional layer that can be turned on and off is a map that shows the areas where
the mean annual temperature is greater than 84 °F (29 °C). Currently, only 0.8% of the
global land surface has a mean annual temperature greater than 84 °F, but in 2070 that is
projected to cover 19% of the global land and impact an estimated 3.5 billion people]]
local URL = "https://sos.noaa.gov/catalog/datasets/human-climate-niche-2020-and-2070/"


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


local LayerPrecip2020 = {
  Identifier = Identifier .. "-2020",
  Name = Name .. " (2020)",
  FilePath = syncedDirectory .. "temp-precip-2020-current-4096.png",
  Description = Description
}

local LayerPrecip2070 = {
  Identifier = Identifier .. "-2070",
  Name = Name .. " (2070)",
  FilePath = syncedDirectory .. "temp-precip-2070-rcp85-4096.png",
  Description = Description
}

local LayerMat2020 = {
  Identifier = Identifier .. "-mat2020",
  Name = Name .. " (MAT 2020)",
  FilePath = syncedDirectory .. "MAT-29-2020-4096.png",
  Description = Description
}

local LayerMat2070 = {
  Identifier = Identifier .. "-mat2070",
  Name = Name .. " (MAT 2070)",
  FilePath = syncedDirectory .. "MAT-29-2070-4096.png",
  Description = Description
}

local Colorbar = {
  Identifier = Identifier,
  Name = Name,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "niche-scale.png",
  FaceCamera = false,
  CartesianPosition = { 0.0, -0.5, -2.0 }
}


asset.onInitialize(function()
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerPrecip2020)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerPrecip2070)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerMat2020)
  openspace.globebrowsing.addLayer(globe.Earth.Identifier, "ColorLayers", LayerMat2070)
  openspace.addScreenSpaceRenderable(Colorbar)
end)

asset.onDeinitialize(function()
  openspace.removeScreenSpaceRenderable(Colorbar)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerMat2070)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerMat2020)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerPrecip2070)
  openspace.globebrowsing.deleteLayer(globe.Earth.Identifier, "ColorLayers", LayerPrecip2020)
end)

asset.export(LayerPrecip2020)
asset.export(LayerPrecip2070)
asset.export(LayerMat2020)
asset.export(LayerMat2070)
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/"
}
