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


local Name = "Biosphere: Marine Chlorophyll Concentration Model"
local Identifier = "noaa-sos-oceans-chlorophyll_model"
local Description = [[This animation shows the daily concentration of ocean surface 
chlorophyll as simulated by the Parallel Ocean Program (POP) with an embedded marine 
ecosystem model. While POP calculates the ocean currents, temperature and salinity, the 
ecosystem model simulates the complex interaction of microscopic marine plants 
(chlorophyll-containing phytoplankton), animals (zooplankton) and nutrients (such as 
nitrogen, phosphorus and iron). In addition to constituting a major part of the global 
food web, phytoplankton remove carbon dioxide from the atmosphere via photosynthesis much 
like their counterparts on land. As conditions in the ocean and atmosphere change due to 
increased carbon emissions, it is important to be able to use these kinds of models to 
understand the possible effects on life in the ocean and the global carbon cycle]]
local URL = "https://sos.noaa.gov/catalog/datasets/biosphere-marine-chlorophyll-concentration-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
}

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

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "3232.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/"
}
