 Right well thanks for having me today and I'm happy to demonstrate my experience with CSDMS modeling framework and and the BMI. A few years ago we got a small chunk of money to to do sort of a demonstration product of wrapping a USGS model around with the BMI and you know at the time when we started this the USGS has a lot of different models that are all basically built around some domain whether it's a watershed domain as in the example I'm going to show today or mod flow is ground water domain there's lots of surface water hydraulic models that are available but none of them had really been integrated and using a common framework and so part of the the interest in working on this project was to really just experiment with the CSDMS modeling framework and and the BMI so what we did is we started with PRMS which is a precipitation runoff modeling system it's a watershed scale model and we decided to break PRMS into four components surface component a soil component a groundwater and stream flow component basically wrapped around sort of each of these reservoirs the surface reservoir soil reservoir groundwater reservoir and stream flow with the intention of ultimately using the surface and soil components to integrate with the mod flow BMI in the future and that's been done so what I'm going to demonstrate today are our our PM PRMS components the other thing we did is we wrapped the BMI around gridbed so the main model inputs to PRMS other than constituent parameters like soil parameters and things like that the model is driven by climate weather and we use grid met which is a cone of scale set of climate forcings minimum and maximum temperature and precipitation these are delivered at four kilometer scale daily so every day this data set is updated through yesterday so we also wanted to look at driving model components with data components so I'll also give an example of that and hopefully this will follow on nicely from from Eric's whoops Eric's demo so what I'm going to show is a is a coupling of PRMS model we're going to look at sort of a small demonstration application we're going to look at a small watershed in the prairie pothole region of North Dakota PRMS is a little bit different it it isn't grid based it's based on hydrologic response units so we're going to look at this small footprint here and that small footprint is composed of 14 hydrologic response units around this main pipe stem creek here and I'm going to be showing some plots uh as a function of time of the values of each of these HRUs um in this spatial footprint so you you will see uh this footprint displayed in plots where each HRU has a different value for example the temperature in HRU 12 or the precipitation rate in HRU 12 and I'll also show some plots that show basically the the footprint of pipe stem creek and values of the stream flow on pipe stem creek um that'll become clearer later but just so when you see the plot you understand that we're looking at this watershed footprint and that watershed is delineated into 14 hydrologic response units and the pipe stem creek here I think has seven different stream segments and please don't hesitate to ask any questions along the way here I'll now increase the size of this hopefully everybody can see that well so I'm gonna I'm gonna run this interactive notebook um the first thing to note here is that we're importing these uh these modeling components from pi empty models we're gonna look at the surface soil groundwater and stream flow PRMS components um I have grid met here actually that shouldn't be here but it'll be okay um I'll explain that again later and because I want to plot our model results on these HRUs I'm gonna load a shape file of those HRUs so we can plot to them this is something outside of pi empty just so you know and then I'm gonna initialize our four components so um we've got a run directory and then for each component we have an input file and um you said I think you were asking about net cdf I mean just for example these input files do have net cdf files that they're reading um that's one thing and the other thing is the grid met data is actually delivered as a net cdf file and we're gonna extract that data from the net cdf file and feed it to the model later and I'll I'll show that more detail later so here we're gonna initialize our bmi's using the initialize method here I've just got some helper methods that that basically use those shape files and put them into a geopandas data frame so that we can use them for plotting and and that's all this is doing and also we're the model is using initially this day met data set for its climate data so I just read that net cdf file into another geodata frame and we're just plotting tmax team in and presip for a given time period on those HRUs so again here's that footprint of the watershed and each of the HRUs has a different value that's delineated by different color so I want to run this model and look at the output and to find a period of time where that output might be interesting I simply just looked at the climate data and looked at precipitation and we're going to look at model results following each of these two periods of precipitation so that the output shows something interesting and again we're just using the plymt bmi methods showing this is this is now time is a prms variable so it's returning the time the start of the model 1980 January 1st it's also showing the end time this is in days so we're going to the model is going to run for a total of 731 days now there's a lot in here this is this is basically I set up a bunch of lists of variables for each component that we're going to use to transfer data from the surface component to the soil component to the groundwater component to the stream flow component and so I just set up these sort of transfer functions and really the thing to see here is that I'm using the set and get value functions to transfer information from one model component to another so for example in transferring surface values to soil here I'm using the get and set values for each of those so it's just going to loop through those lists and get all the values for each one of those parameters and transfer them to the other model so this is really in essence the coupling of each of those four components together and then what I did is I sort of made a master update so it's calling the update method on each one of the components and doing the transfer of information from one component to another in between the updates so I won't you won't see the update method as I'm running the model you'll just see this update coupled but you understand that we're using the update method of the BMI in the background there does that make sense to people yeah sorry real quick so when you update coupled is is it important or sensitive like which of those components you run and update in which order or could you theoretically just run them kind of in any order as long as you're consistent between time steps in this case it is important the order because we're we're sort of transferring information down through the system from the surface to the soil to the groundwater and ultimately to the stream flow so yeah it in this case it does make a difference okay I'm just gonna run it for 455 days to basically get it up to the point where we want to look at a specific precipitation event again this is running that update coupled so we're running the update methods in the background there and now I'm going to run it for seven days and we'll just plot the results and take a look and I've got some helper functions to do these plots in the background here and all the code for those is available in that repo again this PRMS is slightly different from your typical model it's not grid-based so we don't have the capability of using the the plotting routines that are available immediately available in PMT but it's not a big deal so again this is just we've just moved the model ahead seven days and time and I'm just plotting T max pre-sip soil moisture the amount of moisture available in the soil reservoir the surface runoff the subsurface reservoir flow groundwater reservoir flow and segment outflow so again this is this is looking at a footprint of the pipe stem creek and it's colored according to the discharge in each one of the stream segments of this creek so you can see as pre-sip falls on the surface you get runoff and that runoff goes to the stream and increases the flow in the stream it's basically what that's showing oops I didn't mean to run that again sorry now because I ran that again I may really mess up my my order here let's see what happens okay then I'm going to run it for another period of time except this time instead of using the input files which contain that day met data which is being used to drive the climate forcing in the model I'm going to use this grid met component that I wrote and what this component does is it fetches the net cdf climate data from a thread server that net cdf climate data is grid based in order to interpolate that onto the polygons of each hru we do an area weighted mapping so this function is going to go out and in real time here fetch the net cdf data from the thread server and map that data to the hru of this model and then feed that data to the values of precipitation t max and t min so it's kind of a cool way you know there's a lot of work that goes into going out and fetching model input data and formatting it into files and and here we're we're doing that in real time by using a data component to couple to our model and that's the first time that's failed okay I'm sorry I'm going to restart this yeah the reason why that failed is because I reran that one cell with the update method and so I think what happened is our dates got out of step here the dates I have in here for a specific period of time that were matched to where we were in the model runtime okay so again here I've used this grid met data component and I'm pulling preset t max and t min out of that data component using the set value to assign the value to the model at runtime and again it does a nice job so now in this next step what I'm going to do is yeah I'm just going to override the input of precipitation and I'm going to specify a constant value of three in this case inches of precipitation over a watershed over one of the hru's which is a lot of precipitation for a day in an hru and just look at the response and really one of the things we thought when we first started working with csdms and the bmi is at a minimum it's relatively low cost to wrap individual models with the bmi and it would be a great way to sort of investigate different potential model couplings and and also um something like this was never available when I first started modeling I mean it was really hard one to run a model one time step at a time but this is also a great way just to build to develop intuition about your model so here we're just kicking our model in the butt at one hru with a bunch of precipitation and looking at the response so again I I hit this hru with a giant amount of precipitation and we can look at its response with time you know all the way to surface runoff subsurface flow groundwater reserve flow all of those are contributing to the stream flow and you can see that in the increase in stream flow as a function of time from this one event and then the amount of soil moisture decays with time as there's no more input precipitation and you can see that the groundwater reservoir actually starts to get more and more flow as you as you progress in time so that's what that looks like and then we can also view that in a more simple way just by looking at an hru and looking at each one of those functions each one of the responses of of different parameters as a function of time so soil moisture you know just decays with time surface runoff you get a bunch in the first time step and then it turns off the subsurface reservoir decays groundwater reservoir gets more flow as a function of time and then here's the stream flow responding to that one event on then finally just to shut down the model we'll use the finalize method so that's that's what I have to show does anybody have any questions I just say you know I'm an old gray haired guy the other thing to note is this was an existing Fortran model that we wrapped with the BMI so it was an older model component and we wrapped it with the BMI which made it available as a python component and that is totally cool and I really have to say that that working on this project was one of the funnest things I've done in my my career and if you guys are model developers or model users especially if you're model developers I'd really consider using the BMI as a template which to build your model from the ground up I think it will help you in the long run to a great extent so