zsplit 1.0.0__py3-none-any.whl

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.
zsplit/__init__.py ADDED
@@ -0,0 +1,25 @@
1
+ """
2
+ zsplit — Z-Split Normalization (Zero-Preserving Split Normalization)
3
+ =====================================================================
4
+
5
+ A normalization technique for bipolar spectral indices where zero
6
+ carries physical meaning as a class boundary.
7
+
8
+ >>> import numpy as np
9
+ >>> from zsplit import normalize
10
+ >>> arr = np.array([-0.0004, -0.0002, 0.0, 0.0001, 0.00015])
11
+ >>> normalize(arr)
12
+ array([-1. , -0.5 , 0. , 0.667, 1. ])
13
+
14
+ Author : Abdulrhman Almoadi (KACST)
15
+ DOI : https://doi.org/10.5194/egusphere-2026-672
16
+ """
17
+
18
+ from .core import normalize, normalize_raster
19
+
20
+ __version__ = "1.0.0"
21
+ __author__ = "Abdulrhman Almoadi"
22
+ __email__ = "aalmoadi@kacst.edu.sa"
23
+ __doi__ = "https://doi.org/10.5194/egusphere-2026-672"
24
+
25
+ __all__ = ["normalize", "normalize_raster"]
zsplit/core.py ADDED
@@ -0,0 +1,118 @@
1
+ """
2
+ Z-Split Normalization (Zero-Preserving Split Normalization)
3
+ ===========================================================
4
+
5
+ A normalization technique for bipolar indices where zero carries
6
+ physical meaning as a class boundary (e.g., water vs. non-water).
7
+
8
+ Author : Abdulrhman Almoadi
9
+ Affil. : King Abdulaziz City for Science and Technology (KACST)
10
+ DOI : https://doi.org/10.5194/egusphere-2026-672
11
+ """
12
+
13
+ import numpy as np
14
+
15
+
16
+ def normalize(array, nodata=None):
17
+ """
18
+ Apply Z-Split (Zero-Preserving Split Normalization) to a NumPy array.
19
+
20
+ Positive values are normalized to [0, 1] by dividing by max(positive values).
21
+ Negative values are normalized to [-1, 0] by dividing by abs(min(negative values)).
22
+ Zero values remain exactly zero.
23
+
24
+ Parameters
25
+ ----------
26
+ array : array-like
27
+ Input array (1D, 2D, or nD). Typically a spectral index raster.
28
+ nodata : float or None
29
+ NoData value to exclude. These pixels are returned as NaN.
30
+
31
+ Returns
32
+ -------
33
+ result : np.ndarray
34
+ Normalized array in range [-1, 1] with zero strictly preserved.
35
+
36
+ Examples
37
+ --------
38
+ >>> import numpy as np
39
+ >>> from zsplit import normalize
40
+ >>> arr = np.array([-0.0004, -0.0002, 0.0, 0.0001, 0.00015])
41
+ >>> normalize(arr)
42
+ array([-1. , -0.5 , 0. , 0.667, 1. ])
43
+ """
44
+ arr = np.asarray(array, dtype=np.float64).copy()
45
+
46
+ if nodata is not None:
47
+ arr[arr == nodata] = np.nan
48
+
49
+ result = np.zeros_like(arr)
50
+
51
+ # Positive half: normalize to [0, 1]
52
+ pos_mask = arr > 0
53
+ if pos_mask.any():
54
+ max_pos = np.nanmax(arr[pos_mask])
55
+ if max_pos != 0:
56
+ result[pos_mask] = arr[pos_mask] / max_pos
57
+
58
+ # Negative half: normalize to [-1, 0]
59
+ neg_mask = arr < 0
60
+ if neg_mask.any():
61
+ min_neg = np.nanmin(arr[neg_mask])
62
+ if min_neg != 0:
63
+ result[neg_mask] = arr[neg_mask] / abs(min_neg)
64
+
65
+ # Restore NaN
66
+ result[np.isnan(arr)] = np.nan
67
+
68
+ return result
69
+
70
+
71
+ def normalize_raster(input_path, output_path, nodata=None):
72
+ """
73
+ Apply Z-Split normalization to a GeoTIFF raster file.
74
+
75
+ Requires rasterio. Reads the raster, applies normalize(),
76
+ and saves the result as a new GeoTIFF.
77
+
78
+ Parameters
79
+ ----------
80
+ input_path : str
81
+ Path to input raster (e.g., raw ENDWI .tif).
82
+ output_path : str
83
+ Path where normalized raster will be saved.
84
+ nodata : float or None
85
+ NoData value. If None, reads from raster metadata.
86
+
87
+ Returns
88
+ -------
89
+ output_path : str
90
+ Path to the saved output raster.
91
+
92
+ Examples
93
+ --------
94
+ >>> from zsplit import normalize_raster
95
+ >>> normalize_raster('ENDWI_raw.tif', 'ENDWI_zsplit.tif')
96
+ """
97
+ try:
98
+ import rasterio
99
+ except ImportError:
100
+ raise ImportError(
101
+ "rasterio is required for normalize_raster(). "
102
+ "Install it with: pip install rasterio"
103
+ )
104
+
105
+ with rasterio.open(input_path) as src:
106
+ raw = src.read(1).astype(np.float64)
107
+ profile = src.profile
108
+ if nodata is None:
109
+ nodata = src.nodata
110
+
111
+ result = normalize(raw, nodata=nodata)
112
+
113
+ profile.update(dtype=rasterio.float32, nodata=float('nan'))
114
+
115
+ with rasterio.open(output_path, 'w', **profile) as dst:
116
+ dst.write(result.astype(np.float32), 1)
117
+
118
+ return output_path
@@ -0,0 +1,135 @@
1
+ Metadata-Version: 2.4
2
+ Name: zsplit
3
+ Version: 1.0.0
4
+ Summary: Z-Split Normalization: Zero-Preserving Split Normalization for bipolar spectral indices
5
+ Author-email: Abdulrhman Almoadi <aalmoadi@kacst.edu.sa>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Abdulrhman Almoadi
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/aalmoadi/endwi
29
+ Project-URL: Repository, https://github.com/aalmoadi/endwi
30
+ Project-URL: Documentation, https://github.com/aalmoadi/endwi/tree/main/Z-Split_Normalization
31
+ Project-URL: Bug Tracker, https://github.com/aalmoadi/endwi/issues
32
+ Project-URL: DOI, https://doi.org/10.5281/zenodo.20602710
33
+ Project-URL: Paper, https://doi.org/10.5194/egusphere-2026-672
34
+ Keywords: normalization,remote-sensing,flood-detection,spectral-index,ENDWI,NDWI,bipolar,zero-preserving,Otsu,GIS,GeoAI,machine-learning,deep-learning,SAR,Sentinel-2
35
+ Classifier: Development Status :: 5 - Production/Stable
36
+ Classifier: Intended Audience :: Science/Research
37
+ Classifier: License :: OSI Approved :: MIT License
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.8
40
+ Classifier: Programming Language :: Python :: 3.9
41
+ Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Topic :: Scientific/Engineering :: GIS
45
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
46
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
47
+ Requires-Python: >=3.8
48
+ Description-Content-Type: text/markdown
49
+ License-File: LICENSE
50
+ Requires-Dist: numpy>=1.20
51
+ Provides-Extra: raster
52
+ Requires-Dist: rasterio>=1.2; extra == "raster"
53
+ Provides-Extra: dev
54
+ Requires-Dist: pytest; extra == "dev"
55
+ Requires-Dist: rasterio>=1.2; extra == "dev"
56
+ Requires-Dist: matplotlib; extra == "dev"
57
+ Dynamic: license-file
58
+
59
+ # zsplit — Zero-Preserving Split Normalization
60
+
61
+ [![PyPI version](https://badge.fury.io/py/zsplit.svg)](https://pypi.org/project/zsplit/)
62
+ [![DOI](https://zenodo.org/badge/1037018439.svg)](https://doi.org/10.5281/zenodo.20602709)
63
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
64
+
65
+ A normalization technique for **bipolar spectral indices** where **zero carries physical meaning as a class boundary** (e.g., water vs. non-water in flood detection).
66
+
67
+ ## Installation
68
+
69
+ ```bash
70
+ pip install zsplit
71
+ ```
72
+
73
+ With raster support:
74
+
75
+ ```bash
76
+ pip install zsplit[raster]
77
+ ```
78
+
79
+ ## Quick Start
80
+
81
+ ```python
82
+ import numpy as np
83
+ from zsplit import normalize
84
+
85
+ # Simulated raw ENDWI values (DN scale — extremely narrow range)
86
+ arr = np.array([-0.00041, -0.00020, 0.0, 0.00008, 0.00015])
87
+
88
+ result = normalize(arr)
89
+ print(result)
90
+ # [-1. -0.488 0. 0.533 1. ]
91
+ ```
92
+
93
+ ## Raster Support
94
+
95
+ ```python
96
+ from zsplit import normalize_raster
97
+
98
+ normalize_raster('ENDWI_raw.tif', 'ENDWI_zsplit.tif')
99
+ ```
100
+
101
+ ## Formula
102
+
103
+ ```
104
+ ⎧ x / max(X⁺) if x > 0 → [0, 1]
105
+ Z(x) = ⎨ 0 if x = 0 → 0 (preserved)
106
+ ⎩ x / |min(X⁻)| if x < 0 → [-1, 0]
107
+ ```
108
+
109
+ ## Why Z-Split?
110
+
111
+ | Property | Min-Max | Z-Score | **Z-Split** |
112
+ |---|---|---|---|
113
+ | Preserves zero as class boundary | ❌ | ❌ | ✅ |
114
+ | Stable on narrow near-zero ranges | ❌ | ⚠️ | ✅ |
115
+ | Suitable for Otsu thresholding | ❌ | ⚠️ | ✅ |
116
+ | Handles skewed distributions | ❌ | ⚠️ | ✅ |
117
+ | Multi-temporal direction preserved | ❌ | ❌ | ✅ |
118
+ | Output range | [0, 1] | Unbounded | **[−1, 1]** |
119
+
120
+ ## Citation
121
+
122
+ ```bibtex
123
+ @article{almoadi2026endwi,
124
+ author = {Almoadi, Abdulrhman},
125
+ title = {Reducing False Alarms in Urban Flood Detection: An Enhanced NDWI (ENDWI)
126
+ with Hybrid Max Fusion on Sentinel-2 Data},
127
+ journal = {EGUsphere [preprint]},
128
+ year = {2026},
129
+ doi = {10.5194/egusphere-2026-672}
130
+ }
131
+ ```
132
+
133
+ ## License
134
+
135
+ MIT License
@@ -0,0 +1,7 @@
1
+ zsplit/__init__.py,sha256=xFTDpE6xhEBPBlBkU4r9hKhynbgDynBaZtw77Txr5Wk,799
2
+ zsplit/core.py,sha256=48Sz6taLAlYE73H4URBJdOXb2LxKahQPR93cmmtdkH8,3333
3
+ zsplit-1.0.0.dist-info/licenses/LICENSE,sha256=_8N29XRi8p8QyvL5JPM0QN1Ctx_7NZvaFLfNlPdfY6M,1075
4
+ zsplit-1.0.0.dist-info/METADATA,sha256=ZwU6XdIn3K9gkHatRoHPkCazVAv5Taw41iZjde_30nw,5148
5
+ zsplit-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ zsplit-1.0.0.dist-info/top_level.txt,sha256=BWiFE55QJQvX2OttKLw8bwoE563ydr-BVu5KM8vPs04,7
7
+ zsplit-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdulrhman Almoadi
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 @@
1
+ zsplit