Implement first order non-conservative processes between nodes#17
Open
Implement first order non-conservative processes between nodes#17
Conversation
…rather than # of nodes
… sample network networkx DiGraph
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request implements support for first-order non-conservative tracer decay processes between nodes in drainage networks. The PR introduces exponential decay modeling using the formula C₀ exp(-kx), where k is a rate constant and x is the hydrographical distance between nodes.
Changes:
- Extracts and stores hydrographical distances between nodes as edge metadata from D8 raster processing
- Modifies optimization and forward model to include exponential decay terms based on user-provided rate constants
- Updates test suite to verify both conservative (k=0) and non-conservative (0 < k < 3) behavior
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| tests/random_networks_test.py | Adds rate constant parameters to test functions and generates test networks with edge lengths |
| funmixer/network_unmixer.py | Implements rate constant handling in unmixer, forward model, and supporting functions with exponential decay weighting |
| funmixer/flow_acc_cfuncs.pyx | Adds distance calculation between nodes using D8 directions and updates area calculations to use physical units |
| funmixer/d8processing.py | Adds properties for cell sizes and passes D8 array with cell dimensions to graph builder |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…o downstreamdistance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the ability for funmixer to simulate first order decay processes modifying tracer concentrations between sample sites on a drainage network. If we consider that the hydrographical (i.e., along flow-path) distance between two nodes on the sample network is$x$ , and assuming that some tracer is removed as a function of distance according to: $\frac{dC}{dx} = -k$ then the contribution from the upstream node to the downstream node is best described by: $C_0 \exp(-kx)$ , where $C_0$ is the contribution from the upstream node.
This PR implements this by making the following changes:
lengthon thenetworkxsample network (seed8_processing.py,flow_acc_cfuncs.pyx)To consider non-conservative processes, the user simply has to provide a dictionary mapping sample names onto a rate constant. These rate constants apply to the edge downstream of that node. Different rate constants can be set across the entire study area. If$k=0$ are assumed, which recovers the initial non-conservative behaviour.
rate_constantsis not supplied, default values ofNotes
floatCoPilot Summary
This pull request introduces support for first-order (exponential decay) rate constants in the sample network unmixing workflow, enabling modeling of non-conservative tracer behavior along drainage networks. It also improves the handling of spatial information in the D8 flow direction raster, including accurate calculation of distances between nodes and sub-basin areas. The most important changes are grouped below:
Support for First-Order Rate Constants in Network Unmixer:
my_rate_constantattribute to theSampleNodeclass and corresponding handling in theSampleNetworkUnmixer, allowing each sub-basin/reach to have an associated decay rate constant. The rate constants are now used to weight tracer fluxes between nodes using the exponential decay law._set_rate_constantsmethod toSampleNetworkUnmixerto initialize and manage rate constants for each site, with validation and support for user input. The constructor andsolve_montecarlonow acceptrate_constantsas an argument.Improvements to D8 Raster Handling and Sample Graph Construction:
flow_acc_cfuncs.pyx) and Python interface to pass cell sizes (dx,dy) and the D8 flow direction array to the sample graph builder. This enables accurate calculation of distances between nodes and sub-basin areas in physical units.distance_downstreamand using it as edge metadata in the network.dx * dy) instead of pixel counts, and added validation to ensure the total upstream area matches expectations.Documentation and Type Improvements:
SampleNodeto clarify all attributes, including new ones related to rate constants and distances.RateConstantDatatype alias for clarity.