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


local Name = "Sea Ice Animation - 2009"
local Identifier = "noaa-sos-oceans-2009_ice_animation"
local Description = [[Sea ice is simply ocean water that has frozen. At least 15% of the 
ocean is covered by sea ice some part of the year. This means that on average, sea ice 
covers almost 10 million square miles (about 25 million square kilometers) of the Earth. 
Sea ice concentrations are monitored closely by scientists because changing sea ice 
concentrations can have a huge impact on the rest of the globe. Global warming is 
amplified in polar regions. Because of this, monitoring changes in sea ice can be a good 
indicator of climate change. The Global Snow and Ice Cover Map that is used in this 
dataset is created from a combination of observations from NOAA Advanced Very High 
Resolution Radiometer, Meteosat Second Generation Satellite Spectral Response 
Characterisation, GOES Imager and Defense Meteorological Satellite Program Special Sensor 
Microwave/Imager. The resolution is 2 km]]
local URL = "https://sos.noaa.gov/catalog/datasets/sea-ice-animation-2009/"


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
}

local colorbar_2007_2009 = {
  Identifier = Identifier .. "-2007_2009",
  Name = Name .. " (2007-2009 Compare)",
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "2007-2009-Compare.png",
  FaceCamera = false,
  CartesianPosition = { -0.85, -0.5, -2.0 }
}

local colorbar_2008_minimum = {
  Identifier = Identifier .. "-2008_minimum",
  Name = Name .. " (2008 Minimum)",
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "2008-Minimum-Label.png",
  FaceCamera = false,
  CartesianPosition = { 0.6, -0.4, -2.0 }
}

local colorbar_2009_iceconcentration = {
  Identifier = Identifier .. "-2009_iceconcentration",
  Name = Name .. " (2009 Ice Concentration)",
  Enabled = asset.enabled,
  Type = "ScreenSpaceImageLocal",
  TexturePath = syncedDirectory .. "2009-IceConcentration-Label.png",
  FaceCamera = false,
  CartesianPosition = { 0.6, -0.6, -2.0 }
}

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

  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer)
  openspace.addScreenSpaceRenderable(colorbar_2007_2009);  
  openspace.addScreenSpaceRenderable(colorbar_2008_minimum);  
  openspace.addScreenSpaceRenderable(colorbar_2009_iceconcentration);  
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer)
  openspace.removeScreenSpaceRenderable(colorbar_2007_2009)
  openspace.removeScreenSpaceRenderable(colorbar_2008_minimum)
  openspace.removeScreenSpaceRenderable(colorbar_2009_iceconcentration)
end)

asset.export(layer)
asset.export(colorbar_2007_2009)
asset.export(colorbar_2008_minimum)
asset.export(colorbar_2009_iceconcentration)


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