Skip to content

Commit

Permalink
Deprecate GDAL and switch to PIL for reading datasets; Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
itskalvik committed Aug 17, 2024
1 parent c0a0631 commit 1dd669a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ The library includes python code for the following:
</p>

## Installation
The library is available as a ```pip``` package. To install the package, run the following commands:
The library is available as a ```pip``` package. To install the package, run the following command:

```
sudo apt-get install python3-pip libgdal-dev gdal-bin -y
python3 -m pip install sgptools
```

Installation from source:

```
sudo apt-get install libhdf5-dev python3-pip -y
git clone https://github.com/itskalvik/sgp-tools.git
cd sgp-tools/
python3 -m pip install -r requirements.txt
python3 -m pip install -e .
```
Expand Down Expand Up @@ -56,6 +56,7 @@ Please refer to the [examples](https://github.com/itskalvik/sgp-tools/tree/main/
- `augmented_gpr.py`: GPflow's GP that supports transforms (expansion and aggregation)
- `augmented_sgpr.py`: GPflow's SGP that supports transforms (expansion and aggregation)
- `transformations.py`: Expansion and aggregation transforms for IPP
- `osgpr.py`: Thang Bui's implementation of online sparse variational GP used for online/adaptive IPP
- `bo.py`: Bayesian optimization-based sensor placement method that maximizes mutual information
- `cma_es.py`: Genetic algorithm-based sensor placement method that maximizes mutual information
- `continuous_sgp.py`: Continuous SGP-based sensor placement method
Expand All @@ -69,7 +70,7 @@ Please refer to the [examples](https://github.com/itskalvik/sgp-tools/tree/main/
- `tsp.py`: TSP solver

## Datasets
* The US elevation datasets can be downloaded from [here](https://coast.noaa.gov/digitalcoast/)
* High-resolution topography and bathymetry datasets can be downloaded from [NOAA Digital Coast](https://coast.noaa.gov/digitalcoast/).

## About SGP-Tools
Please consider citing the following papers if you use SGP-Tools in your academic work :smile:
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ The library includes python code for the following:
<p align="center"><img src="assets/point_sensing.gif"><img src="assets/non-point_sensing.gif"></p>

## Installation
The library is available as a ```pip``` package. To install the package, run the following commands:
The library is available as a ```pip``` package. To install the package, run the following command:

```
sudo apt-get install python3-pip libgdal-dev gdal-bin -y
python3 -m pip install sgptools
```

Installation from source:

```
sudo apt-get install libhdf5-dev python3-pip -y
git clone https://github.com/itskalvik/sgp-tools.git
cd sgp-tools/
python3 -m pip install -r requirements.txt
python3 -m pip install -e .
```

Note: The requirements.txt file contains packages and their latest versions that were verified to be working without any issues.
Note: The requirements.txt file contains packages and their latest versions that were last verified to be working without any issues.

## Quick Start
Please refer to the [examples](https://github.com/itskalvik/sgp-tools/tree/main/examples) folder for Jupyter notebooks demonstrating all the methods included in the library 😄
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ cma==3.4.0
bayesian-optimization==1.5.1
hkb-diamondsquare==1.0.2
typing_extensions==4.12.2
GDAL==3.4.1
pillow==10.4.0
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = "1.0.3"
__version__ = "1.0.4"

setup(
name='sgptools',
Expand Down Expand Up @@ -29,6 +29,7 @@
'tensorflow>=2.13.0; platform_machine!="arm64"',
'tensorflow-aarch64>=2.13.0; platform_machine=="arm64"',
'typing_extensions',
'gpflow>=2.7.0'
'gpflow>=2.7.0',
'pillow'
]
)
35 changes: 19 additions & 16 deletions sgptools/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
from sklearn.preprocessing import StandardScaler
from hkb_diamondsquare.DiamondSquare import diamond_square

# Load optional dependency
try:
from osgeo import gdal
except:
pass

import PIL
PIL.Image.MAX_IMAGE_PIXELS = 317500000

####################################################
# Utils used to prepare synthetic datasets
Expand Down Expand Up @@ -98,16 +94,23 @@ def prep_tif_dataset(dataset_path):
X: (n, d); Dataset input features
y: (n, 1); Dataset labels
'''
ds = gdal.Open(dataset_path)
cols = ds.RasterXSize
rows = ds.RasterYSize
band = ds.GetRasterBand(1)
data = band.ReadAsArray(0, 0, cols, rows)
data[np.where(data==-999999.0)] = np.nan

x1, x2 = np.where(np.isfinite(data))
X = np.vstack([x1, x2]).T
y = data[x1, x2].reshape(-1, 1)
data = PIL.Image.open(dataset_path)
data = np.array(data)

# create x and y coordinates from the extent
x_coords = np.arange(0, data.shape[1])/10
y_coords = np.arange(data.shape[0], 0, -1)/10
xx, yy = np.meshgrid(x_coords, y_coords)
X = np.c_[xx.ravel(), yy.ravel()]
y = data.ravel()

# Remove invalid labels
y[np.where(y==-999999.0)] = np.nan
X = X[~np.isnan(y)]
y = y[~np.isnan(y)]

X = X.reshape(-1, 2)
y = y.reshape(-1, 1)

return X.astype(float), y.astype(float)

Expand Down

0 comments on commit 1dd669a

Please sign in to comment.