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


local Name = "Ocean Surface Winds"
local Identifier = "noaa-sos-oceans-vector_winds"
local Description = [[The SeaWinds scatterometer, carried aboard NASA's QuikSCAT 
satellite, is a microwave radar designed to measure the backscatter related to 
near-surface wind speed and direction over the oceans. A rougher ocean surface returns a 
stronger signal because the waves reflect more of the radar energy back toward the 
scatterometer antenna (backscatter), and a smoother ocean surface returns a weaker signal 
because less of the energy is reflected. Given the known relationship between the 
roughness of the surface and the strength of the wind, it is possible to compute the wind 
speed and direction - the wind vector - from multiple observations of the signal returned 
from a given area on the ocean surface]]
local URL = "https://sos.noaa.gov/catalog/datasets/ocean-surface-winds/"


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