Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when extracting terrain information from DEM #282

Open
md376 opened this issue Mar 2, 2023 · 5 comments
Open

Error when extracting terrain information from DEM #282

md376 opened this issue Mar 2, 2023 · 5 comments

Comments

@md376
Copy link

md376 commented Mar 2, 2023

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: Ouranosinc/raven#127. However, I have not been able to resolve it myself.

@Zeitsperre Zeitsperre added the bug label Mar 2, 2023
@Zeitsperre
Copy link
Contributor

Zeitsperre commented Mar 2, 2023

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
Copy link
Author

md376 commented Mar 3, 2023

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:

<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema->instance" xsi:schemaLocation="http://www.opengis.net/ows/1.1 >http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd" version="1.0.0">
<ows:Exception exceptionCode="InvalidParameterValue" locator="" >
ows:ExceptionTextCould not convert value '{'init': 'epsg:3978', 'no_defs': >True}' to format 'integer'</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

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
Copy link
Contributor

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
Copy link
Author

md376 commented Mar 3, 2023

Sounds good, I appreciate the help.

@md376
Copy link
Author

md376 commented May 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants