Skip to content

Commit

Permalink
Merge pull request #92 from mapbox/bill/future
Browse files Browse the repository at this point in the history
rio-color 2.0
  • Loading branch information
wboykinm authored Dec 17, 2024
2 parents aa40fc1 + f8c74fd commit 3ecc315
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 103 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: rio-color test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -r requirements.txt -r requirements-dev.txt
- name: Install module
run: python -m pip install -e .

- name: Run tests
run: |
pre-commit run --all-files
python -m pytest --cov rio_color --cov-report term-missing
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
-
repo: https://github.com/psf/black
rev: ed50737290662f6ef4016a7ea44da78ee1eff1e2
rev: 24.10.0 # Update to the latest version
hooks:
- id: black
args: [--safe]
language_version: python3.6
language_version: python3.9
-
repo: 'https://github.com/pre-commit/pre-commit-hooks'
# v1.3.0
Expand All @@ -20,7 +20,7 @@ repos:
-
repo: 'https://github.com/chewse/pre-commit-mirrors-pydocstyle'
# 2.1.1
rev: 22d3ccf6cf91ffce3b16caa946c155778f0cb20f
rev: v2.1.1
hooks:
- id: pydocstyle
args: [
Expand Down
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Changes
=======

2.0.0 (2024-12-16)
------------------

- Drop support for Python <3.8.
- Bump rasterio to 1.4.
- Bump colormath to 3.0.
- Bump click to 8.1.
- Bump numpy to 2.0.2.
- Bump Cython to 3.0.
- Bump pytest to 8.3.
- TravisCI --> GHA

1.0.4 (2021-07-19)
------------------

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# rio-color

[![Build Status](https://travis-ci.com/mapbox/rio-color.svg?branch=master)](https://travis-ci.com/mapbox/rio-color)
[![Coverage Status](https://coveralls.io/repos/mapbox/rio-color/badge.svg?branch=master&service=github)](https://coveralls.io/github/mapbox/rio-color?branch=master)
[![rio-color test](https://github.com/mapbox/rio-color/actions/workflows/test.yml/badge.svg)](https://github.com/mapbox/rio-color/actions/workflows/test.yml)

A rasterio plugin for applying basic color-oriented image operations to geospatial rasters.

Expand Down
27 changes: 16 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
environment:
global:
CIBW_SKIP: "cp27* cp35* pp* *-win32 *-manylinux_i686"
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
APPVEYOR_JOB_NAME: "python37-x64-ubuntu"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
APPVEYOR_JOB_NAME: "python37-x64-vs2015"
- APPVEYOR_BUILD_WORKER_IMAGE: macos-mojave
APPVEYOR_JOB_NAME: "python37-x64-macos-mojave"
CIBW_SKIP: "cp27* cp35* cp38-* pp* *-win32 *-manylinux_i686"
CIBW_BUILD: "cp39-* cp310-* cp311-*"

stack: python 3.7
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu
APPVEYOR_JOB_NAME: "python39-x64-ubuntu"
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
APPVEYOR_JOB_NAME: "python39-x64-vs2015"
- APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma
APPVEYOR_JOB_NAME: "python39-x64-macos-sonoma"

stack: python 3.9

init:
- cmd: set PATH=C:\Python37;C:\Python37\Scripts;%PATH%
- cmd: set PATH=C:\Python39;C:\Python39\Scripts;%PATH%

install: python -m pip install cibuildwheel==1.7.1

build_script: python -m cibuildwheel --output-dir wheelhouse
build_script:
- python -m cibuildwheel --output-dir wheelhouse --platform linux --python 3.9
- python -m cibuildwheel --output-dir wheelhouse --platform windows --python 3.9
- python -m cibuildwheel --output-dir wheelhouse --platform macos --python 3.9

artifacts:
- path: "wheelhouse\\*.whl"
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
requires = [
"setuptools",
"wheel",
"cython==0.29.32",
"oldest-supported-numpy; python_version >= '3.5'",
"numpy; python_version < '3.5'"
"cython==3.0.11",
"numpy==2.0.2"
]
9 changes: 4 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
affine
cligj
colormath==2.0.2
coveralls>=0.4
colormath==3.0.0
delocate
numpy>=1.8.0
numpy==2.0.2
pre-commit
pytest~=3.10.0
pytest~=8.3.4
pytest-cov>=2.2.0
rasterio==1.1.8
rasterio==1.4.3
setuptools>=0.9.8
snuggs>=1.2
wheel
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
click~=8.0
rasterio~=1.0
rio-mucho
enum34; python_version < "3.4"
click~=8.1
numpy==2.0.2
rasterio~=1.4
rio-mucho
2 changes: 1 addition & 1 deletion rio_color/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""rio-color"""

__version__ = "1.0.4"
__version__ = "2.0.0"
26 changes: 25 additions & 1 deletion rio_color/colorspace.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,31 @@ cdef enum:
cpdef convert(double one, double two, double three, src, dst):
cdef color color

if src not in ColorSpace or dst not in ColorSpace:
if isinstance(src, str):
try:
src = ColorSpace[src.lower()]
except KeyError:
raise ValueError(f"Invalid source colorspace: {src}")

if isinstance(dst, str):
try:
dst = ColorSpace[dst.lower()]
except KeyError:
raise ValueError(f"Invalid destination colorspace: {dst}")

if isinstance(src, int):
try:
src = ColorSpace(src)
except ValueError:
raise ValueError(f"Invalid source colorspace: {src}")

if isinstance(dst, int):
try:
dst = ColorSpace(dst)
except ValueError:
raise ValueError(f"Invalid destination colorspace: {dst}")

if not isinstance(src, ColorSpace) or not isinstance(dst, ColorSpace):
raise ValueError("Invalid colorspace")

color = _convert(one, two, three, int(src), int(dst))
Expand Down
3 changes: 1 addition & 2 deletions rio_color/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ def atmos(
creation_options,
as_color,
):
"""Atmospheric correction
"""
"""Atmospheric correction"""
if as_color:
click.echo(
"rio color {} {} {}".format(
Expand Down
3 changes: 1 addition & 2 deletions rio_color/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def to_math_type(arr):


def scale_dtype(arr, dtype):
"""Convert an array from 0..1 to dtype, scaling up linearly
"""
"""Convert an array from 0..1 to dtype, scaling up linearly"""
max_int = np.iinfo(dtype).max
return (arr * max_int).astype(dtype)

Expand Down
2 changes: 1 addition & 1 deletion scripts/optimize_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def update(self, step, T, E, acceptance, improvement):


def histogram_distance(arr1, arr2, bins=None):
""" This function returns the sum of the squared error
"""This function returns the sum of the squared error
Parameters:
two arrays constrained to 0..1
Expand Down
56 changes: 20 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

import os
import sys
from setuptools import setup, find_packages
from setuptools.extension import Extension

# Use Cython if available.
try:
from Cython.Build import cythonize
except ImportError:
cythonize = None
from setuptools import setup, find_packages, Extension
from Cython.Build import cythonize
import numpy as np

include_dirs = []
try:
import numpy

include_dirs.append(numpy.get_include())
include_dirs.append(np.get_include())
except ImportError:
print("Numpy and its headers are required to run setup(). Exiting.")
sys.exit(1)
Expand All @@ -40,56 +33,47 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


if cythonize and "clean" not in sys.argv:
ext_modules = cythonize(
[
Extension(
"rio_color.colorspace",
["rio_color/colorspace.pyx"],
extra_compile_args=["-O2"],
)
]
extensions = [
Extension(
"rio_color.colorspace",
["rio_color/colorspace.pyx"],
include_dirs=[np.get_include()],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
)
else:
ext_modules = [Extension("rio_color.colorspace", ["rio_color/colorspace.c"])]

inst_reqs = [
"click>=4.0",
"rasterio~=1.0",
"rio-mucho",
"enum34 ; python_version < '3.4'",
]

inst_reqs = ["click>=8.0", "rasterio~=1.4", "rio-mucho"]

setup(
name="rio-color",
version=version,
description=u"Color correction plugin for rasterio",
description="Color correction plugin for rasterio",
long_description=long_description,
python_requires=">=3.9",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Programming Language :: Cython",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10"
"Programming Language :: Python :: 3.11"
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
"Topic :: Scientific/Engineering :: GIS",
],
keywords="",
author=u"Charlie Loyd",
author="Charlie Loyd",
author_email="[email protected]",
url="https://github.com/mapbox/rio-color",
license="BSD",
packages=find_packages(exclude=["ez_setup", "examples", "tests"]),
include_package_data=True,
zip_safe=False,
install_requires=inst_reqs,
ext_modules=ext_modules,
ext_modules=cythonize(extensions),
include_dirs=include_dirs,
extras_require={"test": ["pytest", "colormath==2.0.2", "pytest-cov", "codecov"]},
extras_require={"test": ["pytest", "colormath==3.0.0", "pytest-cov", "codecov"]},
entry_points="""
[rasterio.rio_plugins]
color=rio_color.scripts.cli:color
Expand Down
3 changes: 1 addition & 2 deletions tests/test_colorspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def _near(a, b, tol):


def _make_array(x, y, z, dtype="float64"):
""" make a 3, 1, 1 array
"""
"""make a 3, 1, 1 array"""
return np.array([[[x]], [[y]], [[z]]]).astype(dtype)


Expand Down

0 comments on commit 3ecc315

Please sign in to comment.