Skip to content

Commit 79b94d7

Browse files
authored
Merge pull request #2 from ITISFoundation/cbujard/exe
add valset_producer
2 parents d4a82fb + 8e1c75c commit 79b94d7

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
lines changed

.github/badges/coverage.svg

Lines changed: 5 additions & 5 deletions
Loading

coverage.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ tests/test_voronoi.py . [100%]
1313
================================ tests coverage ================================
1414
_______________ coverage: platform linux, python 3.10.18-final-0 _______________
1515

16-
Name Stmts Miss Cover Missing
17-
--------------------------------------------------------------
18-
src/sar_sampling/__init__.py 4 0 100%
19-
src/sar_sampling/lhs.py 182 28 85% 77, 92, 94, 96, 99, 105, 107, 110, 112, 116, 119, 133, 163-166, 182, 238, 294, 305, 312-319, 323
20-
src/sar_sampling/sample.py 95 8 92% 86, 88, 90, 101, 193, 214, 216, 222
21-
src/sar_sampling/sarsampler.py 189 23 88% 124, 128-129, 200, 251-252, 271, 273, 276, 290, 295, 299-300, 306, 318-321, 329, 331, 342-343, 345, 353
22-
src/sar_sampling/voronoi.py 66 4 94% 41, 43, 59, 64
23-
--------------------------------------------------------------
24-
TOTAL 536 63 88%
25-
============================== 17 passed in 5.23s ==============================
16+
Name Stmts Miss Cover Missing
17+
-------------------------------------------------------------------
18+
src/sar_sampling/__init__.py 4 0 100%
19+
src/sar_sampling/data/__init__.py 0 0 100%
20+
src/sar_sampling/lhs.py 182 28 85% 77, 92, 94, 96, 99, 105, 107, 110, 112, 116, 119, 133, 163-166, 182, 238, 294, 305, 312-319, 323
21+
src/sar_sampling/sample.py 95 8 92% 86, 88, 90, 101, 193, 214, 216, 222
22+
src/sar_sampling/sarsampler.py 189 23 88% 124, 128-129, 200, 251-252, 271, 273, 276, 290, 295, 299-300, 306, 318-321, 329, 331, 342-343, 345, 353
23+
src/sar_sampling/valset_producer.py 18 18 0% 1-37
24+
src/sar_sampling/voronoi.py 66 4 94% 41, 43, 59, 64
25+
-------------------------------------------------------------------
26+
TOTAL 554 81 85%
27+
============================== 17 passed in 5.09s ==============================

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
url="https://github.com/ITISFoundation/sarsampling-iec62209",
1818
packages=find_packages(where="src"),
1919
package_dir={"": "src"},
20+
package_data={"sar_sampling": ["data/*.csv"]},
2021
classifiers=[
2122
"Intended Audience :: Science/Research",
2223
"License :: OSI Approved :: MIT License",

src/sar_sampling/data/__init__.py

Whitespace-only changes.
File renamed without changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import importlib.resources as pkg_resources
2+
import pandas as pd
3+
from io import StringIO
4+
from sar_sampling import SarSampler
5+
6+
def main(arg=None) -> None:
7+
"""
8+
Main function to generate a sample dataset using SAR sampling.
9+
10+
This function loads input data from the package resources, creates a SarSampler
11+
instance, generates a sample of 225 data points, and saves the result to a CSV file.
12+
13+
The function handles exceptions gracefully and provides error information if
14+
the sampling process fails.
15+
16+
Returns:
17+
None
18+
19+
Side Effects:
20+
- Creates a file named 'sample_225.csv' in the current directory
21+
- Prints status messages to stdout
22+
- Prints error messages and traceback to stdout if an exception occurs
23+
"""
24+
try:
25+
csv_content = pkg_resources.read_text('sar_sampling.data', 'input_table.csv')
26+
input_df = pd.read_csv(StringIO(csv_content))
27+
sampler = SarSampler(input_df)
28+
sample = sampler(n_samples=225)
29+
sample.to_csv(f"sample_225.csv")
30+
print(f"Sample saved.")
31+
except Exception as e:
32+
print(f"Error: {e}")
33+
import traceback
34+
traceback.print_exc()
35+
36+
if __name__ == "__main__":
37+
main()

0 commit comments

Comments
 (0)