前阵子学完了coursera上悉尼大学的天文数据处理课程,感觉非常适合想学习天文的python初学者所以分享出来,顺便复习一下,网课的地址一会补在评论里。所有的笔记都记录在onenote上,为了方便观看先上图片,想要复制代码的可以往下看,最下面是自己遇到的问题和解答,大家有任何问题也欢迎讨论,一起进步。
python的标准程序已经可以处理很多内容,不过天文的程序开发者为社区编写了许多用于数据处理的程序
In the astronomy community, the most common modules include:
• NumPy – support for numerical computing and matrices;
• SciPy – fundamental libraries for scientific computing;
• Matplotlib – powerful plotting and data visualisation;
• Astropy – community library for astronomy.
We have many modules installed on Grok and throughout this course we'll show you how to use them.
NumPy and Astropy程序包并不在标准python当中,需要分别下载
通常在官网有他们的安装说明
目前通常使用的两个方法:
• a binary installer (you must use the right version for your Python version, operating system and CPU);
• Python's pip installation tool.
另外,也可以使用传统的python安装包 such as Enthought Canopy, Anaconda Python or Python(x, y) that include a large number of scientific and engineering packages. Anaconda and Python(x,y) are completely free, and Canopy is free for students.
所有软件都在linux或者mac上运行,如果是windows用户需要安装虚拟机
函数定义
大多数问题会要求您编写一个需要一些输入并返回结果的函数。
As a quick recap, Python's function syntax works like this:
def func(arg1, arg2, arg3, ...):
return
Function definitions start with the def keyword, followed by the name of the function, and a list of arguments in round brackets.
The body of the function is indented and values are returned using the return statement.
例子:
def double(val):
return val + val
print(double(3))
print(double('3'))
输出结果:
6
33
在submit程序之前测试它的两种方法:
1. Main script environment
您可以使用以下技巧保护您的