r-barnes / faster-unmixer

A faster implementation of the sediment inverse/unmixing scheme proposed in Lipp et al (2021).
5 stars 1 forks source link

Generate 'snap-samples-to-drainage' function #23

Open r-barnes opened 1 year ago

r-barnes commented 1 year ago

@AlexLipp : Are we assuming the user will always be providing:

If so, I think it might be nice to standardize what we expect that data to look like (see #9).

Should we provide a tool of helping users site sample locations or perform some kind of sanity check on the data?

AlexLipp commented 1 year ago

My assumptions are:

  1. Hydrologically conditioned raster. Either as a D8 or a DEM, but in both case the drainage should notionally be 'correct' (more on this here).
  2. Samples at each location.

I think we can't assume that the sample sites align with the drainage raster, so I agree that some tool should be provided that 'snaps' samples onto drainage network. The simplest ones just move samples to the nearest cell with a drainage area greater than some threshold (e.g., one I developed for myself: snap_to_drainage), but we could do something more complicated. If we do implement something, it should certainly have a health-warning and encourage manual checking of the snapping.

Aligning observation sites to drainage networks is actually an issue hydrologists have perennially (e.g. Lindsay et al.) and I don't think there is at present a consistently good way of doing it. There are some implementations in GIS software, but none (as far as I am aware) in python or similar.

AlexLipp commented 1 year ago

@r-barnes Do you think you might be able to implement a snap-to-drainage function in C++ that is callable from python. This would read in the sample-data file and the DEM and align the observation points to the nearest channel node on the DEM greater than a given drainage area threshold (e.g., snap_to_drainage) . It then outputs a sample-data file identical to the original but with updated x and y coordinates. Optionally this could take a manual nudge dictionary ({sample_name: (x_nudge, y_nudge)}, which allows for a user to make sure that each sample aligns with the correct drainage basin.

I am imagining that this would be called first before any analysis, so that when we call get_sample_graphs, the calculated network should be meaningful even in the general case that samples don't align exactly with major channels.

This function would be extremely useful for all sorts of reasons beyond just this project.

r-barnes commented 1 year ago

Sure.

Does the function take a flow accumulation raster as input?

What is there are two rivers in close proximity to a sample point? Should it panic? Might need a little gui?

On Thu, Dec 1, 2022, 13:16 Alex Lipp @.***> wrote:

@r-barnes https://github.com/r-barnes Do you think you might be able to implement a snap-to-drainage function in C++ that is callable from python. This would read in the sample-data file and the DEM and align the observation points to the nearest channel node on the DEM greater than a given drainage area threshold (e.g., snap_to_drainage https://github.com/AlexLipp/autocatchments/blob/main/process_samples.py) . It then outputs a sample-data file identical to the original but with updated x and y coordinates. Optionally this could take a manual nudge dictionary ({sample_name: (x_nudge, y_nudge)}, which allows for a user to make sure that each sample aligns with the correct drainage basin.

I am imagining that this would be called first before any analysis, so that when we call get_sample_graphs, the calculated network should be meaningful even in the general case that samples don't align exactly with major channels.

This function would be extremely useful for all sorts of reasons beyond just this project.

— Reply to this email directly, view it on GitHub https://github.com/r-barnes/faster-unmixer/issues/23#issuecomment-1333756037, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXZHVHGZTJBBNKDIHSWOCTWLCQL3ANCNFSM6AAAAAASJLC4UA . You are receiving this because you were mentioned.Message ID: @.***>

AlexLipp commented 1 year ago

What is there are two rivers in close proximity to a sample point? Should it panic? Might need a little gui?

Yeah, this is the big issue with snapping to DEM. I think something which shows for each sample the a) 'raw' location and b) the proposed snapped location, so that its easy to check if its correct or not. If this is interactive and takes 'nudges' to prompt algorithm to right location that would definitely be useful. I've previously developed scripts which just take a dictionary of nudges, but interactive definitely easier.

Does the function take a flow accumulation raster as input?

We're currently using a D8 .asc file as input. However, we should probably not assume people can calculate this from a DEM. So in which case, can we extend input functions to allow a DEM to be inputted. I will send you the DEM corresponding to the current D8 shortly.

AlexLipp commented 1 year ago

We're currently using a D8 .asc file as input. However, we should probably not assume people can calculate this from a DEM. So in which case, can we extend input functions to allow a DEM to be inputted. I will send you the DEM corresponding to the current D8 shortly.

Actually, lets stick with the flow-direction raster as input for now. We can come back to whether we want to extend to raw DEMs or not later.

AlexLipp commented 1 year ago

We're currently using a D8 .asc file as input. However, we should probably not assume people can calculate this from a DEM. So in which case, can we extend input functions to allow a DEM to be inputted. I will send you the DEM corresponding to the current D8 shortly.

Actually, lets stick with the flow-direction raster as input for now. We can come back to whether we want to extend to raw DEMs or not later.

My thoughts are essentially that a flow-direction raster is a more generic input than a DEM. So, for example, if we did want to extend this as of use to (for example) sewage systems, a function that takes a DEM as input is not immediately useful. Its fairly easy for people to generate a flow-direction raster from a DEM using available tools.