Skip to content

Commit

Permalink
breakout test data build
Browse files Browse the repository at this point in the history
  • Loading branch information
crvernon committed Dec 19, 2023
1 parent 5bca123 commit 5a08ed0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 48 deletions.
48 changes: 0 additions & 48 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from importlib import resources

import pandas as pd
import pytest

import stitches
from stitches.fx_match import match_neighborhood


@pytest.fixture(scope="session", autouse=True)
Expand All @@ -17,46 +12,3 @@ def setup_package_data():
"""

stitches.install_package_data()


def build_test_data():
"""
Build test data for the test suite.
This function creates and writes out test data files used in the test suite.
It reads the matching archive CSV, filters the data for specific model,
experiment, and ensemble values, and then writes out the data after
performing neighborhood matching.
:return: None
"""
archive_path = resources.files("stitches") / "data" / "matching_archive.csv"
data = pd.read_csv(archive_path)

target_data = data[data["model"] == "BCC-CSM2-MR"]
target_data = target_data[target_data["experiment"] == "ssp245"]
target_data = target_data[target_data["ensemble"] == "r1i1p1f1"]
target_data = target_data.reset_index(drop=True)

archive_data = data[data["model"] == "BCC-CSM2-MR"].copy()
match_df = match_neighborhood(
target_data, archive_data, tol=0.1, drop_hist_duplicates=False
)
match_path = "test-match_w_dup.csv"
match_df.to_csv(match_path, index=False)

match_df = match_neighborhood(
target_data, archive_data, tol=0.1, drop_hist_duplicates=True
)
match_path = "test-match.csv"
match_df.to_csv(match_path, index=False)

path = "test-target_dat.csv"
tar = pd.read_csv(path)

path = "test-archive_dat.csv"
arch = pd.read_csv(path)

match_df = match_neighborhood(tar, arch, tol=0.1, drop_hist_duplicates=True)
match_path = "test-match_dat.csv"
match_df.to_csv(match_path, index=False)
41 changes: 41 additions & 0 deletions tests/make_test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
def build_test_data():
"""
Build test data for the test suite.
This function creates and writes out test data files used in the test suite.
It reads the matching archive CSV, filters the data for specific model,
experiment, and ensemble values, and then writes out the data after
performing neighborhood matching.
:return: None
"""
archive_path = resources.files("stitches") / "data" / "matching_archive.csv"
data = pd.read_csv(archive_path)

target_data = data[data["model"] == "BCC-CSM2-MR"]
target_data = target_data[target_data["experiment"] == "ssp245"]
target_data = target_data[target_data["ensemble"] == "r1i1p1f1"]
target_data = target_data.reset_index(drop=True)

archive_data = data[data["model"] == "BCC-CSM2-MR"].copy()
match_df = match_neighborhood(
target_data, archive_data, tol=0.1, drop_hist_duplicates=False
)
match_path = "test-match_w_dup.csv"
match_df.to_csv(match_path, index=False)

match_df = match_neighborhood(
target_data, archive_data, tol=0.1, drop_hist_duplicates=True
)
match_path = "test-match.csv"
match_df.to_csv(match_path, index=False)

path = "test-target_dat.csv"
tar = pd.read_csv(path)

path = "test-archive_dat.csv"
arch = pd.read_csv(path)

match_df = match_neighborhood(tar, arch, tol=0.1, drop_hist_duplicates=True)
match_path = "test-match_dat.csv"
match_df.to_csv(match_path, index=False)

0 comments on commit 5a08ed0

Please sign in to comment.