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


local Name = "Polar Orbiting: Aqua Satellite and MODIS Swath"
local Identifier = "noaa-sos-atmosphere-aqua_swath"
local Description = [[Satellites are important to scientists because the instruments on 
board can provide almost daily global coverage of the Earth that would otherwise not be 
available. There are six instruments on board NASA's Aqua satellite. One of them is 
MODIS, the Moderate Resolution Imaging Spectroradiometer. MODIS measures 36 spectral 
frequencies of light, which provide a wealth of information about the physical properties 
of the atmosphere and the biological and physical properties of the oceans and land. The 
Aqua satellite with MODIS attached was launched May 4, 2002. Since then, Aqua has been 
circling the Earth at an altitude of 438 miles (705 kilometers) every 99 minutes in a 
polar orbit passing within 10 degrees of each pole every orbit. The orbit is 
sun-synchronous, which means that the satellite passes over the same spot of the Earth at
about the same local time everyday. Aqua crosses the equator from south to north at about 
1:30 pm local time]]
local URL = "https://sos.noaa.gov/catalog/datasets/polar-orbiting-aqua-satellite-and-modis-swath/"


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
}

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)
  end

  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer)
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer)
end)

asset.export(layer)


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