Reproducible Data Analysis and Visualization

Terminal, Git, Conda, Pandas, Seaborn, Snakemake

Lars Berling

Definition(s)

  • ability to recalculate a figure from data, parameters, and programs

  • reproducibility requires change, replicability avoids change

  • replication = regeneration of published results from author-provided code and data, reproducibility = more general term

  • repeatability = keep same conditions, and reproducibility = change conditions of the experiment

Corroborate vs. reproducibility

  • corroborate: to support with new evidence, make more certain
  • reproduce: to produce again, make a copy of

→ Reproducing your own work easily

Overview of content

  • Terminal
  • Git
  • Conda
  • Python plotting
    • Pandas
    • Seaborn
  • Snakemake

Why should you care about this?

  • For your thesis or a research paper there are always revisions
  • Errors, bugs, or requests to change something
  • Do your future self a favor now…
  • Having the ability to reproduce your results in case of disaster
  • Reproducible result → Part of the scientific method

Goal of this talk

Not a software tutorial but Exposure

Terminal

Why bother with the terminal?

  • Often no desktop GUI on servers
  • Required/Nicer to use certain tools, e.g. git
  • Helps you undertand computers/programs

Working with files

mkdir project              # Create folder
touch file.txt             # Create file
rm file.txt                # Remove file
cp file.txt backup.txt     # Copy file
mv file.txt newname.txt    # Move/rename file

Useful terminal tools

man     # Documentation
diff    # Compare file differences
cat     # Investigate content of file (bat)
grep    # Search text in files

Version Control

The problem

  • A completely normal folder:
project/
├── report
├── report_v2
├── report_v3_final
├── report_v3_final_REALLY
├── report_v4_comments
├── report_FINAL_THISONE
├── report_FINAL_Final
  • Which file is the latest version?
  • What actually changed?

What is version control?

  • Track changes of files over time
  • Revert changes
  • Go back to previous versions
  • Collaboration off-/online at the same time

Git

Core Concepts

  • Repository (repo)
  • Commit (snapshot)
  • Branch (timelines)
  • HEAD (Where am I?)

Basic Workflow

# Initialize repository
git init

# Inspect changes
git status
git diff

# Stage changes
git add <file>

# Commit snapshots
git commit -m "message"

# Sync with remote
git push

Collaboration via Github

  • Github is a platform that shares repos online
  • Like a cloud for git repos
  • There are also other services such as GitLab or Bitbucket
  • Pull Requests (PR) and Forks are a collaboration feature of Github

Environment Control

Irreproducible Environments

  • Different versions

    → different results

  • Global installation = messy

Reproducible Environments

  • Conda: Open-source, cross-platform package/environment manager
  • Appstore that handles complex dependencies
  • Keeps projects/environments isolated

→ one project = one box = one conda environment

One step further:

  • Containers/Docker → on top of your OS
  • VMs (virtual machine) → a complete standalone OS

Dependency Tree

  • Conda handles software project dependencies
  • More packages, more dependencies
  • What are all the dependencies?

Basic Workflow

# Create and activate an environment
conda create -n demo
conda activate demo
# conda deactivate

# Install packages/software
conda install python pandas seaborn numpy jupyter quarto
pip install snakemake

# List all environments that you have
conda env list

# Search through different versions that exist
conda search python
# Export environment to share it
conda env export > talk_environment.yml
conda env create -f talk_environment.yml -n demo
name: demo
channels:
  - conda-forge
dependencies:
  - _openmp_mutex=4.5=7_kmp_llvm
  - _python_abi3_support=1.0=hd8ed1ab_2
  - anyio=4.13.0=pyhcf101f3_0
  - appnope=0.1.4=pyhd8ed1ab_1
  - argon2-cffi=25.1.0=pyhd8ed1ab_0
  - argon2-cffi-bindings=25.1.0=py314h6482030_2
  - arrow=1.4.0=pyhcf101f3_0
  - asttokens=3.0.1=pyhd8ed1ab_0
  - async-lru=2.3.0=pyhcf101f3_0
  - attrs=26.1.0=pyhcf101f3_0
  - babel=2.18.0=pyhcf101f3_1
  - backports.zstd=1.4.0=py314h680f03e_0
  - beautifulsoup4=4.14.3=pyha770c72_0
  - bleach=6.3.0=pyhcf101f3_1
  - bleach-with-css=6.3.0=hbca2aae_1
  - brotli=1.2.0=hf139dec_1
  - brotli-bin=1.2.0=h8616949_1
  - brotli-python=1.2.0=py314h3262eb8_1
  - bzip2=1.0.8=h500dc9f_9
  - ca-certificates=2026.4.22=hbd8a1cb_0
  - cached-property=1.5.2=hd8ed1ab_1
  - cached_property=1.5.2=pyha770c72_1
  - certifi=2026.4.22=pyhd8ed1ab_0
  - cffi=2.0.0=py314h8ca4d5a_1
  - charset-normalizer=3.4.7=pyhd8ed1ab_0
  - comm=0.2.3=pyhe01879c_0
  - contourpy=1.3.3=py314h22a2ed9_4
  - cpython=3.14.4=py314hd8ed1ab_100
  - cycler=0.12.1=pyhcf101f3_2
  - dart-sass=1.99.0=h8822bef_0
  - debugpy=1.8.20=py314h2f9fc56_0
  - decorator=5.2.1=pyhd8ed1ab_0
  - defusedxml=0.7.1=pyhd8ed1ab_0
  - deno=2.4.5=h42a321a_0
  - deno-dom=0.1.41=h51332c3_0
  - esbuild=0.28.0=h5839d16_0
  - exceptiongroup=1.3.1=pyhd8ed1ab_0
  - executing=2.2.1=pyhd8ed1ab_0
  - fonttools=4.62.1=pyh7db6752_0
  - fqdn=1.5.1=pyhd8ed1ab_1
  - freetype=2.14.3=h694c41f_0
  - h11=0.16.0=pyhcf101f3_1
  - h2=4.3.0=pyhcf101f3_0
  - hpack=4.1.0=pyhd8ed1ab_0
  - httpcore=1.0.9=pyh29332c3_0
  - httpx=0.28.1=pyhd8ed1ab_0
  - hyperframe=6.1.0=pyhd8ed1ab_0
  - icu=78.3=h25d91c4_0
  - idna=3.13=pyhcf101f3_0
  - importlib-metadata=8.8.0=pyhcf101f3_0
  - importlib_resources=7.1.0=pyhd8ed1ab_0
  - ipykernel=7.2.0=pyh5552912_1
  - ipython=9.13.0=pyh53cf698_0
  - ipython_pygments_lexers=1.1.1=pyhd8ed1ab_0
  - ipywidgets=8.1.8=pyhd8ed1ab_0
  - isoduration=20.11.0=pyhd8ed1ab_1
  - jedi=0.19.2=pyhd8ed1ab_1
  - jinja2=3.1.6=pyhcf101f3_1
  - json5=0.14.0=pyhd8ed1ab_0
  - jsonpointer=3.1.1=pyhcf101f3_0
  - jsonschema=4.26.0=pyhcf101f3_0
  - jsonschema-specifications=2025.9.1=pyhcf101f3_0
  - jsonschema-with-format-nongpl=4.26.0=hcf101f3_0
  - jupyter=1.1.1=pyhd8ed1ab_1
  - jupyter-lsp=2.3.1=pyhcf101f3_0
  - jupyter_client=8.8.0=pyhcf101f3_0
  - jupyter_console=6.6.3=pyhd8ed1ab_1
  - jupyter_core=5.9.1=pyhc90fa1f_0
  - jupyter_events=0.12.1=pyhcf101f3_0
  - jupyter_server=2.18.2=pyhcf101f3_0
  - jupyter_server_terminals=0.5.4=pyhcf101f3_0
  - jupyterlab=4.5.7=pyhd8ed1ab_0
  - jupyterlab_pygments=0.3.0=pyhd8ed1ab_2
  - jupyterlab_server=2.28.0=pyhcf101f3_0
  - jupyterlab_widgets=3.0.16=pyhcf101f3_1
  - kiwisolver=1.5.0=py314hd6e1bd6_0
  - krb5=1.22.2=h207b36a_0
  - lark=1.3.1=pyhd8ed1ab_0
  - lcms2=2.19.1=h5ea7634_0
  - lerc=4.1.0=h35c7297_0
  - libblas=3.11.0=6_he492b99_openblas
  - libbrotlicommon=1.2.0=h8616949_1
  - libbrotlidec=1.2.0=h8616949_1
  - libbrotlienc=1.2.0=h8616949_1
  - libcblas=3.11.0=6_h9b27e0a_openblas
  - libcxx=22.1.4=h19cb2f5_0
  - libdeflate=1.25=h517ebb2_0
  - libedit=3.1.20250104=pl5321ha958ccf_0
  - libexpat=2.8.0=hcc62823_0
  - libffi=3.5.2=hd1f9c09_0
  - libfreetype=2.14.3=h694c41f_0
  - libfreetype6=2.14.3=h58fbd8d_0
  - libgcc=15.2.0=h08519bb_18
  - libgfortran=15.2.0=h7e5c614_18
  - libgfortran5=15.2.0=hd16e46c_18
  - libjpeg-turbo=3.1.4.1=ha1e9b39_0
  - liblapack=3.11.0=6_h859234e_openblas
  - liblzma=5.8.3=hbb4bfdb_0
  - libmpdec=4.0.0=hf3981d6_1
  - libopenblas=0.3.32=openmp_h9e49c7b_0
  - libpng=1.6.58=he930e7c_0
  - libsodium=1.0.21=hc6ced15_3
  - libsqlite=3.53.1=h8f8c405_0
  - libtiff=4.7.1=ha0a348c_1
  - libwebp-base=1.6.0=hb807250_0
  - libxcb=1.17.0=hf1f96e2_0
  - libzlib=1.3.2=hbb4bfdb_2
  - llvm-openmp=22.1.4=h0d3cbff_0
  - markupsafe=3.0.3=py314h77fa6c7_1
  - matplotlib-base=3.10.9=py314h7c1ad30_0
  - matplotlib-inline=0.2.1=pyhd8ed1ab_0
  - mistune=3.2.1=pyhcf101f3_0
  - munkres=1.1.4=pyhd8ed1ab_1
  - nbclient=0.10.4=pyhd8ed1ab_0
  - nbconvert-core=7.17.1=pyhcf101f3_0
  - nbformat=5.10.4=pyhd8ed1ab_1
  - ncurses=6.6=hcc0dc9a_0
  - nest-asyncio=1.6.0=pyhd8ed1ab_1
  - notebook=7.5.6=pyhcf101f3_1
  - notebook-shim=0.2.4=pyhd8ed1ab_1
  - numpy=2.4.3=py314h7b24d9b_0
  - openjpeg=2.5.4=h52bb76a_0
  - openssl=3.6.2=hc881268_0
  - overrides=7.7.0=pyhd8ed1ab_1
  - pandas=3.0.2=py314h99bb933_0
  - pandoc=3.8.3=h694c41f_0
  - pandocfilters=1.5.0=pyhd8ed1ab_0
  - parso=0.8.7=pyhcf101f3_0
  - patsy=1.0.2=pyhcf101f3_0
  - pexpect=4.9.0=pyhd8ed1ab_1
  - pillow=12.2.0=py314hc904d5e_0
  - pip=26.1.1=pyh145f28c_0
  - platformdirs=4.9.6=pyhcf101f3_0
  - prometheus_client=0.25.0=pyhd8ed1ab_0
  - prompt-toolkit=3.0.52=pyha770c72_0
  - prompt_toolkit=3.0.52=hd8ed1ab_0
  - psutil=7.2.2=py314hd330473_0
  - pthread-stubs=0.4=h00291cd_1002
  - ptyprocess=0.7.0=pyhd8ed1ab_1
  - pure_eval=0.2.3=pyhd8ed1ab_1
  - pycparser=2.22=pyh29332c3_1
  - pygments=2.20.0=pyhd8ed1ab_0
  - pyobjc-core=12.1=py314h681fd4f_0
  - pyobjc-framework-cocoa=12.1=py314h9720295_0
  - pyparsing=3.3.2=pyhcf101f3_0
  - pysocks=1.7.1=pyha55dd90_7
  - python=3.14.4=h7c6738f_100_cp314
  - python-dateutil=2.9.0.post0=pyhe01879c_2
  - python-fastjsonschema=2.21.2=pyhe01879c_0
  - python-gil=3.14.4=h4df99d1_100
  - python-json-logger=3.2.1=pyh332efcf_0
  - python-tzdata=2026.2=pyhd8ed1ab_0
  - python_abi=3.14=8_cp314
  - pyyaml=6.0.3=py314h10d0514_1
  - pyzmq=27.1.0=py312h2ac7433_2
  - qhull=2020.2=h3c5361c_5
  - quarto=1.9.37=hc49bbda_1
  - readline=8.3=h68b038d_0
  - referencing=0.37.0=pyhcf101f3_0
  - requests=2.33.1=pyhcf101f3_1
  - rfc3339-validator=0.1.4=pyhd8ed1ab_1
  - rfc3986-validator=0.1.1=pyh9f0ad1d_0
  - rfc3987-syntax=1.1.0=pyhe01879c_1
  - rpds-py=0.30.0=py314ha7b6dee_0
  - scipy=1.17.1=py314h5727af0_0
  - seaborn=0.13.2=hd8ed1ab_3
  - seaborn-base=0.13.2=pyhd8ed1ab_3
  - send2trash=2.1.0=pyh5552912_1
  - setuptools=82.0.1=pyh332efcf_0
  - six=1.17.0=pyhe01879c_1
  - sniffio=1.3.1=pyhd8ed1ab_2
  - soupsieve=2.8.3=pyhd8ed1ab_0
  - stack_data=0.6.3=pyhd8ed1ab_1
  - statsmodels=0.14.6=py314hd1ec8a2_0
  - terminado=0.18.1=pyhc90fa1f_1
  - tinycss2=1.4.0=pyhd8ed1ab_0
  - tk=8.6.13=h7142dee_3
  - tomli=2.4.1=pyhcf101f3_0
  - tornado=6.5.5=py314h217eccc_0
  - traitlets=5.15.0=pyhcf101f3_0
  - typing-extensions=4.15.0=h396c80c_0
  - typing_extensions=4.15.0=pyhcf101f3_0
  - typing_utils=0.1.0=pyhd8ed1ab_1
  - typst=0.14.2=h121f529_0
  - tzdata=2025c=hc9c84f9_1
  - unicodedata2=17.0.1=py314h4f144dc_0
  - uri-template=1.3.0=pyhd8ed1ab_1
  - urllib3=2.6.3=pyhd8ed1ab_0
  - wcwidth=0.7.0=pyhd8ed1ab_0
  - webcolors=25.10.0=pyhd8ed1ab_0
  - webencodings=0.5.1=pyhd8ed1ab_3
  - websocket-client=1.9.0=pyhd8ed1ab_0
  - widgetsnbextension=4.0.15=pyhd8ed1ab_0
  - xorg-libxau=1.0.12=h8616949_1
  - xorg-libxdmcp=1.1.5=h8616949_1
  - yaml=0.2.5=h4132b18_3
  - zeromq=4.3.5=h27d9b8f_10
  - zipp=3.23.1=pyhcf101f3_0
  - zlib-ng=2.3.3=h8bce59a_1
  - zstd=1.5.7=h3eecb57_6
  - pip:
    - annotated-types==0.7.0
    - argparse-dataclass==2.0.0
    - conda-inject==1.3.2
    - configargparse==1.7.5
    - connection-pool==0.0.3
    - docutils==0.22.4
    - dpath==2.2.0
    - gitdb==4.0.12
    - gitpython==3.1.50
    - greenlet==3.5.0
    - humanfriendly==10.0
    - immutables==0.21
    - packaging==25.0
    - pulp==3.3.1
    - pydantic==2.13.4
    - pydantic-core==2.46.4
    - smart-open==7.6.0
    - smmap==5.0.3
    - snakemake==9.20.0
    - snakemake-interface-common==1.23.0
    - snakemake-interface-executor-plugins==9.4.0
    - snakemake-interface-logger-plugins==2.0.1
    - snakemake-interface-report-plugins==1.3.0
    - snakemake-interface-scheduler-plugins==2.0.2
    - snakemake-interface-storage-plugins==4.4.1
    - sqlalchemy==2.0.49
    - sqlmodel==0.0.37
    - tabulate==0.10.0
    - tenacity==9.1.4
    - throttler==1.2.3
    - typing-inspection==0.4.2
    - wrapt==2.1.2
    - yte==1.9.4

Data wrangling

Data handling

Raw data is rarely useful:

  • Large amounts of text or numbers
  • Messy formats
  • Hard to grasp information

We need to:

  1. Clean/transform it for a computer
  2. Visualize it for exploration/analysis

Dataframes

  • Dataframe is a 2 dimensional labeled datastructure
  • Like a Matrix we have rows and columns
  • ‘Index’ for rows and different datatypes for columns
  • common file formats are .csv (comma-separated values)
Name,Age,Haircolor
Tom,67,white
Rob,30,black
Vivi,18,blue
import pandas as pd

df = pd.read_csv("data.csv", sep=',')

Other common separators are ; \t

Basic operations

df['col']            # Column by name
df[['col1', 'col3']] # Multiple columns
df.loc[label]        # Row by label
df.iloc[1]           # Row by index
df[5:10]             # Slice of rows
df['col1':'col3']    # Slice of columns
df["has_black_hair"] = df["haircolor"] == 'black'      # New Bool column
df_sub = df[df["haircolor"] == 'white']   # Selection with a bool
df.dropna()                     # Remvoing missing data
df.fillna('-42')                # Replacing missing data ...
# Create and transform
df["log_value"] = np.log(df["value"])
df["product_one_two"] = (
    df["col_one"] * df["col_two"]
)
# Delete columns
del df["two"]

Aggregation (GroupBy)

Idea: Summarize data by category

df.read_csv('data.csv', sep=',')

# Mean per group
df.groupby("Group")["Value"].mean()

# Multiple aggregations
df.groupby("Group")["Value"].agg(
    ["mean", "sum", "count"]
)

Example data.csv

Name,Group,Value
John,A,10
Tris,A,20
Jane,B,5
Vlad,B,7
  • Split data into groups
  • Apply a function to each
  • Combine result
       mean  sum  count
Group
A      15.0   30      2
B       6.0   12      2

Generating Dataframes

Often compute data inside a script

import pandas as pd

data = [
    ["John", "A", 10],
    ["Tris", "A", 20],
    ["Jane", "B", 5],
    ["Vlad", "B", 7]
]
df = pd.DataFrame(data, columns=["Name", "Group", "Value"])
df.to_csv("my_data.csv", index=False)
import pandas as pd

data = {
    "Name": ["John", "Tris", "Jane", "Vlad"],
    "Group": ["A", "A", "B", "B"],
    "Value": [10, 20, 5, 7]
}
df = pd.DataFrame(data)
df.to_csv("my_data.csv", index=False)

Polars as alternative

  • Much faster on large datasets than Pandas
  • Open source Rust package/crate
  • For huge amounts of data and runtime problems reading it

Seaborn + Matplotlib

Basic Guidelines

  • Figures should be derived, not handcrafted
  • Same input → same output
  • Visualization is part of the pipeline
  • No manual edits after export

Plotting with pandas + seaborn

  • Work directly with dataframes
  • Minimal code to generate plots
  • Built on top of matplotlib
import seaborn as sns

sns.lineplot(data=df, x="time", y="value", hue="group")
plt.savefig("plot.pdf")

Reproducible Plot Generation

Code
def make_plot(df, data_name):
    sns.set_context("talk", font_scale=1.4)

    plt.figure(figsize=(7, 5))
    sns.lineplot(data=df, x="time", y="value", hue="group", legend=False)
    plt.xticks([0, 14, 42, 67, 84, 100])
    plt.yticks([4, -1, -6])
    plt.title(f"make_plot({data_name})")
    plt.tight_layout()

Takeaways for figures

  • Treat each plot as code or a script

    → One script produces one (set of) figure(s)

  • Plots should be easy to change

  • Labels should be readable

    → Make it easy to adjust/change font sizes

  • Separate the data processing from plotting

  • Use vector formats (PDF, SVG) for plots

    → for example in python plt.savefig("myplot.pdf")

End-to-End Automation

Definition

  • Fully automated workflow from raw input → final result
  • No manual steps in between
  • Entire process is easily executable

Why?

Reproducibility Same input → same output

Efficiency Avoid repetition, smart recomputation

Reliability Easier debugging, standardized workflows

Collaboration Share your pipeline with others easily

Workflow management

What is Snakemake

A workflow management system defined by rules:

  • input files
  • output files
  • command/script/code to execute

What it does automatically

  • Builds dependency graph (DAG) → execution order
  • Re-runs only changed parts
  • Keeps whole pipeline consistent

Example Workflow

SAMPLES = range(1, 11)

rule all:
    input:
        expand("results/{sample}.out", sample=SAMPLES)

rule analysis:
    input:
        "data/{sample}.txt"
    output:
        "results/{sample}.out"
    shell:
        """
        cp {input} {output}
        echo "Snakemake made this file." >> {output}
        """

Tool Summary

  • Reproducibility (Concept)
  • Terminal
  • Version Control (Git)
  • Computing environment management (Conda)
  • Data processing (Pandas)
  • Data visualization (Matplotlib + Seaborn)
  • Workflow management (Snakemake)

Idea summary

  • Structure > chaos (folder, files, code functions)
  • Don’t be afraid of multiple files
  • Keep things logically separated
  • Commit early, commit often
  • Descriptive names for files and variables > clever abbreviations
  • If you do it more than once → automation?!

Any questions?

Github/Lars-B/computational-math-talk

Thank you!