-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from pfebrer/viz_data_sources
Cleaning tutorial notebooks.
- Loading branch information
Showing
5 changed files
with
66 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import numpy as np | ||
|
||
def normalize(data, vmin=0, vmax=1): | ||
"""Normalize data to [vmin, vmax] range. | ||
Parameters | ||
---------- | ||
data : array_like | ||
Data to normalize. | ||
vmin : float, optional | ||
Minimum value of normalized data. | ||
vmax : float, optional | ||
Maximum value of normalized data. | ||
Returns | ||
------- | ||
data : array_like | ||
Normalized data. | ||
""" | ||
data = np.asarray(data) | ||
data_min = np.min(data) | ||
data_max = np.max(data) | ||
return vmin + (vmax - vmin) * (data - data_min) / (data_max - data_min) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import numpy as np | ||
|
||
from sisl.viz.processors.math import normalize | ||
|
||
def test_normalize(): | ||
|
||
data = [0, 1, 2] | ||
|
||
assert np.allclose(normalize(data), [0, 0.5, 1]) | ||
|
||
assert np.allclose(normalize(data, vmin=-1, vmax=1), [-1, 0, 1]) | ||
|