Commit edcb98c4 authored by Jacob Alexander's avatar Jacob Alexander
Browse files

fixed version for working with netcdf again, by creating local copy. File name...

fixed version for working with netcdf again, by creating local copy. File name can now also be given as optional parameter.
parent dc1b5c5a
def wcps_rasdaman(query, ip='10.8.246.69'):
def wcps_rasdaman(query, ip='saocompute.eurac.edu/sincohmap', file_name=''):
"""
Sends a WCPS query to a Rasdaman server and wraps the response for further use in Python depending on the
the response format chosen in the query.
Args:
query (str) -- WCPS query you want to send to the Rasdaman server
ip (str) -- IP of Rasdaman server (default 10.8.246.69)
ip (str) -- IP of Rasdaman server (default saocompute.eurac.edu)
Returns:
Either one of the following
......@@ -19,7 +19,7 @@ def wcps_rasdaman(query, ip='10.8.246.69'):
http://xarray.pydata.org/en/stable/data-structures.html
Author: Harald Kristen, Alexander Jacob
Date: 2017-09-19
Date: 2019-05-29
"""
import requests
......@@ -38,13 +38,9 @@ def wcps_rasdaman(query, ip='10.8.246.69'):
#print('WCPS init')
if ip == 'saocompute.eurac.edu/sincohmap':
#http://10.8.246.69:8080/rasdaman/ows?&SERVICE=WCS&VERSION=2.0.1&REQUEST=GetCoverage&COVERAGEID=SOUTH_TYROL_RR_GRD_UTM&SUBSET=DATE(%222015-03-30T00:00:00.000Z%22)&FORMAT=application/gml+xml
url = 'http://' + ip + '/rasdaman/ows?SERVICE=WCS&VERSION=2.0.1&REQUEST=ProcessCoverages'
if ip == 'saocompute.eurac.edu/sincohmap' or ip == 'saocompute.eurac.edu':
url = 'http://' + ip + '/rasdaman/ows?SERVICE=WCS&VERSION=2.0.1&REQUEST=ProcessCoverages'
else:
#Fix the special characters used the input query like ' ', $ and so on
url = 'http://' + ip + ':8080/rasdaman/ows?SERVICE=WCS&VERSION=2.0.1&REQUEST=ProcessCoverages'
#Fix the special characters used the input query like ' ', $ and so on
......@@ -90,8 +86,14 @@ def wcps_rasdaman(query, ip='10.8.246.69'):
output = np.array(loaded)
elif r.headers['Content-Type'] == 'application/netcdf':
print(r.headers)
# create x array dataset from input stream
output_open = xr.open_dataset(r.content)
if file_name == '':
file_name = 'wcps_' + str(uuid.uuid4()) + '.nc'
print('the following file has been saved locally: ' + file_name)
with io.open(file_name, 'wb') as outfile:
outfile.write(r.content)
output_open = xr.open_dataset(file_name)
# Xarray is normally lazy loading netCDF files
# As we want to perform intense computation, we load the file directly in the main memory with Dataset.load()
output = xr.Dataset.load(output_open)
......@@ -99,14 +101,15 @@ def wcps_rasdaman(query, ip='10.8.246.69'):
elif r.headers['Content-Type'] in ['image/tiff', 'image/png', 'image/jp2', 'image/jpeg']:
# Write response in choosen image format to disk and print filepath
image_type = r.headers['Content-Type']
file_ending = image_type[6:]
# write TIFF to disk and print filepath
tf = 'wcps_' + str(uuid.uuid4())
filename = work_directory + '\\' + tf + '.' + file_ending
with io.open(filename, 'wb') as outfile:
if file_name == '':
file_ending = image_type[6:]
# write TIFF to disk and print filepath
tf = 'wcps_' + str(uuid.uuid4())
file_name = tf + '.' + file_ending
with io.open(file_name, 'wb') as outfile:
outfile.write(r.content)
print('The file has been saved to ' + filename)
output = filename
print('the following file has been saved locally: ' + file_name)
output = file_name
else:
output = r
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment