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


local Name = "Sea Surface Currents and Temperature (gray land)"
local Identifier = "noaa-sos-oceans-ecco2_sst-gray_land"
local Description = [[To increase understanding and predictive capability for the 
ocean's role in future climate change scenarios, the NASA Modeling, Analysis, and 
Prediction (MAP) program has created a project called Estimating the Circulation and 
Climate of the Ocean, Phase II (ECCO2): High-Resolution Global-Ocean and Sea-Ice Data 
Synthesis. ECCO2 produces increasingly accurate syntheses of all available global-scale 
ocean and sea-ice data at resolutions that start to resolve ocean eddies and other narrow 
current systems, which transport heat, and other properties within the ocean. ECCO2 data 
syntheses are created by using the available satellite and in-situ data in the 
Massachusetts Institute of Technology General Circulation Model (MIT GCM). ECCO2 
simulates ocean flows at all depths, but only surface flows are used in this 
visualization. The global sea surface current flows are colored by corresponding sea 
surface temperatures. The sea surface temperature data is also from the ECCO2 model]]
local URL = "https://sos.noaa.gov/catalog/datasets/sea-surface-currents-and-temperature-gray-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 = "ImageSequenceTileLayer",
  FolderPath = imagesDestination,
  Description = Description
}

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

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "4096-1.zip", imagesDestination, true)    
    openspace.unzipFile(syncedDirectory .. "4096-2.zip", imagesDestination, true)    
    openspace.unzipFile(syncedDirectory .. "4096-3.zip", imagesDestination, true)    
    openspace.unzipFile(syncedDirectory .. "4096-4.zip", imagesDestination, true)    
    openspace.unzipFile(syncedDirectory .. "4096-5.zip", imagesDestination, true)    
    openspace.unzipFile(syncedDirectory .. "4096-6.zip", imagesDestination, true)    
    openspace.unzipFile(syncedDirectory .. "4096-7.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/"
}
