<jupyter_start><jupyter_text>Using Python for your scienceThis is an introduction to moving your science from an IDL environment to Python.Let's make sure that your instillation of anaconda is up to date. From the terminal, type: Now, lets launch an ipython (interactive python) session  Getting started with Python The first thing to note is that by itself, Python is just a platform. You can think of Python as an engine - it is very powerful but unless you connect it to a transmission, axle, and wheels, it isn't very effective at getting you down the road. Fortunatly in most cases you don't need to reinvent the wheel and you can just find some that someone else created that will fit your needs. The Anaconda package comes with literally thousands of tools to help you work with data. Let's explore some basic tools. NumPy is the fundamental package for scientific computing with Python. Let's load it in to our current session.  Notice the syntax we are using: import "the library" as "what we want to call it." Now whenever we want to call a tool in numpy, we can use "np."Next we will want to plot our data, so lets grab some plotting tools. We will use a package called matplotlib. Matplotlib is a 2D plotting library, which produces all kinds figures. We don't need everything that matplotlib can do, so let's import just the tool that produces line plots. This tool is called pyplot.  Again notice the syntax we are using: import "library.tool" as "what we want to call it."Okay, we have the tools 'np' and 'plt' defined. Loading in the tools and libraries you want to use is something you have to do every time you write a program or load a python session. Now lets put our tools to use: We can dynamically define variables (i.e. we don't have to specify the type) and use conventional assignments to make new variables. We also use a tool within np to create t: np.arange. Np.arange is similar to IDL's FINDGEN( ). It creates an evenly spaced array with the syntax of output=np.arange(start,stop,step). So what does t look like? We just type the variable or use a print statement: But what are the dimensions of t? How many elements are in it? In IDL we would have to call a function to return this information, such as MAX( ). In Python, since it is an object oriented programming language, the variable t is actually more than just a simple array. It is self-aware! So let's ask t about itself.  Um... what just happened here? Python just said "yep, that is a valid function of t" but didn't actually return the value. To get the value out, we need to use a different syntax: Also we can ask: These are all "t.something( )" - "something( )" is a function of the object "t".To find out how many elements are the array To see the shape of the array: If you want to see all of the functions already available in t, type "t." and then 'tab'. This will show you dynamically all of the functions that exist. Go ahead, try it!You'll note that .size and .shape don't have brackets after them, but .min and .var do.  This is because the size and the shape of the array are attributes of the array.  The reason .min (and other methods) have brackets is that these functions have different options that you may want to use.Let's create a 2d random array We can find the minimum values along one dimension of the array... or the other one... Or the whole array. The min( ) function with the axis option finds the minimum value along different dimensions of the array rand_nn. We used "axis=None".  There is a special value in Python called **None**, which indicates **no value**.  In this case, this means that axis has no assigned value.  The axis function then resorts to a default behavior, which is to give you the minimum value over the entire array. Now let's create an array of random numbers with the same number of elements as t. We will use the Numpy tool 'random', but there are lots of ways to generate random numbers. In IDL we might use RANDOMN( ) or RANDOMU( ) depending on the distribution we want to sample from. Numpy.random had many ways of calculating random numbers too. Try typing "np.random." and then 'tab'. Let's sample from a normal distribution: Notice that we can use the t.size attribute of 't' without having to define another variable or call a separate function.Let's plot our variables. To do this we will use the matplotlib's plot function.  Matplotlib generates a plot and then in a separate command you have to display it to the screen. Yeah, it's a pain but you get use to it. Let's now generate some more complex data: The convolution returned an array that is twice the size of our other working data sets. We should trim that down. The syntax for segmenting an array uses square brackets: This means we want r_dat from the beginning element to t.size (which is 100). Let's create one more data set to work with using some more of NumPy's functions (sin and pi).  What does all of this generated data look like? Why don't we make five different plots to highlight some different plotting capabilities.First, we will define a plotting space, but instead of showing the plot this time, we are going to plot some more values. First, we will plot the magnitude spectrum of the generated data with a linear scale and a dB (logarithmic) scale. This can all be done within matplotlib. Next, We can easily show the wrapped and unwrapped phase spectrum.  The 'subplot' command means that we want a 3 by 2 grid of plots and we want to operate on the first sextant.  Using matplotlib, we can showcase our generated data set in several different ways. Of course this is just an example and there are many more types of plots that matplotlib can generate.   Basic Programming Techniques in PythonTo showcase some other basic programming techniques using the skills we just learned, lets analytically calculate $\pi$. The easiest way of doing this is using the Monty Carlo Method through finding random points inside a circle inscribed in a square.  Next, we will initialize our counting variables Now we will set up a for-loop to calculate our points. Loops in Python are a bit different than in IDL. First, Notice that in Python loops are tab delimited. Unlike IDL there is no need for 'begin' and 'end' statements since the tabbing indicates where the loop starts and ends.<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.04220472440944882, 'fraction_numerical': 0.0011023622047244095, 'mean_word_length': 4.171824104234528, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '80256', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1476, 'n_words': 1104, 'path': 'ISWI2016_Py1_Blank.ipynb', 'repo_name': 'MSKirk/tutorials', 'size': '6350'}