Linked handout: 0. Development environment

IRF server room Photo: Daniel Kastinen/IRF

IRF server room Photo: Daniel Kastinen/IRF

Software development for researchers

Welcome!

Who am I?

    Daniel Kastinen

  • Living in Kiruna since 2017
  • Finished PhD Nov. 2022
    From Meteors to Space Safety: Dynamical Models and Radar Measurements of Space Objects
  • Hired as permanent staff scientist February 2023
  • Task: Conduct research on meteors and space objects!

My focus: connecting the small and big pictures

  • Radar data analysis & signal processing
  • Meteoroid and small body dynamical simulations
  • Statistical methods and solving inverse problems
  • Meteor phenomena and meteoroid stream formation modelling
  • (now also) Optical data processing and hardware control
  • Space object observations, orbit determination, sensor simulations

This is a WHOLE lot of software development

And so this course was born

Lets get programming!

Now that everyone has an environment and an editor

lets get started with "Hello, World!"...

by calculating $\pi$ in a very roundabout way!

Calculating $\pi$ with randomness

  • Probability is
    $\mathbb{P}(\bar{x} \in A) = \int_{A} f_X(\bar{x})\mathrm{d}\bar{x}$
    where $\bar{x} \sim X$
  • Uniform 2d random distribution on $S = [-1, 1] \times [-1, 1]$
    $f_\mathcal{U}(x, y) = \mathbf{1}_S(x, y) \frac{1}{\text{Area}} = \mathbf{1}_S(x, y)\frac{1}{4}$
  • What is $\mathbb{P}(\sqrt{x^2 + y^2} \leq 1)$?
  • $= \int_{\text{Circle}} \mathbf{1}_S(x, y)\frac{1}{4} \mathrm{d}\bar{x} = \frac{1}{4} A_{\text{Circle}} = \frac{\pi}{4}$

$$\mathbb{P}(\sqrt{x^2 + y^2} \leq 1) = \frac{\pi}{4}$$

Calculating $\pi$ with randomness

$$\mathbb{P}(\sqrt{x^2 + y^2} \leq 1) = \frac{\pi}{4}$$

$$ \lim_{\# \mapsto \infty} 4\frac{\# \text{number of points in circle}}{\# \text{number of points}} \mapsto \pi $$

                    $ pip install numpy
                

Calculating $\pi$ with randomness

                    $ pip install numpy
                
hello.py
                    import numpy as np

samples = 100
x = np.random.rand(samples)*2 - 1
y = np.random.rand(samples)*2 - 1

r = np.sqrt(x**2 + y**2)
pi = 4*np.sum(r < 1)/samples

print(f"{samples=} gives {pi=} (error {np.pi - pi})")
                    
                
                    $ python hello.py
                

Try samples = 1_000_000

Homework

See the handout for today