Skip to content

Commit 3554a86

Browse files
committed
add valset_producer
1 parent d4a82fb commit 3554a86

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

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)