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


local Name = "Ocean Surface Vorticity"
local Identifier = "noaa-sos-oceans-vorticity"
local Description = [[This animation shows daily values of the ocean surface relative 
vorticity as simulated by the Parallel Ocean Program (POP). Vorticity, which can be 
thought of as the rate of fluid rotation, is particularly useful for visualizing ocean 
turbulent flow, highlighting the presence of swirling eddies. A significant amount of the 
total kinetic energy in the world ocean is attributable to these turbulent motions, 
making them an important component in balances of energy, momentum, heat, salt, and 
chemical constituents (such as carbon dioxide) throughout the globe]]
local URL = "https://sos.noaa.gov/catalog/datasets/ocean-surface-vorticity/"


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