Read and analyze binary files output in Fortran 90 with Python. Describe links and cautions that were helpful in development. It will be edited sequentially in the future.
Usually Fortran 90 and IDL (Interactive Data Language). Python is not very familiar. Migrating to Python instead of licensed IDL.
--Pylab is hard to get caught in Google search. Import numpy and matplotlib directly. --from [package] import * is not done as much as possible. --I want to use it on the server, so basically I use it on the console.
Python 3.6.0 |Anacoda 4.3.0 on OS X El Capitan
Follow PEP8. Understanding [Python Coding Standards] PEP8 It is recommended that the variable name / function name is snake_case. Fortran is case insensitive, so it looks good when you have the same kind of naming convention. Summary of English words often used in programming [Updated from time to time] Foreigners talk: how to name classes and methods in English Reference information for successful method naming
How to display the version of numpy or scipy Python Tips: I want to find out the location of library modules
[Python pass by value and pass by reference] (https://python.dogrow.net/?p=274) [Passing by value, passing by reference, passing by reference] (https://qiita.com/ur_kinsk/items/949dabe975bdc1affb82) Is it okay for the default to pass the reference value? [Determine if variable is defined in Python] (https://stackoverflow.com/questions/1592565/determine-if-variable-is-defined-in-python) [Four arithmetic operations-numerical values-Introduction to Python] (http://www.pythonweb.jp/tutorial/num/index2.html)
Avoid multiple loops. itertools.product Avoid multiple loops in Python
17.5. Subprocess — Subprocess Management
[Sort HOW TO] (https://docs.python.jp/3/howto/sorting.html) [Get index of array after sorting with numpy] (https://python.dogrow.net/?p=274)
Fortran output files are unformatted output (data) and formatted output (parameters, etc.).
The scipy.io.FortranFile was useful when reading Fortran unformatted output. The contents are composed of numpy.fromfile etc. scipy.io.FortranFile However, as officially noted, it outputs with direct access or stream in Fortran. You don't have to worry about endianness if you read it with numpy.fromfile.
Read normally. Use str.split, str.splitlines, etc. Pay attention to the newline character at the end of the line. [4.7. Text sequence type — str] (http://docs.python.jp/3.6/library/stdtypes.html#text-sequence-type-str)
NumPy
When specifying in a range, it is different from IDL and it seems to be wrong.
import numpy as np
np.arange(0,10)
# array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
np.arange(0,10)[3]
# 3
np.arange(0,10)[0:3]
# array([0, 1, 2])When specified in a range, the rightmost element is not included.
Array shape conversion Reshape looks good.
Array generation related routine
List of array index related functions
List of logical operation related functions
Since it is basically an analysis, it is implemented obediently if it is not too slow. 2. Tips for Numpy array numpy.roll
If you want to implement various things in Python, speed up Numba etc. Numba
matplotlib Basically, pyplot is enough.
Anatomy of Matplotlib -- tutorial developed for the SciPy conference This seems to be the most understandable. I want to read it properly.
The equivalent of IDL's System Variable (! P. ~,! X. ~, Etc.) is like rcParams. As the equivalent of the startup file (.idl_startup), matplotlibrc should be set. The location is below.
import matplotlib as mpl
mpl.matplotlib_fname()
For the time being, set the following.
backend : TkAgg #The drawing window of matplotlib is treated as a separate application.
interactive : True # show()Display the plot without writing each one.
xtick.top : True # draw ticks on the top side
ytick.right : True # draw ticks on the right side
xtick.direction : in # direction: in, out, or inout
ytick.direction : in # direction: in, out, or inout
xtick.minor.visible : True # visibility of minor ticks on x-axis
ytick.minor.visible : True # visibility of minor ticks on y-axis
When creating a diagram as a batch job, enter the following settings.
import matplotlib.pyplot as plt
plt.rcParams['interactive'] = False
The modified rcParams can be returned with rc_file_defaults ().
import matplotlib as mpl
mpl.rc_file_defaults()
rcParams can also be reset to defaults with matplotlib.rcdefaults (), Note that this will also return the settings changed in matplotlibrc. rc_file_defaults () will make matplotlibrc applied from the default value.
It seems good to write the settings you always want to use in matplotlibrc.
Format the graph of matplotlib
matplotlib: Format the figure for your dissertation
Plot black and white graphs for papers with matplotlib or pylab
The appearance of the graph is also decided by the style sheet.
Changes in matplotlib 2.0 There are a lot of figures and it is helpful.
4 techniques for making diagrams for papers and presentation materials with matplotlib I don't use it much, but bar charts and legends.
Try all the markers that can be used with matplotlib-python
[How to do a scatter plot with empty circles in Python?] (https://stackoverflow.com/questions/4143502/how-to-do-a-scatter-plot-with-empty-circles-in-python)
Log scale display / grid display
pcolor is slow as the data gets bigger. Use pcolor mesh.
Plot of contour lines and other things with matplotlib
There seems to be something called pcolorfast.
Colormap Reference Colormap Normalization
How to change fonts in matplotlib (python)?
Increase the font size of the graph with matplotlib Tight Layout guide [What to do if you get a tight_layout error on Mac OS X](http://myenigma.hatenablog.com/entry/2015/10/09/223629 # What to do if you get a tight_layout error on Mac-OSX] )
matplotlib.figure.Figure.savefig Save high resolution images of Matplotlib
How do I close all pyplot windows (including ones from previous script executions)?
stack overflow: Understanding matplotlib: plt, figure, ax(arr)? AnatomyOfMatplotlib-Part1-Figures_Subplots_and_layouts.ipynb Official description of the role of Pyplot and Axes Basic knowledge of matplotlib that I wanted to know early, or the story of an artist who can adjust the appearance
Apparently, originally, figure manages the window, and axes manages each plot in the window. pyplot seems to be a wrapper that makes it script-like and easy to use.
Recommended Posts