def get_FFMpeg_Paths():
    
    '''###################
        file path        
    ###################'''
    PROJECT_ROOT = cons_27_6_1.FPath.PROJECT_ROOT.value
#     PROJECT_ROOT = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_17"
    
    dname_Folder_Data = "data.27_6_1"
    dname_Images = "images"
    dname_Images_PNG = "images_20180220_140814"
    session_Label = "6_1.test-1"
    tlabel = libs.get_TimeLabel_Now()
    
    dpath_Out = "%s\\%s" % (PROJECT_ROOT, dname_Folder_Data)
    fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)
    dpath_Full = "%s\\%s\\%s" % (dpath_Out, dname_Images, dname_Images_PNG)
    fpath_Glob = "%s\\*(*).png" % (dpath_Full)
#     dpath_In = "%s" + "\\%s" + "\\%s" \
#             + "%s" \
    dpath_In = "%s\\%s\\%s" \
            % (PROJECT_ROOT, dname_Folder_Data, dname_Images)
            
    dpath_In = "%s\\%s" % (dpath_In, dname_Images_PNG)
#     dpath_In = "%s\\%s\\%s" \
#             + "%s" \
#             % (PROJECT_ROOT, dname_Folder_Data, dname_Images, dname_Images_PNG)
#             + "\\images\\images_20180220_141141"
    fpath_In_FFMpeg = "%s\\image.%%03d.png" % (dpath_In)
#     fpath_In = "%s\\image.%03d.png" % (dpath_In)
    
    fpath_Out_FFMpeg = "%s\\movie.%s.mp4" % (dpath_In, libs.get_TimeLabel_Now())
    
#     dpath_Out = "%s\\data.27_6_1" % (PROJECT_ROOT)
    
    ### fpath full
    
    

#     dname_Images_PNG = "images_20180220_140223"
#     dname_Images_PNG = "images_20180220_141101"
    
#     dpath_Full = "%s\\images_20180220_141141" % (dpath_Out)
#     dpath_Full = "%s\\%s\\images_20180220_141141" % (dpath_Out, dname_Images)
    
    
#     dpath_In = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research" \
#             + "\\28_Physics\\1_\\_17\\data_1_17.1" \
            

    '''###################
        return        
    ###################'''
    return dpath_Full, fpath_Glob, fpath_In_FFMpeg, fpath_Out_FFMpeg
def test_2():
    
    #from : C:\WORKS_2\WS\WS_Others\JVEMV6\34\libs\labs.py
    a = 1
    
    s1 = [np.sin(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
    s2 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]

    '''###################
        file path        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
    
    '''###################
        plot
    ###################'''    
    plt.plot(s1, s2)
    
    plt.savefig(fpath_Full)

    print()
    print("[%s:%d] file saved => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , fpath_Full
            ), file=sys.stderr)
def test_6():

    '''###################
        params
    ###################'''
#     x = -1; y = 1
    x = 1; y = 1
    
    x_, y_ = _test_6__Params(x, y)
#     x_, y_ = _test_6__Params()
 
    z = list(zip(x_, y_))
 
    dpath_Images = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\27_math" \
                + "\\27_6_plot\\_1\\data.27_6_1\\images"
 
    file_Label = "6_1.test_6"
     
    lbl_Plot_Title = "Rotate (x = %s / y = %s)" % (x, y)
 
    '''###################
        gen : png files        
    ###################'''
    _clearFigure = False
    
    xlim_Start = -5; xlim_End = 5
    ylim_Start = -5; ylim_End = 5
    
    dpath_Images_Out, tlabel = \
                libs_VX7GLZ.gen_PNGFiles_from_Listof_Points__V2 \
                (z, dpath_Images, file_Label, lbl_Plot_Title
                 , xlim_Start, xlim_End
                 , ylim_Start, ylim_End
                 , clearFigure = _clearFigure)
#                 (z, dpath_Images, file_Label, lbl_Plot_Title, clearFigure = _clearFigure)
#                 libs_VX7GLZ.gen_PNGFiles_from_Listof_Points \
#                 (z, dpath_Images, file_Label, lbl_Plot_Title)
#                 _test_5_Generate_PNGFiles \

    '''###################
        gen : video        
    ###################'''
#     dpath_Images_Out = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1\\data.27_6_1\\images\\images_20180221_152007"
    
    fpath_Glob = "%s\\*(*).png" % (dpath_Images_Out)
#     fpath_Glob = "%s\\*.(*).png" % (dpath_Images_Out)
#     fpath_Glob = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1\\data.27_6_1\\images\\images_20180221_152007\\*.(*).png"
#     fpath_Glob = dpath_Images_Out

    fpath_In_FFMpeg = "%s\\image.%%03d.png" % (dpath_Images_Out)
#     fpath_In_FFMpeg = "%s\\image.%%03d.png" % (fpath_Glob)
    
    tlabel2 = libs.get_TimeLabel_Now()
    
    fpath_Out_FFMpeg = "%s\\movie.%s.%s.mp4" % (dpath_Images_Out, tlabel, tlabel2)
#     fpath_Out_FFMpeg = "%s\\movie.%s.mp4" % (fpath_Glob, tlabel)
    
    libs_VX7GLZ.build_Video_From_PNGFiles__V2 \
        (fpath_Glob, fpath_In_FFMpeg, fpath_Out_FFMpeg)
def test_6():
    
    '''###################
        vars        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17" \
                + "\\images"

    '''###################
        file path        
    ###################'''
#         dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    session_Label  = "1-17-2.test-5"
    
    fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)

    x = np.arange(0.0, 2, 0.01)
    y1 = np.sin(2*np.pi*x)
    y2 = 1.2*np.sin(4*np.pi*x)
    y3 = 1.2*np.sin(8*np.pi*x)
    
    fig, to_Axes = plt.subplots(5, 1, sharex=True)
#     fig, (ax1, ax2, ax3, ax4, ax5) = plt.subplots(5, 1, sharex=True)
#     fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True)
#     fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True)
    
    do_Params = {
        
            0 : (0, y1, "0 / y1"),
            1 : (0, y2, "0 / y2"),
            2 : (0, y3, "0 / y3"),
            3 : (y1, y2, "y1 / y2"),
            4 : (y1, y3, "y1 / y3"),
        
        }
    
    cnt = 0
    
    for ax in to_Axes:

        print(ax)
        print('')

        ax.fill_between(x, do_Params[cnt][0], do_Params[cnt][1])
        ax.set_ylabel("%d / %s" % (cnt, do_Params[cnt][2]))
        
        ###  increment
        cnt += 1
        
    #/for ax in to_Axes:

    
#     print(to_Axes)
    
    plt.show()
def test_1():
    '''###################
        vars        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_15"

    #ref https://stackoverflow.com/questions/9622163/save-plot-to-image-file-instead-of-displaying-it-using-matplotlib answered Apr 28 '15 at 22:35
    fig, ax = plt.subplots(nrows=1, ncols=1)

    x = np.arange(-100, 100, 0.1)
    #     x = np.arange(0, 100, 0.1)

    a = np.arange(-2, 2, 0.5)

    #     b = 2; d = 2
    #     a = 2; b = 2; d = 2
    a = -2.0
    b = 2
    d = 2
    #     a = 2.0; b = 2; d = 2

    y = [i**3 + a * i**2 + b * i + d for i in x]
    #
    ax.plot(x, y)
    #
    ax.show()

    #     ### fpath full
    fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out,
                                            libs.get_TimeLabel_Now(), a)
    #     fpath_Full = "%s\\tmp.%s.png" % (dpath_Out, libs.get_TimeLabel_Now())
    #
    #     fig.savefig(fpath_Full)

    #     time_Label = libs.get_TimeLabel_Now()

    #     for num in a:
    #
    #         y = [i**3 + a * i**2 + b * i + d for i in x]
    #
    #         ax.plot(x,y)
    #
    #         ### fpath full
    #         fpath_Full = "%s\\tmp.%s.a=%s.png" % (dpath_Out, time_Label, str(num))
    #
    #         fig.savefig(fpath_Full)

    # #     fig.savefig('tmp.20180217_134221.png')
    #
    #         ### reset fig
    #         fig, ax = plt.subplots( nrows=1, ncols=1 )

    print()
    print("[%s:%d] file saved => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , fpath_Full
            ), file=sys.stderr)

    plt.close(fig)
def test_4():
    '''###################
        build : paths        
    ###################'''
    '''###################
        file path        
    ###################'''
    PROJECT_ROOT = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_17"

    dpath_Out = "%s\\data_1_17.1" % (PROJECT_ROOT)

    ### fpath full
    tlabel = libs.get_TimeLabel_Now()

    session_Label = "1_17.1.test-3"

    fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)

    dname_Images = "images"

    dname_Images_PNG = "images_20180220_140223"
    #     dname_Images_PNG = "images_20180220_141101"

    #     dpath_Full = "%s\\images_20180220_141141" % (dpath_Out)
    dpath_Full = "%s\\%s\\%s" % (dpath_Out, dname_Images, dname_Images_PNG)
    #     dpath_Full = "%s\\%s\\images_20180220_141141" % (dpath_Out, dname_Images)

    fpath_Glob = "%s\\*(*).png" % (dpath_Full)

    dpath_In = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research" \
            + "\\28_Physics\\1_\\_17\\data_1_17.1" \
            + "\\images\\%s" % (dname_Images_PNG)
    #             + "\\images\\images_20180220_141141"

    fpath_In_FFMpeg = "%s\\image.%%03d.png" % (dpath_In)
    #     fpath_In = "%s\\image.%03d.png" % (dpath_In)

    fpath_Out_FFMpeg = "%s\\movie.%s.mp4" % (dpath_In,
                                             libs.get_TimeLabel_Now())
    '''###################
        build : video        
    ###################'''
    libs_VX7GLZ.build_Video_From_PNGFiles \
        (dpath_Full, fpath_Glob, fpath_In_FFMpeg, fpath_Out_FFMpeg)
def test_4():
    
    '''###################
        vars        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17" \
                + "\\images"

    '''###################
        file path        
    ###################'''
#         dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    session_Label  = "1-17-2"
    
    fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)
    
    '''###################
        ops        
    ###################'''
    #ref https://stackoverflow.com/questions/30209187/matplotlib-chart-area-vs-plot-area answered May 13 '15 at 23:00
    x1 = np.random.randint(-5, 5, 50)
    x2 = np.random.randn(20)
    
    fig = plt.figure(figsize=(8,6))  # sets the window to 8 x 6 inches
    
    # left, bottom, width, height (range 0 to 1)
    # so think of width and height as a percentage of your window size
    big_ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) 
    small_ax = fig.add_axes([0.52, 0.15, 0.3, 0.3]) # left, bottom, width, height (range 0 to 1)
    
    big_ax.fill_between(np.arange(len(x1)), x1, color='blue', alpha=0.3)
#     big_ax.fill_between(np.arange(len(x1)), x1, color='green', alpha=0.3)
    small_ax.stem(x2)
    
    plt.setp(small_ax.get_yticklabels(), visible=False)
    plt.setp(small_ax.get_xticklabels(), visible=False)
#     plt.show()
    
    fig.savefig(fpath_Full)
#     plt.savefig(fpath_Full)
    plt.close(fig)
    
    print()
    print("[%s:%d] file saved : %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fpath_Full
        ), file=sys.stderr)
def test_5_3():

    '''###################
        params
    ###################'''
    x_, y_ = _test_5__Params()
 
    z = list(zip(x_, y_))
 
    dpath_Images = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\27_math" \
                + "\\27_6_plot\\_1\\data.27_6_1\\images"
 
    file_Label = "6_1.test-5-3"
     
    lbl_Plot_Title = "Rotate matrix"
 
    '''###################
        gen : png files        
    ###################'''
    dpath_Images_Out, tlabel = \
                libs_VX7GLZ.gen_PNGFiles_from_Listof_Points \
                (z, dpath_Images, file_Label, lbl_Plot_Title)
#                 _test_5_Generate_PNGFiles \

    '''###################
        gen : video        
    ###################'''
#     dpath_Images_Out = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1\\data.27_6_1\\images\\images_20180221_152007"
    
    fpath_Glob = "%s\\*(*).png" % (dpath_Images_Out)
#     fpath_Glob = "%s\\*.(*).png" % (dpath_Images_Out)
#     fpath_Glob = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1\\data.27_6_1\\images\\images_20180221_152007\\*.(*).png"
#     fpath_Glob = dpath_Images_Out

    fpath_In_FFMpeg = "%s\\image.%%03d.png" % (dpath_Images_Out)
#     fpath_In_FFMpeg = "%s\\image.%%03d.png" % (fpath_Glob)
    
    tlabel2 = libs.get_TimeLabel_Now()
    
    fpath_Out_FFMpeg = "%s\\movie.%s.%s.mp4" % (dpath_Images_Out, tlabel, tlabel2)
#     fpath_Out_FFMpeg = "%s\\movie.%s.mp4" % (fpath_Glob, tlabel)
    
    libs_VX7GLZ.build_Video_From_PNGFiles__V2 \
        (fpath_Glob, fpath_In_FFMpeg, fpath_Out_FFMpeg)
def test_1():
    '''###################
        file path        
    ###################'''
    PROJECT_ROOT = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_17"

    dpath_Out = "%s\\data_1_17.1" % (PROJECT_ROOT)

    ### fpath full
    tlabel = libs.get_TimeLabel_Now()

    session_Label = "1_17.1"

    fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)
    '''###################
        ops        
    ###################'''

    x = np.linspace(0, np.pi * 2, 100)
    #     x = np.linspace(0, np.pi, 1000)

    y = np.sin(x)

    # graph : settings
    plt.ylim(-2, 2)
    plt.xlim(0, np.pi * 2)
    plt.grid(b=None, which='major', axis='both')
    plt.xticks(np.arange(0, np.pi * 2, np.pi / 4))
    plt.yticks(np.arange(-2, 2, 0.5))
    #     plt.yticks([-2,-1,1,2])
    #     plt.xticks([-2,-1,1,2])

    plt.xlabel("x")
    plt.ylabel("sin(x)")
    plt.title("x ~ sin(x)\n%s" % (os.path.basename(fpath_Full)))

    # plot
    plt.plot(x, y)

    plt.savefig(fpath_Full)
    plt.show()
Beispiel #10
0
def test_2():
    '''###################
        file path        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    fpath_Full = "%s\\tmp.%s.png" % (dpath_Out, libs.get_TimeLabel_Now())
    '''###################
        ops        
    ###################'''
    #     print(cv2.__version__)

    fname_In = "image.1-17-2.20180219_093551.png"

    img = cv2.imread(fname_In)

    print()
    print("[%s:%d] img => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , img
        ), file=sys.stderr)
Beispiel #11
0
def test_3():
    '''###################
        file path        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()

    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17\\" \
                + "images\\images_%s" % tlabel

    #     ### make dir
    #     os.makedirs(dpath_Out)

    #     ### fpath full
    #     fpath_Full = "%s\\tmp.%s.png" % (dpath_Out, )
    '''###################
        ops        
    ###################'''
    x = [1]
    y = [0]

    #     fig = plt.figure()
    #     ax = fig.gca()
    #     ax.set_xticks(np.arange(-1, 1, 0.1))
    #     ax.set_yticks(np.arange(-1, 1, 0.1))

    plt.grid(b=None, which='major', axis='both')

    #ref https://stackoverflow.com/questions/19390895/matplotlib-plot-with-variable-line-width answered Nov 29 '14 at 17:42
    plt.scatter(x, y, s=20)
    #     plt.plot(x, y, linewidth = 10)
    #     plt.scatter(x, y, s = 1)
    #     plt.plot(x, y, linewidth = 1)
    #     plt.plot(x, y)

    #     plt.set_xticks(np.arange(-1, 1, 0.1))
    #     plt.set_yticks(np.arange(-1, 1, 0.1))

    plt.show()
def test_7():
    
    '''###################
        vars        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17" \
                + "\\images\\images_%s" % (tlabel)

    ### make dir
    #ref https://www.tutorialspoint.com/python/os_mkdir.htm
    os.makedirs(dpath_Out)

    '''###################
        file path        
    ###################'''
#         dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    session_Label  = "1-17-2.test-7"
    
#     fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)

    tick = 0.01
#     tick = np.pi / 6
    
    rng_X_End = np.pi * (1/2)
    
    x = np.arange(0.0, rng_X_End, tick)
#     x = np.arange(0.0, 2 * np.pi, tick)
#     x = np.arange(0.0, 2, 0.01)
    y1 = np.sin(2*np.pi*x)
    y2 = 1.2*np.sin(4*np.pi*x)
    y3 = 1.2*np.sin(8*np.pi*x)
    
    cnt = 0
    
    tick = np.pi / 12
#     tick = np.pi / 36

    rng_Index_End = np.pi * 4
    
    for index in np.arange(0, rng_Index_End, tick):
#     for index in np.arange(0, np.pi, tick):
#     for index in np.arange(0, np.pi, tick):

        fig, (ax) = plt.subplots(1, 1, sharex=True)
        
        y = 1.2 * np.sin(4 * np.pi * x + index)

        ax.fill_between(x, y1, y)
        
        ax.set_ylabel("sin(2pi*x) / 1.2*sin(4pi*x)")
        
        
        
        '''###################
            save image        
        ###################'''
        fpath_Full = "%s\\image.%s.%s.(%02d).index-%.03f.png" \
                    % (dpath_Out, session_Label, tlabel, cnt, index)
        
        plt.title("1.2 * sin(4pi * x + %.03f" % (index))
            
        plt.savefig(fpath_Full)
        
        plt.close(fig)
        
#         print()
#         print("[%s:%d] fig saved, closed => %s" % \
#         (os.path.basename(libs.thisfile()), libs.linenum()
#         , fpath_Full
#         ), file=sys.stderr)
        
        ###  increment
        cnt += 1
def test_3():
    '''###################
        file path        
    ###################'''
    PROJECT_ROOT = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_17"

    dpath_Out = "%s\\data_1_17.1" % (PROJECT_ROOT)

    ### fpath full
    tlabel = libs.get_TimeLabel_Now()

    session_Label = "1_17.1.test-3"

    #     fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)
    '''###################
        test : video        
    ###################'''
    '''###################
        get : file list        
    ###################'''
    dname_Images = "images"

    #     dpath_Full = "%s\\images_20180220_141141" % (dpath_Out)
    dpath_Full = "%s\\%s\\images_20180220_141141" % (dpath_Out, dname_Images)

    ### validate
    if not os.path.isdir(dpath_Full):  #if os.path.isdir(dpath_Full)

        print()
        print("[%s:%d] dir NOT exist => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , dpath_Full
        ), file=sys.stderr)

        return

    #/if os.path.isdir(dpath_Full)
    aa

    fpath_Glob = "%s\\*(*).png" % (dpath_Full)
    #     fpath_Glob = "%s\\*.png" % (dpath_Full)

    #ref glob https://stackoverflow.com/questions/14798220/how-can-i-search-sub-folders-using-glob-glob-module-in-python answered Feb 10 '13 at 13:31
    lo_Files = glob.glob(fpath_Glob)

    ### validate
    if len(lo_Files) < 1:  #if len(lo_Files) <+ 1

        print()
        print("[%s:%d] len(lo_Files) => less than 1" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(lo_Files), fpath_Glob
            ), file=sys.stderr)

        return

    else:

        print()
        print("[%s:%d] len(lo_Files) => %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(lo_Files)
            ), file=sys.stderr)
    #/if len(lo_Files) < 1
    '''###################
        sort : list        
    ###################'''
    #ref https://www.programiz.com/python-programming/methods/list/sort
    lo_Files.sort()

    #     for item in lo_Files:
    #
    #         print("[%s:%d] item => %s" % \
    #             (os.path.basename(libs.thisfile()), libs.linenum()
    #             , item
    #             ), file=sys.stderr)
    #
    #         print()

    #/for item in lo_Files:
    '''###################
        copy        
    ###################'''
    cnt = 0

    lo_CopiedFiles = []

    for item in lo_Files:

        dpath = os.path.dirname(item)

        fpath_Dst = "%s\\image.%03d.png" % (dpath, cnt)

        copyfile(item, fpath_Dst)

        # append new file path
        lo_CopiedFiles.append(fpath_Dst)

        print()
        print("[%s:%d] file copied : %s => %s" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , item, fpath_Dst
                ), file=sys.stderr)

        # increment
        cnt += 1

    #/for item in lo_Files:
    '''###################
        video : generate        
    ###################'''
    dpath_In = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research" \
            + "\\28_Physics\\1_\\_17\\data_1_17.1" \
            + "\\images\\images_20180220_141141"

    fpath_In = "%s\\image.%%03d.png" % (dpath_In)
    #     fpath_In = "%s\\image.%03d.png" % (dpath_In)

    fpath_Out = "%s\\movie.%s.mp4" % (dpath_In, libs.get_TimeLabel_Now())


    cmd = "ffmpeg -f image2 -r 2 -i " \
            + "%s -vcodec mpeg4 -y %s" % (fpath_In, fpath_Out)
    #     cmd = "ffmpeg -f image2 -r 2 -i image.%03d.png -vcodec mpeg4 -y movie.mp4"

    # execute
    os.system(cmd)

    print()
    print("[%s:%d] executing command => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , cmd
        ), file=sys.stderr)
    '''###################
        delete : copied files        
    ###################'''
    while (not os.path.isfile(fpath_Out)):

        pass

    #/while (not os.path.isfile(fpath_Out)) :

    print()
    print("[%s:%d] copied files ==> deleting..." % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)

    # remove files
    for item in lo_CopiedFiles:

        if os.path.isfile(item):  #if os.path.isfile(item)

            res = os.remove(item)

            print()
            print("[%s:%d] remove file : result => %s (%s)" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                    , res, item
                    ), file=sys.stderr)

        #/if os.path.isfile(item)

    print()
    print("[%s:%d] copied files ==> deleted" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stderr)
def test_3():
    
    '''###################
        vars        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    '''###################
        dir        
    ###################'''
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17" \
                + "\\images\\\images_%s" % (tlabel)
    
    ### make dir
    #ref https://www.tutorialspoint.com/python/os_mkdir.htm
    os.makedirs(dpath_Out)
    
    print()
    print("[%s:%d] dpath_Out => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , dpath_Out
        ), file=sys.stderr)
    
    #from : C:\WORKS_2\WS\WS_Others\JVEMV6\34\libs\labs.py
    
#     for a in np.arange(1,2):
#     for a in np.arange(1,10, 0.5):
#     for a in np.arange(1,2, 0.1):
#     for a in np.arange(1, 5, 0.1):
    
    maxnum = 30
    
#     tick = np.pi / 60
    tick = np.pi / 30

    ### counter
    cnt = 1
    
    for a in np.arange(0, np.pi * 4, tick):
#     for a in np.arange(0, np.pi * 2, tick):
#     for a in np.arange(0, maxnum, tick):
#     for a in np.arange(0, 10, 0.1):

#         a = 1
        
#         s1 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        s1 = [np.sin(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s1 = [np.sin(x * a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        s2 = [np.cos(x * a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s2 = [np.cos(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s2 = [np.cos(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        
#         s3 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s4 = [np.cos(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
        
#         s2 = [np.sin(x) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
#         s2 = [np.sin(x + a) for x in np.arange(-np.pi, np.pi, np.pi / 360)]
    
        '''###################
            file path        
        ###################'''
#         dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
        ### fpath full
        fpath_Full = "%s\\tmp.%s.(%02d).a=%.3f.png" % (dpath_Out, tlabel, cnt, a)
#         fpath_Full = "%s\\tmp.%s.a=%.3f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
#         fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
#         fpath_Full = "%s\\tmp.%s.a=%.1f.png" % (dpath_Out, libs.get_TimeLabel_Now(), a)
        
        ### increment
        cnt += 1
        
        '''###################
            gca        
        ###################'''
        fig = plt.figure()
        ax = fig.gca()
        ax.set_xticks(np.arange(-1, 1, 0.1))
        ax.set_yticks(np.arange(-1, 1, 0.1))

        
        
        '''###################
            plot
        ###################'''    
        plt.plot(s1, s2)
#         plt.plot(s3, s4)
        
        ### ratio
        #ref https://matplotlib.org/examples/pylab_examples/equal_aspect_ratio.html
        #ref https://stackoverflow.com/questions/7965743/how-can-i-set-the-aspect-ratio-in-matplotlib
#         plt.axes().set_aspect('equal', 'datalim')
        plt.axes().set_aspect('equal')
#         plt.axes().set_aspect(2)
#         plt.set_aspect(2)
        
        #ref https://stackoverflow.com/questions/8209568/how-do-i-draw-a-grid-onto-a-plot-in-python answered Nov 21 '11 at 11:00
        
#         fig = plt.figure()
#         ax = fig.gca()
#         ax.set_xticks(np.arange(-1, 1, 0.1))
#         ax.set_yticks(np.arange(-1, 1, 0.1))
        
        plt.grid(b=None, which='major', axis='both')
        
        plt.xlabel("sin(x)")
#         plt.xlabel("sin(x + %.3f)" % a)
        plt.ylabel("cos(x * %.3f)" % a)
#         plt.ylabel("cos(x + %.3f)" % a)
#         plt.ylabel("cos(x)")
        
        plt.title("a = %.3f" % a)
        
#         plt.show()
        plt.savefig(fpath_Full)
        
        
        ### close
        plt.close(fig)
def test_5():

    '''###################
        params
    ###################'''
    x_, y_ = _test_5__Params()

    z = list(zip(x_, y_))

    '''###################
        graph : settings        
    ###################'''

    
    # xlim
    plt.xlim(-2,2)
    plt.ylim(-2,2)
    plt.grid(b=None, which='major', axis='both')
    
#     plt.scatter([z[0][0]], [z[0][1]], s = 60)
# #     plt.scatter([z[0][0]], [z[0][1]], linewidth = 30)
#      
#     plt.show()
# 
#     print()
# #     print("[%s:%d] x_[0] => %s" % \
#     print("[%s:%d] x_ => %s" % \
#         (os.path.basename(libs.thisfile()), libs.linenum()
#         , x_
#         ), file=sys.stderr)
# #     print()
# #     print("[%s:%d] z[0] => %s" % \
# #         (os.path.basename(libs.thisfile()), libs.linenum()
# #         , z[0]
# #         ), file=sys.stderr)
# #     print()
# #     print("[%s:%d] r_[0] => %s" % \
# #         (os.path.basename(libs.thisfile()), libs.linenum()
# #         , r_[0]
# #         ), file=sys.stderr)

    '''###################
        plot        
    ###################'''
#     plt.scatter([r_[0][0]], [r_[0][1]], linewidth = 30)
# #     plt.plot([r_[0][0]], [r_[0][1]], linewidth = 30)
# #     plt.plot(r_[0][0], r_[0][1], linewidth = 20)
#     
#     plt.show()
    
#     #debug
#     return

    
#     print()
#     print("[%s:%d] r_ returned => %d" % \
#             (os.path.basename(libs.thisfile()), libs.linenum()
#             , len(r_)
#             ), file=sys.stderr)
#     
#     #debug
#     return

#     step_Theta = np.pi / 6
#     
#     rng_Theta = np.arange(0, np.pi * 2 + step_Theta, step_Theta)
#     
# #     x = np.sin(rng_Theta)
# #     y = np.cos(rng_Theta)
#     
#     r = Matrix([
#             [1],
#             [0]
#         
#         ])
#     
#     rot = Matrix([
#                 [np.cos(rng_Theta), - np.sin(rng_Theta)], 
#                  [np.sin(rng_Theta), np.cos(rng_Theta)]]
#         )
#     
#     prod = rot * r
#     
#     print()
#     print("[%s:%d] len(rot) => %d" % \
#         (os.path.basename(libs.thisfile()), libs.linenum()
#         , len(rot)
#         ), file=sys.stderr)
#     print("[%s:%d] len(prod) => %d" % \
#         (os.path.basename(libs.thisfile()), libs.linenum()
#         , len(prod)
#         ), file=sys.stderr)
#     
#     #debug
#     return
    
    #
    cnt = 1
    
    tlabel = libs.get_TimeLabel_Now()
    
    # dir
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1"
def test_1():

    '''###################
        get : args
    ###################'''
    
    '''###################
        file path
    ###################'''
    #_20190917_090405:tmp
    #C:\WORKS_2\WS\WS_Others.Art\JVEMV6\46_art\11_guitar
    dpath_Text = "C:\\WORKS_2\\WS\\WS_Others.Art\\JVEMV6\\46_art\\11_guitar"
    
    fname_Text = "memo_guitar.txt"
    
    #_20190917_094525:tmp
    fname_Text_Replaced = "memo_guitar.(replaced).(%s).txt" % libs.get_TimeLabel_Now()
    
    fpath_Text = os.path.join(dpath_Text, fname_Text)
    
    # validate
    if not os.path.isfile(fpath_Text) : #if not os.path.isfile(fpath_CSV)
        
        print()
        print("[%s:%d] text file NOT exist : %s" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()
                         , fpath_Text
                        ), file=sys.stderr)
        
        return
    
    #/if not os.path.isfile(fpath_CSV)

    '''###################
        file : open
    ###################'''
    f_in_Text = open(fpath_Text, "r")
    
    '''###################
        read file content
    ###################'''
    data = f_in_Text.read()
    
    print("[%s:%d] len(data) = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(data)
            ), file=sys.stderr)
    
    '''###################
        file : close
    ###################'''
    f_in_Text.close()

    '''###################
        step : A : 1
            replace
    ###################'''
    #_20190917_090843:tmp
    #ref https://www.tutorialspoint.com/python/python_reg_expressions.htm
    # \|\|     \r\n
    #ref https://uxmilk.jp/8662
    txt_Replaced = re.sub(r"\|\| ", "\r", data)
#     txt_Replaced = re.sub(r"\|\| ", "\r\n", data)

    print("[%s:%d] txt_Replaced => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , txt_Replaced
            ), file=sys.stderr)

    #ref https://stackoverflow.com/questions/5984633/python-re-sub-group-number-after-number
    lo_Replaces = [
#                    ["(s\.\d+):", "$1\t"]
                   ["(s\.\d+):", "\g<1>\t"]
                   , ["\.N", "\t"]
                   #, ["\.n", "\t"]	# 20191009_102653 ==> working
                   #, ["^(.+-\d\).n", "\g<1>\tn"]	# 20191023_091457 ==> error 'unterminated subpattern at position 1'
                   #, ["^(.+-\d\).n", "\g<1>\t.n"]	# 20191024_111819 testing ==> error 'unterminated subpattern at position 1'
                   #, ["^(.+-\d\).n", "\g<1>\t n"]	# 20191024_111934 testing ==> error 'unterminated subpattern at position 1'
                   #, ["^(.+-\d\).n", "\g<1>\t nnn"] # 20191024_112117 testing ==> error 'unterminated subpattern at position 1'
                   #, ["^(.+-\d\).n", "\g<1>\t new"] # 20191024_112117 testing ==> error 'unterminated subpattern at position 1'
                   #, ["^(.+-\d\).n", "\g<1>\tnew"] # 20191024_112231 testing ==> error 'unterminated subpattern at position 1'
                   #, ["^(.+-\d).n", "\g<1>\t n"] # 20191024_112231 testing ==> working --> '(.+-\d\)' ~~> the second '\' omitted
                   #, ["^(.+-\d).n", "\g<1>\tn"] # 20191024_112512 ==> working, but '.n' stays
                   #, ["^(.+-\d)\.n", "\g<1>\tn"] # 20191024_112601 ==> working, but '.n' stays
                   #, ["(.+-\d)\.n", "\g<1>\tn"] # 20191024_112907 ==> omit '^' ---> NO
                   #, ["(et|f|st|ct)-(\d+)\.n", "\g<1>-\g<2>\tn"] # 20191024_112907 ==> working, '.n' converted to "\tn"
                   #, ["(et|f|st|ct|m|ch|cp)-(\d+)\.n", "\g<1>-\g<2>\tn"] # 20191024_112907 ==> working, '.n' converted to "\tn" # 20191129_085145
                   , ["(et|f|st|ct|m|ch|cp|p|prev)-(\d+)\.n", "\g<1>-\g<2>\tn"] # ==> working, '.n' converted to "\tn" # 20200106_111814
                   
                   #, ["(et|f|st|ct)-(\d+),([a-zA-Z])", "\g<1>-\g<2>\t\g<3>"] # 20191024_112907 ==> working, converted
                   #, ["(et|f|st|ct)-(\d+),([a-zA-Z]+),", "\g<1>-\g<2>\t\g<3>\t"] # 20191107_090118 ==> working
                   , ["(et|f|st|ct)-(\d+),([a-zA-Z]{2,}),", "\g<1>-\g<2>\t\g<3>\t"] # 20191107_090411
                   
                   , ["(prev),(s-)", "\g<1>\tprev\t\g<2>"] # 20200106_111924
                   
                   #, ["(\d),rev", "\g<1>\trev"]
                   , ["(\d),rev", "\g<1>\trev\t"] # 20191107_084308
                   , ["(\d),r,", "\g<1>\trev\t"]	# 20191107_084217
                   
                   , ["(\d);v", "\g<1>\tv"]
                   , ["(\d),var", "\g<1>\tvar"]	# 20191006_075953
                   , ["(-\d+),section", "\g<1>\tsection"]	# 20191006_075953
                   , ["(-\d+),practice", "\g<1>\tpractice"]	# 20191006_075953
                   , ["(-\d+),play", "\g<1>\tplay"]	# 20191008_100412
                   , ["(-\d+),patt", "\g<1>\tpatt"]	# 20191021_112614
                   , ["(\d),rec", "\g<1>\trec"]
                   , ["(-\d+),memo", "\g<1>\tmemo\t"]	# 20191126_110214
                   
                   , ["s\.(\d+?)",    "\g<1>"]
                   , ["^(\d+?\t.+-\d+),",    "\g<1>\t"]
                   , ["(\d);var",    "\g<1>\tvar"]
                   , [",R=",    "\tR="]
                   
                   , ["other,",    "other\tother\t"]	# 20191107_090715
                   
                   , ["warm-up,",    "warm-up\wu\t"]	# 20191107_090715
                   , ["wu,",    "warm-up\twu\t"]	# 20191107_090715
                   , ["fs-(\d+),",    "fs-\g<1>\tfs\t"]	# 20191210_095020
                   
                   ]
    
    for item in lo_Replaces:

        print("[%s:%d] item[0] = '%s', item[1] = '%s'" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , item[0], item[1]
                ), file=sys.stderr)

        #debug
        print("[%s:%d] txt_Replaced (before) = '%s'" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , txt_Replaced
                ), file=sys.stderr)
        
    
        txt_Replaced = re.sub(item[0], item[1], txt_Replaced)

        #debug
        print("[%s:%d] txt_Replaced (after) = '%s'" % \
                (os.path.basename(libs.thisfile()), libs.linenum()
                , txt_Replaced
                ), file=sys.stderr)
        
    #/for item in lo_Replaces:

    
#     txt_Replaced = re.sub(r"\|\| ", "\r\n", data)

    print("[%s:%d] txt_Replaced => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , txt_Replaced
            ), file=sys.stderr)

    '''###################
        step : A : 2
            clipboard
    ###################'''
#     #_20190917_094226:tmp
# #     command = 'echo ' + text.strip() + '| clip'
# #     command = 'echo ' + txt_Replaced.strip() + '| clip'
#     command = "echo \"" + txt_Replaced.strip() + "\" | clip"
#     os.system(command)
# 
#     print("[%s:%d] command => %s" % \
#             (os.path.basename(libs.thisfile()), libs.linenum()
#             , command
#             ), file=sys.stderr)
#     
#     print("[%s:%d] text => to clipboard" % \
#             (os.path.basename(libs.thisfile()), libs.linenum()
#             
#             ), file=sys.stderr)

    '''###################
        step : A : 3
            to file
    ###################'''
    f_out_Text_Replaced = open(os.path.join(dpath_Text, fname_Text_Replaced), "w")
    
    f_out_Text_Replaced.write(txt_Replaced)
    
    # close
    f_out_Text_Replaced.close()

    print("[%s:%d] text => written : %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
             , fname_Text_Replaced
            ), file=sys.stderr)
    
    '''###################
        report
    ###################'''
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_1 =======================" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
def test_4():

    '''###################
        plot        
    ###################'''
    rng_X_Scalar = 4
    
    rng_X_Start = - rng_X_Scalar * np.pi
    rng_X_End = rng_X_Scalar * np.pi
    
    x=np.linspace(rng_X_Start, rng_X_End, 1000)
#     x=np.linspace(-2 * np.pi, 2 * np.pi, 1000)
    y=np.sin(x)
    y2= [i**2 for i in y]
    
    
    fig = plt.figure()
    ax  = fig.add_subplot(111)
    
    ax.plot(x,y,'b')
    
    ### sum
    ysum = y
    
    rng_Start = 2; rng_End = 10
#     rng_Start = 2; rng_End = 6
    
    for index in np.arange(rng_Start, rng_End):
#     for index in np.arange(2,4):
#     for index in np.arange(2,3):
#     for index in (2,2):
#     for index in (2, 3):
#     for index in (1,2):
#     for index in (1,2,3):
#     for index in (1,2,3,4):

        y_ = [i ** index for i in y]
        
        ysum = ysum + y_
#         ysum = y_
#         ysum += y_
        
        ax.plot(x, ysum)
        
        print()
        print("[%s:%d] index => %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , index
            ), file=sys.stderr)
        
    #/for index in (1,2,3,4):

    
#     ax.plot(x,y2,'g')
#     ax.plot(x,y + y2,'r')
#     ax.plot(x,y,'b.')
    
#     y_pi   = y/np.pi
#     unit   = 0.25
#     y_tick = np.arange(-0.5, 0.5+unit, unit)
#     
    '''###################
        label : y
    ###################'''
    #ref https://stackoverflow.com/questions/10729737/how-can-i-set-the-y-axis-in-radians-in-a-python-plot
    tickVal_Y = 1
#     tickVal_X = 1
    
    y_tick = np.arange(-2, rng_End + tickVal_Y, tickVal_Y)
#     x_tick = np.arange(-2, 2, 1)
    
    y_label = y_tick
#     y_label = [r"$" + format(r, ".2g")+ r"\pi$" for r in y_tick]
    
    ax.set_yticks(y_tick)
#     ax.set_yticks(y_tick * np.pi)
    
    ax.set_yticklabels(y_label, fontsize = 10)
    
    '''###################
        label : x
    ###################'''
    #ref https://stackoverflow.com/questions/10729737/how-can-i-set-the-y-axis-in-radians-in-a-python-plot
    tickVal_X = 0.5
#     tickVal_X = 1
    
    x_tick = np.arange(- rng_X_Scalar, rng_X_Scalar + tickVal_X, tickVal_X)
#     x_tick = np.arange(-2, 2 + tickVal_X, tickVal_X)
#     x_tick = np.arange(-2, 2, 1)
    
    x_label = [r"$" + format(r, ".2g")+ r"\pi$" for r in x_tick]
    
    ax.set_xticks(x_tick * np.pi)
    
    ax.set_xticklabels(x_label, fontsize = 10)
    
    
#     x_label = np.arange(-10 / np.pi, 10 / np.pi, np.pi / 2)
# #     x_label = np.arange(-np.pi * 3, np.pi * 3, np.pi / 2)
#     
#     x_label_pi = [r"$" + format(r, ".2g")+ r"\pi$" for r in x_label]
#     
#     ax.set_xticks(x_label)
#     
#     ax.set_xticklabels(x_label_pi, fontsize = 10)
#     
# #     x_label_pi = [r"$-\frac{\pi}{2}$", r"$-\frac{\pi}{4}$", r"$0$", r"$+\frac{\pi}{4}$",   r"$+\frac{\pi}{2}$"]
#     
#     '''###################
#         label : y        
#     ###################'''
#     y_label = [r"$-\frac{\pi}{2}$", r"$-\frac{\pi}{4}$", r"$0$", r"$+\frac{\pi}{4}$",   r"$+\frac{\pi}{2}$"]
#     ax.set_yticks(y_tick*np.pi)
#     ax.set_yticklabels(y_label, fontsize=20)
#     
#     y_label2 = [r"$" + format(r, ".2g")+ r"\pi$" for r in y_tick]
#     ax2 = ax.twinx()
#     ax2.set_yticks(y_tick*np.pi)
#     ax2.set_yticklabels(y_label2, fontsize=20)
    fpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
            + "\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1" \
            + "\\6_1.%s.png" % (libs.get_TimeLabel_Now())
            
    print()
    print("[%s:%d] fpath_Out => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fpath_Out
        ), file=sys.stderr)
    
    '''###################
        title
    ###################'''
    plt.title("sin(x)^a : a = %02d ~ %02d\n%s" \
                % (rng_Start, (rng_End - 1), os.path.basename(fpath_Out)))
    '''###################
        grid        
    ###################'''
    plt.grid(b=None, which='major', axis='both')
    
    '''###################
        plot        
    ###################'''
#     ax.savefig("%s\\6_1.%s.png" % (fpath_Out, libs.get_TimeLabel_Now()))
    plt.savefig(fpath_Out)
    
#     plt.savefig("%s\\6_1.%s.png" % (dpath_Out, libs.get_TimeLabel_Now()))
    
    plt.show()
Beispiel #18
0
def test_1():
    '''###################
        get : args
    ###################'''
    '''###################
        file path
    ###################'''
    #_20190307_144837
    dpath_CSV = "C:\\WORKS_2\\WS\\WS_Others.prog\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\curr\\data\\csv_raw"

    if len(sys.argv) > 1:  #if len(sys.argv)

        fname_CSV = sys.argv[1]

    else:  #if len(sys.argv)

        fname_CSV = "44_5.1_10_rawdata.(EURJPY).(Period-D1).(NumOfUnits-2000)"\
                    + ".(Bars-ALL).20190308_083617.csv"
    #     fname_CSV = "44_5.1_10_rawdata.(EURJPY).(Period-M15).(NumOfUnits-4500)"\
    #                 + ".(Bars-ALL).20190214_095445.csv"

    #/if len(sys.argv)

    fpath_CSV = os.path.join(dpath_CSV, fname_CSV)

    # validate
    if not os.path.isfile(fpath_CSV):  #if not os.path.isfile(fpath_CSV)

        print()
        print("[%s:%d] csv file NOT exist : %s" % \
                        (os.path.basename(libs.thisfile()), libs.linenum()

                        ), file=sys.stderr)

        return

    #/if not os.path.isfile(fpath_CSV)
    '''###################
        file : open
    ###################'''
    f_in_CSV = open(fpath_CSV, "r")
    '''###################
        read file content
    ###################'''
    data = f_in_CSV.readlines()

    print("[%s:%d] len(data) = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(data)
            ), file=sys.stderr)
    '''###################
        file : close
    ###################'''
    f_in_CSV.close()
    '''###################
        op : renumbering
    ###################'''
    '''###################
        step : A : 1
            prep
    ###################'''
    lo_New_CSV_Lines = []

    cntOf_Lines = 1

    lenOf_Lines = len(data)

    # file path
    #_20190307_144916
    dpath_CSV_Dst = dpath_CSV
    #     dpath_CSV_Dst = "C:\\WORKS_2\\WS\\WS_Others.prog\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\curr\\data\\csv_raw"

    # E/J, H1
    # build : fname
    # 44_5.1_10_rawdata.(EURJPY).(Period-D1).(NumOfUnits-2000).(Bars-ALL).20190308_083617.csv
    #     tokens = fname_CSV.split(".")

    fname_CSV_Dst = fname_CSV.replace("Bars-ALL",
                                      "Bars-ALL-%s" % libs.get_TimeLabel_Now())
    #     fname_CSV_Dst = "44_5.1_10_rawdata.(EURJPY).(Period-H1).(NumOfUnits-4500)"
    #     fname_CSV_Dst += ".(Bars-ALL-%s).20190307_144106.csv" % libs.get_TimeLabel_Now()

    #     # E/J, M15
    #     fname_CSV_Dst = "44_5.1_10_rawdata.(EURJPY).(Period-M15).(NumOfUnits-4500)"
    #     fname_CSV_Dst += ".(Bars-ALL-%s).20190214_095445" % libs.get_TimeLabel_Now()

    #     fname_CSV_Dst += ".csv"
    #     fname_CSV_Dst += ".(tmp-%s).csv" % libs.get_TimeLabel_Now()

    fpath_CSV_Dst = os.path.join(dpath_CSV_Dst, fname_CSV_Dst)
    '''###################
        step : A : 2.1
            read : header
    ###################'''
    lo_New_CSV_Lines.append(data[0])
    lo_New_CSV_Lines.append(data[1])
    '''###################
        step : A : 2.2
            read : body
    ###################'''
    # iteration
    for i in range(2, lenOf_Lines):

        # split
        tokens = data[i].split(";")

        # renumbering
        tokens[0] = str(cntOf_Lines)
        #         tokens[0] = cntOf_Lines

        # counter
        cntOf_Lines += 1

        # append
        lo_New_CSV_Lines.append(";".join(tokens))

    #/for i in range(2, lenOf_Lines):

    #debug
    print()
    print("[%s:%d] lo_New_CSV_Lines[0] = %s, lo_New_CSV_Lines[-1] = %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , lo_New_CSV_Lines[0]
                     , lo_New_CSV_Lines[-1]
                    ), file=sys.stderr)

    #ccc

    #     for line in data:
    #
    #         tokens = line.split(";")
    #
    #
    #
    #     #/for line in data:
    '''###################
        step : A : 3.1
            file : open
    ###################'''
    f_out_CSV = open(fpath_CSV_Dst, "w")
    '''###################
        step : A : 3.2
            file : write
    ###################'''
    f_out_CSV.write("".join(lo_New_CSV_Lines))
    #     f_out_CSV.write("\n".join(lo_New_CSV_Lines))
    '''###################
        step : A : 3.3
            file : close
    ###################'''
    f_out_CSV.close()

    #debug
    print()
    print("[%s:%d] file written ==> %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , fpath_CSV_Dst
                    ), file=sys.stderr)
    '''###################
        extract target tokesn from each line
    ###################'''
    '''###################
        report
    ###################'''
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_1 =======================" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
def _test_5_Generate_PNGFiles \
(z, dpath_Images, file_Label, lbl_Plot_Title):
    
#     '''###################
#         graph : settings        
#     ###################'''
#     # xlim
#     plt.xlim(-2,2)
#     plt.ylim(-2,2)
#     plt.grid(b=None, which='major', axis='both')

    '''###################
        paths and dirs
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
#     dpath_Images = "C:\\WORKS_2\\WS\\WS_Others\\free" \
#                 + "\\VX7GLZ_science-research\\27_math" \
#                 + "\\27_6_plot\\_1\\data.27_6_1\\images"
    
    dpath_Images_Out = "%s\\images_%s" % (dpath_Images, tlabel)
    
    # dirs
    if not os.path.isdir(dpath_Images_Out) : os.makedirs(dpath_Images_Out)
    
    '''###################
        plot        
    ###################'''
    cnt = 1
    
    for loc in z :
        
        '''###################
            graph : settings        
        ###################'''
        # xlim
        plt.xlim(-2,2)
        plt.ylim(-2,2)
        plt.grid(b=None, which='major', axis='both')

        fpath_Images_Out = "%s\\%s.%s.(%02d).png" \
                % (dpath_Images_Out, file_Label, tlabel, cnt)
#         fpath_Images_Out = "%s\\6_1.%s.(%02d).png" \
                 
        print()
        print("[%s:%d] fpath_Images_Out => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , fpath_Images_Out
            ), file=sys.stderr)
         
        '''###################
            title
        ###################'''
#         plt_Title = "rotate : (%02d) : x = %.4f / y = %.4f\n%s" \
        plt_Title = "%s : (%02d) : x = %.4f / y = %.4f\n%s" \
                    % (lbl_Plot_Title, cnt, loc[0], loc[1], 
                       os.path.basename(fpath_Images_Out))
#                     % (cnt, loc[0], loc[1], os.path.basename(fpath_Images_Out))
                    
        plt.title(plt_Title)
        
        '''###################
            grid        
        ###################'''
#         plt.grid(b=None, which='major', axis='both')
         
        '''###################
            plot        
        ###################'''
        plt.scatter([loc[0]], [loc[1]], s = 60)
         
    #     ax.savefig("%s\\6_1.%s.png" % (fpath_Out, libs.get_TimeLabel_Now()))
        plt.savefig(fpath_Images_Out)
    
        '''###################
            increment        
        ###################'''
        cnt += 1
    
        '''###################
            reset : figure  
        ###################'''
        plt.clf()
    
    '''###################
        return        
    ###################'''
    return dpath_Images_Out, tlabel
def dp_1_Trend_Down(\
          _lo_LO_Lines, _lo_BDs_Tmp
          , _typeOf_DP
          , _index_start
          , numOf_Target_Bars = 4
          ):
#_20191211_130902:caller
#_20191211_130909:head
#_20191211_130914:wl:in-func
    
    '''###################
        step : 0 : 1
            prep : unpack : lines
    ###################'''
    (lo_Lines_Log, lo_Lines_Dat, lo_Lines_Error) = _lo_LO_Lines

    '''###################
        step : 0 : 2
            prep : vars
    ###################'''
    valOf_Ret = False
    
    '''###################
        step : 0 : 3
            log
    ###################'''
    #_20191110_142858:caller
#     flg_commandline_ouput = SWITCH_COMMANDLINE_OUTPUT
    flg_commandline_ouput = cons_fx.Flags.SWITCH_COMMANDLINE_OUTPUT.value
    
    tmp_msg = "dp_1_Trend_Down ==> starting..."
    
    libfx_7.output_Log(os.path.basename(libs.thisfile()), libs.linenum(), libs.get_TimeLabel_Now()
         , tmp_msg, lo_Lines_Log, flg_commandline_ouput)
    
    '''###################
        step : 1
            get : 4 bars
    ###################'''
    #_20191211_135133:next
    e0 = _lo_BDs_Tmp[_index_start - 0]
    e1 = _lo_BDs_Tmp[_index_start - 1]
    e2 = _lo_BDs_Tmp[_index_start - 2]
    e3 = _lo_BDs_Tmp[_index_start - 3]
    
    '''###################
        step : 2
            get : lower price
    ###################'''
    pr_Bottom_0 = e0.price_Close if (e0.price_Close < e0.price_Open) else e0.price_Open
    pr_Bottom_1 = e1.price_Close if (e1.price_Close < e1.price_Open) else e1.price_Open
    pr_Bottom_2 = e2.price_Close if (e2.price_Close < e2.price_Open) else e2.price_Open
    pr_Bottom_3 = e3.price_Close if (e3.price_Close < e3.price_Open) else e3.price_Open

    '''###################
        step : j1
            judge : trend down ?
    ###################'''
    '''###################
        step : j1 : 1
            conditions
    ###################'''
    cond_1 = (
              (pr_Bottom_0 < pr_Bottom_1) \
            and  (pr_Bottom_1 < pr_Bottom_2) \
            and (pr_Bottom_2 < pr_Bottom_3)
            )
    
    '''###################
        step : j1 : 2
            judge
    ###################'''
    if cond_1 == True : #if cond_1 == True
        '''###################
            step : j1 : Y
                judge : trend down
        ###################'''
        '''###################
            step : j1 : Y : 1
                log
        ###################'''
        #_20191110_142858:caller
        flg_commandline_ouput = cons_fx.Flags.SWITCH_COMMANDLINE_OUTPUT.value
        
        tmp_msg = "(step : 3 : 2) judge : trend down ==> True (cond_1 = %s)" % (cond_1)
        
        libfx_7.output_Log(os.path.basename(libs.thisfile()), libs.linenum(), libs.get_TimeLabel_Now()
             , tmp_msg, lo_Lines_Log, flg_commandline_ouput)
        
        '''###################
            step : j1 : Y : 2
                set : vals
        ###################'''
        valOf_Ret = True
    
    else : #if cond_1 == True
        '''###################
            step : j1 : N
                judge : trend NOT down
        ###################'''
    
        '''###################
            step : j1 : N : 1
                log
        ###################'''
        #_20191110_142858:caller
        flg_commandline_ouput = cons_fx.Flags.SWITCH_COMMANDLINE_OUTPUT.value
        
        tmp_msg = "(step : 3 : 2) judge : trend down ==> False (cond_1 = %s)" % (cond_1)
        
        libfx_7.output_Log(os.path.basename(libs.thisfile()), libs.linenum(), libs.get_TimeLabel_Now()
             , tmp_msg, lo_Lines_Log, flg_commandline_ouput)
        
        '''###################
            step : j1 : N : 2
                set : vals
        ###################'''
        valOf_Ret = False
    
    #/if cond_1 == True
    
    
    
    '''###################
        step : X : 1
            return
    ###################'''
    '''###################
        step : X : 1.1
            return values
    ###################'''
#     ret = False
#     ret = True
    ret = valOf_Ret
    
    '''###################
        step : X : 1.2
            return
    ###################'''
    return ret
Beispiel #21
0
def build_result_csv_data():
    '''###################
        step : 1
            dat file
    ###################'''
    # time label
    tlabel = libs.get_TimeLabel_Now()

    #C:\WORKS_2\WS\WS_Others.prog\prog\D-7\2_2\VIRTUAL\Admin_Projects\curr\data\log
    dpath_Log__ROOT = "C:\\WORKS_2\\WS\\WS_Others.prog\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\curr\\data\\log"

    strOf_Project = "[44_8.5].[order-csv-data]"

    dname_Log = "%s.(%s).dir" % (strOf_Project, tlabel)
    '''###################
        step : 1
            dat file
    ###################'''
    lo_Order_Numbers = _build_result_csv_data__Dat_File()
    '''###################
        step : 2
            file : report file
    ###################'''
    #_20190901_151726:caller
    lo_TRs_With_Order_TDS = lo_Order_Reports = \
                _build_result_csv_data__Report_File(\

                        dpath_Log__ROOT
                        , strOf_Project
                        , dname_Log
                        , tlabel

                                                    )

    # 17257299    2019.08.27 08:26:03    buy    1.00    eurjpy    117.345    117.338    117.353    2019.08.27 08:26:27    117.338    0    0    0    -700
    '''###################
        step : 3
            build : a full-data list
    ###################'''
    #_20190902_132829:tmp
    #_20190903_124229:caller
    lo_Orders_Full = _build_result_csv_data__Full_Data_List(
        lo_TRs_With_Order_TDS, lo_Order_Numbers)

    #     '''###################
    #         step : 3.1
    #             vars
    #     ###################'''
    #     lo_Orders_Full = []
    #
    #     for item in lo_TRs_With_Order_TDS:
    #
    #         lo_TDs = item[1]
    #
    #         numOf_Order = int(lo_TDs[0].getText())
    #
    #         # judge
    #         if numOf_Order in lo_Order_Numbers : #if numOf_Order in lo_Order_Numbers
    #
    #             # append
    #             lo_Orders_Full.append(item)
    #
    #         #/if numOf_Order in lo_Order_Numbers
    #
    #
    #     #/for item in lo_TRs_With_Order_TDS:
    #
    #     # report
    #     #debug
    #     if SWITCH_DEBUG == True : #if SWITCH_DEBUG == True
    #
    #         # count
    #         lenOf_LO_Orders_Full = len(lo_Orders_Full)
    #
    #         msg = "[%s:%d] lenOf_LO_Orders_Full ==> %d" % \
    #                         (os.path.basename(libs.thisfile()), libs.linenum()
    #                          , lenOf_LO_Orders_Full
    #                         )
    #
    #         print()
    #         print(msg, file=sys.stderr)
    #
    #     #/if SWITCH_DEBUG == True
    '''###################
        step : 4
            write : file
    ###################'''
    #_20190903_124102:tmp
    #_20190903_124741:caller
    _build_result_csv_data__Write_Full_Data(\

            lo_Orders_Full
            , dpath_Log__ROOT
            , strOf_Project
            , dname_Log
            , tlabel

                                            )
def test_2():

    '''###################
        plot        
    ###################'''
    x=np.arange(-10.0,10.0,0.1)
    y=np.arctan(x)
    
    fig = plt.figure()
    ax  = fig.add_subplot(111)
    
    ax.plot(x,y,'b.')
    
    y_pi   = y/np.pi
    unit   = 0.25
    y_tick = np.arange(-0.5, 0.5+unit, unit)
    
    '''###################
        label : x
    ###################'''
    x_label = np.arange(-10 / np.pi, 10 / np.pi, np.pi / 2)
#     x_label = np.arange(-np.pi * 3, np.pi * 3, np.pi / 2)
    
    x_label_pi = [r"$" + format(r, ".2g")+ r"\pi$" for r in x_label]
    
    ax.set_xticks(x_label)
    
    ax.set_xticklabels(x_label_pi, fontsize = 10)
    
#     x_label_pi = [r"$-\frac{\pi}{2}$", r"$-\frac{\pi}{4}$", r"$0$", r"$+\frac{\pi}{4}$",   r"$+\frac{\pi}{2}$"]
    
    '''###################
        label : y        
    ###################'''
    y_label = [r"$-\frac{\pi}{2}$", r"$-\frac{\pi}{4}$", r"$0$", r"$+\frac{\pi}{4}$",   r"$+\frac{\pi}{2}$"]
    ax.set_yticks(y_tick*np.pi)
    ax.set_yticklabels(y_label, fontsize=20)
#     
#     y_label2 = [r"$" + format(r, ".2g")+ r"\pi$" for r in y_tick]
#     ax2 = ax.twinx()
#     ax2.set_yticks(y_tick*np.pi)
#     ax2.set_yticklabels(y_label2, fontsize=20)
    fpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
            + "\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1" \
            + "\\6_1.%s.png" % (libs.get_TimeLabel_Now())
            
    print()
    print("[%s:%d] fpath_Out => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fpath_Out
        ), file=sys.stderr)
    
    '''###################
        grid        
    ###################'''
    plt.grid(b=None, which='major', axis='both')
    
    '''###################
        plot        
    ###################'''
#     ax.savefig("%s\\6_1.%s.png" % (fpath_Out, libs.get_TimeLabel_Now()))
    plt.savefig(fpath_Out)
    
#     plt.savefig("%s\\6_1.%s.png" % (dpath_Out, libs.get_TimeLabel_Now()))
    
    plt.show()
def test_1():
    '''###################
        file path
    ###################'''
    dpath_Log_Fx = "C:\\Users\\iwabuchiken\\AppData\\Roaming\\MetaQuotes\\Terminal\\56FC49B0C953127FDE33461B90444E81\\MQL4\\Files\\Logs"
    fname_Log_Fx = "dev.20180914_063011.log"
    #     fname_Log_Fx = "dev.20180913_084909.log"
    #     fname_Log_Fx = "dev.20180913_084909.SHRIK-500.log"

    fpath_Log_Fx = os.path.join(dpath_Log_Fx, fname_Log_Fx)

    dpath_Log = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\curr\\ops\\5.1"
    fname_Log = "log_CountTicks.%s.log" % libs.get_TimeLabel_Now()

    fpath_Log = os.path.join(dpath_Log, fname_Log)
    '''###################
        file : open
    ###################'''
    f_Log_FX = open(fpath_Log_Fx, "r")
    '''###################
        read file content
    ###################'''
    data = f_Log_FX.readlines()

    print("[%s:%d] len(data) = %d" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , len(data)
            ), file=sys.stderr)
    '''###################
        extract target tokesn from each line
    ###################'''
    #     ['[2018.09.13', '08:49:18', '/', 'fnc_CountTick.mq4:289]cntOf_Ticks', '=', '1', '/', 'cntOf_Ticks_In_The_Bar', '=', '1', '(2018.09.13', '08:49:18)']
    # >>> len(b)
    # 12
    lenOf_Data = len(data)

    aryOf_Hit_Data = []

    for i in range(1, lenOf_Data - 1):

        item = data[i]
        item2 = data[i - 1]

        # split
        tokens = item.split(" ")
        tokens2 = item2.split(" ")

        # tokens
        cntOf_Ticks = tokens[5]
        cntOf_Ticks_In_The_Bar = tokens[9]
        dateTime_Local = (" ".join([tokens[10], tokens[11]])).strip()
        dateTime_Local2 = (" ".join([tokens2[10], tokens2[11]])).strip()
        #         dateTime_Local = " ".join([tokens[10], tokens[11]])
        #         dateTime_Local = tokens[10]

        # judge
        if cntOf_Ticks_In_The_Bar == "1":  #if cntOf_Ticks_In_The_Bar == "1"

            # append
            #             aryOf_Hit_Data.append([cntOf_Ticks, cntOf_Ticks_In_The_Bar, dateTime_Local])

            #debug
            #             msg = "[%s:%d] dateTime_Local = %s / prev count = %s" % \
            #             msg = "dateTime_Local = %s / prev count = %s" % \
            msg = "dateTime_Local\t%s\tprev count\t%s" % \
                (
                     dateTime_Local2, tokens2[9]
                #                      dateTime_Local, tokens2[9]
                )

            #             print(msg, file=sys.stderr)

            # append
            aryOf_Hit_Data.append(msg)

        #/if cntOf_Ticks_In_The_Bar == "1"

    #/for item in data:
    '''###################
        last item
    ###################'''
    #debug
    item = data[-1]
    tokens = item.split(" ")
    dateTime_Local = (" ".join([tokens[10], tokens[11]])).strip()

    #     msg = "dateTime_Local = %s / prev count = %s" % \
    msg = "dateTime_Local\t%s\tprev count\t%s" % \
                (
                    dateTime_Local, tokens[9]
        #                     dateTime_Local, tokens[9]
                )

    # append
    aryOf_Hit_Data.append(msg)

    #     print(msg, file=sys.stderr)
    '''###################
        file : close
    ###################'''
    f_Log_FX.close()
    '''###################
        report
    ###################'''
    # file : open
    f_Log = open(fpath_Log, "a")

    #debug
    msg = "[%s:%d] len(aryOf_Hit_Data) = %d" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                    , len(aryOf_Hit_Data)
                    )

    print(msg, file=sys.stderr)

    # write file
    # file path
    #     msg = "[%s / %s:%d] file = %s\n" % \
    msg = "[%s / %s:%d]\nfile = %s\ndir = %s" % \
                    (
                    libs.get_TimeLabel_Now()
                    , os.path.basename(libs.thisfile()), libs.linenum()
                    , fname_Log_Fx, dpath_Log_Fx
        #                     , fpath_Log_Fx
                    )

    f_Log.write(msg)

    # len of hit data
    msg = "[%s / %s:%d] len(aryOf_Hit_Data) = %d\n" % \
                    (
                    libs.get_TimeLabel_Now()
                    , os.path.basename(libs.thisfile()), libs.linenum()
                    , len(aryOf_Hit_Data)
                    )

    f_Log.write(msg)

    for item in aryOf_Hit_Data:

        #         print(item)

        # write file
        f_Log.write(item)
        f_Log.write("\n")

    #/for item in aryOf_Hit_Data:

    # separation line
    f_Log.write("\n")

    # file : close
    f_Log.close()
    '''###################
        message
    ###################'''
    print()
    print("[%s:%d] test_1 =======================" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()

                    ), file=sys.stderr)
Beispiel #24
0
def _test_2__20190123_100239__CommandLine_Args():
    '''###################
        vars
    ###################'''
    #ref C:\Users\iwabuchiken\AppData\Roaming\MetaQuotes\Terminal\B9B5D4C0EA7B43E1F3A680F94F757B3D\MQL4\Files\Report_Trades
    dpath_Src_HTML = "C:\\Users\\iwabuchiken\\AppData\\Roaming\\MetaQuotes\\Terminal\\B9B5D4C0EA7B43E1F3A680F94F757B3D\\MQL4\\Files\\Report_Trades"

    fname_Src_HTML = "DetailedStatement.(20190122_230530).(e-j,M1).htm"
    #     fname_Src_HTML = "DetailedStatement.(20190117_231722).(e-j,M1).htm"

    dpath_Dst_CSV = "C:\\Users\\iwabuchiken\\AppData\\Roaming\\MetaQuotes\\Terminal\\B9B5D4C0EA7B43E1F3A680F94F757B3D\\MQL4\\Files\\Report_Trades"
    fname_Dst_CSV = "trade_log.(20190122_230530).(e-j,M1).csv"

    #ddd
    '''###################
        get : command line args
            fname_Src_HTML
    ###################'''
    #ref https://www.tutorialspoint.com/python/python_command_line_arguments.htm
    lo_Args = sys.argv

    print()

    print("[%s:%d] lo_Args =>" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            ), file=sys.stdout)
    print(lo_Args)

    # arg for file name?
    for item in lo_Args[1:]:

        # detection
        '''###################
            fname_Src_HTML
        ###################'''
        #ref https://www.tutorialspoint.com/python/string_startswith.htm
        #         if item.startswith("filename=") : #if item.startswith("filename=")
        if item.startswith(
                "fname_Src_HTML="):  #if item.startswith("filename=")
            # update : file name
            fname_Src_HTML = item.split("=")[1]

            print()

            print("[%s:%d] fname_Src_HTML => updated : %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , fname_Src_HTML
                    ), file=sys.stdout)

    #/if item.startswith("filename=")
        '''###################
            dpath_Src_HTML
        ###################'''
        #ref https://www.tutorialspoint.com/python/string_startswith.htm
        #         if item.startswith("filename=") : #if item.startswith("filename=")
        if item.startswith(
                "dpath_Src_HTML="):  #if item.startswith("filename=")
            # update : file name
            dpath_Src_HTML = item.split("=")[1]

            print()

            print("[%s:%d] dpath_Src_HTML => updated : %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , dpath_Src_HTML
                    ), file=sys.stdout)
        '''###################
            dpath_Dst_CSV
        ###################'''
        #ref https://www.tutorialspoint.com/python/string_startswith.htm
        #         if item.startswith("filename=") : #if item.startswith("filename=")
        if item.startswith("dpath_Dst_CSV="):  #if item.startswith("filename=")
            # update : file name
            dpath_Dst_CSV = item.split("=")[1]

            print()

            print("[%s:%d] dpath_Dst_CSV => updated : %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , dpath_Dst_CSV
                    ), file=sys.stdout)
        '''###################
            fname_Dst_CSV
        ###################'''
        #ref https://www.tutorialspoint.com/python/string_startswith.htm
        #         if item.startswith("filename=") : #if item.startswith("filename=")
        if item.startswith("fname_Dst_CSV="):  #if item.startswith("filename=")
            # update : file name
            fname_Dst_CSV = item.split("=")[1]

            print()

            print("[%s:%d] fname_Dst_CSV => updated : %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , fname_Dst_CSV
                    ), file=sys.stdout)
        '''###################
            add time stamp
        ###################'''
        #ref https://www.tutorialspoint.com/python/string_startswith.htm
        if item.startswith("timestamp"):  #if item.startswith("filename=")
            # update : file name
            #ref https://stackoverflow.com/questions/541390/extracting-extension-from-filename-in-python#541394
            filetrunk, ext = os.path.splitext(fname_Dst_CSV)

            fname_Dst_CSV = "%s.%s%s" % (filetrunk, libs.get_TimeLabel_Now(),
                                         ext)

            print()

            print("[%s:%d] fname_Dst_CSV => updated : %s" % \
                    (os.path.basename(libs.thisfile()), libs.linenum()
                     , fname_Dst_CSV
                    ), file=sys.stdout)

    #/if item.startswith("filename=")

    #/for item in lo_Args[1:]:

    print()

    print("[%s:%d] source file info --------------\n" % \
            (os.path.basename(libs.thisfile()), libs.linenum()

            ), file=sys.stdout)

    print()

    print("fname_Src_HTML => %s\n" % \
            (fname_Src_HTML), file=sys.stdout)

    print("dpath_Src_HTML => %s\n" % \
            (dpath_Src_HTML), file=sys.stdout)
    '''###################
        return        
    ###################'''
    return (dpath_Src_HTML, fname_Src_HTML, dpath_Dst_CSV, fname_Dst_CSV)
def test_2():
    '''###################
        file path        
    ###################'''
    PROJECT_ROOT = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\1_\\_17"

    dpath_Out = "%s\\data_1_17.1" % (PROJECT_ROOT)

    ### fpath full
    tlabel = libs.get_TimeLabel_Now()

    session_Label = "1_17.1"

    #     fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)
    '''###################
        ops        
    ###################'''

    x = np.linspace(0, np.pi * 2, 100)
    #     x = np.linspace(0, np.pi, 1000)

    ### dir path
    dpath_Full = "%s\\images\\images_%s" % (dpath_Out, tlabel)
    ### make dir
    #ref is directory https://stackoverflow.com/questions/82831/how-to-check-whether-a-file-exists answered Sep 17 '08 at 15:01
    if not os.path.isdir(dpath_Full): os.makedirs(dpath_Full)
    #     os.makedirs(dpath_Out)
    '''###################
        graph : settings        
    ###################'''
    #     # graph : settings
    #     plt.ylim(-2,2)
    #     plt.xlim(0, np.pi * 2)
    #     plt.grid(b=None, which='major', axis='both')
    #     plt.xticks(np.arange(0, np.pi*2, np.pi / 4))
    #     plt.yticks(np.arange(-2, 2, 0.5))

    for index in np.arange(0, 12, 1):
        #     for index in np.arange(0, 11, 1):
        #     for index in np.arange(0, 20, 1):

        # graph : settings
        plt.ylim(-2, 2)
        plt.xlim(0, np.pi * 2)
        plt.grid(b=None, which='major', axis='both')
        plt.xticks(np.arange(0, np.pi * 2, np.pi / 4))
        plt.yticks(np.arange(-2, 2, 0.5))

        ### fpath
        fpath_Full = "%s\\image.%s.%s.(%02d).png" \
                    % (dpath_Full, session_Label, tlabel, index)

        tick = np.pi / 6 * index

        y = np.sin(x + tick)

        #         # graph : settings
        #         plt.ylim(-2,2)
        #         plt.xlim(0, np.pi * 2)
        #         plt.grid(b=None, which='major', axis='both')
        #         plt.xticks(np.arange(0, np.pi*2, np.pi / 4))
        #         plt.yticks(np.arange(-2, 2, 0.5))
        #     plt.yticks([-2,-1,1,2])
        #     plt.xticks([-2,-1,1,2])

        plt.xlabel("x")
        plt.ylabel("sin(x + %.3f)" % (tick))
        plt.title("x ~ sin(x + a) (index = %d)\n%s" \
                    % (index, os.path.basename(fpath_Full)))

        # plot
        plt.plot(x, y)

        plt.savefig(fpath_Full)

        # clear
        #         plt.gcf().clear()
        plt.clf()
def test_3():

    '''###################
        plot        
    ###################'''
    x=np.linspace(-2 * np.pi, 2 * np.pi, 1000)
    y=np.sin(x)
    y2= [i**2 for i in y]
    
    
    fig = plt.figure()
    ax  = fig.add_subplot(111)
    
    ax.plot(x,y,'b')
    ax.plot(x,y2,'g')
    ax.plot(x,y + y2,'r')
#     ax.plot(x,y,'b.')
    
#     y_pi   = y/np.pi
#     unit   = 0.25
#     y_tick = np.arange(-0.5, 0.5+unit, unit)
#     
    '''###################
        label : x
    ###################'''
    #ref https://stackoverflow.com/questions/10729737/how-can-i-set-the-y-axis-in-radians-in-a-python-plot
    tickVal_X = 0.5
#     tickVal_X = 1
    
    x_tick = np.arange(-2, 2 + tickVal_X, tickVal_X)
#     x_tick = np.arange(-2, 2, 1)
    
    x_label = [r"$" + format(r, ".2g")+ r"\pi$" for r in x_tick]
    
    ax.set_xticks(x_tick * np.pi)
    
    ax.set_xticklabels(x_label, fontsize = 10)
    
    
#     x_label = np.arange(-10 / np.pi, 10 / np.pi, np.pi / 2)
# #     x_label = np.arange(-np.pi * 3, np.pi * 3, np.pi / 2)
#     
#     x_label_pi = [r"$" + format(r, ".2g")+ r"\pi$" for r in x_label]
#     
#     ax.set_xticks(x_label)
#     
#     ax.set_xticklabels(x_label_pi, fontsize = 10)
#     
# #     x_label_pi = [r"$-\frac{\pi}{2}$", r"$-\frac{\pi}{4}$", r"$0$", r"$+\frac{\pi}{4}$",   r"$+\frac{\pi}{2}$"]
#     
#     '''###################
#         label : y        
#     ###################'''
#     y_label = [r"$-\frac{\pi}{2}$", r"$-\frac{\pi}{4}$", r"$0$", r"$+\frac{\pi}{4}$",   r"$+\frac{\pi}{2}$"]
#     ax.set_yticks(y_tick*np.pi)
#     ax.set_yticklabels(y_label, fontsize=20)
#     
#     y_label2 = [r"$" + format(r, ".2g")+ r"\pi$" for r in y_tick]
#     ax2 = ax.twinx()
#     ax2.set_yticks(y_tick*np.pi)
#     ax2.set_yticklabels(y_label2, fontsize=20)
    fpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
            + "\\VX7GLZ_science-research\\27_math\\27_6_plot\\_1" \
            + "\\6_1.%s.png" % (libs.get_TimeLabel_Now())
            
    print()
    print("[%s:%d] fpath_Out => %s" % \
        (os.path.basename(libs.thisfile()), libs.linenum()
        , fpath_Out
        ), file=sys.stderr)
    
    '''###################
        grid        
    ###################'''
    plt.grid(b=None, which='major', axis='both')
    
    '''###################
        plot        
    ###################'''
#     ax.savefig("%s\\6_1.%s.png" % (fpath_Out, libs.get_TimeLabel_Now()))
    plt.savefig(fpath_Out)
    
#     plt.savefig("%s\\6_1.%s.png" % (dpath_Out, libs.get_TimeLabel_Now()))
    
    plt.show()
def test_5_2():

    '''###################
        params
    ###################'''
    x_, y_ = _test_5__Params()

    z = list(zip(x_, y_))

    '''###################
        graph : settings        
    ###################'''
    # xlim
    plt.xlim(-2,2)
    plt.ylim(-2,2)
    plt.grid(b=None, which='major', axis='both')

    '''###################
        paths and dirs
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    dpath_Images = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\27_math" \
                + "\\27_6_plot\\_1\\data.27_6_1\\images"
    
    dpath_Images_Out = "%s\\images_%s" % (dpath_Images, tlabel)
    
    # dirs
    if not os.path.isdir(dpath_Images_Out) : os.makedirs(dpath_Images_Out)
    
    '''###################
        plot        
    ###################'''
    cnt = 1
    
    for loc in z :
         
        fpath_Images_Out = "%s\\6_1.%s.(%02d).png" \
                % (dpath_Images_Out, tlabel, cnt)
                 
        print()
        print("[%s:%d] fpath_Images_Out => %s" % \
            (os.path.basename(libs.thisfile()), libs.linenum()
            , fpath_Images_Out
            ), file=sys.stderr)
         
        '''###################
            title
        ###################'''
        plt_Title = "rotate : (%02d) : x = %.4f / y = %.4f\n%s" \
                    % (cnt, loc[0], loc[1], os.path.basename(fpath_Images_Out))
                    
        plt.title(plt_Title)
        
        '''###################
            grid        
        ###################'''
#         plt.grid(b=None, which='major', axis='both')
         
        '''###################
            plot        
        ###################'''
        plt.scatter([loc[0]], [loc[1]], s = 60)
         
    #     ax.savefig("%s\\6_1.%s.png" % (fpath_Out, libs.get_TimeLabel_Now()))
        plt.savefig(fpath_Images_Out)
    
        '''###################
            increment        
        ###################'''
        cnt += 1
def test_5():
    
    '''###################
        vars        
    ###################'''
    tlabel = libs.get_TimeLabel_Now()
    
    dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\free" \
                + "\\VX7GLZ_science-research\\28_Physics\\1_\\_17" \
                + "\\images"

    '''###################
        file path        
    ###################'''
#         dpath_Out = "C:\\WORKS_2\\WS\\WS_Others\\prog\\D-7\\2_2\\VIRTUAL\\Admin_Projects\\others\\VX7GLZ\\28_physics\\1_\\_16"
    ### fpath full
    session_Label  = "1-17-2"
    
    fpath_Full = "%s\\image.%s.%s.png" % (dpath_Out, session_Label, tlabel)

    x = np.arange(0.0, 2, 0.01)
    y1 = np.sin(2*np.pi*x)
    y2 = 1.2*np.sin(4*np.pi*x)
    
    plt.plot(x, y1, label="sin(2πx)")
    plt.plot(x, y2, label="1.2*sin(4πx)")
#     plt.plot(x, y1, label="x and y1")
#     plt.plot(x, y2, label="x and y2")
    
    #ref https://matplotlib.org/users/legend_guide.html
#     plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
#     plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3,
#     plt.legend(bbox_to_anchor=(0.5, 1.02, 1., .102), loc=3,
#     plt.legend(bbox_to_anchor=(0.5, 1.02, 0.7, .102), loc=3,
#     plt.legend(bbox_to_anchor=(0., 1.02, 0.3, .102), loc=3,

    _anchor = (.7, 1.)
#     _anchor = (.9, .1)
#     _anchor = (.9, .5)
#     _anchor = (1.05, .5)
#     _anchor = (1.05, 1)
#     _anchor = (0., 1.02, 0.5, .102)
    loc_Legend = 2
#     loc_Legend = "best"
#     loc_Legend = 1
    ncol_Legend = 1
#     ncol_Legend = 2
    
    _borderaxespad = 0.5
    
#     plt.legend(bbox_to_anchor=(0., 1.02, 0.5, .102), loc=1,
    plt.legend(bbox_to_anchor= _anchor, loc= loc_Legend,
            ncol= ncol_Legend, borderaxespad= _borderaxespad)
#            borderaxespad= _borderaxespad)
#            ncol= ncol_Legend, borderaxespad=0.)
#            ncol= ncol_Legend, mode="expand", borderaxespad=0.)
#            ncol=2, mode="expand", borderaxespad=0.)
    
#     plt.plot(x, y1, y2)
#     plt.plot(x, y1)
    
    plt.xlabel("x")
    plt.ylabel("y1")
    plt.title("test_5 : anchor=[%s]\nloc=%s borderaxespad=%.2f" \
                % (
                    ",".join([str(x) for x in _anchor])
                    , str(loc_Legend), _borderaxespad
#                     , loc_Legend
                )
        )
#     plt.title("test_5")
    
#     red_patch = mpatches.Patch(color='red', label='The red data')
#     plt.legend(handles=[red_patch])
    
    plt.savefig(fpath_Full)
Beispiel #29
0
def test_1():

    cons_Width = 10

    x = np.linspace(-cons_Width * np.pi, cons_Width * np.pi, 1000)
    #     x = np.linspace(-3 * np.pi, 3 * np.pi, 1000)
    #     x = np.linspace(-3 * np.pi, 3 * np.pi, 100)

    #     fig = plt.figure()
    #
    #     ax  = fig.add_subplot(111)

    # time label
    tlabel = libs.get_TimeLabel_Now()

    # num of files
    numOf_ImageFiles = 30
    #     numOf_ImageFiles = 15

    for i in range(numOf_ImageFiles):
        #     for i in range(6):

        plt_Title = "sin(x - %.02f x np.pi)" % (i / 2 * 3)
        #         plt_Title = "sin(x + %.02f x np.pi)" % (i / 2 * 3)
        #         plt_Title = "sin(x + %.02f * np.pi)" % (i / 2 * 3)
        #         plt_Title = "sin(x + %02f * np.pi)" % (i / 2 * 3)
        #         plt_Title = "sin(x + %02f * np.pi)" % (i / 2)
        #         plt_Title = "sin(x + %d * np.pi)" % (i)

        plt.title(plt_Title, fontsize=15)

        y1 = np.sin(x - (i / 2) * np.pi)
        #         y1 = np.sin(x + (i / 2) * np.pi)
        #         y1 = np.sin(x + i * np.pi)
        #     y2 = np.sin(x * 2)

        plt.plot(x, y1)
        #     plt.plot(x, y2)
        '''###################
            graph : settings        
        ###################'''
        plt.grid(b=None, which='major', axis='both')

        #     x_tick = np.arange(-3*np.pi, 3*np.pi, np.pi / 4)
        #
        #     x_label2 = [r"$" + format(r, ".2g")+ r"\pi$" for r in x_tick]
        #
        #     plt.set_xticklabels(x_label2, fontsize = 10)

        dpath_Images_Out = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research\\28_Physics\\10_electromagnetic\\1_\\images\\8_"
        fname_Images_Out = "image.%s.%s.png" % (tlabel, plt_Title)
        #         fname_Images_Out = "image.%s.(sin_+%02f).png" % (tlabel, i / 2)
        #         fname_Images_Out = "image.%s.(i=%d).png" % (tlabel, i)
        #         fname_Images_Out = "image.%s.png" % (libs.get_TimeLabel_Now())

        fpath_Images_Out = "%s\\%s" % (dpath_Images_Out, fname_Images_Out)

        plt.savefig(fpath_Images_Out)

        # clear plot
        plt.clf()
Beispiel #30
0
def test_1():
    '''###################
        setup        
    ###################'''
    # time label
    tlabel = libs.get_TimeLabel_Now()

    dpath_Images_Out = "C:\\WORKS_2\\WS\\WS_Others\\free\\VX7GLZ_science-research" \
                + "\\28_Physics\\10_electromagnetic\\1_\\images\\" \
                + "9_%s" % tlabel
    #                 + "9_"

    # dirs
    if not os.path.isdir(dpath_Images_Out): os.makedirs(dpath_Images_Out)

    #ref https://stackoverflow.com/questions/36470343/how-to-draw-a-line-with-matplotlib
    x = np.linspace(0, 5)
    #     y = x**2

    e = 1
    r = 2

    t = np.pi / 4

    #     A = [0, 0]
    # #     B = [0, e]
    #     B = [e, 0]
    #     C = [r * np.cos(t), r * np.sin(t)]
    #     D = [e + r * np.cos(t), r * np.sin(t)]

    #     print("[%s:%d] D =>" % \
    #             (os.path.basename(libs.thisfile()), libs.linenum()
    #
    #             ), file=sys.stderr)
    #
    #     print(D)
    '''###################
        graph setup        
    ###################'''
    plt.grid(b=None, which='major', axis='both')

    #ref https://stackoverflow.com/questions/2849286/python-matplotlib-subplot-how-to-set-the-axis-range
    plt.ylim([-3, 3])
    #     plt.ylim([-1 * (e * r * 1.5) * 1.0, (e * r * 1.5) * 1.0])
    plt.xlim([-1 * (e * r * 1.5) * 1.0, (e * r * 1.5) * 1.0])
    #     plt.ylim([-3, 3])
    #     plt.xlim([-1, 3])

    #ref https://stackoverflow.com/questions/4136244/matplotlib-pyplot-how-to-enforce-axis-range
    ax = plt.gca()
    ax.set_autoscale_on(False)

    #ref https://matplotlib.org/examples/pylab_examples/equal_aspect_ratio.html
    # xy ratio ---> equal
    #     plt.axes().set_aspect('equal')
    #     plt.axes().set_aspect('equal', 'datalim')
    '''###################
        lines        
    ###################'''
    cons_Width = 10

    #     rng = np.linspace(0, np.pi / 2, 12)
    #     rng = np.linspace(0, np.pi, 6)
    rng = np.linspace(0, np.pi / 2, 24)
    #     rng = np.linspace(0, np.pi / 2, 12)
    #     rng = np.linspace(0, np.pi / 2, 6)
    #     rng = np.linspace(0, np.pi / 2, np.pi / 8)

    #debug
    print("rng =>")
    print(rng)
    #     return

    # counter for iteration
    cntOf_Iter = 0

    for th in rng:
        '''###################
            data        
        ###################'''
        A = [0, 0]
        #     B = [0, e]
        B = [e, 0]
        C = [r * np.cos(th), r * np.sin(th)]
        D = [e + r * np.cos(th), r * np.sin(th)]

        E = [0, -r * np.cos(th)]
        F = [e, -r * np.cos(th)]

        # AC, AB
        x1, y1 = [A[0], C[0], A[0], B[0]], \
                    [A[1], C[1], A[1], B[1]]
        # CD BD
        x2, y2 = [C[0], D[0], B[0], D[0]], \
                    [C[1], D[1], B[1], D[1]]
        # AE
        x3, y3 = [A[0], E[0]], \
                    [A[1], E[1]]
        # BF
        x4, y4 = [B[0], F[0]], \
                    [B[1], F[1]]

        # EF
        x5, y5 = [E[0], F[0]], \
                    [E[1], F[1]]

        #     x2, y2 = [C[0], D[0]], \
        #                 [C[1], D[1]]
        #     x1, y1 = [-1, 12], [1, 4]
        #     x2, y2 = [1, 10], [3, 2]
        '''###################
            graph        
        ###################'''
        plt.ylim([-3, 3])
        #     plt.ylim([-1 * (e * r * 1.5) * 1.0, (e * r * 1.5) * 1.0])
        plt.xlim([-1 * (e * r * 1.5) * 1.0, (e * r * 1.5) * 1.0])

        plt.grid(b=None, which='major', axis='both')

        # title
        plt_Title = "theta=%d-over-pi" % (cntOf_Iter)

        # increment counter
        cntOf_Iter += 1
        #         plt_Title = "theta=%d-over-pi" % (th)
        #         plt_Title = "theta = %d / pi" % (th)
        #         plt_Title = "theta = %.02f pi" % (th / np.pi)
        #         plt_Title = "theta = %.02f pi" % (t / np.pi)

        plt.title(plt_Title, fontsize=15)

        plt.axes().set_aspect('equal')

        #         #ref https://stackoverflow.com/questions/19125722/adding-a-legend-to-pyplot-in-matplotlib-in-the-most-simple-manner-possible
        #         plt.legend(loc='upper left')
        '''###################
            plot        
        ###################'''
        #         handle_AC_AB, = plt.plot(x1, y1, x2, y2, marker = 'o', label='AC AB')
        #         handle_AE, = plt.plot(x3, y3, marker = 'o', label='AE')
        #         handle_AE, = plt.plot(x3, y3, marker = 'o', label='AE')
        #         plt.plot(x4, y4, x5, y5, marker = 'o')
        #         plt.plot(x3, y3, x4, y4, x5, y5, marker = 'o')
        #         plt.plot(x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, marker = 'o')

        #         plt.plot(x1, y1, x2, y2, x3, y3, x4, y4, marker = 'o')
        #         plt.plot(x1, y1, x2, y2, x3, y3, marker = 'o')
        #         plt.plot(x1, y1, x2, y2, marker = 'o')

        plt.plot(x1, y1, marker='o', label="AC AB")
        plt.plot(x2, y2, marker='^', label="CD BD")
        plt.plot(x3, y3, marker='1', label="AE")
        plt.plot(x4, y4, marker='s', label="BF")
        plt.plot(x5, y5, marker='P', label="EF")

        #         plt.legend()
        #ref https://qiita.com/okadate/items/00227316187b60f861f5 "枠外に出す"
        plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0)

        # legend
        #ref https://matplotlib.org/users/legend_guide.html
        #         plt.legend(handles=[handle_AC_AB, handle_AE])
        #         plt.legend(handles=[line_up, line_down])
        '''###################
            save : image        
        ###################'''
        fname_Images_Out = "image.%s.%s.png" % (tlabel, plt_Title)

        fpath_Images_Out = "%s\\%s" % (dpath_Images_Out, fname_Images_Out)

        plt.savefig(fpath_Images_Out)

        # clear plot
        plt.clf()