kiwi

安装kiwi时如果收到没有找到libmseed的头文件信息的错误,那就是没有安装libmseed,只支持libmseed2的版本。如果之前安装了libmseed3,那么一定要在lib库里把so文件删除干净,再重新安装libmseed2。

可能会提示找不到hdf5,安装hdf5,同时在makefile文件中,给定INCHDF和LIBHDF的路径,lib的库名也要给定好。运行过程中有可能会找不到hdf5.mod,但可以在系统的lib中找到,拷贝过来,并想办法留在本地。

fftw3的头文件和库位置同样在makefile中给定。如果一直提示找不到fftw3f的库,生成一个软链接。

安装成功后,一定要试运行某个程序,可能会出行找不到某个so库的情况。找到这个库文件的真身,然后复制到系统lib下,一定要复制,软链接不行。

openMP中的动态数组私有化

有一个需求,需要对for循环中创建的动态数组进行操作,记录一下历程:

最开始在函数开头定义了循环变量i和动态数组trace,并紧接着用malloc对trace分配空间,在for循环的前一行用#pragma omp for private(i)能编译成功,但结果错误。分析原因是因为每次循环都共享了trace,导致计算错误;

然后将for前定义改为#pragma omp for private(i,trace),编译出现段错误;

https://www.coder.work/article/1564167给出了解决问题的正确方法:先用omp定义parallel块,然后动态分配内存,再用omp开启for循环,结束for循环后释放内存,并结束parallel块。如下:

#pragma omp parallel num_threads(40) private(i,trace)
{ // parallel 块是需要大括号的
    trace=(float *)malloc(sizeof(float)*sz);
    # pragma omp for 
    for(i=0;i<len;i++)
    {
        trace=xxxxxxx;
        .......
    }
    free(trace);
}

shell小技巧

1.seq嵌入for循环

for i in $(seq 0 10)
do
xxxxxx
done

2.expr不支持非整型运算

###############
c=echo “13.2-10.1” | bc
echo $c
###############
a=13.2
b=10.1
c=$(echo “$a-$b” | bc)
echo $c

3. bc计算精度

echo “6/9” | bc 的计算结果会是0,可以事先设置精度
echo “scale=3;6/9” | bc就会得到指定精度的结果

4. gawk中调用shell变量

awk -v awk变量名= shell变量名

 #!/bin/bash

var4bash=test

awk -v var4awk=”$var4bash”  ‘BEGIN { print  var4awk}’ 

macOS无法打开X11图形?

在macOS系统中用vpn登陆linux服务器后出现这样的提示:

Warning: untrusted X11 forwarding setup failed: xauth key data not generated

且无法打开程序的图形界面,后来搜到了这样的解决方案:

https://stackoverflow.com/questions/27384725/ssh-x-warning-untrusted-x11-forwarding-setup-failed-xauth-key-data-not-gener

具体操作就是:

1. Edit ~/.ssh/config, add

 XAuthLocation = /opt/X11/bin/xauth  to the host config

2. Ensure xauth is installed on the destination host

3. ssh -X your_server works in a secure manner

bbe-更改二进制数据流

某个程序输出的文本结果中出现了特殊字符^ @,用grep匹配字符串时说是二进制文本,只好想办法去掉。

方法一:在vim下打开文件,可以看出本身就是个正常的文本文件,仅只是多了那几个特殊字符,输入:%s/\x00//g回车后即可删除。本来想照猫画虎用sed来处理,毕竟几百个文件都用vim操作是不现实的,结果发现用sed删除字符不成功,https://unix.stackexchange.com/questions/346291/editing-binary-streams-containing-x00-bytes

这里表示sed只能用来处理text文件。这个网站提供了另一种处理工具:

方法二:bbe,是一种类似于sed的流编辑工具,能处理二进制字符,可以这么操作bb -e ‘s/\x00//g’ output

另,在gawk中输出单引号,可以用\47

计算两点间的距离

from great_circle_calculator.__conversion import _point_to_radians, _point_to_degrees, _radians_to_degrees, \
    _degrees_to_radians
from great_circle_calculator.__error_checking import _error_check_point
from great_circle_calculator._constants import *


def distance_between_points(p1, p2, unit='meters', haversine=True):
    """ This function computes the distance between two points in the unit given in the unit parameter.  It will
    calculate the distance using the haversine unless the user specifies haversine to be False.  Then law of cosines
    will be used
    :param p1: tuple point of (lon, lat)
    :param p2: tuple point of (lon, lat)
    :param unit: unit of measurement. List can be found in constants.eligible_units
    :param haversine: True (default) uses haversine distance, False uses law of cosines
    :return: Distance between p1 and p2 in the units specified.
    """
    lon1, lat1 = _point_to_radians(_error_check_point(p1))
    lon2, lat2 = _point_to_radians(_error_check_point(p2))
    r_earth = getattr(radius_earth, unit, 'meters')
    if haversine:
        # Haversine
        d_lat, d_lon = lat2 - lat1, lon2 - lon1
        a = sin(d_lat / 2) * sin(d_lat / 2) + cos(lat1) * cos(lat2) * sin(d_lon / 2) * sin(d_lon / 2)
        c = 2 * atan2(sqrt(a), sqrt((1 - a)))
        dist = r_earth * c
        return dist
    # Spherical Law Of Cosines
    dist = acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1)) * r_earth
    return dist


def bearing_at_p1(p1, p2):
    """ This function computes the bearing (i.e. course) at p1 given a destination of p2.  Use in conjunction with
    midpoint(*) and intermediate_point(*) to find the course along the route.  Use bearing_at_p2(*) to find the bearing
    at the endpoint
    :param p1: tuple point of (lon, lat)
    :param p2: tuple point of (lon, lat)
    :return: Course, in degrees
    """
    lon1, lat1 = _point_to_radians(_error_check_point(p1))
    lon2, lat2 = _point_to_radians(_error_check_point(p2))
    x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2 - lon1)
    y = sin(lon2 - lon1) * cos(lat2)
    course = atan2(y, x)
    return _radians_to_degrees(course)


def bearing_at_p2(p1, p2):
    """ This function computes the bearing (i.e. course) at p2 given a starting point of p1.  Use in conjunction with
    midpoint(*) and intermediate_point(*) to find the course along the route.  Use bearing_at_p1(*) to find the bearing
    at the endpoint
    :param p1: tuple point of (lon, lat)
    :param p2: tuple point of (lon, lat)
    :return: Course, in degrees
    """
    return (bearing_at_p1(p2, p1) + 180) % 360


def midpoint(p1, p2):
    """ This is the half-way point along a great circle path between the two points.
    :param p1: tuple point of (lon, lat)
    :param p2: tuple point of (lon, lat)
    :return: point (lon, lat)
    """
    lon1, lat1 = _point_to_radians(_error_check_point(p1))
    lon2, lat2 = _point_to_radians(_error_check_point(p2))
    b_x = cos(lat2) * cos(lon2 - lon1)
    b_y = cos(lat2) * sin(lon2 - lon1)
    lat3 = atan2(sin(lat1) + sin(lat2), sqrt((cos(lat1) + b_x) * (cos(lat1) + b_x) + b_y * b_y))
    lon3 = lon1 + atan2(b_y, cos(lat1) + b_x)
    lat3 = _radians_to_degrees(lat3)
    lon3 = (_radians_to_degrees(lon3) + 540) % 360 - 180
    p3 = (lon3, lat3)
    return p3


def intermediate_point(p1, p2, fraction=0.5):
    """ This function calculates the intermediate point along the course laid out by p1 to p2.  fraction is the fraction
    of the distance between p1 and p2, where 0 is p1, 0.5 is equivalent to midpoint(*), and 1 is p2.
    :param p1: tuple point of (lon, lat)
    :param p2: tuple point of (lon, lat)
    :param fraction: the fraction of the distance along the path.
    :return: point (lon, lat)
    """
    lon1, lat1 = _point_to_radians(_error_check_point(p1))
    lon2, lat2 = _point_to_radians(_error_check_point(p2))
    delta = distance_between_points(p1, p2) / radius_earth.meters
    a = sin((1 - fraction) * delta) / sin(delta)
    b = sin(fraction * delta) / sin(delta)
    x = a * cos(lat1) * cos(lon1) + b * cos(lat2) * cos(lon2)
    y = a * cos(lat1) * sin(lon1) + b * cos(lat2) * sin(lon2)
    z = a * sin(lat1) + b * sin(lat2)
    lat3 = atan2(z, sqrt(x * x + y * y))
    lon3 = atan2(y, x)
    return _point_to_degrees((lon3, lat3))


def point_given_start_and_bearing(p1, course, distance, unit='meters'):
    """ Given a start point, initial bearing, and distance, this will calculate the destina­tion point and final
    bearing travelling along a (shortest distance) great circle arc.
    :param p1: tuple point of (lon, lat)
    :param course: Course, in degrees
    :param distance: a length in unit
    :param unit: unit of measurement. List can be found in constants.eligible_units
    :return: point (lon, lat)
    """
    lon1, lat1 = _point_to_radians(_error_check_point(p1))
    brng = _degrees_to_radians(course)
    r_earth = getattr(radius_earth, unit, 'meters')
    delta = distance / r_earth
    lat2 = asin(sin(lat1) * cos(delta) + cos(lat1) * sin(delta) * cos(brng))
    lon2 = lon1 + atan2(sin(brng) * sin(delta) * cos(lat1), cos(delta) - sin(lat1) * sin(lat2))
    lon2 = (_radians_to_degrees(lon2) + 540) % 360 - 180
    p2 = (lon2, _radians_to_degrees(lat2))
    return p2

matplotlib同x轴作图,y轴反转

matplotlib同x轴作图,y轴反转
编辑删除转载2018-10-08 15:08:09
标签:linux
stackoverflow.com/questions/37737538/merge-matplotlib-subplots-with-shared-x-axis 

这里给了个例子,用了gridspec,其实只用subplot就可以了。


ax1=plt.subplot(211)

plt.vlines(tm1,0,mg1,color='r')

plt.xlim((1700,2020))

plt.ylim((0,8))

plt.setp(ax1.get_xticklabels(),visible=False)  ###隐藏第一个图的x轴标注



ax2=plt.subplot(212,sharex=ax1)

plt.vlines(tm2,0,mg2,color='b')

plt.xlim((1700,2020))

plt.ylim((8,0))   ##### 这里反着写,让y轴倒过来

yticks=ax2.yaxis.get_major_ticks()

yticks[0].label1.set_visible(False)  #### 两个图相交的y轴第一个标注会重叠,让第二个坐标的标注隐藏

plt.subplots_adjust(hspace=.0)    ##### 让两个图的间隔为0