# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# <img src="../images/UBRA_Logo_DATA_TRAIN.png" style="width: 800px;">

# # Scientific modules and IPython

# %matplotlib inline
import matplotlib.pylab as plt

# ## Core scientific packages

# When people say that they do their scientific computations in Python it's only half true. Python is a construction set, similar to MITgcm or other models. Without packages it's only a core, that although very powerful, does not seems to be able to do much by itself.
#
# There is a set of packages, that almost every scientist would need:
#
# <img src="../images/core.jpeg" style="width: 800px;">
#
# source: https://devopedia.org/python-for-scientific-computing

# We are going to talk about several basic ones

# ## Installation

# Installation instructions can be found in the README.md file of this repository. Better to use [rendered version from GitHub](https://github.com/koldunovn/python_data_train).
#

# ## IPython

# In order to be productive you need comfortable environment, and this is what IPython provides. It was started as enhanced python interactive shell, but with time become architecture for interactive computing.

# ## Jupyter notebook 

# Since the 0.12 release, IPython provides a new rich text web interface - IPython notebook. Here you can combine:

# #### Code execution

print('I love Python')

# #### Text (Markdown)

# IPython [website](http://ipython.org/).
#
# List:
#
# * [Python on Codeacademy](http://www.codecademy.com/tracks/python)
# * [Google's Python Class](https://developers.google.com/edu/python/)
#
# Code:
#
#     print('hello world')
#

# #### $\LaTeX$ equations

# $$\int_0^\infty e^{-x^2} dx=\frac{\sqrt{\pi}}{2}$$
# $$
# F(x,y)=0 ~~\mbox{and}~~
# \left| \begin{array}{ccc}
#   F''_{xx} & F''_{xy} &  F'_x \\
#   F''_{yx} & F''_{yy} &  F'_y \\
#   F'_x     & F'_y     & 0 
#   \end{array}\right| = 0
# $$

# #### Plots

x = [1,2,3,4,5]
plt.plot(x);

# #### Rich media

from IPython.display import YouTubeVideo
YouTubeVideo('F4rFuIb1Ie4')

# * [IPython website](http://ipython.org/)
# * [Notebook gallery](https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks) 

# ## Run notebook

# In order to start Jupyter notebook from the command line you have to type:
#
#     jupyter notebook
#

# ### You can download and run this lectures:

# Web version can be accesed from the [github repository](https://github.com/koldunovn/python_data_train).

# ## Main IPython features

# ### Getting help

# You can use question mark in order to get help. To execute cell you have to press *Shift+Enter*

# +
# ?
# -

# Question mark after a function will open pager with documentation. Double question mark will show you source code of the function. 

# +
# plt.plot??
# -

# Press SHIFT+TAB after opening bracket in order to get help for the function (list of arguments, doc string).

sum()

# ## Magic functions

# The magic function system provides a series of functions which allow you to
# control the behavior of IPython itself, plus a lot of system-type
# features.

# Let's create some set of numbers using [range](http://docs.python.org/2/library/functions.html#range) command:

list(range(10))

# And find out how long does it take to run it with *%timeit* magic function:

# %timeit list(range(10))

# Print all interactive variables (similar to Matlab function):

# %whos

# ### Cell-oriented magic

# Receive as argument both the current line where they are declared and the whole body of the cell. 

# %%timeit
range(10)
range(100)

# Thre are several cell-oriented magic functions that allow you to run code in other languages:

# + language="bash"
#
# echo "My shell is:" $SHELL

# + language="perl"
#
# $variable = 1;
# print "The variable has the value of $variable\n";
# -

# You can write content of the cell to a file with *%%writefile* (or *%%file* for ipython < 1.0):

# %%writefile hello.py
#if you use ipython < 1.0, use %%file comand
# #%%file 
a = 'hello world!'
print(a)


# And then run it:

# %run hello.py

# The *%run* magic will run your python script and load all variables into your interactive namespace for further use.

# %whos

# In order to get information about all magic functions type:

# %magic

# ### Links:

# [The cell magics in IPython](http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/1.x/examples/notebooks/Cell%20Magics.ipynb)

StarcoderdataJupyterScriptsDedupFiltered