Skip to content

(3) MegaStratBuilder.ipynb ReadME

salpheus edited this page Aug 18, 2022 · 4 revisions

This is a how-to/why-i-did/wtf/references guide to the MegaStratBuilder code (MSB). Caveat, I wrote this code when I began learning to use Python so it's not most efficient but THAT'S OKAY because if it ain't broke...

It is called MSB because it is MEGA but there are a couple of key components:-

The main draw of this code is that it houses the components to interpret cross-stream and down stream sections, you just have to declare it. This code works by importing the full grids from NAYS2DH as a NumPy array and pulling out the model results for a specified location. It basically functions in 3 parts:

  1. Data import
  2. Plotting
  3. Exports and some preliminary statistics

3.1. Data Import

MSB imports the converted array file from ConvertFiles.ipynb, this creates an array called datamaster. You must declate first whether you want to plot cross-sections or streamwise sections from the data using the flags 'XS' or 'DWN'. After this, there are a couple of inputs like the cross section location iloc, streamwise section location jloc (for this just use 0, wither its cross-stream or streamwise).

Digression--I haven't quite figured out how to get other streamwise sections from the dataset but I think streamwise section in the model domain that is always within the channel should work (technically any value between -40 and 40, but I haven't had time to test this as of yet).

After you declare the section you want, the code sorts and removes all of the other data from the datamaster.

Now, because NAYS2DH uses a curvilinear grid with boundary-fitted co-ordinates, the gridding system vs x-y location indexing gets weird as the bank widens and narrows during the model run. To account for this, all of the bed data (topography, depth, shearstress etc) is projected onto an array that is number-of-timesteps long (axis = 0) x maximum-cross-section-width-during-the-model-run wide * spacing, e.g. if datamaster covers 500 timesteps, and the iloc section being build widens to a max width of 200m wide with a spacing = 1m, MSB will produce a 500 x 200 array of NaNs and at each timestep. In this way, all of the columns are positions along the cross-section, and for every timestep (axis = 0) MSB will infill this array of NaNs at the column index equivalent to the true XS-position (metres) in the grid, if it were in XY space and not grid space. Makes sense? After it does this, it will interpolate across all of the NaN values for each timestep to give us a 'denser' grid of more continuous data to work with. This is done for all desired output variables (typically shear stress, depth, flow velocity.

The process for building streamwise sections is similar, except since the domain is so large, we must define a sub-reach over which we want to look at the streamwise sections. This is done by making a 2D mesh interpolation over the bed at every timestep, and can take a while to run. In my experience, anything that is <1000m long will run in a decent amount of time (couple of minutes for 400 timesteps). Then it does the same 1D interpolation thing as for the cross-sections.

Creating age and erosion surfaces

MSB builds arrays of erosion and hiatal surfaces by user-set rules for erosion and hiatuses. There are three erosion/hiatal scenarios:

  1. SCENARIO 1: Hiatus = any elevation change that is less than x cm
  2. SCENARIO 2: Hiatus = any elevation change that is less than x % of the average elevation change
  3. SCENARIO 3: Hiatus = any elevation change that is less than the xth percentile of change at the timestep

With this, the code searches the bed elevation array below every each x-location at each timestep for elevations higher than (or meeting the erosion rules set) and replaces that elevation with the elevation at the current timestep. This is done for all timesteps. The model also creates arrays of only erosion, erosion and hiatal, and deposition surfaces (with only ero, ero-hiat or dep topography stored and NaNs otherwise).


3.2. Plotting

You can plot a range of things, I'm not going to explain this here, it's general matplotlib plotting stuff. Have questions? Email me or add a comment.


3.3. Calculating other fun stuff

Pseudofacies

I calculate 'pseudofacies' in the model using bedform stability diagrams. In Chamberlin and Hajek (2019), they define upper and lower bar facies by some geometric features, the distribution of bedforms seen in each. Upper bar facies are characterised by generally low shear stress stable bedforms--lower-stage plane beds, ripples, and lower bar facies as high-shear stress stable bedforms--dunes, upper stage plane beds.

Using the bedform stability diagrams of Van Rijn and Van Gelder (1993), MSB computes the mobility parameter mmp across the model stratigraphy using the local flow depth and velocity conditions for each point along the bed, at each timestep. The mmp is then binned using the Van Rijn and Van Gelder (1993) bins for no movement, lower stage plane bedding, dunes, and upper stage plane bedding defined for the specific model grain size.

Wheeler Diagrams

MSB also produces Wheeler diagrams for the sections. This is done for each depositional package (currently at the resolution of the datamaster but can be expanded if desired). These Wheelers can be viewed in time, or elevation change (and probably other things too if you want).

Package Statistics

The depositional packages can also be used to get statistics that give more detail about how the bed and bars develop (growth trajectory, hop length of packages of sediment, geometry etc). And there's heaps of other stuff too.

Widening trends

There is some rough widening trend work that can be done in the section. To be able to run this part of the code you need to have run the StratBuilder_buildchannelwidth.ipynb to extract the channel width data.


If you want to map bars and get more detailed statistics (in bulk), you have to use BPick_fnl.ipynb


3.4. Extracting main (highest order) bounding surfaces

For package-scale, automated analysis

The final component of MSB is a semi-automated component for extracting the main bounding surfaces, I had to make this bc the erosional surface array has NaNs at locations where there is no erosion or depositional hiatus so there isn't a 'complete' surface.

(tl;dr) Skip to the 5th paragraph for the code logic, paragraphs 1-5 are sort of an amuse-bouche:

Okay, I spent a lot of time tinkering with different methods of picking out the most pervasive/prominent/erosive/longest non-depositional surfaces in the stratigraphy and it feels immensely complicated. I've tried multiple methods that are equally shitty, but some have their own advantages.

In an ideal case, I'd be able to plot out entire, through-going and complete surfaces at each timestep that repesent the major bounding surfaces in the stratigraphy after the end of the entire model run. I have, to this date, never seen this done in a paper. The closest to this was the extracion of surfaces of erosion in Wietse Van de Lageweg's dissertation (Chapter 5, van De Lageweg et al., 2016--Sedimentology). Being able to pull out these surfaces is important because they are likely the best corollary to what we'd map in the field, so naturally, we would want to compare the model stratigraphy at this similar scale.

The problem I'm having is that I only have snippets of locations of erosion and non-deposition that do not make complete surfaces on the plots, ergo I cannot create polygons (read: bar packages) to get various statistics from the model stratigraphy.

In an ideal case I would be able to plot all the piecemeal erosion and hiatal surfaces on a plot that is technically 3D (x-y-time) as I plotted it using a for loop then flatten the plot onto only the x-y dimension, then I would have essentially a polyline (I think, idk what a polyline is tbh, but essentially I'd have a complex shape made up of multiple polygons..maybe I'll have a muiltipolygon idk) that I can analyse for package sttaistics. There are two problems with this approach:

  1. I do not know how to do that, and I worry that the exercise in figuring it out will literally take all of the power my two brain cells possess and take forever because I ain't no coder and have yet to find a comp scientist that can help with this problem in a helpful way.

  2. This mightn't even be beneficial because then we will have the same problem of assessing the universiality of image based statistical approaches to building statistics like this (re Ellen and Liz stick model avulsion problems with relating model space to field space).

With this in mind, I am trying to adopt a vector-based, pseudo-statistical approach to figure put exactly which surfaces will statistically get preserved in outcrop.

The final approach-- So, right now I'm using (today is Feb 5th 2021 btw) a 'proportion of bed surface reworked' type approach to find the main erosional and hiatal surfaces in the stratigraphy. The fundamental tenet here is that the most 'boundy' bounding surfaces will be be surfaces that have had the longest times of non-deposition or the most erosion, ie. I'm assuming that the stratigraphy is made up of deposition along the most active reworking surfaces.

So the method I employ to do this is to find the sum of locations across the section, at each timestep, that undergo hiatal or erosion events and represent that as the fraction of the bed that is reworked. Then, I find, from the distribution of these fractions, the nth percentile, my threshold for what is major vs minor. To check to find which percentile is the 'best' percentile, I have a nifty little loop that basically tests the stratigraphy/main surfaces output at each percentile against the true erohiatalsurf array for similarity.

My rule for similarity is as follows: the percentiles that produce the best stratigraphy will be the percentiles where (1) as many unique elevation points are incorporated into the bounding surface array as possible and (2) as little true erosion data are deleted. This 2nd rule requires then, that the number of elements in the bounding surface array cannot be less than the number of elements in the erohiatal array, which is why, as you'll see, the percentile value is so low-I'm leaving in a lot of extra stratigraphy to make sure that this statistical stratigraphy I develop is as faithful to the actual erohiatal data as possible.

As you'll see, we end up with a lot of extra surfaces that are likely unresolveable in the field, much like the hiatal situation. I think it's fair to say that for a 100m wide outcrop, we will not be able to resolve bars/mar kinematics that are less than ~2cm thickness, so I removed any surface that aggrades by less than that, kind of like how those folks remove surfaces for dunes...maybe this is something worth checking out. I think the Van Rijn literature cites that the scaling/removal relationship for sub-bar scale topography is 0.3 x flowdepth dune scale)...what I'm getting at is that for my ~0.8m flow depths, removing 2cm of topography is a non-issue.

As you will see, this method produces a very nice estimation of the EH stratigraphy, with much of the small scale topography removed. I think, for my efforts and the value of this piece, this method will suffice and I am moving on to statistics headaches.