{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1.3 Python的安装与使用" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "在众多的编程语言中,Python比较适合于遥感模式识别的实验课程。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.3.1 选择Python的理由" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (1) 学习成本低,受欢迎" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Python使用的人越来越多,越来越受人欢迎。使用的人越多,已有的代码工具就越多,学习成本越低。可以在Google Trends 上面查看Python和其他语言的热度图,其中的热度代表该词汇在该地区搜索词汇中所占比率:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![pythonmap](images/PythonHeatMap.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (2) Arcgis 的脚本语言" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Arcgis以Python为脚本语言,可以进行批量处理,使得制图和处理的流程全自动化." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![arcgis](images/Arcgis.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.3.2 Python的安装" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Python的安装推荐使用Anaconda工具包,自带了常用的一些代码库。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Python语言简单灵活,开发效率高,有众多的机器学习算法的代码库支持。从Arcgis 10.0版本开始,Arcgis支持Python脚本调用。Ipython是Python的一个工具包,可以进行交互式的操作与输出。\n", "\n", "本节将介绍关于 Ipython Notebook 的四个内容:\n", "1. 功能用途\n", "2. 软件安装\n", "3. 使用方法\n", "4. LaTeX与Markdown" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (1) IPython Notebook的功能与用途" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ipython Notebook应用程序,是2011年由美国加州大学伯克利分校数据科学家Fernando Pérez和加州州立综合科技大学计算物理学家Brian Granger带领的研究团队共同开发的。它是一个基于python语言的**交互式**命令界面。最大的亮点在于,以笔机的形式记录显示:\n", "* 文章思路\n", "* 编码过程\n", "* 代码注释\n", "* 输出结果\n", "* 分享演示" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "不同于普通的注释,它的注释可以包含以下内容:\n", "1. **公式**:LaTeX数学公式\n", "2. **文本**:Markdown文本\n", "3. **图表**\n", "4. **视频**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Imageofjupyter](images/jupyterpreview.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "IPython 4.0正式发布后,IPython分离成IPython和Jupyter,支持Ruby、R语言等,所以在左上角可以看到Jupyter的标识。这样的一款软件是易于使用的,按照下面的步骤就可以轻松获取它。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (2) 软件安装" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "有多种安装Ipython Notebook的方式,推荐使用Anaconda安装包。Anaconda集成了大量的常用数据分析、科学计算的库,可以在Windows、Mac和Linux下一键安装。Python有很多的版本,Anaconda都支持。这里我们使用Python 3.6 版本的Anaconda安装包,这个版本的python代码库是功能最全面的。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "软件可以一键安装,安装包下载地址为:\n", "https://www.continuum.io/downloads" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (3) 运行启动" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. 在windows系统下,选择自己的目录;\n", "2. 在空白处,点击“shift+右键”,弹出菜单;\n", "3. 在菜单中选择“打开命令行”选项;\n", "4. 在命令行中输入: \n", "```bash\n", "jupyter notebook\n", "```\n", "将会自动在浏览器中弹出软件页面。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![jupyter](images/new.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (4) 使用方法" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "这里简单介绍最常用到的操作。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**%pylab** 可以导入常用的函数名称空间,直接使用常用函数。 " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using matplotlib backend: MacOSX\n", "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**inline** 是把显示的图片嵌入到notebook中,而不是单独显示一个窗口。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Shift+Tab** 快捷键用来快速查看函数信息。" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "linspace" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "函数名后面跟随一个问号,可以查看函数的帮助信息。" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "sum?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "类名后面跟随两个问号,可以显示定义类的源码" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "sum??" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**%run** 命令把文件中的代码执行一遍,并不复制。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "%run PythonCode/lorenz.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**%load** 命令会把文件中的代码复制到notebook里。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```bash\n", "%load PythonCode/lorenz.py\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### (5) Python 语言快速概览 " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "课程中将简单地介绍Python语言的语法,不涉及具体编程应用的内容。对于完全不熟悉Python语言的同学,还需要适当额外补充相应的知识和练习。涉及到的Python编程为以下主题:\n", "* 数据基本类型,表达式,变量及其赋值\n", "* 基本数据结构\n", "* 控制语句\n", "* 函数和对象" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "推荐书目为:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Barry P. Head First Python: A Brain-Friendly Guide[M]. \" O'Reilly Media, Inc.\", 2016." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hetland M L. Python 基础教程[J]. 2014." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }