Giter VIP home page Giter VIP logo

python-tools's Introduction

Python-Tools

This is a collection of small modules that I often/sometimes/not anymore use for my day-to-day scripting needs. I keep them in a separate directory that I keep always on the Python search path so that I can include them like installed site-packages.

Installation(ish)

I just clone this repo into the directory that is returned by the following Python snippet:

import site
print(site.USER_SITE)

Depending on your operating system and Python version, this evaluates to

Windows, Python 3.5: C:\Users\ojdo\AppData\Roaming\Python\Python35\site-packages
Linux, Python 2.7:   /home/ojdo/.local/Python27/site-packages
Linux, Python 3.5:   /home/ojdo/.local/lib/python3.5/site-packages

Anyway, open a terminal in that directory (create it if necessary) and clone this repo into that directory:

git clone https://github.com/ojdo/python-tools.git .

You should now be able to import any of the following packages. Depending on what you need, you might alternatively just grab one of these files/functions.

Useful packages

pandashp

Basically my private implementation of a GeoPandas GeoFrame. This module provides two functions, read_shp and write_shp. The first one reads an ESRI shapefile to a pandas DataFrame, saving the geometry information (Points, Lines, Polygons) in the column geometry. The second function does the reverse. These functions do not care about transformations, much different to GeoPandas. I plan to migrate to using Geopandas myself, so better don't use these two functions.

However, there is utility function find_closest_edge, which looks deceptively simple but took some time to get this "clean". It performs an operation similar to ArcGIS's Near for the special case of matching point features to their nearest line passing by. It heavily relies on several functions implemented in my other toolbox shapelytools.

Dependencies

shapelytools

Many handy small functions dealing with collections of shapely objects, i.e. points, lines and polygons. I use them to script small geographic algorithms on my own. The module implements a naive nearest neighbor algorithm, pruning of short line segments, finding isolated endpoints among a list of possibly touching lines.

:!: Note: shapely is not aware of geographic coordinates! So while some of these functions might work with lat/lon coordinates in degrees, I use them mainly in projected coordinate systems with x/y coordinates in metres. So use something like GeoPandas' to_crs function to convert your geographic (lat, lon) data to a projected (x, y) coordinate system before using anything from this package.

Dependencies

skeletrontools

Wrapper module that provides function skeletonize, which reads in a pandashp DataFrame of road segments and returns a simplified version of it. The most expensive step is the skeletonization of a buffered version of this road network, decorated with some pre- and postprocessing steps.

Dependencies

Deprecated

pandaspyomo

Provides functions like get_entity to read data from coopr.pyomo models to pandas DataFrames. (Un)fortunately, pyomo changed its internals some time around the 3.5 release version, so these functions don't work with current pyomo versions. See urbs for an up-to-date version of these functions.

Dependencies

pyomotools

Archive for some misc functions needed for migrating urbs from GAMS to Python. Function read_xls for example implements automatic detection of Capital lettre column titles for onset detection. I don't use it any longer, but its functions might remain useful in other contexts.

Dependencies

shptools

Convenience wrapper of pyshp, including automatic type detection (numeric, string) when reading/writing shapefiles. Might be not needed anymore, but was quite handy when written. This is the predecessor to my pandashp toolbox, which itself now is partially unneeded because of GeoPandas.

Dependencies

python-tools's People

Contributors

ojdo avatar

Watchers

 avatar

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.