This section provides code examples on how to access data from the restful Application Programming Interfaces (API). For more information on the API services please see the API Services Section.
Guidance on Multiprocessing Download (Synchronous Requests)
When requesting data from the POWER API:
Please ensure you do not submit too many synchronous requests; if it is determined that you are negatively impacting server performance you potentially will be blocked.
Please ensure that you properly request data from the POWER Data Services at no higher than its current resolution. The POWER data products are currently available at 0.5 x 0.625 degree resolution for meteorology and 1 x 1 for solar parameters. If you are requesting data at a too high a resolution (i.e, less than 0.5 degree or about 50 km), you are potentially repetitively requesting the same information.
*Within two to three (2-3) months after real-time, the meteorological data products are replaced with improved climate quality data products. This needs to be taken into account when downloading the POWER Data Archive.
This is an overview of the process to request data from multiple single point locations from the POWER API.
The Loop (Points) tab below allows for the download directly from the API for any format offered.
The Multiprocessing (Points) and Multiprocessing (Region) support multiprocessing and read the data from the JSON response pulling the data into a Pandas DataFrame prior to being exported as a CSV. This can be edited to create any format with Python and/or the Pandas module.
1 2 3 4 5 6 7 8 9101112131415161718192021222324
'''*Version: 2.0 Published: 2021/03/09* Source: [NASA POWER](https://power.larc.nasa.gov/)POWER API Multi-Point DownloadThis is an overview of the process to request data from multiple data points from the POWER API.'''importos,json,requestslocations=[(32.929,-95.770),(5,10)]output=r""base_url=r"https://power.larc.nasa.gov/api/temporal/daily/point?parameters=T2M,T2MDEW,T2MWET,TS,T2M_RANGE,T2M_MAX,T2M_MIN&community=RE&longitude={longitude}&latitude={latitude}&start=20150101&end=20150305&format=JSON"forlatitude,longitudeinlocations:api_request_url=base_url.format(longitude=longitude,latitude=latitude)response=requests.get(url=api_request_url,verify=True,timeout=30.00)content=json.loads(response.content.decode('utf-8'))filename=response.headers['content-disposition'].split('filename=')[1]filepath=os.path.join(output,filename)withopen(filepath,'w')asfile_object:json.dump(content,file_object)
'''*Version: 2.0 Published: 2021/03/09* Source: [NASA POWER](https://power.larc.nasa.gov/)POWER API Multi-Point DownloadThis is an overview of the process to request data from multiple data points from the POWER API.'''importos,sys,time,json,urllib3,requests,multiprocessingurllib3.disable_warnings()defdownload_function(collection):''' '''request,filepath=collectionresponse=requests.get(url=request,verify=False,timeout=30.00).json()withopen(filepath,'w')asfile_object:json.dump(response,file_object)classProcess():def__init__(self):self.processes=5# Please do not go more than five concurrent requests.self.request_template=r"https://power.larc.nasa.gov/api/temporal/daily/point?parameters=T2M,T2MDEW,T2MWET,TS,T2M_RANGE,T2M_MAX,T2M_MIN&community=RE&longitude={longitude}&latitude={latitude}&start=20150101&end=20150305&format=JSON"self.filename_template="File_Lat_{latitude}_Lon_{longitude}.csv"self.messages=[]self.times={}defexecute(self):Start_Time=time.time()locations=[(39.9373,-83.0485),(10.9373,-50.0485)]requests=[]forlatitude,longitudeinlocations:request=self.request_template.format(latitude=latitude,longitude=longitude)filename=self.filename_template.format(latitude=latitude,longitude=longitude)requests.append((request,filename))requests_total=len(requests)pool=multiprocessing.Pool(self.processes)x=pool.imap_unordered(download_function,requests)fori,dfinenumerate(x,1):sys.stderr.write('\rExporting {0:%}'.format(i/requests_total))self.times["Total Script"]=round((time.time()-Start_Time),2)print("\n")print("Total Script Time:",self.times["Total Script"])if__name__=='__main__':Process().execute()
'''*Version: 1.0 Published: 2020/02/11* Source: [NASA POWER](https://power.larc.nasa.gov/)POWER API Multipoint Download (CSV)This is an overview of the process to request data from multiple data points from the POWER API.'''importos,sys,time,json,urllib3,requests,multiprocessingurllib3.disable_warnings()importnumpyasnpdefdownload_function(collection):''' '''request,filepath=collectionresponse=requests.get(url=request,verify=False,timeout=30.00).json()withopen(filepath,'w')asfile_object:json.dump(response,file_object)classProcess():def__init__(self):self.processes=5# Please do not go more than five concurrent requests.self.request_template=r"https://power.larc.nasa.gov/api/temporal/daily/point?parameters=T2M,T2MDEW,T2MWET,TS,T2M_RANGE,T2M_MAX,T2M_MIN&community=RE&longitude={longitude}&latitude={latitude}&start=20150101&end=20150305&format=JSON"self.filename_template="File_Lat_{latitude}_Lon_{longitude}.csv"self.messages=[]self.times={}defexecute(self):Start_Time=time.time()latitudes=np.arange(-1.75,1.0,0.5)# Update your download extent.longitudes=np.arange(-1.75,1.0,0.5)# Update your download extent.requests=[]forlongitudeinlongitudes:forlatitudeinlatitudes:request=self.request_template.format(latitude=latitude,longitude=longitude)filename=self.filename_template.format(latitude=latitude,longitude=longitude)requests.append((request,filename))requests_total=len(requests)pool=multiprocessing.Pool(self.processes)x=pool.imap_unordered(download_function,requests)fori,dfinenumerate(x,1):sys.stderr.write('\rExporting {0:%}'.format(i/requests_total))self.times["Total Script"]=round((time.time()-Start_Time),2)print("\n")print("Total Script Time:",self.times["Total Script"])if__name__=='__main__':Process().execute()