Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Saturday, July 18, 2020

Code:多项参考

  1. [Matlab]删除XLS文件特定Sheet或空白Sheet(默认Sheet);
  2. [SPEI_SPI]计算栅格、站点;
  3. [Matlab]统计知网关键词词频;
  4. [Matlab]
  5. 1
    2
    3
    4
    5
    % Read Image
    [image, geo]=readgeoraster(imgpath);
    info=georasterinfo(imgpath);
    % Save Image
    geotiffwrite('newimg.tif', image, geo); 
    
    % read a geo-referenced image 
    [image, geo]=readgeoraster(filepath);
    
    try
        info=geotiffinfo(filepath);
    catch
        info=georasterinfo(filepath);
    end
    
    % write a geo-referenced image 
    try
        geotiffwrite(otpath, uint8(class_imag), geo);
    catch
        strcmd=['gdalinfo ', filepath];
        [~, cmdout]=system(strcmd);
        epsg=extractBetween(cmdout, "EPSG:"," got from GeoTIFF keys");
        epsg=epsg{1};
        % geotiffwrite(otpath, uint8(class_imag), geo, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
        geotiffwrite(otpath, uint8(class_imag), geo, 'CoordRefSysCode', ['EPSG:', epsg]);
    end
    
    1
    geotiffwrite(otpath, uint8(class_imag), geo, 'CoordRefSysCode', ['EPSG:', epsg], 'TiffType', 'bigtiff');
    
    1
    geotiffwrite('m2.tif', image, geo, 'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);
    
  6. [Matlab] A powerful toolbox for exporting images, refer to the online documentation for usage instructions; to save images and prevent accidents, use export_fig('exportfig_painters.png', '-png', '-painters', '-r300');. When the image contains Chinese characters, refer to this code snippet: export_fig([name,'.png'], '-png', '-r400','-q300');.
  7. [Matlab] Get the parent folder path
  8.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    %==========================================================================================================================
    % Gets the folder one level up.  If startingFolder is a filename with an extension it gets the containing folder and the child folder is null.
    % Returns null for both if the folder does not exist, and it's not a filename either.
    function [parentFolder, childFolder] = GetParentFolder(startingFolder)
    parentFolder = []; % Initialize
    childFolder = []; 
    try
    	if isfolder(startingFolder)
    		[parentFolder, childFolder, ext] = fileparts(startingFolder);
    		% Need to append extension for rare cases where deepest folder has a dot in the name.
    		childFolder = [childFolder, ext];
    	elseif isfile(startingFolder)
    		% It's a filename, not a folder.  Need to change otherwise childFolder will be returned as the base file name.
    		[parentFolder, childFolder, ext] = fileparts(startingFolder);
    		childFolder = []; % No child folder since it's a filename, not a folder name.
    	end
    catch ME
    	message = sprintf('Error in GetParentFolder():\n%s', ME.message);
    	uiwait(msgbox(message));
    end
    return; % from GetParentFolder
    end
    
  9. [Matlab]Export text on a text file.
  10. 1
    2
    3
    4
    fid=fopen(txtpath, 'w', 'n', 'US-ASCII');
    fprintf(fid, '%s\r\n', num2str(value));
    fclose(fid);
    fclose('all');
    
  11. [Matlab]Enhance RGB Image Code.
  12.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    function enhan_image=GenenhanImage(filepath)
    %  https://www.mathworks.com/matlabcentral/fileexchange/64932-files-for-demystifying-deep-learning-semantic-segmentation-and-deployment?s_tid=srchtitle
         % Load the images located in the above path using imageDatstore - ML Function
        imds = imageDatastore(filepath);
        pic_num = 1;
        I_raw = readimage(imds, pic_num);
    
        enhan_image= histeq(uint8(I_raw)); 
    
    end
    
    1
    image=imadjust(image, stretchlim(image), []);
    
  13. [Matlab]To decrease computation time, use GPU processing, if it is available.
  14. 1
    2
    3
    4
    I = imread("peppers.png");
    if(canUseGPU)
        I = gpuArray(I);
    end
    
  15. [Matlab]输出图片的强大Toolbox,用法说明参考在线文档(可能需要翻墙)以export_fig('exportfig_painters.png', '-png', '-painters', '-r300');保存图片,避免意外情况;当图片包含中文字符时参考此段代码export_fig([name,'.png'], '-png', '-r400','-q300');;
  16. [Matlab]Figure全屏命令:set(gcf,'outerposition',get(0,'screensize'));;
  17. A GEO file in latitude-longitude projection.
  18. [Matlab]按比例在Plot上打上文字.
  19.  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    % Add Text
    fnum=48;
    loX=0.568;
    laY=0.1;
    GenTextMap(loX, laY, t, fnum);
    
    function GenTextMap(loX, laY, yymm, fnum)
    
        % text(-94.78674012, 53.88222466, "   Island Lake", 'FontSize', 15)
        xxx=get(gca, 'XLim');
        yyy=get(gca, 'YLim');
    
        x=loX*(max(xxx)-min(xxx))+min(xxx);
        y=laY*(max(yyy)-min(yyy))+min(yyy);
    
        text(x, y, yymm, 'FontName', 'Arial', 'FontSize', fnum);
    
    
    
    
    end
    
    fnum=48;
    loX=0.1;
    laY=0.7;
    t=char(ia-1+97+5+5);
    t=['(', t, ')'];
    GenTextMapkk(loX, laY, t, fnum);
    function GenTextMapkk(loX, laY, yymm, fnum)
        xxx=get(gca, 'LatitudeLimits');
        yyy=get(gca, 'LongitudeLimits');
        x=loX*(max(xxx)-min(xxx))+min(xxx);
        y=laY*(max(yyy)-min(yyy))+min(yyy);
        text(x, y, yymm, 'FontName', 'Arial', 'FontSize', fnum);
    end
    
    fnum=90;
            loX=0.85;
            laY=0.5;
            t=dsname;
            GenTextMapCenter(loX, laY, t, fnum)
    function GenTextMapCenter(loX, laY, yymm, fnum)
        xxx=get(gca, 'LatitudeLimits');
        yyy=get(gca, 'LongitudeLimits');
        x=loX*(max(xxx)-min(xxx))+min(xxx);
        y=laY*(max(yyy)-min(yyy))+min(yyy);
        text(x, y, yymm, 'FontName', 'Arial', 'FontSize', fnum, 'HorizontalAlignment', 'center');
    end
    
  20. 世界各国边界(简化).
  21. 替换至NaN
  22. 1
    2
    3
    4
    5
    6
    7
    8
    9
    missing_idx = cellfun(@(x) is_missing(x), rawdat, 'UniformOutput', true);
    rawdat(missing_idx) = {NaN};
    
    function tf = is_missing(x)
        tf = false;
        if ismissing(x)
            tf = true;
        end
    end
    
  23. 自制图例
  24. 1
    2
    3
    4
    5
    6
    7
    8
    9
    % Add legend
    h = gobjects(3, 1);  % preallocate graphic handles
    h(1)=plot(-100, -100, 'hexagram', 'MarkerSize', 6, 'LineWidth', 1, 'MarkerEdgeColor', 'k', ...
        'MarkerFaceColor', 'none');
    h(2)=plot(-100, -100, 'o', 'MarkerSize', 6, 'LineWidth', 1, 'MarkerEdgeColor', 'none', ...
        'MarkerFaceColor', 'r');
    h(3)=plot(-100, -100, 'o', 'MarkerSize', 6, 'LineWidth', 1, 'MarkerEdgeColor', 'b', ...
        'MarkerFaceColor', 'none');
    legend(h, labels, 'Location', 'northwest');  % call once after the loop
    
  25. Convert a cell array of datetime to an array of datetime
  26. datcol=[datcol{:}];
    datcol=datcol';
    
  27. Multipal Plots
  28. Nh=4;
    Nw=17;
    gap=[0.00, 0.01];
    marg_h=[0.20];
    marg_w=0.05;
    figure;
    ha = tight_subplot(Nh, Nw, gap, marg_h, marg_w);
    set(gcf,'outerposition',get(0,'screensize'));
    
    
  29. annotation
  30. annotation('textbox', [0.1 0.936 0.8 0.06], ...
        'String', {'Number of Hours with PM2.5 Concentrations Exceeding 15 µg/m³ at Each Monitoring Station'}, ...
        'HorizontalAlignment', 'center', ...
        'VerticalAlignment', 'middle', ...
        'FontSize', 20, ...
        'FontWeight', 'bold', ...
        'LineStyle', 'none');
    
  31. export_fig
  32. otpath=fullfile('2Num2025');
    export_fig(otpath, '-png', '-painters', '-r300');
    pause(3);
    close all;
    

Thursday, November 10, 2016

Tip: 关闭弹窗程序

Introduction

一个黑框的弹窗让我很烦恼,终于关掉了。
金山毒霸之弹窗定位器,定位弹窗程序的地址和名称。
Fig. 1
Fig. 2定位到弹窗程序的名称后,打开Task Manager,在Processes之下找到弹窗程序,结束它(可能是多个相同名称的程序,都一一结束),弹窗就消失了。
Fig. 2

Sunday, May 29, 2016

安全与不安全

Introduction

安全科学是人类生产、生活、生存过程中,避免和控制人为技术、自然因素或人为-自然因素所带来的危险、危害、意外事故和灾害的学问。她以技术风险作为研究对象,通过事故与灾害的避免、控制和减轻损害及损失,达到人类生产、生活和生存的安全。
Fig. 1
国家安全生产监督管理总局(国家煤矿安全监察局)主要职责节选:研究提出安全生产重大方针政策和重要措施的建议;综合监督管理全国安全生产工作;依法行使安全生产综合监督管理职权;负责综合监督管理危险化学品和烟花爆竹安全生产工作。
Fig. 2

References

[2] 国务院办公厅关于印发国家安全生产监督管理总局主要职责内设机构和人员编制规定的通知. 国办发[2005]11号.

Tuesday, March 29, 2016

Tips: Land Use Data

土地利用类型图是很多研究中必不可少或至关重要的基础数据。但是,研究时段往往与已有的土地利用类型图在时间上并不匹配,若要取得时间重叠的土地利用数据可能代价过大,这时是否可以将已有的土地利用类型图视为同期数据加以采用,部分文献的数据处理过程确有这样的应用,请参考下表列出的部分文献:

编号研究数据年代对应土地覆盖数据年份间隔引用

11989~19932000(1 km)≥7 a朱文泉, 潘耀忠, 张锦水. 中国陆地植被净初级生产力遥感估算. 植物生态学报, 2007, 31(3): 413~424.

21989~19932000(1 km)≥7 aZhu, Pan, He, et al.. Simulation of maximum light use efficiency for some typical vegetation types in China. Chinese Science Bulletin, 2006, 51(4): 457~463.

320001995(30 m)5 aHonnay, Piessens, Landuyt, et al.. Satellite based land use and landscape complexity indices as predictors for regional plant species diversity. Landscape and Urban Planning, 2003, 63: 241~250.

419901992~19932~3 aFrolking, Xiao, Zhuang, et al.. Agricultural land-use in China: a comparison of area estimates from ground-based census and satellite-borne remote sensing. Global Ecology and Biogeography, 1999, 8, 407~416.

51998~20132000(1 km)2~3 aLiu, Zhu, Zhu, et al.. Changes in Spring Phenology in the Three-Rivers Headwater Region from 1999 to 2013. Remote Sensing, 2014, 6: 9130~9142.

71982~20061992~1993(1 km)0~14 aZhu, Tian, Xu, et al.. Extension of the growing season due to delayed autumn over mid and high latitudes in North America during 1982–2006. Global Ecology and Biogeography, 2012, 21(2): 260-271.

81982~19991981~19940~10+ aDeyong Yu, Wenquan Zhu* and Yaozhong Pan. The Role of Atmospheric Circulation System playing in Coupling Relationship between Spring NPP and Precipitation in East Asia Area. Environmental Monitoring and Assessment, 2008, 145: 135-143.

Wednesday, March 23, 2016

Tips: 横向评价、纵向评价、全局评价

Introduction

A longitudinal survey(纵向调查) is a correlational research study that involves repeated observations of the same variables over long periods of time, often many decades. It is often a type of observational study, although they can also be structured as longitudinal randomized experiments. Longitudinal studies are often used in psychology, to study developmental trends across the life span, and in sociology, to study life events throughout lifetimes or generations. The reason for this is that unlike cross-sectional studies, in which different individuals with the same characteristics are compared, longitudinal studies track the same people and so the differences observed in those people are less likely to be the result of cultural differences across generations. Longitudinal studies thus make observing changes more accurate and are applied in various other fields.
这里讨论基于地理空间数据的横向评价、纵向评价以及全局评价。地理空间数据是指包含地理位置的二维栅格数据,典型如NDVI数据。二维栅格数据的评价工作往往以单个的栅格单元为评价单位,评价结果是得到多期数据的评估量化数值,区分它们的优劣等差异程度。
以1982~2013年中国某地七月的NDVI数据为例,辨析横向评价、纵向评价及全局评价的内涵与外延。NDVI数值表示健康植被的状况,所以它是效益型指标,该数值越大越有利于生态系统健康状态。Fig. 1显示某地2003年七月的NDVI,图上上下两个像元数值依次是0.6610、0.5950,以下的分析还将围绕着这一年的数据以及这两个像元为实例展开讨论。这里的评价方法选择灰靶决策,由于仅就单一指标进行评价和排序,所以评价过程不涉及多权重的计算。
Fig. 1

横向评价

如果我想对比Fig. 1上两个像元NDVI数值在整幅图像上的相对状况,那么就以这幅影像上的最优标准(靶心)评价这二者,计算他们的靶心度,我们就可以得知这两个像元在当年当地达到的水平,这就是典型的横向评价。
Fig. 2
Fig. 2显示2003年七月NDVI横向评价结果。Fig 1~2使用相同的色带渲染,渲染范围同样是0至1之间。这期NDVI数据最大值是0.9,它也就是横向评价的靶心值。很显然,NDVI-0.6610比0.5950更接近于靶心位置,所以上下两个像元的靶心系数表现为上大于下,同时这两个像元以及整幅影像的像元均可以进行比较,这是由于他们共用同一靶心值。但是,不同时间的各个像元(即使是同一位置)却不能进行对比,因为各自评价的靶心值不同。
Fig. 3
Fig. 3显示整幅影像的评价单元之间的对比情况,上下两个像元的相对位置如图中所示。

纵向评价

我们再设想一下,同一位置(像元)与自身以往的情况进行对比,并定位自身在以往过程中的位置,这就是纵向评价。对于二维空间数据而言,此时评价一幅影像的靶心值则以同样行列的矩阵形式呈现。任意位置(像元)的评价结果是它比照以往自身的最优状态(靶心)得到的靶心系数,也就是这一靶心系数表示当前状态与它自身最优状态的接近程度。可以想见,不同位置的靶心系数虽属同一时期,但之间的靶心系数不能直接对比,原因在于各自的靶心值不同。
本示例中各位置(像元)的评价靶心值是它们以往数值中的最大值。
Fig. 4
Fig. 4左右依次是2003年七月NDVI纵向评价的得分结果及其排序。左图黄色至深绿表示数值在0~1之间逐渐增大,上下两像元评价值分别是0.5612、0.6658,这二数值不能直接比较,也不能直接说明孰优孰虑(实际上,上像元NDVI大于下像元),他们仅表示下像元比上像元更接近于自身的最优状态(靶心)。右图是逐像元纵向评价的排序结果(降序),由绿色至蓝色表示排名逐步靠后,上像元在2003年7月的状态位列33a的第七位,同期的下像元状态也位列自身的第七位。
Fig. 5
从两像元33a纵向评价结果与排序来看,二者的状态变化可能比较同步,如1986年上下像元的状态依次位列自身的29、28位,也可能差距甚大,如2008年他们又分别各自位列1、29位。

全局评价

如果全部时间不同位置(像元)的最优状态一律设置为同一靶心值,则此时的评价结果将可在不同时间及任意位置(像元)之间进行比较,这种评价能够兼顾横向及纵向对比,这就是全局评价。
Fig. 6
全局评价1981~2013年某地NDVI指标评价的靶心值为1,2003年七月NDVI评价靶心系数如Fig. 4所示,图上两像元评价结果可以直接进行比较,上一像元比之下方像元更加接近靶心,状态优于后者。
两像元多年序列的评价结果可以一同进行对比分析,即为不同时间与不同位置的横向及纵向对比。Fig. 7显示两像元在33a之间的评价结果,多数年份上像元状态优于下像元,但个别年份则不然,如1982、1983、1987、2007、2011、2012年。
Fig. 7

References

Monday, March 21, 2016

Tips: 中文字号对照表


中文字号英文字号(磅)毫米像素

一英寸72pt25.30mm95.6px

大特号63pt22.14mm83.7px

特号54pt18.97mm71.7px

小初36pt12.70mm48px

一号26pt9.17mm34.7px

小一24pt8.47mm32px

二号22pt7.76mm29.3px

小二18pt6.35mm24

三号16pt5.64mm21.3px

小三15pt5.29mm20px

四号14pt4.94mm18.7px

小四12pt4.23mm16px

五号10.5pt3.70mm14px

小五9pt3.18mm12px

六号7.5pt2.56mm10px

小六6.5pt2.29mm8.7px

七号5.5pt1.94mm7.3px

八号5pt1.76mm6.7px

Reference

[1] 字号尺寸大小对照表.

Sunday, February 28, 2016

Tips: Defining Contiguity

In spatial autocorrelation analysis some measure of contiguity is required. Contiguity has a rather broad definition depending on the research question, however, most analyses in spatial autocorrelation adhere to a common definition of neighborhood relations. Namely, neighborhood relations are defined as either rooks case, bishops case or queens (kings) case. These are rather simple and intuitive as their names suggest (Fig. 1). Rooks case contiguity is by a neighborhood of 4 locations adjacent to each cell, Bishops only considers the diagonals of the relation and queens or kings case considers a neighborhood of eight cells. These are the most common forms of contiguity used in spatial autocorrelation when considering continuous data in a raster format. Of these three the rooks case is the most commonly used and most programs only will compute this particular case.
However, this type of contiguity is not sufficient for vector data formats or irregularly spaced points. In these cases distances to the four or even n nearest neighbors can be used or distance between a variate X and all neighbors can be used.
Fig. 1

References

Friday, February 26, 2016

Tips:OA期刊的风险

自阅读凤凰周刊的文章《OA期刊“中国版面费”争议》之后,我深深的认同部分OA(Open Access)期刊存在着圈钱的可能性。
有鉴于此,国外已经有人关注部分OA期刊的正当性,他是University of Colorado Denver的Jeffrey Beall副教授,他有着20年以上的图书馆学术馆员工作经验,他个人列出了涉嫌圈钱的OA期刊目录可供相关人士参考。
LIST OF PUBLISHERS 涉嫌出版者