%matplotlib notebook
import dh_py_access.lib.datahub as datahub
import dh_py_access.package_api as package_api

"""
Explanation: ARC2 download example
In this demo we show how to download ARC2 data
End of explanation
"""


server = 'api.planetos.com'
API_key = open('APIKEY').readlines()[0].strip() #'<YOUR API KEY HERE>'
version = 'v1'

"""
Explanation: <font color='red'>Please put your datahub API key into a file called APIKEY and place it to the notebook folder or assign your API key directly to the variable API_key!</font>
End of explanation
"""


dh=datahub.datahub(server,version,API_key)
dataset1='noaa_arc2_africa_01'
variable_name1 = 'pr'
time_start = '1983-01-01T00:00:00'
time_end = '2018-01-01T00:00:00'

"""
Explanation: At first, we need to define the dataset names and temporal ranges. Please note that the datasets have different time ranges. So we will download the data from 1981, when CHRIPS starts (ARC2 is from 1983).
End of explanation
"""


area_name = 'Africa'
latitude_north = 42.24; longitude_west = -24.64
latitude_south = -45.76; longitude_east = 60.28

"""
Explanation: Then we define spatial range. In this case we define all Africa. Keep in mind that it's a huge area and downloading all the data from Africa for 35 years is a lot and can take even several hours.
End of explanation
"""


package_arc2_africa_01 = package_api.package_api(dh,dataset1,variable_name1,longitude_west,longitude_east,latitude_south,latitude_north,time_start,time_end,area_name=area_name)

package_arc2_africa_01.make_package()

package_arc2_africa_01.download_package()

"""
Explanation: Download the data with package API

Create package objects
Send commands for the package creation
Download the package files
End of explanation
"""


