-
Notifications
You must be signed in to change notification settings - Fork 5
[com4]: Select raster computation depending on output files #1075
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
base: master
Are you sure you want to change the base?
Conversation
|
Hello @PaulaSp3! Thanks for updating this PR.
Comment last updated at 2025-01-23 15:17:04 UTC |
|
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. |
4 new issues
|
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cell.sl_gamma) | ||
| travelLengthArray[cell.rowindex, cell.colindex] = max(travelLengthArray[cell.rowindex, cell.colindex], | ||
| if 'travelLength' in outputFileList: | ||
| if (not cell.is_start): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calculation()into dictionariescalc_fp_travelangle()andcalc_fp_travelangle()) when needed (when the respective outputs are required) (save ~10% of the computation time whenfpTravelAngle,sl_TravelAngleandtravelLengthare not in theoutputListclass Cellusing dictionaries -> issue [com4FlowPy]: minor improvements #1062