From 22258b264caf8cd87e75364179166c4e8931e94e Mon Sep 17 00:00:00 2001 From: "behinger (s-ccs 001)" Date: Thu, 28 Sep 2023 14:09:08 +0000 Subject: [PATCH] improved materials --- material/1_mon/envs/envs_handout.qmd | 125 +++++++++++------- material/1_mon/envs/tasks.qmd | 8 ++ .../1_mon/firststeps/statistic_functions.jl | 3 +- material/1_mon/firststeps/tasks.qmd | 11 ++ material/3_wed/vis/Manifest.toml | 2 +- material/3_wed/vis/Project.toml | 1 + 6 files changed, 97 insertions(+), 53 deletions(-) create mode 100644 material/1_mon/envs/tasks.qmd diff --git a/material/1_mon/envs/envs_handout.qmd b/material/1_mon/envs/envs_handout.qmd index 2b87d5b..48fca4f 100644 --- a/material/1_mon/envs/envs_handout.qmd +++ b/material/1_mon/envs/envs_handout.qmd @@ -139,6 +139,64 @@ version = "0.3.4" [...] ``` + +## Projects in Julia + +Formally, projects don't have specific requirements. You should activate an environment (`Project.toml`+`Manifest.toml`) in the main folder though. I recommend the following minimal structure: + +- `./src/` - all functions should go there +- `./scripts/` - all actual scripts should go here, +- `./README.md` - Write what this is about, who you are etc. +- `./Project.toml` - Your explicit dependencies +- `./Manifest.toml` - Your implicit dependencies + versions <-- this makes it reproducible! + +::: callout-tip +One recommendation is to use `DrWatson.initialize_project([path])` to start a new project - it will generate a nice folder structure + provide some other helpful `DrWatson.jl` features. + + + +::: + + +:::{.callout-tip collapse="true"} +## Click to expand the full datastructure +``` +│projectdir <- Project's main folder. It is initialized as a Git +│ repository with a reasonable .gitignore file. +│ +├── _research <- WIP scripts, code, notes, comments, +│ | to-dos and anything in an alpha state. +│ └── tmp <- Temporary data folder. +│ +├── data <- **Immutable and add-only!** +│ ├── sims <- Data resulting directly from simulations. +│ ├── exp_pro <- Data from processing experiments. +│ └── exp_raw <- Raw experimental data. +│ +├── plots <- Self-explanatory. +├── notebooks <- Jupyter, Weave or any other mixed media notebooks. +│ +├── papers <- Scientific papers resulting from the project. +│ +├── scripts <- Various scripts, e.g. simulations, plotting, analysis, +│ │ The scripts use the `src` folder for their base code. +│ └── intro.jl <- Simple file that uses DrWatson and uses its greeting. +│ +├── src <- Source code for use in this project. Contains functions, +│ structures and modules that are used throughout +│ the project and in multiple scripts. +│ +├── README.md <- Optional top-level README for anyone using this project. +├── .gitignore <- by default ignores _research, data, plots, videos, +│ notebooks and latex-compilation related files. +│ +├── Manifest.toml <- Contains full list of exact package versions used currently. +└── Project.toml <- Main project file, allows activation and installation. + Includes DrWatson by default. +``` +::: + + ## Packages in Julia Several thousand packages exist in Julia already. Take a thorough look before starting something new! @@ -181,10 +239,10 @@ The default registry is [JuliaRegistries/General](https://github.com/JuliaRegist ### Adding dependencies ```julia ]activate ./path/to/MyStatsPackage -]add UnicodePlots +]add ProgressMeter ]compat # <1> ``` -1. let's directly add a compat entry for UnicodePlots +1. let's directly add a compat entry for ProgressMeter ### Semantic Versioning Following `semver` - three parts: @@ -234,57 +292,22 @@ As you can see, develop version (`version < 1`) are treated a bit special in Jul keep the compat list in alphabetical order - github-actions might behave very strange else. ::: -## Projects in Julia +### Internals of a package -Formally, projects don't have specific requirements. You should activate an environment (`Project.toml`+`Manifest.toml`) in the main folder though. I recommend the following minimal structure: +The file `./src/MyStatsPackage.jl` should contain: +```julia +module MyStatsPackage +using ProgressMeter # <1> +include("src/stats_functions.jl") -- `./src/` - all functions should go there -- `./scripts/` - all actual scripts should go here, -- `./README.md` - Write what this is about, who you are etc. -- `./Project.toml` - Your explicit dependencies -- `./Manifest.toml` - Your implicit dependencies + versions <-- this makes it reproducible! +export sum +export mean, tstat -::: callout-tip -One recommendation is to use `DrWatson.initialize_project([path])` to start a new project - it will generate a nice folder structure + provide some other helpful `DrWatson.jl` features. - -(click the following tipp to expand the full datastructure) - -::: - - -:::{.callout-tip collapse="true"} +end ``` -│projectdir <- Project's main folder. It is initialized as a Git -│ repository with a reasonable .gitignore file. -│ -├── _research <- WIP scripts, code, notes, comments, -│ | to-dos and anything in an alpha state. -│ └── tmp <- Temporary data folder. -│ -├── data <- **Immutable and add-only!** -│ ├── sims <- Data resulting directly from simulations. -│ ├── exp_pro <- Data from processing experiments. -│ └── exp_raw <- Raw experimental data. -│ -├── plots <- Self-explanatory. -├── notebooks <- Jupyter, Weave or any other mixed media notebooks. -│ -├── papers <- Scientific papers resulting from the project. -│ -├── scripts <- Various scripts, e.g. simulations, plotting, analysis, -│ │ The scripts use the `src` folder for their base code. -│ └── intro.jl <- Simple file that uses DrWatson and uses its greeting. -│ -├── src <- Source code for use in this project. Contains functions, -│ structures and modules that are used throughout -│ the project and in multiple scripts. -│ -├── README.md <- Optional top-level README for anyone using this project. -├── .gitignore <- by default ignores _research, data, plots, videos, -│ notebooks and latex-compilation related files. -│ -├── Manifest.toml <- Contains full list of exact package versions used currently. -└── Project.toml <- Main project file, allows activation and installation. - Includes DrWatson by default. +1. We use GLMakie as a simple example as you need it on Wednesday again anyway - it does take a while to install though! + +Now we are ready to use the package from a different environment +```julia +]dev ./path/to/MyStatsPackage ``` -::: \ No newline at end of file diff --git a/material/1_mon/envs/tasks.qmd b/material/1_mon/envs/tasks.qmd new file mode 100644 index 0000000..be6e862 --- /dev/null +++ b/material/1_mon/envs/tasks.qmd @@ -0,0 +1,8 @@ +# Task +1. Create a new package `MyStatsPackage` using `generate` +2. Add your `statistic.jl` & "include" it. +3. Export all functions +4. Create a new environment in a separate folder and add the package. +5. Does `using MyStatsPackage` work now? :tada: congratulations! +6. Go back to your package environment. Now add a dependency (e.g. ProgressMeter) and a `compat`-entry +7. Go back to your project environment, has the dependency been updated? Think: should you use `resolve` or `instantiate`? \ No newline at end of file diff --git a/material/1_mon/firststeps/statistic_functions.jl b/material/1_mon/firststeps/statistic_functions.jl index d73f274..490ba09 100644 --- a/material/1_mon/firststeps/statistic_functions.jl +++ b/material/1_mon/firststeps/statistic_functions.jl @@ -1,8 +1,9 @@ #--- +using ProgressMeter function rse_sum(x) s = 0 - for k = eachindex(x) + @showprogress for k = eachindex(x) s = s+x[k] end return s diff --git a/material/1_mon/firststeps/tasks.qmd b/material/1_mon/firststeps/tasks.qmd index 5c602c9..6eb4408 100644 --- a/material/1_mon/firststeps/tasks.qmd +++ b/material/1_mon/firststeps/tasks.qmd @@ -19,7 +19,18 @@ You can mark some code and execute it using `ctrl` + `enter` - you can also gene Well done! You now have all functions defined with which we will continue our journey. +::: callout +## Bonus Task ProgressMeter +for very large sums we might want to add a progressmeter. To do so: +```julia +]add ProgressMeter +using ProgressMeter +... +@showprogress for ... +``` + +And that's it! You should have a nice progress bar now # Task 2 {#2} 1. Implement a type `StatResult` with fields for `x`, `n`, `std` and `tvalue` diff --git a/material/3_wed/vis/Manifest.toml b/material/3_wed/vis/Manifest.toml index 19cf741..51295e6 100644 --- a/material/3_wed/vis/Manifest.toml +++ b/material/3_wed/vis/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.9.2" manifest_format = "2.0" -project_hash = "72e4df15571f2f16bde88622e0b2d85533f8eea7" +project_hash = "6b7e018e1e42b9e8dc72df15bdc780c4b72357b0" [[deps.AbstractFFTs]] deps = ["LinearAlgebra"] diff --git a/material/3_wed/vis/Project.toml b/material/3_wed/vis/Project.toml index 7e8ae63..c55aa92 100644 --- a/material/3_wed/vis/Project.toml +++ b/material/3_wed/vis/Project.toml @@ -3,3 +3,4 @@ AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" PalmerPenguins = "8b842266-38fa-440a-9b57-31493939ab85" +ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"