Skip to main content
Raster Correlation
====================

The library provides an easy way correlate raster of the same size. It returns a json containing statistical outputs and frequencies information to be directly used with Highcharts JS or Matplotlib chart libraries.

# Installation

## Dependencies

The library has different dependencies (see also requirements.txt) click, watchdog, flask, flask-cors, numpy, scipy, pysal, brewer2mpl, rasterio, GeobricksCommon.

## On Ubuntu

```bash
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install python-numpy libgdal1h gdal-bin libgdal-dev
```

In case of compiling errors for numpy
```bash
sudo apt-get install libblas3gf libc6 libgcc1 libgfortran3 liblapack3gf libstdc++6 build-essential gfortran python-all-dev libatlas-base-dev python-dev
```

In case of compiling errors for scipy
```bash
sudo apt-get install libblas-dev liblapack-dev
```

## Installation

The library is distributed through PyPi and can be installed by typing the following commands in the console:
```
pip -r https://raw.githubusercontent.com/geobricks/geobricks_raster_correlation/master/requirements.txt

pip install GeobricksRasterCorrelation
```

**N.B.** Due to a well known PyPi issue it's not possible to install scipy and pysal through setup.py or requirements.txt

In order to install pysal run the following command
```bash
pip install pysal
```


# Examples

## Library usage

```python
from geobricks_raster_correlation.core.raster_correlation_core import get_correlation

raster_path1 = "path_to_raster1.tif"
raster_path2 = "path_to_raster2.tif"
# Number of bins to be applied to the scatter chart
bins = 300
corr = get_correlation(raster_path1, raster_path2, bins)
print corr
```

## Example with matplotlib

This example generate a correlation chart with matplotlib

```python
from geobricks_raster_correlation.core.raster_correlation_core import get_correlation
from matplotlib import pyplot as plt
from matplotlib.pylab import polyfit, polyval

# input to your raster files
raster_path1 = "path_to_raster1.tif"
raster_path2 = "path_to_raster2.tif"

# Number of sampling bins
bins = 150

corr = get_correlation(raster_path1, raster_path2, bins)
x = []
y = []
colors = []
# print corr['series']
for serie in corr['series']:
colors.append(serie['color'])
for data in serie['data']:
x.append(data[0])
y.append(data[1])

# Adding regression line
(m, b) = polyfit(x, y, 1)
yp = polyval([m, b], x)
plt.plot(x, yp)

# plotting scatter
plt.scatter(x, y, c=colors)
plt.show()
```

The returned json:

* corr['stats'] contains the statistics: slope, p_value, std_err, intercept, r_value
* corr['series'] contains the output series that can be used directly as an Highcharts input or with Matplotlib.

Metadata

Release files for GeobricksRasterCorrelation 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for GeobricksRasterCorrelation 0.1.13
File Size Uploaded
GeobricksRasterCorrelation-0.1.13.tar.gz 11.6 kB Details

Release files / GeobricksRasterCorrelation-0.1.13.tar.gz

Download URL GeobricksRasterCorrelation-0.1.13.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cf910fc3d3c0694bcf99ce3c7f06e15f32d8f3ec4fb7e518774c9d54d101b02a
BLAKE2b-256 checksum
How to use checksums
c4d798bbb0c8326aec5b1958a8fb71238d0cefc39aeae7a5de9f1530634cef29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.13 This release

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page