A hands-on workshop for learning astronomy with Python
From Python basics to real astronomical data analysis
Organized by Wilson College in collaboration with IAPT
This repository is a complete learning resource for undergraduate and postgraduate students who want to explore astronomy through Python programming. Whether you're writing your first line of code or already comfortable with Python, this workshop takes you from the fundamentals all the way to analyzing real astronomical data.
What you'll learn:
- Python fundamentals and scientific computing with NumPy
- Astronomical calculations using Astropy (units, coordinates, time, constants)
- Curve fitting and numerical methods with SciPy
- Working with real astronomical data formats (CSV, FITS)
- Data analysis and visualization with Pandas and Matplotlib
The materials are structured as a progressive learning journey:
START HERE
|
v
[1] Getting Started .............. Jupyter setup & environment
|
v
[2] Session 1 .................... Python basics, NumPy arrays
|
v
[3] Session 2 .................... Astropy: units, coordinates, time
|
v
[4] Lecture - 27 Dec ............. Functions, curve fitting, SciPy
|
v
[5] Lecture - 28 Dec ............. Pandas, CSV & FITS data import
|
v
[6] Assignments .................. Test your understanding
|
v
[7] Additional Questions ........ Challenge problems
|
v
DONE! You're ready for research-level data analysis
PythonAstronomyWorkshop/
|
|-- lectures/ # Core workshop materials
| |-- Getting started.ipynb # Setup & Jupyter intro
| |-- Session 1 - Basics & Numpy.ipynb # Python fundamentals + NumPy
| |-- Session 2 - Astropy.ipynb # Astropy deep dive
| |-- Lecture Notes for 27th Dec 2024.ipynb # Functions & curve fitting
| |-- Lecture Notes for 28th Dec 2024.ipynb # Data import & analysis
| |-- additional_questions.md # Challenge problems with solutions
| +-- data/ # FITS files for exercises
|
|-- assignments/ # Practice & assessment
| |-- Assignments.ipynb # Problem sets
| +-- Assignment Solutions.ipynb # Detailed solutions
|
|-- Referring Docs/ # Quick-reference guides
| |-- Python Quick Guide.ipynb
| |-- Curve Fitting and Numerical Computation Reference.ipynb
| |-- Astronomical Coordinate Conversion Reference.ipynb
| |-- Working with FITS Files.ipynb
| +-- Sample Data Sets for Python Astronomy Workshop.ipynb
|
|-- data/ # Datasets
| +-- Cepheids.csv # Cepheid variable star data
|
|-- requirements.txt
+-- LICENSE
- Python 3.9+ installed (Anaconda recommended)
- Basic familiarity with using a terminal/command line
- No prior astronomy knowledge required!
1. Clone the repository
git clone https://github.com/Astrojigs/PythonAstronomyWorkshop.git
cd PythonAstronomyWorkshop2. Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows3. Install dependencies
pip install -r requirements.txt4. Launch Jupyter
jupyter labThen open lectures/Getting started.ipynb to begin!
If you prefer not to install anything locally, you can open any notebook directly in Google Colab by uploading the .ipynb files.
| Date | Topic | Notebook |
|---|---|---|
| Day 1 | Python basics, NumPy, functions | Session 1 - Basics & Numpy.ipynb |
| Day 2 | Astropy: units, coordinates, constants, time | Session 2 - Astropy.ipynb |
| 27 Dec | Functions, curve fitting, SciPy | Lecture Notes for 27th Dec 2024.ipynb |
| 28 Dec | Pandas, CSV, FITS file handling | Lecture Notes for 28th Dec 2024.ipynb |
| 30 Dec | Exoplanet data analysis | Coming soon |
| 31 Dec | Cosmology & solar flare analysis | Coming soon |
| 1 Jan | X-ray binary data analysis | Coming soon |
Python Fundamentals
- Variables, data types, and operators
- Lists, tuples, dictionaries, and sets
- Control flow (if/else, loops)
- Functions and list comprehensions
- String formatting and operations
Scientific Computing with NumPy
- Array creation and manipulation
- Indexing, slicing, and reshaping
- Mathematical and statistical operations
- Trigonometric functions
- Random number generation
Astronomy with Astropy
- Unit handling and conversions
- Physical constants (G, M_sun, c, etc.)
- Celestial coordinate systems (ICRS, Galactic, AltAz)
- Time handling and Julian dates
- Equivalencies (mass-energy, parallax, Doppler)
Curve Fitting & Numerical Methods
- Linear and nonlinear curve fitting with
scipy.optimize.curve_fit - Numerical integration with
scipy.integrate.quad - Root finding with
scipy.optimize.root - Fitting real astronomical data (Cepheid light curves)
Data Analysis
- Reading CSV and FITS files
- Pandas DataFrames: filtering, grouping, aggregation
- FITS header inspection and data extraction
- Coordinate transformations on datasets
- Data visualization with Matplotlib
The Referring Docs/ folder contains standalone reference notebooks you can use anytime:
| Guide | Description |
|---|---|
| Python Quick Guide | Python syntax and essential libraries cheat sheet |
| Curve Fitting Reference | Detailed curve fitting and numerical computation examples |
| Coordinate Conversion Reference | Astronomical coordinate systems and transformations |
| Working with FITS Files | Complete guide to FITS file operations |
| Sample Data Sets | Overview of available datasets for practice |
The workshop includes hands-on assignments to reinforce each topic:
-
Assignment 1 — Functions, curve fitting, and numerical integration
- Calculate celestial distances from equatorial coordinates
- Fit sinusoidal curves to Cepheid variable star data
- Integrate blackbody radiation curves
-
Assignment 2 — Data importing and analysis
- Filter and group star catalog data
- Read and visualize FITS image data
- Convert between coordinate systems
-
Challenge Problems — See
additional_questions.mdfor advanced problems including galactic time calculations, Kepler's law fitting, supernova luminosity decay, and more.
| Package | Version | Purpose |
|---|---|---|
astropy |
>= 5.3 | Astronomical computations |
numpy |
>= 1.23 | Numerical computing |
scipy |
>= 1.10 | Scientific computing & curve fitting |
matplotlib |
>= 3.7 | Data visualization |
pandas |
>= 2.0 | Data analysis |
jupyterlab |
>= 4.0 | Interactive notebooks |
Contributions are welcome! If you'd like to add new lecture materials, fix errors, or improve explanations:
- Fork the repository
- Create a feature branch (
git checkout -b add-new-lecture) - Commit your changes
- Open a Pull Request
This project is licensed under the MIT License — see the LICENSE file for details.
Made with curiosity about the cosmos
Workshop by Jigar Patel | Wilson College & IAPT