Closed datamongerbonny closed 5 months ago
Dear Bonny (@datamongerbonny),
When using the forestatrisk
package for a Brazilian state (with iso3="BRA-XX" for example), you need to manually download the shapefile of this state in the output directory (here data_raw
) and name it gadm36_BRA-XX_0.shp
. This is because forestatrisk uses GADM (https://gadm.org) for country borders and that you can only retrieve data from the GADM website using the country iso3 code (eg. BRA).
Such shapefile for the BRA-AC state is available in the raw data folder for Brazilian states on the forestatrisk.cirad.fr website: Raw data/Brazil/BRA-AC/data_raw/gadm36_BRA-AC_0.shp. Do not forget to also download the .dbf, .prj, and .shx files in the same folder. Doing so, you should be able to run .country_forest_run()
with success.
I should probably add an option in the forestatrisk
package to build data for Brazilian states automatically without passing by that first manual step. I added issue #75.
Best regards,
Ghislain
Thank you! I will give it a try. I was manually moving the files but not sure into the correct folder!
Best, Bonny
The file is already in the folder BRA-AC!? So I guess that isn’t the problem...I will keep examining the code.
Rconfig points to all the right folders in terminal...
Compute gee forest data
far.data.country_forest_run( iso3, proj="EPSG:4326", output_dir="data_raw", keep_dir=True, fcc_source="jrc", perc=50, gdrive_remote_rclone="gdrive_xxx", gdrive_folder="GEE-forestatrisk-notebooks")
HTTPError Traceback (most recent call last) /var/folders/hv/rrx0n8mj291dq3qrfcb9x9bw0000gn/T/ipykernel_68748/465982169.py in <cell line: 2>() 1 # Compute gee forest data ----> 2 far.data.country_forest_run( 3 iso3, proj="EPSG:4326", 4 output_dir="data_raw", 5 keep_dir=True,
~/opt/miniconda3/envs/FAR/lib/python3.10/site-packages/forestatrisk/build_data/data.py in country_forest_run(iso3, proj, output_dir, keep_dir, fcc_source, perc, gdrive_remote_rclone, gdrive_folder) 137 fname = output_dir + "/" + iso3 + "shp.zip" 138 url = "http://biogeo.ucdavis.edu/data/gadm3.6/shp/gadm36" + iso3 + "_shp.zip" --> 139 urlretrieve(url, fname) 140 141 # Extract files from zip
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in urlretrieve(url, filename, reporthook, data) 239 url_type, path = _splittype(url) 240 --> 241 with contextlib.closing(urlopen(url, data)) as fp: 242 headers = fp.info() 243
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 214 else: 215 opener = _opener --> 216 return opener.open(url, data, timeout) 217 218 def install_opener(opener):
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in open(self, fullurl, data, timeout) 523 for processor in self.process_response.get(protocol, []): 524 meth = getattr(processor, meth_name) --> 525 response = meth(req, response) 526 527 return response
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in http_response(self, request, response) 632 # request was successfully received, understood, and accepted. 633 if not (200 <= code < 300): --> 634 response = self.parent.error( 635 'http', request, response, code, msg, hdrs) 636
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in error(self, proto, args) 555 http_err = 0 556 args = (dict, proto, meth_name) + args --> 557 result = self._call_chain(args) 558 if result: 559 return result
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in _call_chain(self, chain, kind, meth_name, args) 494 for handler in handlers: 495 func = getattr(handler, meth_name) --> 496 result = func(args) 497 if result is not None: 498 return result
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in http_error_302(self, req, fp, code, msg, headers) 747 fp.close() 748 --> 749 return self.parent.open(new, timeout=req.timeout) 750 751 http_error_301 = http_error_303 = http_error_307 = http_error_302
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in open(self, fullurl, data, timeout) 523 for processor in self.process_response.get(protocol, []): 524 meth = getattr(processor, meth_name) --> 525 response = meth(req, response) 526 527 return response
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in http_response(self, request, response) 632 # request was successfully received, understood, and accepted. 633 if not (200 <= code < 300): --> 634 response = self.parent.error( 635 'http', request, response, code, msg, hdrs) 636
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in error(self, proto, args) 555 http_err = 0 556 args = (dict, proto, meth_name) + args --> 557 result = self._call_chain(args) 558 if result: 559 return result
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in _call_chain(self, chain, kind, meth_name, args) 494 for handler in handlers: 495 func = getattr(handler, meth_name) --> 496 result = func(args) 497 if result is not None: 498 return result
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in http_error_302(self, req, fp, code, msg, headers) 747 fp.close() 748 --> 749 return self.parent.open(new, timeout=req.timeout) 750 751 http_error_301 = http_error_303 = http_error_307 = http_error_302
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in open(self, fullurl, data, timeout) 523 for processor in self.process_response.get(protocol, []): 524 meth = getattr(processor, meth_name) --> 525 response = meth(req, response) 526 527 return response
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in http_response(self, request, response) 632 # request was successfully received, understood, and accepted. 633 if not (200 <= code < 300): --> 634 response = self.parent.error( 635 'http', request, response, code, msg, hdrs) 636
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in error(self, proto, args) 561 if http_err: 562 args = (dict, 'default', 'http_error_default') + orig_args --> 563 return self._call_chain(args) 564 565 # XXX probably also want an abstract factory that knows when it makes
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in _call_chain(self, chain, kind, meth_name, args) 494 for handler in handlers: 495 func = getattr(handler, meth_name) --> 496 result = func(args) 497 if result is not None: 498 return result
~/opt/miniconda3/envs/FAR/lib/python3.10/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs) 641 class HTTPDefaultErrorHandler(BaseHandler): 642 def http_error_default(self, req, fp, code, msg, hdrs): --> 643 raise HTTPError(req.full_url, code, msg, hdrs, fp) 644 645 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 404: Not Found