I am preparing to build an application in Python that works with a lot of spatial data. I am looking for a Python module that provides a nice set of spatially-enabled classes that I can inherit from. Two things I would like to have baked in are:
Support for both vector and raster data, and conversions between both formats.
Support for projecting coordinates between datums.
The best module I have been able to find so far is shapely but it focuses on vector data and does not include support for datum transformations. An example of the kind of library I am looking for is the sp package for R which provides classes for holding both vector point data and dense or sparse raster data along with datum transformation support.
Are there any Python modules that provide a nice set of spatially enabled classes that I may be overlooking?
Did you try the Geospatial Data Abstraction Library?
I found it on Linux where its called python-gdal.
Abstract of Debians GDAL:
GDAL supports 40+ popular data formats, including commonly used
ones (GeoTIFF, JPEG, PNG and more) as well as the ones used in
GIS and remote sensing software packages (ERDAS Imagine,
ESRI Arc/Info, ENVI, PCI Geomatics). Also supported many remote
sensing and scientific data distribution formats such as HDF,
EOS FAST, NOAA L1B, NetCDF, FITS.
OGR library supports popular vector formats like ESRI Shapefile,
TIGER data, S57, MapInfo File, DGN, GML and more.
see on trac.osgeo.org
More precisely: Shapely is about planar computational geometry and nothing more. It's not a vector data library at all. I use it with Pyproj (http://code.google.com/p/pyproj/). I haven't come across any Python foundation classes for geospatial. They abound, of course, in Java projects like GeoTools. Python arrays could be a good starting point: arrays of coordinates can be used by Shapely and raster-like arrays can be used by GDAL. You might also take a look at the GeoJSON-ish interfaces provided by Shapely, ArcPy, and the SimpleGeo APIs.
Almost all Python modules are listed at the CheeseShop so start there. I can't find anything obvious, though.
RSGISLib is a suite of command line tools with python bindings for processing remote sensing/spatial data in both vector and raster format, which you may find useful.
The link to the webiste is http://www.rsgislib.org and it can easily be installed using Anaconda
Related
I've been working with spatstat in R for quite a while now and am curious what the big differences between the packages (PySAL in python and spatstat in R) are functionality-wise. Is either more potent or faster, does one have more pre-set functions?
Thanks loads
This is not really an appropriate question for this forum.
However, the main differences between the two packages can be seen by reading their documentation: spatstat is designed for analysing spatial point patterns, is written by statisticians following statistical principles and conventions, contains current techniques from the statistical literature, and does not handle file input/output directly. PySAL is designed for spatial data in general (with relatively less functionality for spatial point patterns), is written by geographers, and includes capabilities for reading spatial data file formats.
Is there any libraries similar to igraph where I can create a hypergraph. I am working with hypergraph now and wanted to use some HyperGraph libraries to work on.
MGtoolkit and its paper
pygraph
halp
PyMETIS
SageMath's implementation, 1, 2. SageMath is not a python library but more like a python distribution (ships python 2.7 currently) which lots of interesting libraries are pre-installed.
I hope we see NetworkX and igraph support also soon.
There's also HyperNetX which is able to represent and visualise hypergraphs.
It seems very accessible. They have a number of nice tutorials on their GitHub page.
However, when working with it I identified some issues:
Performance: The library struggles with graphs that have several thousand nodes. I recommend igraph instead, although it does not have explicit support for hypergraphs. It does offer functionality for bipartite graphs, though. I believe if no hyperedge is fully contained in another, you can work with a bipartite graph that is isomorphic to your given hypergraph?
I encountered an issue in which the ordering of nodes would not be deterministic, i.e. if you constructed the same graph several times and iterated over the nodes, they would be given to you in different orders. This can probably be worked around.
So, I use SPM to register fMRI brain images between the same patient; however, I am having trouble registering images between patients.
Essentially, I want to register a brain atlas to a patient-specific scan, so that I can do some image patching. So register, then apply that warping and transformation to any number of images.
SPM was unsuccessful in such a registration. It cannot warp the atlas to be in the same brain shape as the patient brain.
Would software such as freesurfer be good for this?? Or is there something better out there in either matlab or python (but preferably python)??
Thanks!
tylerthemiler
There is a bulk of tools for image registration, e.g. look at http://www.nitrc.org under "Spatial transformation" -> "Registration". Nipype is indeed a nice Python module which wraps many of those (e.g. FSL, Freesurfer, etc) so you could explore different available tools within somewhat unified interface.
Besides those well known (SPM, FSL, AFNI) also you could give a try to somewhat less known but very powerful CMTK (http://www.nitrc.org/projects/cmtk) which comes with non-linear registration(s), population-based template construction, many other features and SRI24 atlas. Such script as asegment_sri24 could be used for a quick start with registering/reslicing each subject using labels available in SRI24 atlas.
To start using CMTK (or dozens of other neuroimaging software) in a matter of minutes I would recommend you to look at http://neuro.debian.net -- the platform to allow very easy deployment of (maintained) neuroscience software. FSL, AFNI, CMTK, SRI24 atlas etc are available there upon your demand ;)
Freesurfer segments and annotates the brain in the patient's native space, resulting in patient-specific regions, like so.
I'm not sure what you mean by patching, or to what other images you'd like to apply this transformation, but it seems like the software most compatible for working with individual patient data, rather than normalized data across patients.
I think ITK is made for this kind if purpose. A Python wrapper exists (Paul Novotny distributes binaries for Ubuntu on his site), but this is mainly C++. If you work under Linux then it is quite simple to compile if you are familiar with cmake.
As this toolkit is a very low-level framework I can advise you to try elastix which is a command line utility allowing one to make registration on picture using multiscale Bspline dense registration.
Another interesting tool based on Maxwell demons and improved with diffeomorphic capabilities is MedINIRA.
Along SPM's lines, you can use IBSPM. It was developed to solve exactly that problem.
You can use ANTs software, or u can use Python within 3dSclicer for template registration.
However, I did mane template registration in SPM and I recommend it for fMRI data better than ITK or Slicer.
I found these links very helpful :) let me know if you need more help.
https://fmri-training-course.psych.lsa.umich.edu/wp-content/uploads/2017/08/Preprocessing-of-fMRI-Data-in-SPM-12-Lab-1.pdf
https://nipype.readthedocs.io/en/latest/users/examples/fmri_spm.html
I'm pretty much a beginner when it comes to GIS, but I think I understand the basics - it doesn't seem to hard. But: All these acronyms and different libraries, GEOS, GDAL, PROJ, PCL, Shaply, OpenGEO, OGR, OGC, OWS and what not, each seemingly depending on any number of others, is slightly overwhelming me.
Here's what I would like to do: Given a number of points and a linestring, I want to determine the location on the line closest to a certain point. In other words, what PostGIS's line_locate_point() does:
http://postgis.refractions.net/documentation/manual-1.3/ch06.html#line_locate_point
Except I want do use plain Python. Which library or libraries should I have a look at generally for doing these kinds of spatial calculations in Python, and is there one that specifically supports a line_locate_point() equivalent?
For posterity:
http://bitbucket.org/miracle2k/pyutils/changeset/156c60ec88f8/
In another forum I suggested reimplementing the (simple) PostGIS algorithm in Python using Shapely.
For posterity, these functions are available in Shapely 1.2
All you need is Shapely, if you have shapefiles for points and linestrings, a line.distance(point) in for loop will do the trick. With that you can find the closest point to the line or vice versa. Make sure you check GDAL, Fiona, Shapely in order to complete this.
I would like to perform a few basic machine vision tasks using Python and I'd like to know where I could find tutorials to help me get started.
As far as I know, the only free library for Python that does machine vision is PyCV (which is a wrapper for OpenCV apparently), but I can't find any appropriate tutorials.
My main tasks are to acquire an image from FireWire. Segment the image in different regions. And then perform statistics on each regions to determine pixel area and center of mass.
Previously, I've used Matlab's Image Processing Tootlbox without any problems. The functions I would like to find an equivalent in Python are graythresh, regionprops and gray2ind.
Thanks!
OpenCV is probably your best bet for a library; you have your choice of wrappers for them. I looked at the SWIG wrapper that comes with the standard OpenCV install, but ended up using ctypes-opencv because the memory management seemed cleaner.
They are both very thin wrappers around the C code, so any C references you can find will be applicable to the Python.
OpenCV is huge and not especially well documented, but there are some decent samples included in the samples directory that you can use to get started. A searchable OpenCV API reference is here.
You didn't mention if you were looking for online or print sources, but I have the O'Reilly book and it's quite good (examples in C, but easily translatable).
The FindContours function is a bit similar to regionprops; it will get you a list of the connected components, which you can then inspect to get their info.
For thresholding you can try Threshold. I was sure you could pass a flag to it to use Otsu's method, but it doesn't seem to be listed in the docs there.
I haven't come across specific functions corresponding to gray2ind, but they may be in there.
documentation: A few years ago I used OpenCV wrapped for Python quite a lot. OpenCV is extensively documented, ships with many examples, and there's even a book. The Python wrappers I was using were thin enough so that very little wrapper specific documentation was required (and this is typical for many other wrapped libraries). I imagine that a few minutes looking at an example, like the PyCV unit tests would be all you need, and then you could focus on the OpenCV documentation that suited your needs.
analysis: As for whether there's a better library than OpenCV, my somewhat outdated opinion is that OpenCV is great if you want to do fairly advanced stuff (e.g. object tracking), but it is possibly overkill for your needs. It sounds like scipy ndimage combined with some basic numpy array manipulation might be enough.
acquisition: The options I know of for acquisition are OpenCV, Motmot, or using ctypes to directly interface to the drivers. Of these, I've never used Motmot because I had trouble installing it. The other methods I found fairly straightforward, though I don't remember the details (which is a good thing, since it means it was easy).
I've started a website on this subject: pythonvision.org. It has some tutorials, &c and some links to software. There are more links and tutorials there.
You probably would be well served by SciPy. Here is the introductory tutorial for SciPy. It has a lot of similarities to Matlab. Especially the included matplotlib package, which is explicitly made to emulate the Matlab plotting functions. I don't believe SciPy has equivalents for the functions you mentioned. There are some things which are similar. For example, threshold is a very simple version of graythresh. It doesn't implement "Otsu's" method, it just does a simple threshold, but that might be close enough.
I'm sorry that I don't know of any tutorials which are closer to the task you described. But if you are accustomed to Matlab, and you want to do this in Python, SciPy is a good starting point.
I don't know much about this package Motmot or how it compares to OpenCV, but I have imported and used a class or two from it. Much of the image processing is done via numpy arrays and might be similar enough to how you've used Matlab to meet your needs.
I've acquired image from FW camera using .NET and IronPython. On CPython I would checkout ctypes library, unless you find any library support for grabbing.
Foreword: This book is more for people who want a good hands on introduction into computer or machine vision, even though it covers what the original question asked.
[BOOK]: Programming Computer Vision with Python
At the moment you can download the final draft from the book's website for free as pdf:
http://programmingcomputervision.com/
From the introduction:
The idea behind this book is to give an easily accessible entry point to hands-on
computer vision with enough understanding of the underlying theory and algorithms
to be a foundation for students, researchers and enthusiasts.
What you need to know
Basic programming experience. You need to know how to use an editor and run
scripts, how to structure code as well as basic data types. Familiarity with Python or other scripting style languages like Ruby or Matlab will help.
Basic mathematics. To make full use of the examples it helps if you know about
matrices, vectors, matrix multiplication, the standard mathematical functions
and concepts like derivatives and gradients. Some of the more advanced mathe-
matical examples can be easily skipped.
What you will learn
Hands-on programming with images using Python.
Computer vision techniques behind a wide variety of real-world applications.
Many of the fundamental algorithms and how to implement and apply them your-
self.