Coding

Introduction

In climate science, we have to manipulate computer programing or coding using the software. The common software includes Unix shell, Python, NCAR Language (NCL), GrADS, Fortran, and C. In this document, you will develop your coding skill based on Python. Whereas R is mainly used in natural and social sciences, R is not appropriate to analyze climate dynamics because of the computational speed.

Generally speaking, most software has two types of modes: interactive mode and script mode. In the interactive mode, you type your command with one line and get a response immediately. It is easy to debug particularly for beginners but you have to memorize what you did and repeat the same processes many times. In the script mode, you need to make a script file with multiple commands based on a computer language and then run the script file to get the result. It may take time to debug but this is the most efficient way to analyze climate data. In this document, you will learn the script mode based on Python.

File naming and type

File Extension

We require an appropriate file name to make a script file. The file name generally looks like “filename.xxx”. “xxx” after the dot is the file extension, which sticks with software. The example of a file extension is listed below.

File extension

Software

.sh

UNIX shell

.py

Python

.ncl

NCAR Language

.f .f90 .f95 .F

Fortran

.c

C Langauge

.txt

Text file

.csv

Comma separated value

.xls .xlsx

Microsoft Excel

Naming

You can use any name for “filename” but there are several ideas to make it easy for you.

  • No space in the filename. Instead, Use underscore (“_”) or hyphen (“-“).

  • Use alphabets and numbers but avoid specific characters (e.g., >, ?, *, & etc).

  • Use the version number if you want to update (e.g., test-v0.1.py, test-v1.2.py, etc).

  • When you want to use the date for the filename, follow the order of year, month, and day (i.e., the date of July 15, 2020, would be 20200715). It helps you to sort the file with the date order.

O - Better

X - Avoid

file_name.sh

file name.sh

test01.py

test01&02.py

test-v0.1.py

test.py

2020-0716-example.txt

July16_2020-example.txt