-- Download a dataset of 618 million stars (28 GB), already preprocessed and stored in a binary octree.
-- The octree was generated from the full DR2 by filtering away all stars with a parallax error higher than 0.5
-- Max Star Per Node = 50,000 and max distance = 500kpc
local gaia618Destination = asset.syncedResource({
  Name = "Gaia DR2 618M Octree",
  Type = "HttpSynchronization",
  Identifier = "gaia_stars_618M_octree",
  Version = 1
})
local gaia618DestinationExtracted = gaia618Destination .. "data";

-- Download the full DR2 dataset with 24 values per star (preprocessed with theReadFitsTask (gaia_read.task) into 8 binary files).
-- From these files new subsets can be created with the ConstructOctreeTask (gaia_octree.task). 
-- Total size of download is 151 GB.
local gaiaFull = asset.syncedResource({
  Name = "Gaia DR2 Full Raw",
  Type = "HttpSynchronization",
  Identifier = "gaia_stars_dr2_raw",
  Version = 1
})

asset.onInitialize(function()
  if not openspace.directoryExists(gaia618DestinationExtracted) then
    openspace.printInfo("Extracted Gaia dataset")
    openspace.unzipFile(gaia618Destination .. "DR2_full_Octree[50kSPN,500dist]_50,50.zip", gaia618DestinationExtracted, true)
  end
end)

asset.export("GaiaDR2_618M", gaia618DestinationExtracted)
asset.export("GaiaFullDataset", gaiaFull)


asset.meta = {
  Name = "GaiaDR2 Download Stars",
  Version = "1.1",
  Description = [[This asset contains code to sync gaia subsets from the OpenSpace
  servers. Edit this file to choose which subsets to sync. WARNING can use 150GB]],
  Author = "ESA/Gaia/DPAC",
  URL = "https://gea.esac.esa.int/archive/documentation/GDR2/index.html",
  License = [[The Gaia data are open and free to use, provided credit is given to
    'ESA/Gaia/DPAC'. In general, access to, and use of, ESA's Gaia Archive (hereafter
    called 'the website') constitutes acceptance of the following general terms and
    conditions. Neither ESA nor any other party involved in creating, producing, or
    delivering the website shall be liable for any direct, incidental, consequential,
    indirect, or punitive damages arising out of user access to, or use of, the website.
    The website does not guarantee the accuracy of information provided by external
    sources and accepts no responsibility or liability for any consequences arising from
    the use of such data]]
}
