Skip to content

Conversation

@PaulaSp3
Copy link
Contributor

  • take the arguments of function calculation() into dictionaries
  • only compute the numpy arrays that should be output rasters
  • only execute otherwise unneccessary cell - methods (calc_fp_travelangle() and calc_fp_travelangle()) when needed (when the respective outputs are required) (save ~10% of the computation time when fpTravelAngle, sl_TravelAngle and travelLength are not in the outputList
  • think of also simplify the argument for the class Cell using dictionaries -> issue [com4FlowPy]: minor improvements #1062

@PaulaSp3 PaulaSp3 added enhancement New feature or request flowPyDev Ideas for future development labels Jan 23, 2025
@PaulaSp3 PaulaSp3 requested a review from ahuber-bfw January 23, 2025 15:11
@PaulaSp3 PaulaSp3 linked an issue Jan 23, 2025 that may be closed by this pull request
1 task
@pep8speaks
Copy link

pep8speaks commented Jan 23, 2025

Hello @PaulaSp3! Thanks for updating this PR.

Line 623:13: E265 block comment should start with '# '
Line 622:13: E265 block comment should start with '# '
Line 571:121: E501 line too long (121 > 120 characters)
Line 343:121: E501 line too long (121 > 120 characters)

Line 556:11: E127 continuation line over-indented for visual indent
Line 497:121: E501 line too long (128 > 120 characters)

Comment last updated at 2025-01-23 15:17:04 UTC

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit e1979b5 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 0.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 69.0%.

View more on Code Climate.

@qltysh
Copy link
Contributor

qltysh bot commented May 20, 2025

4 new issues

Tool Category Rule Count
qlty Structure Deeply nested control flow (level = 4) 3
qlty Structure Function with high complexity (count = 45): computeSaveTileResults 1

bug

only compute gamma when needed for output

minor changes

pep8
cell.max_gamma)
slTravelAngleArray[cell.rowindex, cell.colindex] = max(slTravelAngleArray[cell.rowindex, cell.colindex],
if 'slTravelAngle' in outputFileList:
if (not cell.is_start):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deeply nested control flow (level = 4) [qlty:nested-control-flow]

cell.sl_gamma)
travelLengthArray[cell.rowindex, cell.colindex] = max(travelLengthArray[cell.rowindex, cell.colindex],
if 'travelLength' in outputFileList:
if (not cell.is_start):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deeply nested control flow (level = 4) [qlty:nested-control-flow]

if processedCells[(cell.rowindex, cell.colindex)] == 1:
countArray[cell.rowindex, cell.colindex] += int(1)
if 'cellCounts' in outputFileList:
if processedCells[(cell.rowindex, cell.colindex)] == 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deeply nested control flow (level = 4) [qlty:nested-control-flow]

Comment on lines +669 to +763
def computeSaveTileResults(outputFileList, results, dem, tempDir, indI, indJ):
"""function computes the output rasters for the processed tile and saves the rasters
in the temporary fodler
Parameters
-----------
outputFileList: list
contains the names of the outputs
results: dict
contains output rasters computed by every CPU core
dem: numpy array
digital elevation model of the processed tile
tempDir: str
path to temporary directory
indI: int
i index of the processed tile (for loading correct data for tiles)
indJ: int
j index of the processed tile (for loading correct data for tiles)
"""

if 'zDelta' in outputFileList:
zDeltaArray = np.zeros_like(dem, dtype=np.float32)
if 'flux' in outputFileList:
fluxArray = np.zeros_like(dem, dtype=np.float32)
if 'cellCounts' in outputFileList:
cellCountsArray = np.zeros_like(dem, dtype=np.int32)
if 'zDeltaSum' in outputFileList:
zDeltaSumArray = np.zeros_like(dem, dtype=np.float32)
if 'routFluxSum' in outputFileList:
routFluxSumArray = np.zeros_like(dem, dtype=np.float32)
if 'depFluxSum' in outputFileList:
depFluxSumArray = np.zeros_like(dem, dtype=np.float32)
if 'backcalc' in outputFileList:
backcalc = np.zeros_like(dem, dtype=np.int32)
if 'fpTravelAngle' in outputFileList:
fpTravelAngleArray = np.zeros_like(dem, dtype=np.float32)
if 'slTravelAngle' in outputFileList:
slTravelAngleArray = np.zeros_like(dem, dtype=np.float32)
if 'travelLength' in outputFileList:
travelLengthArray = np.zeros_like(dem, dtype=np.float32)
if 'forestInteraction' in outputFileList:
forestIntArray = np.ones_like(dem, dtype=np.int32) * -9999

for i in range(len(results)):
res = results[i]
if 'zDelta' in outputFileList:
zDeltaArray = np.maximum(zDeltaArray, res['zDelta'])
if 'flux' in outputFileList:
fluxArray = np.maximum(fluxArray, res['flux'])
if 'cellCounts' in outputFileList:
cellCountsArray += res['cellCounts']
if 'zDeltaSum' in outputFileList:
zDeltaSumArray += res['zDeltaSum']
if 'backcalc' in outputFileList:
backcalc = np.maximum(backcalc, res['backcalc'])
if 'fpTravelAngle' in outputFileList:
fpTravelAngleArray = np.maximum(fpTravelAngleArray, res['fpTravelAngle'])
if 'slTravelAngle' in outputFileList:
slTravelAngleArray = np.maximum(slTravelAngleArray, res['slTravelAngle'])
if 'travelLength' in outputFileList:
travelLengthArray = np.maximum(travelLengthArray, res['travelLength'])
if 'routFluxSum' in outputFileList:
routFluxSumArray += res['routFluxSum']
if 'depFluxSum' in outputFileList:
depFluxSumArray += res['depFluxSum']
if 'forestInteraction' in outputFileList:
forestIntArray = np.where((forestIntArray >= 0) & (res['forestInteraction'] >= 0),
np.minimum(forestIntArray, res['forestInteraction']),
np.maximum(forestIntArray, res['forestInteraction']))

logging.info("Calculation finished, getting results.")

# Save Calculated tiles
if 'zDelta' in outputFileList:
np.save(tempDir / ("res_z_delta_%s_%s" % (indI, indJ)), zDeltaArray)
if 'zDeltaSum' in outputFileList:
np.save(tempDir / ("res_z_delta_sum_%s_%s" % (indI, indJ)), zDeltaSumArray)
if 'routFluxSum' in outputFileList:
np.save(tempDir / ("res_rout_flux_sum_%s_%s" % (indI, indJ)), routFluxSumArray)
if 'depFluxSum' in outputFileList:
np.save(tempDir / ("res_dep_flux_sum_%s_%s" % (indI, indJ)), depFluxSumArray)
if 'flux' in outputFileList:
np.save(tempDir / ("res_flux_%s_%s" % (indI, indJ)), fluxArray)
if 'cellCounts' in outputFileList:
np.save(tempDir / ("res_count_%s_%s" % (indI, indJ)), cellCountsArray)
if 'fpTravelAngle' in outputFileList:
np.save(tempDir / ("res_fp_%s_%s" % (indI, indJ)), fpTravelAngleArray)
if 'slTravelAngle' in outputFileList:
np.save(tempDir / ("res_sl_%s_%s" % (indI, indJ)), slTravelAngleArray)
if 'travelLength' in outputFileList:
np.save(tempDir / ("res_travel_length_%s_%s" % (indI, indJ)), travelLengthArray)
if 'backcalc' in outputFileList:
np.save(tempDir / ("res_backcalc_%s_%s" % (indI, indJ)), backcalc)
if 'forestInteraction' in outputFileList:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with high complexity (count = 45): computeSaveTileResults [qlty:function-complexity]

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

Labels

enhancement New feature or request flowPyDev Ideas for future development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[com4FlowPy]: Selective calculation of Model Output Rasters

4 participants