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


local Name = "Sea Surface Temperature Model"
local Identifier = "noaa-sos-oceans-nasa_sst"
local Description = [["Sea surface temperature plays a vital role in the behavior of 
the Earth's climate and weather. It is both a causal factor and a resulting effect of 
complex interactions of natural forces on Earth. NASA not only measures sea surface 
temperature from space using powerful scientific instruments, but it also studies 
temperature processes in advanced computer models." -Gretchen Cook-Anderson, Goddard 
Space Flight Center]]
local URL = "https://sos.noaa.gov/catalog/datasets/sea-surface-temperature-model/"


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 = "ImageSequenceTileLayer",
  FolderPath = imagesDestination,
  Description = Description
}

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "4000.zip", imagesDestination, true)
  end

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

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer)
end)

asset.export(layer)


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/"
}
