Friday, December 19, 2014
[R] install rgdal, rgeos packages dependency in Centos
sudo yum install geos geos-devel
For gdal:
sudo yum install gdal gdal-devel proj-devel proj-nad proj-epsg
Tuesday, July 2, 2024
[Pycharm] New way to create project from existing sources
In the past versions, to start a new project, I need to use New Project from the File menu.
But with the 2024 edition, I need to use Open instead. Otherwise it will create a new folder called PythonProject by default under the existing folder. Here is the guidance.
This change makes some sense, but it is quite difficult to navigate.
Wednesday, December 7, 2022
Learning how to feed arguments to command line - Argparse
Beginner on Argparse. The following are from the Official documentation.
The argparse module’s support for command-line interfaces is built around an instance of argparse.ArgumentParser. It is a container for argument specifications and has options that apply the parser as whole. The first descriptive message for the program is determined from sys.argv[0] or from the prog= argument.
Tuesday, October 21, 2014
[GrADS] Environment Variables 环境变量设置
For example:
example% setenv GADDIR /ford1/local/lib/grads
example% setenv GASHP $HOME/grads/shapefiles
example% setenv GASCRP "$HOME/grads/scripts /opt/local/share/grads/library"
example% setenv GAUDFT $HOME/grads/udf/table
Thursday, February 13, 2014
Wednesday, February 7, 2018
[Python] How to shift the midpoint of the colorbar? -Normalizing colormap
单向渐变多用于单增的信号,且空间分布非常简单。复杂的空间分布应该采用多色渐变,区分度更大,比如地形图。
双向渐变常用于有正负值的数据,比如相关系数、敏感性等等。今天就是要来讲一讲双向渐变colorbar。
我们平时经常遇到这样的数据,就是正负值不对称,比如值域范围是-1~100。为了能够使用双向渐变colorbar,我们需要调整数据中点,不然调色盘不对称,造成读数的困难!一个暴力的方法就是通过人为设定最大、最小值来设定数据中点:
plt.imshow(data, vmin=-100, vmax=100)
下面介绍一个更加合理、不浪费空间的简便方法:
from matplotlib.colors import Normalize
class MidpointNormalize(Normalize):
def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
self.midpoint = midpoint
Normalize.__init__(self, vmin, vmax, clip)
def __call__(self, value, clip=None):
# I'm ignoring masked values and all kinds of edge cases to make a
# simple example...
x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
return np.ma.masked_array(np.interp(value, x, y))
data = np.random.random((10,10))
data = 10 * (data - 0.8)
fig, ax = plt.subplots()
norm = MidpointNormalize(midpoint=0)
im = ax.imshow(data, norm=norm, cmap=plt.cm.bwr, interpolation='none')
fig.colorbar(im)
plt.show()
是不是很简单呀?原作者Joe还有好几种其他方法,以后可以试验一下。
Tuesday, November 2, 2021
[Windows 10] Multiple displays with docking station II - enable Night Light
After I reinstalled all the drivers, I found that the external monitors didn't react to the Windows 10 Night Light adjustment through the dock. This Night Light feature is super cool and it is annoying that the dock cannot support it naturally.
I found the instruction from this DisplayLink webpage How to enable night light or f.lux on DisplayLink displays on Windows. It worked! The only thing - you need to run the Registry Editor using the administrator credential.
Tuesday, January 19, 2021
[Python] Learning a new package pbr
https://pypi.org/project/pbr/
https://michaelkuty.com/howto/build-python-with-pbr/
https://dzone.com/articles/packaging-python-software-with-pbr
Wednesday, October 28, 2015
[R]Reset the environment variable for R in El Capitan
1. Find the R binary.
I have the Rstudio, where I can open R console. In Rstudio, use the following command to track where R binary is or RHOME.
If you can't track your directory, you can also look for R in this path. My system is El Capitan.
2. Modify the path profile.
Add the directory to your system path. In terminal:
$ sudo nano /etc/paths
Enter your password, when prompted.
Go to the bottom of the file, and enter the path you found in the first step.
Hit control-x to quit.
Enter “Y” to save the modified buffer.
Hit enter t confirm when prompted by "File name to write".
Major reference:
Add to the PATH on Mac OS X 10.8 Mountain Lion
Set environment variables on Mac OS X Lion
Tuesday, May 6, 2014
[GrADS]maskout()
syntax:
maskout(expression, mask)
It basically means using a mask from 'mask' file/variable to remove the corresponding grids in 'expression' data/variable.
(1) If you already have some mask files:
ga->d maskout(data,mask(t=1))
this command will suffice.
Remember to put (t=1) behind the mask, because most of well-made mask files don't have time step.
if the mask is 0 and 1, then you either change the undef value in the mask control file into 0 (the actual missing value in the binary file); or just use maskout(data,data-0.5), then all the value below 0 will be maskout.
(2) If you need to make mask files by yourself:
for example,
if you want to mask out the value lower than 100, in other words, you want to leave the value greater than 100,
ga->define mask = const(maskout(data,data-100),1)
if you want to mask out the slope that insignificant with p>0.05,
ga->define mask = const(maskout(p,0.05-p),1)
Notice the difference here, for conditioning data > value, then the mask = data-value; for conditioning data < value, then the mask = value-data.
Besides using with const() function to produce mask, maskout can also be combined with aave and tloop to plot time series.
ga->d tloop(aave(maskout(data,mask(t=1)),g))
The idea here is to upscale by spatial averaging the masked region.
Sunday, March 19, 2023
[Git] Migrating a Git Repository to a New GitHub account - Case 1
Tuesday, February 4, 2014
技术学习期末小结
过去的一个学期,在这上面没有太用功,但多多少少更加了解了各种语言和环境。
回首看来,Justin说的东西都非常正确,我以后一定要认真听老板的话!
首先,接触两个全新的操作系统。
(11月上旬)MacOS:需要适应的主要是触摸盘,文件管理系统,多任务管理,系统整理,移动硬盘读取。
Mac让我感觉最爽的除了和Linux内核相通,任务管理的高效,还有和ipad iphone的同步。
不太适应的是,两个平台上软件不太一样,需要寻找更适合的替代工具。(这种情况下,于是发现过去大部分软件其实都是多余的…… )
(11-1月)Linux:一开始并没有当一个系统用,现在逐渐有这个概念了。。。逐渐接触terminal, bash, shell, vi...
逻辑大概是:
》vim这种text editor就是写各种script的工具,写适用于各种软件的script/source code源代码,如R(.R),GrADS(.gs),matlab(.m), C(.c), Python(.py), Shell(.sh)。
》对于C和Fortran,是需要compile编译成计算机可识别的语言来执行的,所以需要make file;
》对于其他scripting language,是直译式的(比编译要慢),不需要make file,但需要通过chmod +x来使之可以执行。
》用相应的软件或者环境来运行源代码。
因此,Python有着空前绝后的优越性!!
我觉得此前最错误的就是,不理解基本概念,把各种工具混为一谈,导致自己没有选择正确的方向下手!
然后,开始上手画图工具GrADS。GrADS其实可以说是一个数据可视化的快捷工具,附有非常简便的数据读取、分析功能,可以做简单的分析。
接着,开始学R。R其实就是统计版的Matlab,界面好像,语法好像。
如今,正式开始学习Python。
短短几个月,接触的范围还是挺广的呵呵。
Tuesday, April 17, 2018
[Linux] Files permission
$ Chmod -R 700 /directory
Tuesday, February 10, 2015
[Python] Plot
(1)
plt.imshow(data, vmin=0, vmax=10, cmap='jet', aspect='auto')
(2)
plt.pcolor(X, Y, v, cmap=cm)
plt.clim(-4,4)
plt.show()
(3) Change the range of a colormap for a certain values
import matplotlib.colors as colors
(a)
cmap = cm.get_cmap('jet', 20)
cvals = cmap(arange(5, 20, 1))
ncmap = colors.ListerdColormap(mcolors)
(b)
mcolors = plt.cm.jet(linspace(0.3, 1, 256))
ncmap = colors.ListedColormap(mcolors)
(3)Remove the top and bottom axis
def simpleaxis(ax):
plot([xmin, xmax],[ymin, ymax])
Monday, November 4, 2019
[WSL] Set up Visual Studio Code and Pycharm editors in Windows Subsystem for Linux
Here is some background. I mainly work with Linux and use Python and Javascript. The first question I have is whether I need to install two Python distributions for Windows and WSL. I felt that it may trigger a problem because (1) the compiling of Python in different operating systems must be different, and (2) the slashes in the two file systems are opposite. I did a quick test by launching the anaconda python.exe from the WSL linux terminal (in my case, Ubuntu). Surprisingly, I am able to open Windows Python.exe in WSL! However, it is not much meaningful because in WSL I am not able to invoke the virtual environment and all the packages installed in Windows. So the short answer to this question is that you should install separate Python distribution in Windows and WSL, in order to manage your packages and avoid conflicts. Ideally, one should use virtual environment for each Python project, no matter in Windows or in WSL.
I use two major editors, Visual Studio Code and Pycharm. I use VSC for most languages, such as Python, Javascript, Markdown, Dockerfile, R, etc. I use Pycharm when I focus myself on one single Python project. These two editors are fantastic from their interface designs to the elaborative documentation and online support.
Surprisingly, both editors support dual-system launching! By that I mean, after you install the software in Windows, you not only can open it from Windows (e.g., start menu), but also are able to launch it from the WSL linux terminal (in my case, Ubuntu). I've never seen this dual-system functionality before in Linux nor OSX, which is unbelievably amazing and smart! This feature is really important because the running/debugging environment is entirely different in Windows and WSL. With that, you can now run Python from VSC internally (with your WSL bashrc file launched).

Tuesday, March 14, 2023
[ChatGPT] User experience so far... AMAZING
I have to say chatGPT is much more powerful that I can imagine - definitely eye-opening!
I realize the followings when using it:
1. Pay attention to the interrogatives: What/Which/If/Why/How much
2. Give as much context as possible in the question. It WILL understand!
3. It can debug your code at all different levels... This is nuts!!!
Friday, November 1, 2019
[Windows] How to set up conda path in PowerShell
But what if you already use PowerShell and don't want to open an extra Anaconda Prompt window? Or what if you are using visual studio to edit python scripts and run python within it?
The first time you type in "conda" in PowerShell, you may see the following error:
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
The solution is to go to the anaconda directory (either PowerShell, command line, or WSL, it doesn't matter), and simply type "./conda.exe init".
Wednesday, May 11, 2016
[Python] Regrid/Remap using python/cdo/gdal
If we want to use scipy, here are the functions I found relevant, but not good enough because they are disconnected from their geographic coordinates.
scipy.ndimage.map_coordinates
scipy.interpolate.RectBivariateSpline
I use the second one and found several issues. First, the latitude and longitude seems get wrong. While the other problem is more problematic. That is the boundary is wrong.
Another way to work around is using cdo remapgrid. CDO has a wrapper of SCRIP (Spherical Coordinate Remapping and Interpolation Package), which could be found on line (Los Alamos National Laboratory). I strongly recommend use this functionality of CDO, a powerful and fast tool based on Fortran. It has bilinear, bicubic, distance-weighted average, nearest neighbor, conservative (box-average), and largest area fraction interpolations.
I haven't really looked at gdal, but I guess it takes more time to figure out the commands from the unfriendly gdal manual...
Wednesday, January 13, 2021
[Git] Study git and github in Pycharm
Set up git in Pycharm:
- https://www.jetbrains.com/help/pycharm/set-up-a-git-repository.html#add-remote
- There are two ways of set up. One is that you create a new repo on github and then git clone to the local file. The second way, which is more convenient, is to share your local project to Github.
Set up run/debug configuration:
- https://www.jetbrains.com/help/pycharm/creating-and-editing-run-debug-configurations.html
Configure project structure in Pycharm:
- https://www.jetbrains.com/help/pycharm/configuring-project-structure.html
Unversioned a file:
- https://superuser.com/questions/898165/remove-file-from-git-version-control-without-deleting-it-from-the-filesystem
Manually delete file and then manage through git:
- https://stackoverflow.com/questions/12987907/git-how-to-commit-a-manually-deleted-file
- https://stackoverflow.com/questions/492558/removing-multiple-files-from-a-git-repo-that-have-already-been-deleted-from-disk
- https://www.educative.io/edpresso/how-to-change-a-git-commit-message-after-a-push
Compare different files in Pycharm
- Use compare with clipboard to compare current file (in editor) with the copied file
- In "Show history", at the left navigation pane, right click on one commit, and select compare with local. Local will show up on the right.
Monday, May 30, 2016
[Linux] server
log in as root
$ su
$ mount /home/{hostname}
2. unmount the server
$ umount /home/{hostname}
