Skip to content

Commit

Permalink
Update STAC item centroid to use Python float instead of numpy.float64 (
Browse files Browse the repository at this point in the history
#55)

* Update STAC item centroid to use Python float instead of numpy.float64

* Change to use type and ==
  • Loading branch information
ghidalgo3 authored Feb 2, 2024
1 parent 984a60e commit 1f0aa9f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This project attempts to match the major and minor versions of [stactools](https://github.com/stac-utils/stactools) and increments the patch number as needed.

## Unreleased

### Changed

- STAC item centroid uses Python `float` instead of `numpy.float64`.

## [v0.5.0] - 2024-01-17

### Added
Expand Down
6 changes: 5 additions & 1 deletion src/stactools/naip/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ def create_item(
projection.shape = image_shape
projection.bbox = original_bbox
projection.transform = transform
projection.centroid = {"lat": round(centroid.y, 5), "lon": round(centroid.x, 5)}
# Avoid shipping numpy floats
projection.centroid = {
"lat": round(centroid.y, 5).item(),
"lon": round(centroid.x, 5).item(),
}

# Grid Extension
grid = GridExtension.ext(item, add_if_missing=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,6 @@ def test_create_item_2022(self):
self.assertEqual(item.id, "ca_m_4112001_sw_10_060_20220716")
schemas = item.validate()
self.assertTrue(schemas)

assert type(item.properties["proj:centroid"]["lat"]) == float
assert type(item.properties["proj:centroid"]["lon"]) == float

0 comments on commit 1f0aa9f

Please sign in to comment.