slides/modules/dataset-production.html

497 lines
18 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<title>Producing datasets</title>
<meta name="description" content="FILLIN">
<meta name="author" content="FILLIN">
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<!-- Original reveal JS stylesheets-->
<link rel="stylesheet" href="../reveal.js/dist/reset.css">
<link rel="stylesheet" href="../reveal.js/dist/reveal.css">
<link rel="stylesheet" href="../reveal.js/dist/theme/beige.css">
<!-- custom styles, e.g., imgcredit -->
<link rel="stylesheet" href="../custom/css/main-no-copy.css" id="theme">
<script src="../custom/js/printpdf.js"></script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<section data-markdown data-transition="none"><script type="text/template">
# Creating datasets
We create a DataLad dataset from scratch, take a look at version control,
and how to do digital transformations transparently and reproducibly.
</script></section>
<section style="text-align:left" data-markdown data-transition="none"><script type="text/template">
## Terminal time!<!-- .element: style="text-align:center" -->
We will be using the datalad command line interface in a terminal
on your machine.
Make sure to activate your DataLad installation:
Mac/Linux:
```console
source $(uv tool dir)/datalad/bin/activate
```
Windows (`cmd.exe`):
```console
AppData\Roaming\uv\tools\datalad\Scripts\activate.bat
```
</script></section>
<section style="text-align:left" data-markdown data-transition="none"><script type="text/template">
## Create a dataset<!-- .element: style="text-align:center" -->
Open a terminal and run the following command
```console
datalad create -c yoda penguin-beaks
```
<!-- .element: style="font-size:75%" -->
On success, you should see something like
```
create(ok): ... (dataset)
```
What did you get as a result?
</script></section>
</section>
<section>
<section data-markdown data-transition="none"><script type="text/template">
# Version control - let's make history
![](../img/xkcd/3064.png)<!-- .element: style="height:800px" -->
</script></section>
<section data-transition="None">
<dl style="font-size:40px">
<dt>The building blocks of a scientific result are rarely static</dt>
<table><tr><td style="vertical-align:middle">
Analysis code, manuscripts, ... evolve.<br>
<small>(Rewrite, fix bugs, add functions,
refactor, extend, ...)</small>
</td> </tr></table>
<dt>Version control helps you to... </dt>
<table><tr><td>
<img src="../img/turing-way-figures/projecthistory-withouttext.svg" width="600">
<imgcredit><a href="https://the-turing-way.netlify.app/reproducible-research/vcs/vcs-data.html" target="_blank">
CC-BY Scriberia & The Turing Way</a></imgcredit>
</td><td>
<ul style="vertical-align:bottom">
<li>keep things organized</li>
<li>keep track of changes</li>
<li>revert changes or go <br>
back to previous states</li>
<li>collect and share digital provenance</li>
</ul>
</td></tr></table>
</dl>
</section>
<section data-transition="None">
<dl style="font-size:40px">
<dt>The building blocks of a scientific result are rarely static</dt>
<table><tr><td style="vertical-align:middle">
<strong>Data</strong> changes, too! <br>
<small>(errors are fixed, data is extended, naming standards change, <br>
an analysis requires only a subset of your data...)
</small>
</tr>
</table>
</dl>
<br><br>
Sadly, Git doesn't handle large files well.
<div class="r-stack">
<img class="fragment fade-out" src="../img/concepts/gitsnapshot.png">
<img src="../img/concepts/gitsnapshot2.png">
</div>
</section>
</section>
<section>
<section data-markdown data-transition="none"><script type="text/template">
# DataLad Datasets
A DataLad dataset is a joined Git + git-annex repository
![](../img/concepts/datalad_sandwhich.svg)
![](../img/comics/comic_box4.svg)
</script></section>
<section style="text-align:left" data-markdown data-transition="none"><script type="text/template">
## Explore the dataset<!-- .element: style="text-align:center" -->
- Run the following command in the root of the dataset (`cd penguin-beaks`).
```
git log
```
<!-- .element: style="font-size:75%" -->
- ``-c yoda`` is a special configuration. What did it do? (You can also use a file manager or the terminal to explore)
</script></section>
<section style="text-align:left" data-markdown data-transition="none"><script type="text/template">
## Changing states<!-- .element: style="text-align:center" -->
- The dataset will become a home to a penguin-related data science project.
Edit the `README.md` file with a text editor of your choice and add the description
"A penguin related data science project".
- Run the following commands in the root of the dataset (`cd penguin-beaks`).
```
datalad status
```
<!-- .element: style="font-size:75%" -->
```
git diff
```
<!-- .element: style="font-size:75%" -->
</script></section>
<section style="text-align:left" data-markdown data-transition="none"><script type="text/template">
## Save a change<!-- .element: style="text-align:center" -->
- Save the modification using the following command
```
datalad save -m "Add dataset description"
```
<!-- .element: style="font-size:75%" -->
```
git log
```
<!-- .element: style="font-size:75%" -->
- You can make more modifications. What happens when you save modifications without ``-m "..."``, or several modifications?
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
## Local version control
Procedurally, version control is easy with DataLad!
![](../img/concepts/local_wf.svg)<!-- .element: style="height:500px" -->
**Advice:**
- Save *meaningful* units of change
- Attach helpful commit messages
</script></section>
</section>
<section>
<section data-markdown data-transition="none"><script type="text/template">
# Dataset hierarchies
### subdatasets and superdatasets
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
## Nesting
Datasets can be linked in superdataset - subdataset relationships.
![](../img/concepts/linkage_subds.svg)<!-- .element: style="height:400px"-->
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
## Make a nest<!-- .element: style="text-align:center" -->
- Run the following command in the root of the ``penguin-beaks`` dataset. How does it differ from the previous `clone`?
```
datalad clone -d . https://hub.datalad.org/edu/penguins.git inputs
```
<!-- .element: style="font-size:75%" -->
- Explore:
- What does the superdataset (`penguin-beaks`) know about its subdataset (`inputs`)?
- In which way is the subdatasets version recorded?
- Hint: you can use `gitk`/`tig` or `git log`
</script></section>
<section data-transition="None">
<h2>Dataset linkage</h2>
<img data-src="../img/concepts/linkage.svg" height="300px">
<pre><code class="bash" style="font-size:115%;max-height:none">$ datalad clone --dataset . http://example.com/ds inputs/rawdata
</code></pre>
<pre><code class="diff" style="max-height:none">$ git diff HEAD~1
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..c3370ba
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "inputs/rawdata"]
+ path = inputs/rawdata
+ url = http://example.com/importantds
diff --git a/inputs/rawdata b/inputs/rawdata
new file mode 160000
index 0000000..fabf852
--- /dev/null
+++ b/inputs/rawdata
@@ -0,0 +1 @@
+Subproject commit fabf8521130a13986bd6493cb33a70e580ce8572
</code></pre>
Each (sub)dataset is a separate, but jointly version-controlled entity.
If its data isn't retrieved, subdatasets are an extremely <strong>lightweight</strong> yet
<strong>actionable</strong> data dependency
<aside class="notes">weighs just a few bytes</aside>
</section>
</section>
<section>
<section data-markdown data-transition="none"><script type="text/template">
# A few theoretical basics...
[YODA Principles](./yoda.html)<!-- .element: target="_blank"-->
</script></section>
</section>
<section>
<section data-markdown data-transition="none"><script type="text/template">
# Provenance and reproducibility
### Keep track, redo, verify
</script></section>
<section>
<img height="400px" src="../img/xkcd/2054.png"><imgcredit>xkcd comic<a href="https://xkcd.com/2054/" target="_blank">
2054</a></imgcredit>
</section>
<section data-markdown data-transition="None"><script type="text/template">
## Reproducibility: Why should *I* care?
</script></section>
<section data-markdown data-transition="None"><script type="text/template">
## Your schools, your pension, your comfort!
> Reinhart and Rogoff’s work showed average real economic growth slows (a 0.1% decline) when a country’s debt rises to more than 90% of gross domestic product (GDP) – and this 90% figure was employed repeatedly in political arguments over high-profile austerity measures.
<!-- .element: style="text-align:left;margin:0px;width:100%" -->
> The most serious was that, in their Excel spreadsheet, Reinhart and Rogoff had not selected the entire row when averaging growth figures: they omitted data from Australia, Austria, Belgium, Canada and **Denmark**.
<!-- .element: style="text-align:left;margin:0px;width:100%" -->
> When that error was corrected, the **“0.1% decline” data became a 2.2% average increase** in economic growth.
<!-- .element: style="text-align:left;margin:0px;width:100%" -->
<note>https://theconversation.com/the-reinhart-rogoff-error-or-how-not-to-excel-at-economics-13646</note>
</script></section>
<section data-markdown data-transition="None"><script type="text/template">
## The good, the bad, and the ugly
> Traditionally, researchers have been taught to record every detail of their work, including experimental design, procedures, equipment, raw results, data processing, statistical methods and other tools used to analyse the results.
<!-- .element: style="text-align:left;margin:0px;width:100%" -->
> In contrast, relatively few researchers who employ computing in modern science [...] typically take such care in their work.
In most cases, there is no record of workflow, hardware and software configuration, and often even the source code is no longer available (or has been revised numerous times since the study was conducted).
<!-- .element: style="text-align:left;margin:0px;width:100%"" -->
> We think this is a seriously lax environment in which **deliberate fraud** and **genuine error** can proliferate.
<!-- .element: style="text-align:left;margin:0px;width:100%"" -->
<note>https://theconversation.com/the-reinhart-rogoff-error-or-how-not-to-excel-at-economics-13646</note>
</script></section>
</section>
<section>
<section data-markdown data-transition="None"><script type="text/template">
If everything is important... **track everything!**
We can only track things that are written... **write down/out everything!**
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
We perform a reproducible data processing task in the previously created <code>penguin-beaks</code>dataset hierarchy.<br><br>
- Download the following script, and save it as "code/extract.py": [hub.datalad.org/edu/scripts/raw/branch/main/penguins/extract.py](https://hub.datalad.org/edu/scripts/raw/branch/main/penguins/extract.py)
```
curl https://hub.datalad.org/edu/scripts/raw/branch/main/penguins/extract.py \
-o code/extract.py
```
<!-- .element: style="font-size:75%" -->
```
datalad status
```
<!-- .element: style="font-size:75%" -->
```
datalad save -m "Add processing script"
```
<!-- .element: style="font-size:75%" -->
"`python code/extract.py`" executes the script on data in `inputs/`.
Wrapping this command in a "`datalad run`" records what happens:
```
datalad run \
-m "extract culmen length of male adelie penguins" \
-i inputs/adelie/table_219.csv \
-o reproducible-results.dat \
"python code/extract.py > reproducible-results.dat"
```
<!-- .element: style="font-size:75%" -->
- Take a look at the command's result summary and check the revision history of the dataset. What provenance was recorded?
```
gitk
```
<!-- .element: style="font-size:75%" -->
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
## Actionable Provenance
- Drop the file (with force), and check whether `get` can retrieve it back.
```
datalad drop --reckless availability reproducible-results.dat
```
<!-- .element: style="font-size:75%" -->
```
datalad get reproducible-results.dat
```
<!-- .element: style="font-size:75%" -->
- Repeat the processing by running the following command. What happens?
```
datalad rerun
```
<!-- .element: style="font-size:75%" -->
- Check the result summary and dataset history again. Did anything change?
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
**datalad run** wraps around anything expressed in a command line call and saves the dataset modifications resulting from the execution.</p>
![](../img/concepts/run.svg)
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
**datalad rerun** repeats captured executions.
If the outcomes differ, it saves a new state of them.
![](../img/concepts/rerun.svg)
</script></section>
</section>
<section>
<section data-markdown data-transition="none"><script type="text/template">
# Command summaries
</script></section>
<section data-markdown data-transition="none"><script type="text/template">
### Summary - Local version control
<dl>
<dt><code>datalad create</code> creates an empty dataset.</dt>
<dd>Configurations (e.g., <b>-c yoda</b></b>)
add useful structure and/or configurations.</dd><br>
<dt>A dataset has a <i>history</i> to track files and their modifications. </dt>
<dd>Explore it with Git (<b>git log</b>, <b>gitk</b>) or external tools (e.g., <b>tig</b>).</dd><br>
<dt><code>datalad save</code> records the dataset or file state to the history. </dt>
<dd>Concise <b>commit messages</b> should summarize the change for future you and others.</dd><br>
<dt><code>datalad status</code> reports the current state of the dataset.</dt>
<dd>A clean dataset status (no modifications, not untracked files) is good practice.</dd>
</dl>
</script></section>
<section data-transition="none">
<h3>Summary - Dataset consumption & nesting</h3>
<ul>
<dt><code>datalad clone</code> installs a dataset.</dt><dd> It can be installed “on its own”:
Specify the source (url, path, ...) of the dataset, and an optional <b>path</b> for it to be installed to.</dd><br>
<dt>Datasets can be installed as subdatasets within an existing dataset. </dt>
<dd> The <b>--dataset/-d</b> option needs a path to the root of the superdataset.</dd><br>
<dt>Only small files and metadata about file availability are present locally after an install. </dt>
<dd>To retrieve actual file content of annexed files,
<code>datalad get </code> downloads file content on demand.</dd><br>
<dt>Datasets preserve their history.</dt>
<dd>The superdataset records only the <i>version state</i> of the subdataset.</dd>
</ul>
</section>
<section data-transition="none">
<h3>Summary - Reproducible execution</h3>
<ul>
<dt><code>datalad run</code> records a command and its impact on the dataset.</dt>
<dd>All dataset modifications are saved - use it in a clean dataset.</dd><br>
<dt>Data/directories specified as <code>--input</code>are retrieved first.</dt>
<dd> Use one flag per input.</dd><br>
<dt>Data/directories specified as <code>--output</code>will be unlocked for modifications prior to a rerun of the command. </dt>
<dd>Its optional to specify, but helpful for recomputations.</dd><br>
<dt><code>datalad rerun</code> can automatically re-execute run-records later.</dt>
<dd>They can be identified with any commit-ish (hash, tag, range, ...)</dd>
</ul>
</section>
</section>
</div> <!-- /.slides -->
</div> <!-- /.reveal -->
<script src="../reveal.js/dist/reveal.js"></script>
<script src="../reveal.js/plugin/notes/notes.js"></script>
<script src="../reveal.js/plugin/markdown/markdown.js"></script>
<script src="../reveal.js/plugin/highlight/highlight.js"></script>
<script src="../custom/js/copy-code.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
// The "normal" size of the presentation, aspect ratio will be preserved
// when the presentation is scaled to fit different resolutions. Can be
// specified using percentage units.
width: 1280,
height: 960,
// Factor of the display size that should remain empty around the content
margin: 0.1,
// Bounds for smallest/largest possible scale to apply to content
minScale: 0.2,
maxScale: 1.0,
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
plugins: [ RevealMarkdown, RevealHighlight, RevealNotes ]
});
</script>
<!-- A footer with a "1" and "home" button to get back to the first slide and the index page
<div id="hidden" style="display:none;">
<div id="header">
<div id="footer-left"><a href="#0">1️⃣</a></div> -->
<!--<div id="footer-right"><a href="../index.html">🏠</a></div>
<div id="footer-right"><a href="../workshops/2025-DKZ.2R.html">🏠</a></div>
</div>
</div> -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="../custom/js/headerandfooter.js"></script>
</body>
</html>