Pages

Python Class: A simple and clear explanation.

I have been trying to understand class in python and failed to use it any useful purpose. Then, I came across this  webage where I got a clear understanding of Class in Python. To understand this, I went through so many pages and blogposts. But I didn't get it. 

https://micropyramid.com/blog/understand-self-and-__init__-method-in-python-class/

See the code blow (taken from above link). 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Car(object):
  """
    blueprint for car
  """

  def __init__(self, model, color, company, speed_limit):
    self.color = color
    self.company = company
    self.speed_limit = speed_limit
    self.model = model

  def start(self):
    print("started")

  def stop(self):
    print("stopped")

  def accelarate(self):
    print("accelarating...")
    "accelarator functionality here"

  def change_gear(self, gear_type):
    print("gear changed")
    " gear related functionality here"

This code is an example for a class in python language.

As you can see, this is a collection of functions (def) grouped in a class named Car. 

What is the use of Class?

Class is used to collect list of definitions and provide a functionality to crosscommunicate with all other definitions inside the Class. 

What is the best explanation for Class? Do you have any link? 

Comment and provide link here. 

Thanks. 

Postdocs: Dos and Don'ts for getting tenure

I read an intereting article "What 50 principal investigators taught me about my failure to land tenure" by Bela Z. Schmidt’s. 

After multiple postdocs for long years, and failing to get a tenure, the author provide eight pieces of advice for researchers. Here is what I understood from this article. 

1. Don't over check your results. Believe your data:
After getting very good result, most of the time, you may have a feeling that the result is good and anything wrong with the experiment, or calculation. These kinds of thinking should be avoided. Of course, you should cross check your data and confirm that they are correct. But, too much thinking would not be healthy. The author simply put this as "Accept your data".

2. Don't ask what I should do further. Instead, tell what you have done and got and what you are going to do further.
Most of the postdocs ask their supervisors what should they do further. Instead, you take responsibility to the project, do experiments, calculations, and everything without waiting for an approval. Do something useful and get progress and inform to the supervisors that you have done this and that and got this result. In addtion, you may give a hint on what you are going to do further. This would be useful to get feed back and advice from your supervisors.

3. Don't think like a postdoc. You treat yourself like a co-PI.
    Treat your supervisor as a future collaboration and you like a co-PI of the current project. 

4. Have confident in what you are doing.
    Some times, your supervisor may not realize the importance of a result. If you beleive that something is important, do it and try to convince the importance of your experiment or calculation or result.

5. Keep track on the timeline of the project and publish as soon as you get results.
    As a postdoc, the term will be renewed every year or so. This is the time to show your potential in a short duration of the time. Publish your results at as soon as you get results. This will also increase the chance of getting renewal and a good boost for you.

6. Think ahead what you want to do next.
    While in Ph.D, think about what you want to do in postoc. During postdoc, think about what you want to when you join an institution and where would you apply. Always think ahead of future.

7. Take decision quickly and act on it.
    You should take quick decision and act on it. At the same time you should have multiple ideas and have to follow your intution.

8. Finish what you start.
    Michael Faraday said "Work, Finish, Publish", finish what you start and publish. If you are trying to unravel big problems, reveal as soon as you find some thing. 
 




Postdocs: What they should know?

“I don’t feel that anything significant that I’ve done has been truly independent,”.

This Nature article on "The quest for postdoctoral independence" ends with this quote. I also feel the same.

This articles provide important points. I compare with the points provided here in another articles from TimesHigherEducation.com article 10 habits for a successful postdoc

Take ownership of your project.
Read broadly and learn more about research.
Learn how to train people.
Learn how to write scientific papers, and learn how to give scientific talks
Position yourself to get good letters of reference.
Learn organisational skills.
Be a good citizen of the lab and the department.
Network.
Learn how to write grants and apply for your own funding.
Finish papers before you leave your postdoc.

Interetigly, only a few points match between these two article. While most of the postocs do what is given in above points, many postdocs fail to do what is mentioned in the Nature article. 

You just need to prove that you have the skills, expertise, collobrative skills, communicative skills, fund writing skills, getting grant, articulative skills, ect in order to convince any committe to land in tenured jobs. These skills would be of great help regardless of whether you prefer academia or industry.

Big tech companies look for those who has these skills with PhDs. Having just Ph.D is not enough for companies. 

What do you thing about this? Leave a comment. 


 

Matplotlib y-axis label not displayed when saved as .eps .pdf file

I encountered this error in matplotlib.pyplot.

When I tried to save the plotted graph in matplotlib, the y-axis label was not displayed in the saved file (.eps, .pdf, etc files).

Just add this line (as a previous line) before saving the graph as a file using savefig command.

plt.tight_layout()

The problem will be solved and the saved file will contain y-axis label.


Matpotlib error: Image size of 3831x7771797 pixels is too large. It must be less than 2^16 in each direction.

This is due to the large file size of the figs. you have plotted.
If you get this error, you may not visualize the figure(s) on the matplotlib.
However, you can save as a file (.pdf or .eps ir .png) and you can open and see the figures.

If you want to elimate the error message, the only solution is to decrease the file size (you may decrease the size of the figure or the pixel size)

Here is a related post in GitHub.
https://github.com/matplotlib/matplotlib/issues/16234


Another reason you may get this error may be due to the following reason.

If you have plt.text option as follow,

plt.text(6.0, 7.4, '(b)', ha='center', va='center', fontsize=14, rotation='horizontal', fontweight='bold')

then, this may be causing the problem (especially if you use alreadying existing script to plot figs.)
To solve this problem, just comment this plt.text() using # and try to save the file.
Now, if there is no error, you just adjust the location of the text values in the plt.text() to proper place.

This would solve this error.



How to translate documents from one language to another language using google drive (google docs)?

How to translate documents from one language to another language using google drive (google docs)?

You can convert .doxc or .doc file from one language as follow:

1. First, upload the file (e.g. .docx) to google drive (Since the file is in .docx format, you can not find the translate option in Tools.)

2. Now Go to File --> Save As Google Docs.

3. Go to the file converted google docs. In this document, chose:
   Tools --> Translate --> (select the language)

Now you will get the translated .docx doument.

Hope this helps. Comment here if this is useful.

Using ls command (ls) to sort file names by number.

If you work with a lot of files, you often save the files with numbers for each system.

For example, 

1sample.out
2sample.out
3sample.out
4sample.out
......
......
......
......
10sample.out
11sample.out
12sample.out
.......
.......
Nsample.out

Suppose, you want to extract some information from these files in order from 1sample in order. If you type 'ls', the file 10sample.out will be listed first. You will get list as follow. So the extracted info will be different from what you expect as follow.

10sample.out
11sample.out
12sample.out
...... 
......
15sample.out
1sample.out
2sample.out
.....
.....
Nsample.out

To order file names based on the numbers in the file, use 'ls -v"

Now, the files will be ordered properly.

So, to list the files based on the numbers, use:

ls -v *.out    [to list files with extension .out]

This is a series of post on the "Efficient use of Linux" as well as "Linux Tips for beginners" series. To see all the post, click the link on the right side. 


Using ls command to list all the files in the current directory recursively:

Use:

ls -R

This will list all the files int he current directory recursively.

Jupyter-notebook not running after Ubuntu upgrade

$ jupyter-notebook 

Traceback (most recent call last):
  File "/usr/local/bin/jupyter-notebook", line 7, in <module>
    from notebook.notebookapp import main
ModuleNotFoundError: No module named 'notebook'

$pip install jupyter --user installed the jupyter-note book.

But I want python3 version.
I tried to install jupyter using following command.

$ pip3 install jupyter --user

Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'

To solve this problem do the following.
Remove the installed jupyter using:

$sudo apt-get uninstall jupyter (and hit 'y' to confirm)

or,

$pip uninstall jupyter

and update using:

$sudo apt-get update

Now do the following:

$sudo apt-get install jupyter-notebook

Now, you can open the jupyter-notebook.

Symbols above the letters (for scientific publications)

When writing papers, we often come up with author(s) names with symbols above some characters of author(s) names.

How do you use those symbols in LaTeX?

Here is a Wikipedia link where the details are provided.

https://en.wikipedia.org/wiki/Diacritic

In order to use in LaTeX, a number of answers in the following SE site is given.

https://tex.stackexchange.com/tags/accents/info

Some of the frequently used symbols are (from SE site):

Text mode

Plain TeX makes it possible to typeset the most commonly used accents:
  • \` (grave accent): à
  • \' (acute accent): á
  • \^ (circumflex or “hat”): â
  • \" (umlaut or dieresis): ä
  • \~ (tilde or “squiggle”): ã
  • \= (macron or “bar”): ā
  • \. (dot accent): ȧ
  • \u (breve accent): ă
  • \v (háček or “check”): ǎ
  • \H (long Hungarian umlaut): ő
  • \t (tie-after accent): a͡
  • \c (cedilla): ş
  • \d (dot-under accent): ạ
  • \b (bar-under accent): ο̩
  • \k (ogonek): ą
The Unicode character encoding UTF8 includes several special characters and characters with accents. The following code specifies that the encoding of the LaTeX document source file is UTF8. As font encoding is specified T1, because it supports the encoding of extended character sets in fonts:
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
Of course, the encoding in the text editor needs to be set to utf8, as well.

Math mode

The following commands may be used only in math mode to produce accents;
  • \hat{o} (circumflex): enter image description here
  • \widehat{oo} (wide version of \hat over several letters): enter image description here
  • \check{o} (vee or check): enter image description here
  • \tilde{o} (tilde) enter image description here
  • \widetilde{oo} (wide tilde) enter image description here
  • \acute{o} (acute accent): enter image description here
  • \grave{o} (grave accent): enter image description here
  • \dot{o} (dot over the letter): enter image description here
  • \ddot{o} (two dots over the letter): enter image description here
  • \breve{o} (breve): enter image description here
  • \bar{o} (macron): enter image description here
  • \vec{o} (vector (arrow) over the letter): enter image description here

You may be interested in these posts

Error in image file conversion: convert-im6.q16: not authorized `test.eps' @ error/constitute.c/WriteImage/1037.

This error is because of the vulnerability. This allows remote execution of code using image formats. So, some Linux distributions by defaul...