smoother-py 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ cmake_minimum_required(VERSION 3.15...3.27)
2
+
3
+ project(_smoother LANGUAGES CXX)
4
+
5
+ set(CMAKE_CXX_STANDARD 17)
6
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
7
+ set(CMAKE_CXX_EXTENSIONS OFF)
8
+
9
+ if(NOT CMAKE_BUILD_TYPE)
10
+ set(CMAKE_BUILD_TYPE Release)
11
+ endif()
12
+
13
+ # Python
14
+ # SKBUILD_SABI_COMPONENT is set by scikit-build-core when wheel.py-api
15
+ # requests a stable ABI build (Development.SABIModule)
16
+ find_package(Python 3.11 COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT} REQUIRED)
17
+
18
+ # nanobind
19
+ # nanobind is installed as a Python package, so we find it through its CMake dir
20
+ execute_process(
21
+ COMMAND ${Python_EXECUTABLE} -m nanobind --cmake_dir
22
+ OUTPUT_VARIABLE nanobind_ROOT
23
+ OUTPUT_STRIP_TRAILING_WHITESPACE
24
+ RESULT_VARIABLE nanobind_FIND_RESULT
25
+ ERROR_QUIET
26
+ )
27
+
28
+ if(NOT nanobind_FIND_RESULT EQUAL 0)
29
+ message(FATAL_ERROR
30
+ "nanobind not found!\n"
31
+ "Please install nanobind:\n"
32
+ " pip install nanobind\n"
33
+ "\n"
34
+ "If nanobind is installed, make sure you're using the same Python\n"
35
+ "interpreter that has nanobind installed."
36
+ )
37
+ endif()
38
+
39
+ find_package(nanobind CONFIG REQUIRED)
40
+
41
+ # STABLE_ABI: builds abi3 wheels on Python >= 3.12, regular builds otherwise
42
+ nanobind_add_module(_smoother STABLE_ABI src/smooth.cpp)
43
+
44
+ install(TARGETS _smoother LIBRARY DESTINATION smoother)
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ efelipecarlos'at'gmail.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Felipe Carlos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.2
2
+ Name: smoother-py
3
+ Version: 0.1.0
4
+ Summary: Spatial smoothing methods for probability maps.
5
+ Keywords: land use and land cover,lulc,satellite,time-series,metrics,remote-sensing
6
+ Author-Email: Felipe Carlos <efelipecarlos@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 Felipe Carlos
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Classifier: Development Status :: 4 - Beta
30
+ Classifier: Intended Audience :: Science/Research
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python :: 3
33
+ Classifier: Programming Language :: Python :: 3.11
34
+ Classifier: Programming Language :: Python :: 3.12
35
+ Classifier: Programming Language :: Python :: 3.13
36
+ Classifier: Topic :: Scientific/Engineering
37
+ Project-URL: homepage, https://github.com/m3nin0-labs/smoother.py
38
+ Project-URL: repository, https://github.com/m3nin0-labs/smoother.py
39
+ Requires-Python: >=3.11
40
+ Requires-Dist: numpy>=1.26.4
41
+ Provides-Extra: xarray
42
+ Requires-Dist: xarray>=2024.1; extra == "xarray"
43
+ Provides-Extra: examples
44
+ Requires-Dist: rasterio>=1.3; extra == "examples"
45
+ Requires-Dist: rioxarray>=0.15; extra == "examples"
46
+ Requires-Dist: matplotlib>=3.8; extra == "examples"
47
+ Description-Content-Type: text/markdown
48
+
49
+ ## smoother.py 🧹
50
+
51
+ Spatial smoothing methods for probability maps.
52
+
53
+ ### Installation
54
+
55
+ To install the package, you can use pip:
56
+
57
+ ```bash
58
+ pip install git+https://github.com/m3nin0-labs/smoother.py
59
+ ```
60
+
61
+ ### Methods available
62
+
63
+ Currently, the `smoother` implements the [Bayes smoothing method](https://e-sensing.github.io/sitsbook/cl_smoothing.html), adapting the code from the [sits](https://github.com/e-sensing/sits) R package.
64
+
65
+ ### Usage
66
+
67
+ First, import the package:
68
+
69
+ ```python
70
+ import smoother
71
+ ```
72
+
73
+ Then, use the `smooth` function on the `numpy` data of your map. The smoothing method is selected with `method` (defaults to `"bayes"`), and any method-specific options are passed as keyword arguments:
74
+
75
+ ```python
76
+ smoothed = smoother.smooth(your_numpy_array)
77
+
78
+ # selecting the method explicitly and tuning it
79
+ smoothed = smoother.smooth(your_numpy_array, method="bayes", window_size=5)
80
+ ```
81
+
82
+ You can use [rasterio](https://rasterio.readthedocs.io/en/latest/index.html) or other library to load the numpy array.
83
+
84
+ #### xarray
85
+
86
+ `smooth` also accepts `xarray` objects. To use it, first install the `xarray` dependencies:
87
+
88
+ ```bash
89
+ pip install "smoother-py[xarray]"
90
+ ```
91
+
92
+ Then, using your `xarray` data, you can call the `smooth` function:
93
+
94
+ ```python
95
+ # DataArray with class, y and x dimensions
96
+ smoothed = smoother.smooth(your_data_array)
97
+
98
+ # dimension names are inferred (e.g. band/class, y/latitude, x/longitude)
99
+ # you can also name them explicitly
100
+ smoothed = smoother.smooth(your_data_array, class_dim="band")
101
+ ```
102
+
103
+ Extra dimensions (e.g. `time`) are smoothed per layer automatically.
104
+
105
+ #### Discovering the options
106
+
107
+ `smoother.smooth` documents every option, the smoothing parameters and the xarray-only dimension names:
108
+
109
+ ```python
110
+ help(smoother.smooth)
111
+ ```
112
+
113
+ ### Development
114
+
115
+ The project uses [uv](https://docs.astral.sh/uv/) to manage the development environment:
116
+
117
+ ```bash
118
+ # create the environment and build/install the package
119
+ uv sync
120
+
121
+ # run the tests
122
+ uv run pytest
123
+ ```
124
+
125
+ ### Learn more
126
+
127
+ The smoothing methods implemented in this package uses the approach described in the [sits documentation](https://e-sensing.github.io/sitsbook/bayesian-smoothing-for-post-processing.html). This method helps in refining the probability maps by considering the spatial context of each pixel.
128
+
129
+ ### Acknowledgments
130
+
131
+ We would like to thank the developers and contributors of the `sits` R package for their work on spatial smoothing methods for Earth observation data. Their comprehensive [documentation](https://e-sensing.github.io/sitsbook/) and methodologies have been invaluable in the development of `smoother.py`.
132
+
133
+ ### Contributing
134
+
135
+ We welcome contributions! If you have suggestions for improvements or bug fixes, please feel free to fork the repository and submit a pull request.
136
+
137
+ ### License
138
+
139
+ `smoother.py` is distributed under the MIT license. See [LICENSE](./LICENSE) for more details.
@@ -0,0 +1,91 @@
1
+ ## smoother.py 🧹
2
+
3
+ Spatial smoothing methods for probability maps.
4
+
5
+ ### Installation
6
+
7
+ To install the package, you can use pip:
8
+
9
+ ```bash
10
+ pip install git+https://github.com/m3nin0-labs/smoother.py
11
+ ```
12
+
13
+ ### Methods available
14
+
15
+ Currently, the `smoother` implements the [Bayes smoothing method](https://e-sensing.github.io/sitsbook/cl_smoothing.html), adapting the code from the [sits](https://github.com/e-sensing/sits) R package.
16
+
17
+ ### Usage
18
+
19
+ First, import the package:
20
+
21
+ ```python
22
+ import smoother
23
+ ```
24
+
25
+ Then, use the `smooth` function on the `numpy` data of your map. The smoothing method is selected with `method` (defaults to `"bayes"`), and any method-specific options are passed as keyword arguments:
26
+
27
+ ```python
28
+ smoothed = smoother.smooth(your_numpy_array)
29
+
30
+ # selecting the method explicitly and tuning it
31
+ smoothed = smoother.smooth(your_numpy_array, method="bayes", window_size=5)
32
+ ```
33
+
34
+ You can use [rasterio](https://rasterio.readthedocs.io/en/latest/index.html) or other library to load the numpy array.
35
+
36
+ #### xarray
37
+
38
+ `smooth` also accepts `xarray` objects. To use it, first install the `xarray` dependencies:
39
+
40
+ ```bash
41
+ pip install "smoother-py[xarray]"
42
+ ```
43
+
44
+ Then, using your `xarray` data, you can call the `smooth` function:
45
+
46
+ ```python
47
+ # DataArray with class, y and x dimensions
48
+ smoothed = smoother.smooth(your_data_array)
49
+
50
+ # dimension names are inferred (e.g. band/class, y/latitude, x/longitude)
51
+ # you can also name them explicitly
52
+ smoothed = smoother.smooth(your_data_array, class_dim="band")
53
+ ```
54
+
55
+ Extra dimensions (e.g. `time`) are smoothed per layer automatically.
56
+
57
+ #### Discovering the options
58
+
59
+ `smoother.smooth` documents every option, the smoothing parameters and the xarray-only dimension names:
60
+
61
+ ```python
62
+ help(smoother.smooth)
63
+ ```
64
+
65
+ ### Development
66
+
67
+ The project uses [uv](https://docs.astral.sh/uv/) to manage the development environment:
68
+
69
+ ```bash
70
+ # create the environment and build/install the package
71
+ uv sync
72
+
73
+ # run the tests
74
+ uv run pytest
75
+ ```
76
+
77
+ ### Learn more
78
+
79
+ The smoothing methods implemented in this package uses the approach described in the [sits documentation](https://e-sensing.github.io/sitsbook/bayesian-smoothing-for-post-processing.html). This method helps in refining the probability maps by considering the spatial context of each pixel.
80
+
81
+ ### Acknowledgments
82
+
83
+ We would like to thank the developers and contributors of the `sits` R package for their work on spatial smoothing methods for Earth observation data. Their comprehensive [documentation](https://e-sensing.github.io/sitsbook/) and methodologies have been invaluable in the development of `smoother.py`.
84
+
85
+ ### Contributing
86
+
87
+ We welcome contributions! If you have suggestions for improvements or bug fixes, please feel free to fork the repository and submit a pull request.
88
+
89
+ ### License
90
+
91
+ `smoother.py` is distributed under the MIT license. See [LICENSE](./LICENSE) for more details.
@@ -0,0 +1,31 @@
1
+ # Examples
2
+
3
+ Usage example of `smoother.py` on a real classification output.
4
+
5
+ ## Data
6
+
7
+ [`data/`](./data) holds a [`sits`](https://github.com/e-sensing/sits) classification probs GeoTIFF with one band per land-use class, in this order:
8
+
9
+ | Band | Class | Color |
10
+ |------|----------|-----------|
11
+ | 1 | Cerrado | `#a2d43f` |
12
+ | 2 | Forest | `#1E8449` |
13
+ | 3 | Pasture | `#FAD12D` |
14
+ | 4 | Soy_Corn | `#D68910` |
15
+
16
+ The colors come from the QGIS style `data/style.qml` and are reused in the notebook for plotting.
17
+
18
+ ## Running
19
+
20
+ Install the example dependencies:
21
+
22
+ ```bash
23
+ pip install "smoother-py[examples]"
24
+ # or, in this repo: uv sync --extra examples
25
+ ```
26
+
27
+ Then open the notebook:
28
+
29
+ ```bash
30
+ jupyter lab bayes.ipynb
31
+ ```