Skip to content

Conversation

@PaulaSp3
Copy link
Contributor

@PaulaSp3 PaulaSp3 commented Jan 28, 2026

runC2TopRunDF.pyexecutes pyTopRunDF for one scenario.

The file TopRunDF.py is modified, batch_select_process.py is not used here (since a run of multiple scenarios is not enabled yet), the other files are directly used from the pyTopRunDF repository. The pyTopRunDF repository is integrated via a submodule into c2TopRunDF/pyTopRunDF, from where the original scripts are executed.

The modification of TopRunDF.py enables more consistency with the AvaFrame/DebrisFrame configuration and input handling:

  • a different handling with input parameters: we use an c2TopRunDFCfg.ini file instead of a .json file (including a different location!)
  • Input data (the DEM) is located in avalanchedir/Inputs, the avalanchedir is defined in debrisframe.ini (or local_debrisframe.ini) instead of Scenarios/Scenario_{num}
  • Output data are saved in avalanchedir/Outputs instead of Outputs/Scenario_{num}

Adding a global seed to the random functions yields the same result as that computed with the original code (with the same seed) for Scenario_1 (in pyTopRunDF repository.

Documentation ends up here:
https://docs.debrisframe.org/en/ps_toprundf/installation.html

@PaulaSp3 PaulaSp3 self-assigned this Jan 28, 2026
@PaulaSp3 PaulaSp3 linked an issue Jan 28, 2026 that may be closed by this pull request
7 tasks
@PaulaSp3 PaulaSp3 added the enhancement New feature or request label Jan 28, 2026
@qltysh
Copy link
Contributor

qltysh bot commented Jan 28, 2026

❌ 1 blocking issue (3 total)

Tool Category Rule Count
ruff Lint pytest imported but unused 1
qlty Structure Function with high complexity (count = 40): c2TopRunDFMain 1
qlty Structure Deeply nested control flow (level = 4) 1

area += 1
else:
mcs += 1
position = [row, col]
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]


plotter = HillshadePlotter()

# Generate the plot
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 = 40): c2TopRunDFMain [qlty:function-complexity]

@qltysh
Copy link
Contributor

qltysh bot commented Jan 28, 2026

Qlty

Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (1)

RatingFile% DiffUncovered Line #s
New file Coverage rating: A
debrisframe/tests/test_c2TopRunDF.py100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@PaulaSp3 PaulaSp3 requested a review from fso42 January 29, 2026 08:12
import configparser
import pathlib
import shutil
import pytest
Copy link
Contributor

Choose a reason for hiding this comment

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

pytest imported but unused [ruff:F401]

Copy link
Contributor

@fso42 fso42 left a comment

Choose a reason for hiding this comment

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

Please add an init.py in c2


artificial_height = cfgDebris["GENERAL"]["energyHeight"]
if artificial_height == "elevation":
artificial_raster_height = rasterio.open(output_dir / "elevation.asc")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is never closed. Either use with or explicitly close it

# Open the DEM file
# Preprocess the DEM file if necessary
processed_dem_file = preprocess_raster(dem_file)
dataset = rasterio.open(processed_dem_file)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

# Clean up the temporary file if preprocessing was done
if processed_dem_file != dem_file:
processed_dem_file.unlink() # Deletes the temporary file
fin = "finished"
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the if seen to be dead code? fin is alway finished?

max_val = np.amax(band3)
band3 = band3 / max_val
meanh = volume / perimeter
band4 = band3 * meanh
Copy link
Contributor

Choose a reason for hiding this comment

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

This is overwritten 5 lines down without ever being used. Is this intentional?

position = [row, col]
band2.fill(0)

band3[0, 0] = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

mcsmax = 500

# Flowpath simulation
for x in range(0, 100000):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this value go to ini?

band3 = np.copy(band)
band3.fill(0)
area = 0
mcsmax = 500
Copy link
Contributor

Choose a reason for hiding this comment

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

Value for ini?

# significant over longer distances. A smaller denominator causes faster decay, meaning
# the decay factor approaches zero more quickly.
distance = np.sqrt((position[0] - row) ** 2 + (position[1] - col) ** 2)
decay_factor = np.exp(-distance / 100) # Example decay factor with denominantor=100
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, controlable via ini?

# and distribute them more evenly. It simulates the physical process of diffusion,
# in which material or energy moves from areas of high concentration to areas of low
# concentration.
kernel = np.array([[0.05, 0.1, 0.05],
Copy link
Contributor

Choose a reason for hiding this comment

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

Values for ini?

and edit ``local_debrisframeCfg.ini`` with your favorite text editor and adjust the variable
``avalancheDir`` for example to ``data/debrisTopRun``, then run::

python runC2ToprunDF.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: TopRun instead of Toprun

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants