Respected Professor,
Thank you for your guidance on JSON and Python script pairs. The approach you suggested has been implemented for the example file as follows:
What is accomplished:
a) *All variables in JSON:* Input data paths, processing parameters, tool configurations, and visualization settings are stored in watershed_analysis.json rather than being hardcoded in the script.
A Notebook called "JSON Generator" where we can edit all the input parameters and run; then run the main python program that will take all input from the newly generated JSON file. Since, for jupyter, direct editing of JSON was not available.
b) *Comments included:* The JSON file includes clear descriptions of the parameters to make it user-friendly and self-explanatory.
c) *User-friendly editing: *Users can easily edit all settings (DEM paths, threshold values, tool paths, visualization parameters) by modifying only the JSON file.
d) *Minimal Python script changes: *The Python script reads the configuration from the JSON file and requires no user changes to work with different datasets or parameters.
e) *Same name convention:* Created the pair watershed_analysis.py and watershed_analysis.json as you suggested.
Implementation follows the above changes. Thank you!
- Bhuwan
On Fri, Aug 8, 2025 at 9:34 AM Venkatesh Raghavan via PyGILE < pygile@geoinfo-lab.org> wrote:
Hi Bhuwan,
Good morning! Thanks for the update.
a) not only variable 'EPSG: 4326', but any variable (input data, program parameter etc.)
that the user would need to change can be defined in the json file
b) The json file could include comments to make it more understandable
c) Using a) and b) above, it should be possible for user to edit the json file
to suit his/her needs.
d) with c) above, changing the python script could not be necessary or
minimal.
e) You can try out a) to d) create/test a python script and a json file pair
(with the same name and different file extension) and see if it works OK.
f) after you have done e), you can upload the python and json file pair
to git hub.
Hope what I mention makes sense.
Best,
Venka
On 8/8/2025 2:00 AM, Bhuwan Awasthi wrote:
Respected Professor,
Thank you for your very good advice. You are completely right with everything: a) EPSG:4326 stored in JSON: Done! Instead of hardcoding them directly in the Python script, the string variables 'EPSG: 4326' are now in the JSON (config) file.
b) Avoid the redundant config_data dictionary: Done! The hardcoded lines were unnecessary and are now removed, since the config_data is also read from the JSON file.
The JSON file is created if it does not yet exist (first start of the software) The configuration is always read from the JSON file The redundant hardcoded dictionary is removed
c) Naming is not matching: Done! The watershed_analysis.py will always create and read the corresponding watershed_analysis.json, leading to a perfectly logical relationship between Python file and JSON config.
This in fact created a clean, professional, and maintainable codebase !!
Thank you for these great tips that have strongly improved the code structure.
- Bhuwan
On Thu, Aug 7, 2025 at 6:11 PM Venkatesh Raghavan via PyGILE < pygile@geoinfo-lab.org> wrote:
Bhuvan,
a) Even variables like 'EPSG:4326' can be defined in the json file
b) are the lines below necessary in yje Python script?
config_data = { "dem_path": "/workspace/Road_Induced_Solu/Solu_Dem/Solu.tif", "temp_dir": "temp_watershed", "output_dir": "results", "watershed_dem": "results/clipped_dem.tif", "conda_env_path": "/opt/conda/envs/pygile", "saga_cmd": "/opt/saga/bin/saga_cmd", "saga_lib": "/opt/saga/lib/saga", "grass_bin": "/opt/grass/grass84/bin", "otb_bin": "/opt/otb/bin", "whitebox_tools": "/opt/conda/envs/pygile/bin/whitebox_tools" }
I think the data is being read from the json file.
c) each python script will read parameters from json file, so it is
better
if the python file and json file share the same name.
Venka
On 8/7/2025 7:29 PM, Bhuwan Awasthi wrote:
Respected Professor,
As per your instructions, the updated example has been pushed to the
GITHUB
repository of PyGILE-Plus. This looks more convenient to work with.
Thank
you for pointing it out.
- Bhuwan
On Thu, Aug 7, 2025 at 2:02 PM Venkatesh Raghavan via PyGILE < pygile@geoinfo-lab.org> wrote:
Here's a simple example of json and python script pair.
The python script will read input and output variables from
json file and execute. No need to hardcode (or edit python script)
and you can run the script on different data by editing json file.
Venka _______________________________________________ PyGILE mailing list -- pygile@geoinfo-lab.org To unsubscribe send an email to pygile-leave@geoinfo-lab.org
PyGILE mailing list -- pygile@geoinfo-lab.org To unsubscribe send an email to pygile-leave@geoinfo-lab.org
PyGILE mailing list -- pygile@geoinfo-lab.org To unsubscribe send an email to pygile-leave@geoinfo-lab.org