usingMakieusingFileIO,GeometryTypes,Colors,GDAL,ZipFileenv=get(ENV,"LD_LIBRARY_PATH","")#=
This example requires the GDAL package, from https://github.com/JuliaGeo/GDAL.jl
For more information about GDAL, see the official documentation at: https://gdal.org/
=## register GDAL driversGDAL.gdalallregister()# function to check if a file is a .tif fileistiff(x)=endswith(x,".tif")# set up 7zipfunctionunzip(input,out)dir=ZipFile.Reader(input)mkpath(out)forfileindir.filesopen(joinpath(out,file.name),"w")doioBase.write(io,read(file))endendclose(dir)end# function to read the raster data from the GeoTIFFfunctionloadf0(x)img=GDAL.gdalopen(x,GDAL.GA_ReadOnly)band=GDAL.gdalgetrasterband(img,1)xsize=GDAL.gdalgetrasterbandxsize(band)ysize=GDAL.gdalgetrasterbandysize(band)data=Array{Float32}(undef,xsize,ysize)GDAL.gdalrasterio(band,GDAL.GF_Read,0,0,xsize,ysize,data,xsize,ysize,GDAL.GDT_Float32,0,0)data'end# since we cannot re-distribute the dataset, this function grabs the dataset from the host serverfunctionload_dataset(name)# get the dataset from:# http://worldclim.org/version2"""
This is WorldClim 2.0 Beta version 1 (June 2016) downloaded from http://worldclim.org
They represent average monthly climate data for 1970-2000.
The data were created by Steve Fick and Robert Hijmans
You are not allowed to redistribute these data.
"""if!isfile("$name.zip")# This might fail on windows - just try again a couple of times -.-# download with curl breaks if julia is in LD_LIBRARY_PATH# which GDAL is putting thereENV["LD_LIBRARY_PATH"]=""download("http://biogeo.ucdavis.edu/data/worldclim/v2.0/tif/base/wc2.0_10m_$name.zip","$name.zip")endif!isdir(name)unzip("$name.zip",name)endENV["LD_LIBRARY_PATH"]=envloadf0.(filter(istiff,joinpath.(name,readdir(name))))end# load the actual datasets!water=load_dataset("prec")temperature=load_dataset("tmax")# calculate geometriesm=GLNormalUVMesh(Sphere(Point3f0(0),1f0),200)p=decompose(Point3f0,m)uv=decompose(UV{Float32},m)norms=decompose(Normal{3,Float32},m)# plot the temperature as color map on the globecmap=[:darkblue,:deepskyblue2,:deepskyblue,:gold,:tomato3,:red,:darkred]# function to scale precipitation to a suitable marker sizefunctionwatermap(uv,water,normalization=908f0*4f0)markersize=map(uv)douvwsize=reverse(size(water))wh=wsize.-1x,y=round.(Int,Tuple(uv).*wh).+1val=water[size(water)[1]-(y-1),x]/normalizationval<0.0?-1f0:valendendscene=Scene(resolution=(800,800))scene=mesh!(m,color=temperature[10],colorrange=(-50,50),colormap=cmap,shading=true,show_axis=false)temp_plot=scene[end];# plot precipitation as vertical barswatervals=watermap(uv,water[1])extrema(watervals)xyw=0.01meshscatter!(scene,p,rotations=norms,marker=Rect3D(Vec3f0(0),Vec3f0(1)),markersize=Vec3f0.(xyw,xyw,watervals),raw=true,color=watervals,colormap=[(:black,0.0),(:skyblue2,0.6)],shading=false)wplot=scene[end]# update eye positioneye_position,lookat,upvector=Vec3f0(0.5,0.8,2.5),Vec3f0(0),Vec3f0(0,1,0)update_cam!(scene,eye_position,lookat,upvector)scenescene.center=false# save animationr=record(scene,"output.mp4",0:(11*4))doi# Make simulation slower. TODO figure out how do this nicely with ffmpegifi%4==0i2=(iรท4)+1temp_plot[:color]=temperature[i2]watervals=watermap(uv,water[i2])wplot[:color]=watervalswplot[:markersize][].=Vec3f0.(xyw,xyw,watervals)# since we modify markersize inplace above, we need to notify the signalAbstractPlotting.notify!(wplot[:markersize])endendENV["LD_LIBRARY_PATH"]=""r