Дизайн уроку

Останнє оновлення 2026-07-01 | Редагувати цю сторінку

Примітка

Де потрібна допомога

Ми додаємо вправи нижче для того, щоб план уроку був більш детальним. Будемо вдячні за пропозиції (як у вигляді нових готових вправ, так і у вигляді коментарів щодо конкретних вправ, їх порядку та часу виконання).

Процес розробки


Поради Майкла Поллана, якби він викладав програмування на R або Python:

  1. Пишіть код.
  2. Не надто багато.
  3. Переважно для побудови графіків.

Michael Koontz {: .quotation}

Урок розроблено за скороченою версією методу “Розуміння за дизайном”. The main sections are:

  1. Припущення щодо аудиторії, часу тощо. (Поточні нотатки також містять певні висновки та рішення в цьому розділі — їх слід переробити.)

  2. Бажані результати: загальні цілі, підсумкові оцінювання кожні півдня викладання, що слухачі мають знати та вміти.

  3. Навчальний план: кожен епізод містить заголовок з узагальненням матеріалу, що буде розглянуто, оцінку часу на викладання та виконання вправ, а також перелік вправ у вигляді маркованого списку.

Етап 1: Припущення


  • Аудиторія
    • Аспіранти з різних наукових напрямків — від космології до археології
    • Які у минулому обробляли дані в електронних таблицях, а також за допомогою інтерактивних інструментів, таких як SAS
    • Але не просунулися далі CPD (copy-paste-despair / скопіював-вставив-впав в розпач)
  • Обмеження
    • Один повний день 09:00-16:30
      • 06:15 час для занять
      • 0:45 обід
      • 0:30 загалом на дві перерви на каву
    • Слухачі використовують власні інсталяції програмного забезпечення на своїх комп’ютерах
      • Можуть використовувати віртуальні машини або хмарні ресурси на розсуд інструктора
      • Але локально інстальоване програмне забезпечення на власному комп’ютері має залишатися варіантом
    • Немає залежності від інших модулів Carpentry
      • Зокрема, не вимагається знання роботи з командним рядком та системи контролю версій
    • Використовується Jupyter Notebook
      • Надійний інструмент, який використовують багато інструкторів
      • Насправді альтернативи просто немає
      • І це означає, що навіть ті, хто вже трохи працював із Python, скоріше за все, дізнаються для себе щось нове
  • Мотиваційний приклад
    • Створення двовимірних графіків, придатних для включення до наукових публікацій
    • Цікавий майже всім
    • Робить урок придатним для використання в обох програмах Carpentries (тобто Software Carpentry, Data Carpentry)
      • І це означає, що навіть ті, хто вже трохи працював із Python, скоріше за все, дізнаються для себе щось нове
  • Дані
    • Використовувати дані gapminder протягом усього уроку
    • Але розділити на кілька файлів за континентами
      • Щоб зробити виведення результатів з прикладів охайнішим (наприклад, використовувати Australia/New Zealand, що містять лише два рядки)
      • Та показати приклади роботи з кількома наборами даних одночасно
  • Зробити фокус на Pandas замість NumPy
    • Зробити урок придатним до використання для Data Carpentry та Software Carpentry
    • Абсолютні початківці, ймовірно, захочуть побачити приклад аналізу даних
    • Водночас слухачі з деяким попереднім досвідом:
      • сприймуть аналіз даних як реальне завдання,
      • and are unlikely to have encountered Pandas, so they’ll still get something useful out of the lesson
  • Завдання здебільшого не будуть вимагати “написати цей код з нуля”
    • Бажано мати багато коротких вправ, які можна надійно закінчити за відведений час
    • Тому використовуємо питання з множинним вибором, заповнення пропусків, проблеми Парсонса, “змініть цей код” тощо.

Етап 2: Бажані результати


Питання

Як мені…

  • …read tabular data?
  • …plot a single vector of values?
  • …create a time series plot?
  • …create one plot for each of several data sets?
  • …get extra data from a single data set for plotting?
  • …write programs I can read and re-use in future?

Skills

I can…

  • …write short scripts using loops and conditionals.
  • …write functions with a fixed number of parameters that return a single result.
  • …import libraries using aliases and refer to those libraries’ contents.
  • …do simple data extraction and formatting using Pandas.

Concepts

I know…

  • …that a program is a piece of lab equipment that implements an analysis
    • Needs to be validated/calibrated before/during use
    • Makes analysis reproducible, reviewable, shareable
  • …that programs are written for people, not for computers
    • Meaningful variable names
    • Modularity for readability as well as re-use
    • No duplication
    • Document purpose and use
  • …that there is no magic: the programs they use are no different in principle from those they build
  • … як призначити значення змінним
  • …what integers, floats, strings, NumPy arrays, and Pandas dataframes are
  • …як відстежувати виконання циклу for
  • …як відстежувати виконання команд if/else
  • …how to create and index lists
  • … як створити та індексувати масиви NumPy
  • …how to create and index Pandas dataframes
  • …how to create time series plots
  • … різниця між визначенням і викликом функції
  • …where to find documentation on standard libraries
  • …how to find out what else scientific Python offers

Stage 3: Learning Plan


Summative Assessment

  • Midpoint: create time-series plot for each file in a directory.
  • Final: extract data from Pandas dataframe and create comparative multi-line time series plot.

Running and Quitting Interactively (9:00)

  • Teaching: 15 min (because setup issues)
    • Launch the Jupyter Notebook, create new notebooks, and exit the Notebook.
    • Create Markdown cells in a notebook.
    • Create and run Python cells in a notebook.
  • Challenges: 0 min (accounted for in teaching time - no separate exercise)
    • Creating lists in Markdown
    • What is displayed when several expressions are put in a single cell?
    • Change an existing cell from code to Markdown
    • Rendering LaTeX-style equations

Variables and Assignment (9:15)

  • Teaching: 10 min
    • Write programs that assign scalar values to variables and perform calculations with those values.
    • Correctly trace value changes in programs that use scalar assignment.
  • Challenges: 10 min
    • Trace execution of code swapping two values using an intermediate variable.
    • Predict final values of variables after several assignments.
    • What happens if you try to index a number?
    • Which is a better variable name, m, min, or minutes?
    • What do the following slice expressions produce?

Data Types and Type Conversion (09:35)

  • Teaching: 10 min
    • Explain key differences between integers and floating point numbers.
    • Explain key differences between numbers and character strings.
    • Use built-in functions to convert between integers, floating point numbers, and strings.
  • Challenges: 10 min
    • What type of value is 3.4?
    • What type of value is 3.25 + 4?
    • What type of value would you use to represent:
      • Number of days since the start of the year.
      • Time elapsed since the start of the year.
      • Etc.
    • How can you use // (integer division) and % (modulo)?
    • What does int("3.4") do?
    • Given these float, int, and string values, which expressions will print a particular result?
    • What do you expect 1+2j + 3 to produce?

Built-in Functions and Help (09:55)

  • Teaching: 15 min
    • Explain the purpose of functions.
    • Correctly call built-in Python functions.
    • Correctly nest calls to built-in functions.
    • Use help to display documentation for built-in functions.
    • Correctly describe situations in which SyntaxError and NameError occur.
  • Challenges: 10 min
    • Explain the order of operations in the following complex expression.
    • What will each nested combination of min and max calls produce?
    • Why don’t max and min return None when given no arguments?
    • Given what we have seen so far, what index expression will get the last character in a string?

Бібліотеки (10:35)

  • Teaching: 10 min
    • Explain what software libraries are and why programmers create and use them.
    • Write programs that import and use libraries from Python’s standard library.
    • Find and read documentation for standard libraries interactively (in the interpreter) and online.
  • Challenges: 10 min
    • Which function from the standard math library could you use to calculate a square root?
    • What library would you use to select a random value from data?
    • If help(math) produces an error, what have you forgotten to do?
    • Fill in the blanks in code below so that the import statement and program run.

Читання табличних данних (10:55)

  • Teaching: 10 min
    • Import the Pandas library.
    • Use Pandas to load a simple CSV data set.
    • Get some basic information about a Pandas DataFrame.
  • Challenges: 10 min
    • Read the data for the Americas and display its summary statistics.
    • What do .head and .tail do?
    • What string(s) should you pass to read_csv to read files from other directories?
    • How can you write CSV data?

DataFrames (11:15)

  • Teaching: 15 min
    • Select individual values from a Pandas dataframe.
    • Select entire rows or entire columns from a dataframe.
    • Select a subset of both rows and columns from a dataframe in a single operation.
    • Select a subset of a dataframe by a single Boolean criterion.
  • Challenges: 15 min
    • Write an expression to find the Per Capita GDP of Serbia in 2007.
    • What rule governs what is (or isn’t) included in numerical and named slices in Pandas?
    • What does each line in the following short program do?
    • What do idxmin and idxmax do?
    • Write expressions to get the GDP per capita for all countries in 1982, for all countries after 1985, etc.
    • Given the way its borders have changed since 1900, what would you do if asked to create a table of GDP per capita for Poland for the Twentieth Century?

Побудова графіків (11:45)

  • Teaching: 15 min
    • Create a time series plot showing a single data set.
    • Create a scatter plot showing relationship between two data sets.
  • Exercise: 15 min
    • Fill in the blanks to plot the minimum GDP per capita over time for European countries.
    • Modify the example to create a scatter plot of GDP per capita in Asian countries.
    • Explain what each argument to plot does in the following example.

Перерва (12:15): 45 min

Списки (13:00)

  • Teaching: 10 min
    • Explain why programs need collections of values.
    • Write programs that create flat lists, index them, slice them, and modify them through assignment and method calls.
  • Challenges: 10 min
    • Fill in the blanks so that the program produces the output shown.
    • How large are the following slices?
    • What do negative index expressions print?
    • What does a “stride” in a slice do?
    • How do slices treat out-of-range bounds?
    • What are the differences between sorting these two ways?
    • What is the difference between new = old and new = old[:]?

Цикли (13:20)

  • Teaching: 10 min
    • Explain what for loops are normally used for.
    • Trace the execution of a simple (unnested) loop and correctly state the values of variables in each iteration.
    • Write for loops that use the Accumulator pattern to aggregate values.
  • Challenges: 15 min
    • Is an indentation error a syntax error or a runtime error?
    • Trace which lines of this program are executed in what order.
    • Fill in the blanks in this program so that it reverses a string.
    • Fill in the blanks in this series of examples to get practice accumulating values.
    • Reorder and indent these lines to calculate the cumulative sum of the list values.

Looping Over Data Sets (13:45)

  • Teaching: 5 min
    • Be able to read and write globbing expressions that match sets of files.
    • Use glob to create lists of files.
    • Write for loops to perform operations on files given their names in a list.
  • Challenges: 10 min
    • Which filenames are not matched by this glob expression?
    • Modify this program so that it prints the number of records in the shortest file.
    • Write a program that reads and plots all of the regional data sets.

Writing Functions (14:00)

  • Teaching: 10 min
    • Explain and identify the difference between function definition and function call.
    • Write a function that takes a small, fixed number of arguments and produces a single result.
  • Challenges: 15 min
    • This code defines and calls a function - what does it print when run?
    • Explain why this short program prints things in the order it does.
    • Fill in the blanks to create a function that finds the minimum value in a data file.
    • Fill in the blanks to create a function that finds the first negative value in a list. What does your function do if the list is empty?
    • Why is it sometimes useful to pass arguments by naming the corresponding parameters?
    • Fill in the blanks and turn this short piece of code into a function.

Variable Scope (14:25)

  • Teaching: 10 min
    • Identify local and global variables.
    • Identify parameters as local variables.
    • Read a traceback and determine the file, function, and line number on which the error occurred.
  • Challenges: 10 min
    • Trace the changes to the values in this program, being careful to distinguish local from global values.

Coffee (14:45): 15 min

Conditionals (15:00)

  • Teaching: 10 min
    • Correctly write programs that use if and else statements and simple Boolean expressions (without logical operators).
    • Trace the execution of unnested conditionals and conditionals inside loops.
  • Challenges: 15 min
    • Trace the execution of this conditional statement.
    • Fill in the blanks so that this function replaces negative values with zeroes.
    • Modify this program so that it only processes files with fewer than 50 records.
    • Modify this program so that it always finds the largest and smallest values in a list no matter what the list’s values are.

Стиль програмування (15:25)

  • Teaching: 15 min
    • How can I make my programs more readable?
    • How do most programmers format their code?
    • How can programs check their own operation?
  • Challenges: 15 min
    • Which lines in this code will be available as online help?
    • Turn the comments in this program into docstrings.
    • Rewrite this short program to be more readable.

Підведення підсумків (15:55)

  • Teaching: 20 min
    • Name and locate scientific Python community sites for software, workshops, and help.
  • Challenges: 0 min
    • None.

Feedback (16:15)

  • Teaching: 0 min
  • Challenges: 15 min
    • Collect feedback

Finish (16:30)