搜索此博客

2018年6月27日星期三

Zip files using Python(基于Python压缩文件夹)

# -*- coding: utf-8 -*-
"""
Created on Wed Jun 27 2018

@author: Baikal
"""
#Purpose: To zip unzip folders of Sentinel-1 files and rename zipfile(Mainly to remove this '.SAFE' four characters) 
#         to adapt the python processing.

#利用的是对目录进行深度优先遍历,首先把第一级目录中的文件进行遍历,如果是文件,
#则把它连同当前路径一起加入result(list),如果是子目录,则在整个目录上继续DFS
#直到所有的文件都被加入。


import os
import time
import zipfile

# 迭代判断是否到达根目录 def dfs_get_zip_file(  S1_dir, result ):
    
    id = 0
    files = os.listdir( S1_dir )
    for file in files:
        if os.path.isdir( S1_dir + '/' + file ):
            dfs_get_zip_file( S1_dir + '/'+ file, result )
        else:   
            result.append( S1_dir + '/' + file  )

def zip_path(In_dir, Out_dir):

    time_start = time.time()
    FOLDERS = os.listdir( In_dir )
    for S1_FOLDER in FOLDERS:
        if len( S1_FOLDER ) == 72:
            Output_name = In_dir + S1_FOLDER[ :-4 ] + 'zip'
            if os.path.exists( Output_name ) == 0:
                f = zipfile.ZipFile( Output_name ,'w' ,zipfile.ZIP_DEFLATED )
                filelists = []      
                S1_dir = In_dir + S1_FOLDER
                dfs_get_zip_file( S1_dir, filelists )
                for file in filelists:
                    f.write(  file , arcname= S1_FOLDER + file[ 113: ] )
                f.close()
            print S1_FOLDER[ :-4 ] + 'have down'
    
    time_end = time.time()
    ZIP_Time = time_end - time_start
    print 'Classification Time:'
    print str( "%.*f" % (3, ZIP_Time / 60 ) ) + 'min' + str( "%.*f" % (3, ZIP_Time % 60 ) ) + 's'
    print "Well Down"
    
    
##Main
In_dir = r'G:\201606Sen\scihub.copernicus.eu\201611/'
Out_dir = In_dir
zip_path(In_dir, Out_dir)


Reference:
https://blog.csdn.net/wangtua/article/details/68943231

2018年6月6日星期三

IDL Plot函数绘制散点图时设置透明度

目标:
如图1散点图中如果点数太多,簇与簇之间的混淆则难以辨识。因而,希望通过更改某一类簇的透明度来清晰表现不同类簇之间的混淆性与可分性。
图1 散点图

IDL中PLOT函数的关键字:

Syntax


graphic = PLOT(Y[Format] [, Keywords=value] [, Properties=value])
graphic = PLOT(XY[Format] [, Keywords=value] [, Properties=value])
graphic = PLOT(Equation[Format] [, Keywords=value] [, Properties=value])

Keywords

Keywords are applied only during the initial creation of the graphic.
AXIS_STYLE=value
/BUFFER, /CURRENT, /DEVICEDIMENSIONS=[widthheight], LAYOUT=arrayLOCATION=[xy], MARGIN=scalar or [leftbottomrighttop], /NO_TOOLBAR, /NODATA, /OVERPLOT, /WIDGETS

Properties

Properties can be set as keywords to the function during creation, or retrieved or changed using the "." notation after creation.

参数有很多,与目标相关的参数为SYM_TRANSPARENCY,范围为0-100。其中,默认值为0,即不透明,100为完全透明。

SYM_TRANSPARENCY

An integer between 0 and 100 that specifies the percent transparency of the symbols. The default value is 0.

Reference:


2018年6月5日星期二

Word表格前面怎么添加一个空白行?

快捷键法:


将光标定位在表格的第一个单元格再用快捷键CTRL+SHIFT+ENTER可以快速的在表格前增加一个空白行。



Installing pip and LibSVM package and installing LibSVM in python and LibSVM Usage

1.
PIP安装步骤,详见参考[1]

说明:
我的电脑此前已经安装有Anaconda2(32bit),因而,pip默认的安装地址并非帖子中所列的C:\Python27\Scripts,而是D:\Anaconda2\Lib\site-packages。
因而,对我来说,我需要导航至这个目录,进行pip安装结果的验证,

2.
 LibSVM的安装步骤请参考[2]

Steps:
1. Navigate to http://www.lfd.uci.edu/~gohlke/pythonlibs/#libsvm
2. Download the .whl file of libsvm corresponding to your OS.
3. Open command prompt and navigate to that folder containing the downloaded .whl file.
4. Type the following command in command prompt-

pip install libsvm-3.22-cp27-cp27m-win32.whl
NOTE: Type name of your .whl file after pip install
 安装成功

3.
LibSVM在Python中的安装步骤,参考链接详见[3]

4.
关于在Python中调用LibSVM的方法,请参考[4].

5.
关于程序中的预测函数svm_predict()中的标签疑惑问题(困扰我一天有余。。。),参考链接[5].


Reference:
[1]
https://dev.to/el_joft/installing-pip-on-windows
[2]
https://stackoverflow.com/questions/12877167/how-do-i-install-libsvm-for-python-under-windows-7/32358275#32358275
[3]
https://www.jianshu.com/p/c3573ddba793
[4]
http://www.cnblogs.com/Dzhouqi/p/3653823.html
[5]
http://www.cnblogs.com/xiaodi914/p/5493646.html





2018年6月4日星期一

Break Line Difference of PrintF and WriteU keyword of IDL『IDL PrintF(默认换行输出)与WriteU(默认不换行输出)打印输出差异』

目的:

利用IDL实现打印输出如下表:


实现:
   ;设置第一行纹理特征名称
    Corr_Name = [ ' ' ,'Mean ' ,'Variance ' ,'Homogeneity ' ,'Contrast ' ,'Dissimilarity ' ,'Entropy ' ,'Second_Moment ' ,'Correlation ' ]

    ;输出第一行纹理特征名
    PrintF , FYI_LUN , Corr_Name
    FOR ii = 0,7 DO BEGIN
      ;输出第一列纹理特征名

      WriteU , FYI_LUN , Corr_Name[ii + 1]

      ;输出各项纹理特征值
      PrintF , FYI_LUN , Correlation_FYI[* , ii]
    ENDFOR

LibSVM Chinese Brief Infroduction

Reference: [1]  https://blog.csdn.net/v_july_v/article/details/7624837 [2]  https://wenku.baidu.com/view/c402e983336c1eb91b375d37.html?fr...

  • Word (2)