Pathlib issue with TauDEM on Tallgrass
@xrnogueira any thoughts on this? I'm trying to test the new tools on one of our HPC systems. I attempted to run this cell in the test notebook on our Tallgrass cluster:
%%time
fac_taudem = fcpgtools.accumulate_flow(
d8_fdr=us_fdr,
engine='taudem',
upstream_pour_points=None,
)
print(f'TauDEM FAC nodata value: {fac_taudem.rio.nodata}')
I got this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File <timed exec>:1
File ~/mambaforge/envs/fcpgtools_base/lib/python3.9/site-packages/fcpgtools/terrainengine/engine_validator.py:39, in validate_engine.<locals>.validator.<locals>.valid_func(*args, **kwargs)
36 if not isinstance(kwargs['engine'], protocol):
37 raise TypeError(f'Invalid engine provided, {func.__name__}'
38 f' requires engine implementing {protocol.__name__} protocol')
---> 39 return func(*args, **kwargs)
File ~/mambaforge/envs/fcpgtools_base/lib/python3.9/site-packages/fcpgtools/tools.py:1048, in accumulate_flow(d8_fdr, engine, upstream_pour_points, weights, out_path, **kwargs)
1045 d8_fdr = utilities._match_d8_format(d8_fdr, engine)
1047 # execute function w/ the chosen engine
-> 1048 return engine.accumulate_flow(
1049 d8_fdr,
1050 upstream_pour_points=upstream_pour_points,
1051 weights=weights,
1052 out_path=out_path,
1053 **kwargs,
1054 )
File ~/mambaforge/envs/fcpgtools_base/lib/python3.9/site-packages/fcpgtools/terrainengine/taudem_engine.py:119, in TauDEMEngine.accumulate_flow(d8_fdr, upstream_pour_points, weights, out_path, **kwargs)
95 @staticmethod
96 def accumulate_flow(
97 d8_fdr: Raster,
(...)
101 **kwargs,
102 ) -> xr.DataArray:
103 """Create a Flow Accumulation Cell (FAC) raster from a TauDEM format D8 Flow Direction Raster.
104
105 NOTE: this is a command line wrapper of TauDEM:aread8 and replaces tools.tauFlowAccum() from V1 FCPGtools.
(...)
117 The output Flow Accumulation Cells (FAC) raster.
118 """
--> 119 d8_fdr_path = TauDEMEngine._taudem_prepper(d8_fdr)
121 # get tempoarary files for necessary inputs
122 if upstream_pour_points is None and weights is None:
File ~/mambaforge/envs/fcpgtools_base/lib/python3.9/site-packages/fcpgtools/terrainengine/taudem_engine.py:24, in TauDEMEngine._taudem_prepper(in_raster)
22 """Converts an input raster into a TauDEM compatible path string. Creates a temp file if necessary."""
23 if isinstance(in_raster, xr.DataArray):
---> 24 temp_path = Path(
25 tempfile.TemporaryFile(
26 dir=Path.cwd(),
27 prefix='taudem_temp_input',
28 suffix='.tif',
29 ).name
30 )
31 tools.save_raster(
32 in_raster,
33 temp_path,
34 )
35 in_raster = str(temp_path)
File ~/mambaforge/envs/fcpgtools_base/lib/python3.9/pathlib.py:1082, in Path.__new__(cls, *args, **kwargs)
1080 if cls is Path:
1081 cls = WindowsPath if os.name == 'nt' else PosixPath
-> 1082 self = cls._from_parts(args, init=False)
1083 if not self._flavour.is_supported:
1084 raise NotImplementedError("cannot instantiate %r on your system"
1085 % (cls.__name__,))
File ~/mambaforge/envs/fcpgtools_base/lib/python3.9/pathlib.py:707, in PurePath._from_parts(cls, args, init)
702 @classmethod
703 def _from_parts(cls, args, init=True):
704 # We need to call _parse_args on the instance, so as to get the
705 # right flavour.
706 self = object.__new__(cls)
--> 707 drv, root, parts = self._parse_args(args)
708 self._drv = drv
709 self._root = root
File ~/mambaforge/envs/fcpgtools_base/lib/python3.9/pathlib.py:691, in PurePath._parse_args(cls, args)
689 parts += a._parts
690 else:
--> 691 a = os.fspath(a)
692 if isinstance(a, str):
693 # Force-cast str subclasses to str (issue #21127)
694 parts.append(str(a))
TypeError: expected str, bytes or os.PathLike object, not int
This looks like an issue with creating the temporary TauDEM output file.
This returns 72 for some reason.
tempfile.TemporaryFile(
dir=Path.cwd(),
prefix='taudem_temp_input',
suffix='.tif',
).name