Menu Close

Python Libraries?

Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #4003
    Taylor MutchTaylor Mutch
    Participant

    Hi All,

    Lots of great progress working with ST-Sim linux tools. Has there been any work towards exposing that functionality as either Python or C#? While working with the command line is great for on-the-fly reports and model runs, it would be nice to have some ability to programmatically do the same.

    If not, I could possibly work out wrapping the functionality in Python or some language. Just wanted to see if there has been any work in this area before forging forward.

    Cheers,

    Taylor

    #4005
    colin-danielcolin-daniel
    Keymaster

    Hi Taylor – good question about working with Python. We have in fact begun developing a pair of packages for interacting with ST-Sim – our plan is to develop a package for each of Python and R. Our initial focus will be on post-processing output, but we will eventually be adding a full suite of functionality for setting up and running models also. We are hoping to have a first version of at least one of these packages by the end of the calendar year – which language will come first is still a matter of debate!

    For now my suggestion would be for you to wrap your command-line calls in whatever language you prefer – Python or R would be my suggestion, as then you might be able to take advantage of the packages once they come online. The more people we have working in these 2 languages, the better! We have others doing the same – both in Python and R – and it is these initial scripts that are forming the basis for our packages. If you are interested in sharing your scripts at some point – or even what functionality you are interested in – then it could possibly help us shape the direction and scope of the initial package – we are always interested in learning what features and functionality are important to others.

    Regards, Colin.

    #4006
    Taylor MutchTaylor Mutch
    Participant

    Hi Colin,

    That is excellent news! By nature of my question I am personally leaning Python (though R is also known to me), and I have begun to do the command-line calls using Python 3.5 and the subprocess module.

    One thing that we are really finding useful is the ability to set the initial conditions based on user input from our web interface. For example, we are allowing the user to adjust the percent cover of a given state class for a vegetation type, and we are planning to let the user have a scaler/slider that adjusts existing probabilistic transitions (e.x. fire, grazing) and run the model based on these new values to gather differences between different model runs. Currently this involves writing out to a .csv and then importing that as a sheet (e.x. importing into --import --sheet=STSim_InitialConditionsNonSpatialDistribution --file=path/to/myfile.csv --sid=123). While this isn’t an awful way to go at it by no means, it would be nice to have some sort of interface to say 1) grab each row, 2) list those values, and 3) update each value in that row at runtime. This could be treated as a python object that gets updated by the program and then applied back to the library, does some sanity checking to make sure that the vegetation and stateclass values are valid from the project definitions, and then executes the transaction change.

    Extracting out the transitional and deterministic pathways as a connected graph data structure would also be useful, since the visualization we are developing is attempting to illustrate the change from one state class to another within the vegetation type, since we can use the quantity transitioned specified in the transition-stateclass-summary report to symbolize the change from one to another along a given transition pathway (e.x. showing fire when a portion of the landscape transitions due to fire).

    These are just two things that come to mind directly.

    Thoughts on either of these?

    Cheers,
    Taylor

    #4007
    Taylor MutchTaylor Mutch
    Participant

    On such a note, I have thrown together what I have into a simple, one file module, available at https://github.com/TaylorMutch/stsimpy.

    #4008
    colin-danielcolin-daniel
    Keymaster

    Very cool – nice start on the module!

    Our plan with the packages is to simplify the interaction with ST-Sim model inputs so as to avoid intermediate CSV files – pretty much as you suggest for the initial conditions. Same would be true for outputs. As for the connected graph, that’s not something we’ve ever come across before – perhaps at some point you could show us an example of how you use this? Colin

    #4009
    Taylor MutchTaylor Mutch
    Participant

    It would be awesome if we could avoid intermediate CSV files. I have planned for the time being to work around the file creation by having a temp file to export out to, read that file into a csv.DictReader object, do the changes in memory, write on top of the file with csv.DictWriter, import back in to the same sheet and then cleanup/remove the file. The trick will be doing that for a given set of users, and I haven’t been tried having SyncroSim run with multiple instances/jobs on Linux yet, but that is something I plan on trying to test out.

    I also updated the module with some changes (mainly internalizing the static functions I had into the classes by simplifying the code).

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.