Giter Club home page Giter Club logo

visum_to_pandas's Introduction

visum_to_pandas

python scripts to parse visum .net and .dmd file to pandas and store as .csv files (c) Rafal Kucharski, Politechnika Krakowska, Krakow, Poland

usage

open ptv_visum_to_pandas.py and go to main() where you can find the below pipeline:

0. Set your paths - your ver files and export paths

NETPATH = "./test/MOMM_net.net"  # .net file to parse into csv tables
DMDPATH = "./test/MOMM_full_dmd.dmd"  # .dmd file to parse into csv tables
OUTPATH = "./test/data/"  # save the .csv's here
VERPATH = "./test/test_matrices.ver"

1. Export .ver file to editable .net and .dmd

export_net_dmd(path=VERPATH)

2. export network to csv

parse(NETPATH, export_path=OUTPATH) # a) full export
parse(NETPATH, export_path=OUTPATH, export_list=["Links", "Nodes"])  # b) just some tables

3. export demand files to csv

parse(DMDPATH, export_path=OUTPATH)

4. Export matrices (export from .dmd is not very useful)

matrices_export_via_com(VERPATH, export_path=OUTPATH)  # a) full export
matrices_export_via_com(VERPATH, export_path=OUTPATH, export_list=[101, 102])   # b) just some matrices

5. see if everything went fine and understand how to use it further with pandas

test_read("./test/data/Tripgeneration.csv")
test_read("./test/data/Links.csv")
test_read("./test/data/Mtx_10.csv")  

Third party

We link PTV Visum with pandas

test

run test.py to see if the links.csv is as we expect and if matrix entries.csv are the same. Use only for the original files.

contributors

https://github.com/PatrikHlobil

possible modifications

  • pd.DataFrame(data, columns=cols).to_csv(OUTPATH+table_name+".csv") can be easily modified to be used directly in pandas (e.g. dict of DataFrames, or h5 store).
  • pipeline can be smoother if this is called from within Visum, you shall add Visum.IO.SaveNet, Visum.IO.SaveDmd to prepare the files under good paths and then use them in parse done

visum_to_pandas's People

Contributors

patrikhlobil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

visum_to_pandas's Issues

Improvement of parse function

Hi Rafal,

I have to say that your visum_to_pandas script is great. I worked a bit on the most recent version and made the following changes/improvement for the "parse" function:

  • use os.path.join for the combination of paths
  • use "string".split(9 to get rid of newline and space characters
  • auto-detect COL_SEPARATOR
  • do not export index of DataFrame
  • add parameters (export_path, export) to the parse function:

:param export_path (optional): Path to folder, where to save the CSV files.
If not specified, the CSV files are save in
folder of the net files.
:param export (optional): List of network objects that should be exported. If
not specified, all network objects will be exported.

If you like, you can just include my changes in your code. The file was uploaded with the name "ptv_visum_to_pandas_2.py".

Best regards,

Patrik

Usability and capsulation

Hi Rafal,

what do you think about the following ideas?

  1. If the script is called as main, we could show the user a prompt (using wxpython or tkinter) where he can select via a file dialogue, where the .net, .dmd or matrix files lie. This would be very user friendly. On the other hand, if imported as a module one can still use the functions as they are.
  2. For me, it seems as if the visum_to_pandas.py file contains quite a lot of testing code. I think we should separate that purely to the test.py file. This encapsulation simplifies the reusability of the module in my opinion.
  3. I also have a script that automatically reads in an attribute file to a DataFrame. It also contains functions to remove units and convert to datetime objects. It is attached
    VisumPy_add.zip
    One could also consider adding such functions to your package.

Best,

Patrik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.