Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scripts to repo #5

Merged
merged 5 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions scripts/convert-with-core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from pathlib import Path

import janitor.polars # noqa: F401
import polars as pl

resource_dir = Path(__file__).resolve().parent.parent
folder_path = resource_dir / "data-raw"

df_experiment1 = pl.read_csv(folder_path / "Expe1.csv", infer_schema_length=100_000)

df_experiment1 = df_experiment1.rename(
{
"bead_size": "bead_size_mm",
"burial_depth": "burial_depth_cm",
"cylinder": "cylinder_id",
"movedup": "num_beads_moved_up",
"moveddown": "num_beads_moved_down",
"nomoved": "num_beads_no_movement",
"total_beads": "total_num_beads",
"proportion_movedup": "proportion_beads_moved_up",
"proportion_moveddown": "proportion_beads_moved_down",
"proportion_nomoved": "proportion_beads_no_movement",
}
)
df_experiment1.write_csv(folder_path / "data-experiment1-ready.csv")

df_experiment2 = pl.read_csv(folder_path / "Expe2.csv", infer_schema_length=100_000)

treatment_mapping1 = {
"masHmasE": "with_feces_cover_after_48h",
"masHmenE": "with_feces_cover_after_0h",
"menHmenE": "without_feces_cover_after_0h",
}

df_experiment2 = (
df_experiment2.with_columns(pl.col("beetle_treatment").replace(treatment_mapping1))
.rename(
{
"site": "site_id",
"burial_depth": "burial_depth_cm",
"bottle": "bottle_id",
"plant_species": "plant_species_name",
"total_seeds": "total_num_seeds",
"emerged_seedlings": "num_emerged_seedlings",
"proportion": "proportion_emerged_seedlings",
}
)
.clean_names()
)

df_experiment2.write_csv(folder_path / "data-experiment2-ready.csv")

df_abundance = pl.read_csv(
folder_path / "Expe3Abundance.csv", infer_schema_length=100_000
)

treatment_mapping2 = {
"masHmasE1": "feces_once_beetle_access",
"masHmenE1": "feces_once_beetle_exclusion",
"masHmasE4": "feces_four_beetle_access",
"masHmenE4": "feces_four_beetle_exclusion",
"menHmenE": "feces_exclusion_beetle_exclusion",
}
df_abundance = df_abundance.with_columns(
pl.col("beetle_treatment").replace(treatment_mapping2)
)

df_richness = pl.read_csv(
folder_path / "Expe3Richness.csv", infer_schema_length=100_000
)

df_experiment3_all = pl.concat([df_abundance, df_richness], how="align") # concat wide

df_experiment3_all = df_experiment3_all.rename(
{"time_measurement": "time_measurement_weeks", "site": "site_id", "plot": "plot_id"}
)

df_experiment3_all.write_csv(folder_path / "data-experiment3-ready.csv")

df_experiment1.glimpse()
df_experiment2.glimpse()
df_experiment3_all.glimpse()
18 changes: 18 additions & 0 deletions scripts/download-data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pathlib import Path
from zipfile import ZipFile

import requests

resource_dir = Path(__file__).resolve().parent.parent
folder_path = resource_dir / "data-raw"

# Download and save the zip file
all_files = requests.get("https://zenodo.org/api/records/4965431/files-archive")

all_files_path = folder_path / "all_files.zip"
with open(all_files_path, "wb") as file:
file.write(all_files.content)

# Extract the zip file
with ZipFile(all_files_path, "r") as zip_ref:
zip_ref.extractall(folder_path)
Empty file removed src/PACKAGE-NAME/__init__.py
Empty file.