Ouranosinc / pavics-sdi

Power Analytics and Visualization for Climate Science - Spatial Data Infrastructure
https://pavics-sdi.readthedocs.io
6 stars 2 forks source link

Error when extracting terrain information from DEM #282

Open md376 opened 1 year ago

md376 commented 1 year ago

I have been attempting to replicate the workflow outlined in the tutorial titled "02 - Extract geographical watershed properties" (found here: https://pavics.ouranos.ca/jupyter/hub/user-redirect/lab/tree/tutorial-notebooks/raven-master/docs/source/notebooks/02_Extract_geographical_watershed_properties.ipynb using my own shapefile : 02EA005.zip

I have been able to successfully reproduce the workflow (including extracting watershed land use information) up until the terrain information extraction step, where terrain data for the polygon is collected from the default DEM.

Specifically this code below: terrain_resp = wps.terrain_analysis(shape=feature_url, select_all_touching=True, projected_crs=3978)

produces the error: "owslib.wps.WPSException : {'code': 'NoApplicableCode', 'locator': 'None', 'text': 'Process failed, please check server error log'}"

I have noted the issue is similar to the one identified here: https://github.com/Ouranosinc/raven/issues/127. However, I have not been able to resolve it myself.

Zeitsperre commented 1 year ago

Hi @md376,

We recently updated some of the base libraries that the shape and CRS-handling code depends on, so it could be that something isn't working with the new backend APIs. Just for curiosity, could you try passing the following to the WPS process:

from fiona.crs import CRS

crs = CRS.from_epsg(3978)
# and if that doesn't work, add:
# crs = crs.to_dict()

terrain_resp = wps.terrain_analysis(shape=feature_url, select_all_touching=True, projected_crs=crs)

Please let me know if either of those approaches work for you.

md376 commented 1 year ago

Thanks for the response, @Zeitsperre. I've tried your suggestion but ran into issues.

I found that:

from fiona.crs import CRS

produced:

ImportError Traceback (most recent call last) Cell In [37], line 1 ----> 1 from fiona.crs import CRS

ImportError: cannot import name 'CRS' from 'fiona.crs' (/opt/conda/envs/birdy/lib/python3.8/site-packages/fiona/crs.py)

However, I was able to import the package and run the function using:

from fiona import crs as CRS

crs = CRS.from_epsg(3978)

terrain_resp = wps.terrain_analysis(shape=feature_url, select_all_touching=True, projected_crs=crs)

this produced the error:

ServiceException Traceback (most recent call last) Cell In [41], line 7 3 crs = CRS.from_epsg(3978) 5 #crs = CRS.to_dict() ----> 7 terrain_resp = wps.terrain_analysis( 8 shape=feature_url, select_all_touching=True, projected_crs=crs 9 )

File </opt/conda/envs/birdy/lib/python3.8/site-packages/birdy/client/base.py-18>:5, in terrain_analysis(self, shape, >projected_crs, raster, select_all_touching, output_formats)

File /opt/conda/envs/birdy/lib/python3.8/site-packages/birdy/client/base.py:368, in WPSClient._execute(self, pid, **kwargs) 365 mode = self._mode if self._processes[pid].storeSupported else SYNC 367 try: --> 368 wps_response = self._wps.execute( 369 pid, 370 inputs=wps_inputs, 371 output=wps_outputs, 372 mode=mode, 373 lineage=self._lineage, 374 ) 376 if self._interactive and self._processes[pid].statusSupported: 377 if self._notebook:

File /opt/conda/envs/birdy/lib/python3.8/site-packages/owslib/wps.py:361, in WebProcessingService.execute(self, identifier, >inputs, output, mode, lineage, request, response) 359 # submit the request to the live server 360 if response is None: --> 361 response = execution.submitRequest(request) 362 else: 363 response = etree.fromstring(response)

File /opt/conda/envs/birdy/lib/python3.8/site-packages/owslib/wps.py:933, in WPSExecution.submitRequest(self, request) 926 self.request = request 927 reader = WPSExecuteReader( 928 verbose=self.verbose, 929 auth=self.auth, 930 language=self.language, 931 timeout=self.timeout, 932 ) --> 933 response = reader.readFromUrl( 934 self.url, request, method='Post', headers=self.headers) 935 self.response = response 936 return response

File /opt/conda/envs/birdy/lib/python3.8/site-packages/owslib/wps.py:604, in WPSExecuteReader.readFromUrl(self, url, data, >method, username, password, headers, verify, cert) 597 def readFromUrl(self, url, data={}, method='Get', username=None, password=None, 598 headers=None, verify=None, cert=None): 599 """ 600 Reads a WPS status document from a remote service and returns the XML etree object. 601 :param str url: the URL to submit the GET/POST request to. 602 """ --> 604 return self._readFromUrl(url, data, self.timeout, method, username=username, password=password, 605 headers=headers, verify=verify, cert=cert)

File /opt/conda/envs/birdy/lib/python3.8/site-packages/owslib/wps.py:515, in WPSReader._readFromUrl(self, url, data, >timeout, method, username, password, headers, verify, cert) 512 return etree.fromstring(u.read()) 514 elif method == 'Post': --> 515 u = openURL(url, data, method='Post', 516 username=self.auth.username, password=self.auth.password, 517 headers=headers, verify=self.auth.verify, cert=self.auth.cert, timeout=timeout) 518 return etree.fromstring(u.read()) 520 else:

File /opt/conda/envs/birdy/lib/python3.8/site-packages/owslib/util.py:211, in openURL(url_base, data, method, cookies, >username, password, timeout, headers, verify, cert, auth) 208 req = requests.request(method.upper(), url_base, headers=headers, **rkwargs) 210 if req.status_code in [400, 401]: --> 211 raise ServiceException(req.text) 213 if req.status_code in [404, 500, 502, 503, 504]: # add more if needed 214 req.raise_for_status()

ServiceException: <?xml version="1.0" encoding="UTF-8"?>

Could not convert value '{'init': 'epsg:3978', 'no_defs': >True}' to format 'integer'

I checked the object type of crs was <class 'dict'>

I also tried passing crs = CRS.to_dict() but received:

AttributeError Traceback (most recent call last) Cell In [43], line 1 ----> 1 crs = CRS.to_dict()

AttributeError: module 'fiona.crs' has no attribute 'to_dict'

This might just be a product of not being able to import in the package properly? I've played around with it a little bit but am still somewhat new to Python so my troubleshooting skills are still somewhat lacking and are based on my experience using R.

Zeitsperre commented 1 year ago

Thanks for the update and trace back (helpful!). No worries on the lack of python experience.

Regrettably, we haven't been maintaining our notebooks very well. It's in my plans to look into this in the next week. Will post updates soon.

md376 commented 1 year ago

Sounds good, I appreciate the help.

md376 commented 1 year ago

An update: If you use a .geojson file as the watershed input as opposed to the zipped shapefiles described in the tutorials, the DEM extraction is successful.