local globeIdentifier = asset.require("../../earth").Earth.Identifier


local Name = "Sea Surface Temperature NOAA Model (black land)"
local Identifier = "noaa-sos-oceans-gfdl_sst-black_background"
local Description = [[This dataset shows how the global ocean's surface water 
temperatures vary over the course of few years. In addition to seeing the effects of the 
seasonal cycle, the viewer can see how surface ocean currents and eddies transport heat 
and water around the globe. The images were generated not from observations, but from a 
state-of-the-art computer model of Earth's climate created at NOAA's Geophysical Fluid 
Dynamics Laboratory (GFDL)]]
local URL = "https://sos.noaa.gov/catalog/datasets/sea-surface-temperature-noaa-model-black-land/"


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

local imagesDestination = syncedDirectory .. "images"

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

local colorbar = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "colorbar.png",
  FaceCamera = false,
  Scale = 0.04,
  CartesianPosition = { 0.85, 0.0, -2.0 }
}

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "2048_png-1.zip", imagesDestination, true)
    openspace.unzipFile(syncedDirectory .. "2048_png-2.zip", imagesDestination, true)
  end

  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer)
  openspace.addScreenSpaceRenderable(colorbar);  
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer)
  openspace.removeScreenSpaceRenderable(colorbar)
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/"
}
