Source code for opendrift.models.openoil.adios.harvest_oils

import requests
import json
import tarfile
import lzma
from adios_db.models.oil.oil import Oil
from adios_db.computation import gnome_oil

[docs] def download(): url = '' print(f'Downloading all oils from {url}') oils = [] response = requests.get(url, stream=True) tar =, mode='r|gz') for file in tar: if file.isfile() and'.json'): f = tar.extractfile(file) o = json.load(f.raw) AO = Oil.from_py_json(o) #if 'norw' in AO.metadata.location.lower() and not AO.metadata.gnome_suitable: if not AO.metadata.gnome_suitable: print(f'Discarding {}, not GNOME suitable') continue else: oils.append(o) print(f'Downloaded {len(oils)} oils, saving to oils.xz') with'oils.xz', 'wt') as c: json.dump(oils, c)
if __name__ == '__main__': download()