I have written a Python script which models an academic problem which I wish to publish. I will put the source on Github and some academics that just happen to know Python may get my source and play with it themselves. However there are probably more academics that may be interested in the model but that are not python programmers and I would like them to be able to run my model too. Even though they are not programmers they could at least try out editing the values of some of the parameters to see how that affects the results. So now my question is how could I arrange for a non-python programmer to run a Python program as easily (for them) as possible. I would guess that my options may be...
google colab
an online python compiler like this one
compiling the program into an exe (and letting the user set parameters via a config file)
something else?
So now a couple of complications that makes my problem trickier.
The output of the program is graphical and uses matplotlib. As I understand it, the utilities that turn python scripts into exe files struggle or fail altogether when it comes to matplotlib.
The source is split into two separate files, one small neat file which contains the model and the user might like to have a good look at it and get the gist of it even if they're not really a python programmer. And a separate large ugly file which just handles the graphics - an academic would have no interest in this and I'd like to spare them the gory details.
EDIT: I did ask a related question here - but that was all about programmers that won't mind doing things like installing python and using pip... this question is in relation to non-programmers who would not be comfortable doing things like that.
Colab can handle the 2 problems, but you may need to adapt some code.
Matplotlib interface: Colab can display plots just fine. But you may want user to interact with slider, checkbox, dropdown menu. Then, you need to use Colab's own Form UI, or pywidgets. See an example here
2 separate python files: you can convert one of them to a notebook. Then import the other. Or you can create a new notebook that import both files. Here's an example.
Related
I am trying to create a simple way to add new keywords into PocketSphinx. The idea is to have a temporary text file that can be used to (via a script) add a word (or phrase) automatically added to the corpus.txt, dictionary.dic and language_model.lm.
Currently the best way to do this seems to be to use lmtool and then replace the aforementioned files with the updated versions. However this presents three problems:
Lmtool is slow for large libraries, so the process will become exponentially slower as more words are added.
Lmtool requires a semi-reliable internet connection to work and I'd like to be able to add commands while offline.
This is not the most efficient way to add commands, and won't work with the setup I'm putting together.
What I'd like to be able to do is to (if possible) use/create an offline version of lmtool that takes inputs from a temporary text file (input.txt) processes them and prints the contents into three temporary text files (dic.txt, lm.txt, corp.txt).
The last step would be to run a script that will:
Take the output in corp.txt and add it to the end of corpus.txt.
Look through dictionary.dic and add any new words in dic.txt.
Somehow modify language_model.lm to include the new terms in lm.txt.
Erase the contents of the three output files.
My question is if it is possible to get an offline version of lmtool that is capable of outputting results into specific text files? I know it is possible to automate lmtool (according to their site), but I would like to be able to run the process offline if possible.
Also, has anyone attempted something like this before that I can use as a guide?
I am running pocketsphinx on a raspberry pi and I am aware that it will likely not be able to run lmtool on it's own. My plan is to have lmtool run on a local server and sync files with the pi via wifi/ethernet.
Any help would be appreciated.
You have few choice, If you want to generate dict and language model locally on Raspberry Pi (Model 2B at least)
For Language Model generation, you can use either
CMUCLMTK or
SRILM (SRI Language Modeling Toolkit)
To compile SRILM on Raspbian you need to tweak some files.
Take a look here https://github.com/G10DRAS/SRILM-on-RaspberryPi
For dictionary generation, you can use either
Phonetisaurus with G2P Model available here (or you can generate FST by yourself using phonetisaurus-cmudict-split), or
g2p-seq2seq (Sequence-to-Sequence G2P toolkit)
g2p-seq2seq based on TensorFlow which is not officially supported on RaspberryPi. For more details see Installing TensorFlow on Raspberry Pi 3
For more details (usage, how to compile etc....) please go through the documents of respective toolkit.
I'm exploring 2D interpolations for the purpose of writing a script in Python. I've been using the PIL (Pillow) modules to quickly display the results of the algorithms - this is best for cases when interactive input isn't necessary (i.e. testing on a random set of points).
For interactive testing I've found jsfiddle to be the most lightweight solution, but I admit it isn't ideal to rewrite functions in another language merely to be able to move points around, and input specific shapes of quads.
simple example, 4 verts drawn at random (JavaScript in JS fiddle; would like to do the same in Python)
What would be a fastest way to play around with a Python script graphically? Is there a Python counterpart of jsfiddle? I googled 'Python fiddle', of course, but it's not what I'm looking for. What I need is a simple canvas implementation and click events support.
Thanks in advance,
Well, there is Python Fiddle, but I think this question is going to be closed by admins as being off-topic on Stack Overflow; see this thread here.
I'd also come to think of Jupyter and Anaconda. The latter includes the former. These will harness matplotlib, amongst others, and Jupyter gives you a Matlab-like interpreter that shows you variable values for each line and you're able to step by step look at those variables and any graphs you are making.
As mentioned in previous answer, there is Jupyter notebook – a software for interactive Python programming including graphical output.
You can run Jupyter locally or on your own server, but there are free cloud versions:
https://colab.research.google.com/
https://notebooks.azure.com/
So, I have looked around Google, and here, I do get some interesting results, like using Tkinter and some example from YouTube videos, but I don't think I am asking the right question.
Basically, I want to create a GUI, in Python, and I want to be able to use the standard Windows drop-down menu. By this I mean; File, Edit, Help, Etc. Is there some sort of template to create this or do I need to create my own, using button configurations?
I am assuming I am missing a large portion of information, specifically relating to Windows manipulation, in my studies so far.
You are looking for a GUI framework, there are several to choose from but personally I would say the main ones are:
Tkinter comes with python so nothing to download, looks "unixy"
QT & pyQT very powerful, cross platform, big downloads, always looks QT
wxPython Uses wrappers around native controls so small, fast, cross platform, looks native. Especially download & install the documents & examples package - gives you lots of code examples in the searchable demo that you can edit and run within the demo.
I really should mention that my personal favorite is wxPython, as I have used it a lot over the years.
Here are the facts:
I have a collection of python scripts that work together as part of a program
It takes a user input and outputs .docx and .excel files
Right now, only executable through command-line/editor (i.e. you call one script, it does the rest)
Non-CS people have difficulties downloading the necessary modules, and running the program
I want to make my program easily executable/portable to different OSs. So far, I have the following options:
Create a website that takes input visually, and does what it has to do. How do I get the website to refer to my code? Do I have to put it in some sort of web server?
Create an executable that others can simply run (Not sure if this is possible)
Create a GUI that does everything visually.
What are the pros and cons of each one of these options? Which one would you say is most feasible?
My apologies if I said something silly. I'm still learning most of this stuff.
Thank you!
As a result for my graduation paper I am trying to create a new toolbox for ArcGIS using Python scripting. The problem is I am stuck with my code because none of the existing functions in Arcpy does what I need to do. So my question is, is it possible to create a new function in Arcpy or this is restricted to ESRI developers?
Another way to solve this problem would be implement some changes in the tool Cost Distance from Spatial Analyst. So my other question is, do I have access to the coding of the native tools from ArcGIS? And if I have, can I change it to achieve my goal? Or this is also restricted?
Thanks,
Gabriel
You can create your own functions using Python and the Python arcpy site-package. All of ESRI's tools are proprietary, and therefore, most have restricted access. You can check to see if you can edit the tools in the ArcToolbox. For example, you can see the Cost Distance tool is restricted:
While the Spline with Barriers tool can be edited by right-clicking on the script tool.
You can create your own python toolbox for ArcPy following this help: http://resources.arcgis.com/en/help/main/10.2/index.html#//001500000022000000
also checkout the environment variables for your existing tool, it might have some options that you are looking for.
I know this is a year late, but I would like to add a couple ideas to what has been posted for folks like me who are searching for python toolbox help.
For educational purposes, begin by creating a model in Model Builder. This is one way to use ESRI's proprietary tools in new ways. Decide what you want to do and look at ESRI's presence on GitHub. The developers there have a lot of open-source tools ready to use in ArcMap. Here is one such repository: GeospatialPython
Side note, contributing to a repository is a great resume builder.
After creating your working model builder, right click on it in ArcCatalog and select 'export as Python script'. Open the script in your favorite IDE and begin cleaning it up!
Now that you have a python script, it is ready to become a python toolbox. Use gDexter42's link and get to work on that.
My team has some interesting uses for python toolboxes and I am currently creating my very first one.
We use a runner scripts to debug our software. (hard-coded parameters)
We use inheritance for functions that we use over and over again (class BaseToolboxMixin(object):) Stack Exchange Article on Mixins
Most importantly, we have created our own python module around the tool.
The .pyt file we made simply imports arcpy, the module we created, executes the module from a list we created in our 'toolbox_loader.py' file, and has a class that calls the init file that created the module in the first place. >20 lines of code.
As our team creates more tools for the module/python toolbox, we will add them to the list. They will appear inside our toolbox alongside all the ESRI tools. "Seamless integration" was thrown around a lot at the Dev Summit this year.
ESRI is encouraging creativity and open-source usage (check out esri leaflet). I wouldn't constrain my thinking because ESRI's tools are proprietary.
All of this functionality began as a model in ArcMap. Not everyone is going to need to create their own module - complete overkill for most tasks - but it is good to know that the ceiling for Python functionality is high. I am not an experienced developer, but I was able to go from nothing to a functional python toolbox in about 25 man-hours of work. Someone who knows their stuff could do it in a morning.