예제 #1
0
 def run(self, log=False):
     # Algorithm from III. PROBLEM FORMULATION
     for k in range(self.time):  # this is step 4
         self.__step1(k)
         self.__step2(k)
         self.__step3(k)
     if log:
         prnt(self.__agents_history)
예제 #2
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_cancel_accept():
    print("\nIF_TR_CANCEL_ACCEPT")
    request_json = IF_TR_cancel_accept
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #3
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_cancel_order():
    print("\nIF_TR_CANCEL_ORDER")
    request_json = IF_TR_cancel_order
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #4
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_finish():
    print("\nIF_TR_FINISH")
    request_json = IF_TR_finish
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #5
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def id_retrieve():
    # print("\nIF_ID_RETRIEVE")
    request_json = IF_ID_retrieve
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #6
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def id_create():
    print("\nIF_ID_CREATE")
    request_json = IF_ID_create
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('PTM ==> BI: ')
    prnt(response)

    return response["parameter"]
예제 #7
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_list_ongoingEID():
    print("\nIF_TR_LIST_ONGOINGEID")
    request_json = IF_TR_list_ongoingEID
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #8
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_production_retrieveTotalVolume():
    print("\nIF_TR_PRODUCTION_RETRIEVETOTALVOLUME")
    request_json = IF_TR_production_retrieveTotalVolume
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #9
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_list_canceled():
    print("\nIF_TR_LIST_CANCELED")
    request_json = IF_TR_list_canceled
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #10
0
def check_letters(signs, digits):
    """ check_letters and ASK quit() or proceed scrolling """
    from pyprnt import prnt
    print("\nsigns = digits['x'] ..['2'] ..['0'] ..['2'] ..['0'] ..[!]")
    prnt(signs)

    print("\ndigits['x'] :")
    prnt(digits['x'])

    answer = "\n\n... To Continue ==> YES=[Enter] / NO=[!]: "
    if input(answer).startswith("!"):
        quit()
예제 #11
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_browse_dealIDSeller(eid):
    print("\nIF_TR_BROWSE_DEALIDSELLER")
    request_json = IF_TR_browse_dealIDSeller
    parameter_json = {"eid": str(eid)}
    request_json["parameter"] = json.dumps(parameter_json)
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #12
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_accept(buyer_eid):
    print("\nIF_TR_ACCEPT")
    request_json = IF_TR_accept
    parameter_json = {"order": str(buyer_eid)}
    request_json["parameter"] = json.dumps(parameter_json)
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #13
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_offer(quantity, price):
    print("\nIF_TR_OFFER")
    request_json = IF_TR_offer
    parameter_json = {"quantity": str(price), "price": str(quantity)}
    request_json["parameter"] = json.dumps(parameter_json)
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response
예제 #14
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def id_document(eid):
    print("\nIF_ID_DOCUMENT")
    request_json = IF_ID_document
    parameter_json = {"eid": str(eid)}
    request_json["parameter"] = json.dumps(parameter_json)
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #15
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_list_ordered(deal_id):
    print("\nIF_TR_LIST_ORDERED")
    request_json = IF_TR_list_ordered
    parameter_json = {"deal_id": str(deal_id)}
    request_json["parameter"] = json.dumps(parameter_json)
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #16
0
def endMsg():
    try:
        user = request.get_json()  #json 데이터를 받아옴
        prnt(user)
        if user["parameter"]["cm_type"] == "end":
            with open("ems_ed_msg.json", 'w') as ems_ed_msg:
                json.dump(user, ems_ed_msg, indent=4)
            return jsonify(IF_TR_endMsg)
        else:
            return jsonify(IF_TR_endMsg_error)

    except:
        return jsonify(IF_TR_endMsg_error)
예제 #17
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_production_retrieveHistory(eid):
    print("\nIF_TR_PRODUCTION_RETRIEVEHISTORY")
    request_json = IF_TR_production_retrieveHistory
    parameter_json = {"eid": str(eid)}
    request_json["parameter"] = json.dumps(parameter_json)
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #18
0
파일: 2_main.py 프로젝트: Ryul-K/ptm_test
def tr_production_record(kwh, production_time):
    print("\nIF_TR_PRODUCTION_RECORD")
    request_json = IF_TR_production_record
    parameter_json = {"kwh": str(kwh), "time": str(production_time)}
    request_json["parameter"] = json.dumps(parameter_json)
    print('PTM ==> BI: ')
    prnt(request_json)
    client.send(request_json)
    response = client.recv()
    print('BI ==> PTM: ')
    prnt(response)

    return response["parameter"]
예제 #19
0
 def test_dict_with_newline(self):
     # For python version 3.4 and below
     menu = collections.OrderedDict()
     menu["kimchi"] = 5000
     menu["Ice\nCream"] = "1 €\n1.08 $"
     testee = prnt(menu, output=True, width=50)
     expect = "┌──────────┬───────────┐\n│kimchi    │5000       │\n│Ice\\nCream│1 €\\n1.08 $│\n└──────────┴───────────┘"
     self.assertEqual(testee, expect)
예제 #20
0
 def test_dict_basic(self):
     # For python version 3.4 and below
     menu = collections.OrderedDict()
     menu["kimchi"] = 5000
     menu["Ice Cream"] = 100
     testee = prnt(menu, output=True, width=50)
     expect = "┌─────────┬────┐\n│kimchi   │5000│\n│Ice Cream│100 │\n└─────────┴────┘"
     self.assertEqual(testee, expect)
예제 #21
0
파일: test.py 프로젝트: why-shin/pyprnt
 def test_truncate_false(self):
     testee = prnt([
         "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz",
         12345678910
     ],
                   output=True,
                   width=50)
     expect = "┌─┬──────────────────────────────────────────────┐\n│0│abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst│\n│ │uvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmn│\n│ │opqrstuvwxyzabcdefghijklmnopqrstuvwxyz        │\n│1│12345678910                                   │\n└─┴──────────────────────────────────────────────┘"
     self.assertEqual(testee, expect)
    def get_instruction_info(self, current_step, group_info, connector_info):
        request = InstructionRequestType.get_instruction_info
        self.logger.info("Request {} to Instruction Module".format(request))
        sendall_pickle(self.c_instruction, request)
        response = recvall_pickle(self.c_instruction)
        assert response, "Not ready to get instruction info"
        # send group_info and get instruction info
        for group_id in group_info.keys():
            obj_path = group_info[group_id]["obj_file"]
            with open(obj_path, "r") as f:
                group_info[group_id]["obj_raw"] = f.readlines()
        request = {
            "current_step": current_step,
            "group_info": group_info,
            "connector_info": connector_info,
        }
        sendall_pickle(self.c_instruction, request)
        instruction_info = recvall_pickle(self.c_instruction)
        self.logger.info("Instruction info is")
        prnt(instruction_info)

        return instruction_info
예제 #23
0
def main(args):
    path = os.path.join('./data',args.dataset)
    h5Files = []
    print('\n \tLoading the ibw files...')

    for filename in tqdm([f for f in os.listdir(path) if f[-3:] == 'ibw']):
        if os.path.isfile(os.path.join(path, filename[:-3]+'h5')):
            h5 = ibw.ibw2h5(os.path.join(path, filename[:-3]+'h5'), exist=True)
        else:
            h5 = ibw.ibw2h5(os.path.join(path, filename))
        ImageObj = ibw.AngleImage(filename[:-4], h5)
        h5Files.append(ImageObj)
        if filename.split('_')[-1][:-4] == str(0):
            MidObj = ImageObj

    #MidObj = [obj for obj in h5Files if obj.angle == 0][0]
    h5Files = sorted(h5Files, key=lambda h5: h5.namedangle)
    angles = [obj.namedangle for obj in h5Files]
    angle_diff = list(set([j-i for i, j in zip(angles[:-1], angles[1:])]))

    if not len(angle_diff) == 1:
        print('Angle differences between images are not even!')
        ans = input('Which angle do you want to use for angle-resolving?')
        angle_diff = int(ans)
    else:
        angle_diff = angle_diff[0]
    print('\nDefined Angle between images is {}'.format(angle_diff))
    
    ## Channel Info
    TypeNum, channels = ibw.channel_list_folder(h5Files)
    if TypeNum == 1:
        print('\n Channel list')
        prnt(channels)
    else:
        type_dict, type_files, channel_type = channels
        print('\nThere are multiple types of files in the folder...')
        for key, val in type_dict.items():
            print('Type {}'.format(key))
            print('{} files in this type:\n{}'.format(len(val.split(',')), val))
            print('Channel List of Type {}'.format(key))
            prnt(channel_type[type_files[key-1]])
    channel_name = h5Files[0].ChannelName(args.channel)
    ans = input('Selected channel is [Channel_{0}:{1}]. \nDo you want to proceed?\n'.format(args.channel, channel_name))
    ans = ans.lower()
    if ans == 'y' or ans == 'ye' or ans == 'yes' or ans == '':
        TargetChannel = args.channel
    else:
        ans = input('\nPlease select channel Number or type any letter for exit.\n')
        try:
            TargetChannel = int(ans)
            channel_name = h5Files[0].ChannelName(TargetChannel)
            print('Selectd channel is [Channel_{0}:{1}].'.format(TargetChannel, channel_name))
        except:
            print('Aborted!')
            sys.exit(1)
    ## 시계 방향이 + 방향
    # Result information
    result_path = os.path.join(path, 'Results')
    mkfolder(result_path)
    ans = input('Choose image channel number for alignment\n')
    try:
        # If Flatten height image channel is exist,
        AlignChannel = int(ans)
        h5Files[0].ChannelName(AlignChannel)
    except:
        # Set alignment channel to Heightretrace
        print('Input channel has some problem, proceed with Heightretrace channel')
        AlignChannel = 2

    MidObj.alignimg = ibw.h5toimg(MidObj.data, AlignChannel)[0]
    MidObj.SaveBinaryImg(ibw.h5toimg(MidObj.data, TargetChannel)[0])
    
    print('\nCalculating...')
    
    for i in tqdm(range(len(h5Files))):
        h5file = h5Files[i]
        h5file.alignimg = ibw.h5toimg(h5file.data, AlignChannel)[0]
        if h5file.namedangle == 0:
            h5file.Piezoresponse(15, 13)
            continue
        else:
            h5file.trans, h5file.angle = alignment(h5file.alignimg, MidObj.alignimg, h5file.namedangle, args.mannual, score_threshold=0.9)
        ChannelImg = ibw.h5toimg(h5file.data, TargetChannel)[0]
        ChannelImg = imutils.translate(ChannelImg, h5file.trans[0], h5file.trans[1])
        ChannelImg = imutils.rotate(ChannelImg, h5file.angle)

        h5file.SaveBinaryImg(ChannelImg)
        h5file.Piezoresponse(15, 13, fix=True)

        h5Files[i] = h5file
    QuiverOriginsX, QuiverOriginsY, QuiverU, QuiverV = Vector(h5Files)
    plt.quiver(QuiverOriginsX, QuiverOriginsY, 10*QuiverU, 10*QuiverV, color='red')
    plt.savefig('./quivertest_noamp.png')
    plt.show()
    
    return 0
예제 #24
0
def main():
    dataset = input(
        'Please enter the name of dataset; "data/[Name of dataset]" \n')
    path = os.path.join('./data', dataset)
    h5Files = []
    print('Loading the ibw files...')

    for filename in tqdm([f for f in os.listdir(path) if f[-3:] == 'ibw']):
        if os.path.isfile(os.path.join(path, filename[:-3] + 'h5')):
            h5 = h5py.File(os.path.join(path, filename[:-3] + 'h5'), 'r')
            h5 = h5['Measurement_000/']
        else:
            h5 = ibw.ibw2h5(os.path.join(path, filename))
        ImageObj = ibw.AngleImage(filename[:-4], h5)
        h5Files.append(ImageObj)
    h5Files = sorted(h5Files, key=lambda h5: h5.namedangle)

    channel = input(
        'Please enter the channel to convert \n If you want to check list of channel, input 999 \n'
    )

    if channel == str(999):
        TypeNum, channels = ibw.channel_list_folder(h5Files)
        if TypeNum == 1:
            print('\nChannel List of {} Folder'.format(dataset))
            prnt(channels)
        else:
            type_dict, type_files, channel_type = channels
            print('\nThere are multiple types of files in the folder...')
            for key, val in type_dict.items():
                print('Type {}'.format(key))
                print('{} files in this type:\n{}'.format(
                    len(val.split(',')), val))
                print('Channel List of Type {}'.format(key))
                prnt(channel_type[type_files[key - 1]])
        a = input('Press enter to exit...')
    elif channel == str(998):
        channels = ibw.channel_list(h5Files[0].data)
        ampchannel = input('Please enter the amplitude channel number:\n')
        try:
            ampchannel = int(ampchannel)
        except:
            print('Please enter channel number as integer!! \n Exiting!')
            sys.exit(1)
        phasechannel = input('Plaes enter the phase channel number:\n')
        try:
            phasechannel = int(phasechannel)
        except:
            print('Please enter channel number as integer!! \n Exiting!')
            sys.exit(1)
        PhaseChannelName = channels['Channel_' + str(phasechannel).zfill(3)]
        AmpChannelName = channels['Channel_' + str(ampchannel).zfill(3)]

        norm = input('Do you want to normalize images?')
        ImagePath = os.path.join(path, 'Images')
        if PhaseChannelName[:3] == 'Lat' and AmpChannelName[:3] == 'Lat':
            if func_yes(norm):
                ChannelPath = os.path.join(ImagePath, 'LatPiezoNorm')
            else:
                ChannelPath = os.path.join(ImagePath, 'LatPiezo')
            print('Selected channel is Lateral Piezoresponse images.')
        elif PhaseChannelName[:
                              5] == 'Phase' and AmpChannelName[:
                                                               9] == 'Amplitude':
            if func_yes(norm):
                ChannelPath = os.path.join(ImagePath, 'VerPiezoNorm')
            else:
                ChannelPath = os.path.join(ImagePath, 'VerPiezo')
            print('Selected channel is Vertical Piezoresponse images.')
        else:
            print('Please match the channel type! \n Exiting!')
            sys.exit(1)
        mkfolder(ImagePath)
        mkfolder(ChannelPath)
        for idx in range(len(h5Files)):
            if func_yes(norm):
                PiezoImg = h5Files[idx].NormPiezoresponse(
                    phasechannel, ampchannel)
            else:
                PiezoImg = h5Files[idx].Piezoresponse(phasechannel, ampchannel)
            plt.imsave(os.path.join(ChannelPath,
                                    h5Files[idx].imagename + '.png'),
                       PiezoImg,
                       cmap='gray')
            print(h5Files[idx].imagename + '.png', 'is saved!')
        a = input('Press enter to exit...')
    else:
        channels = ibw.channel_list(h5Files[0].data)
        if not channel:
            print('You have to designate channel! \n')
            sys.exit(1)

        ChannelName = channels['Channel_' + str(channel).zfill(3)]
        print('Selected channel name: ', ChannelName)

        ImagePath = os.path.join(path, 'Images')
        flatten = input('Do you want to do flatten?')
        if func_yes(flatten):
            ChannelPath = os.path.join(ImagePath, ChannelName + '_Flatten')
        else:
            ChannelPath = os.path.join(ImagePath, ChannelName)
        mkfolder(ImagePath)
        mkfolder(ChannelPath)

        for idx in range(len(h5Files)):
            img, cmap_img = ibw.h5toimg(h5Files[idx].data, str(channel))
            if func_yes(flatten):
                img = ibw.ImageFlatten(img, int(flatten))
            plt.imsave(os.path.join(ChannelPath,
                                    h5Files[idx].imagename + '.png'),
                       img,
                       cmap=cmap_img)
            print(h5Files[idx].imagename + '.png', 'is saved!')
        a = input('Press enter to exit...')
예제 #25
0
파일: test.py 프로젝트: why-shin/pyprnt
 def test_depth_2_basic(self):
     testee = prnt([[[]], []], depth=2, output=True, width=50)
     print(repr(testee))
     expect = "┌─┬──────┐\n│0│┌─┬──┐│\n│ ││0│[]││\n│ │└─┴──┘│\n│1│[]    │\n└─┴──────┘"
     self.assertEqual(testee, expect)
예제 #26
0
파일: test.py 프로젝트: why-shin/pyprnt
 def test_depth_1_complex(self):
     testee = prnt([[[{}]], []], depth=1, output=True, width=50)
     expect = "┌─┬──────┐\n│0│[[{}]]│\n│1│[]    │\n└─┴──────┘"
     self.assertEqual(testee, expect)
예제 #27
0
파일: test.py 프로젝트: why-shin/pyprnt
 def test_depth_infinity_complex(self):
     testee = prnt([[[{}]], []], output=True, width=50)
     expect = "┌─┬──────────┐\n│0│┌─┬──────┐│\n│ ││0│┌─┬──┐││\n│ ││ ││0│{}│││\n│ ││ │└─┴──┘││\n│ │└─┴──────┘│\n│1│[]        │\n└─┴──────────┘"
     self.assertEqual(testee, expect)
예제 #28
0
파일: test.py 프로젝트: why-shin/pyprnt
 def test_both_true(self):
     creation = ['Adam', 'Eve']
     testee = prnt(creation, both=True, output=True, width=50)
     expect = "['Adam', 'Eve']\n┌─┬────┐\n│0│Adam│\n│1│Eve │\n└─┴────┘"
     self.assertEqual(testee, expect)
예제 #29
0
파일: test.py 프로젝트: why-shin/pyprnt
 def test_enable_false(self):
     creation = ['Adam', 'Eve']
     testee = prnt(creation, enable=False, output=True, width=50)
     expect = "['Adam', 'Eve']"
     self.assertEqual(testee, expect)
예제 #30
0
파일: test.py 프로젝트: why-shin/pyprnt
 def test_list_basic(self):
     creation = ["Adam", "Eve"]
     testee = prnt(creation, output=True, width=50)
     expect = "┌─┬────┐\n│0│Adam│\n│1│Eve │\n└─┴────┘"
     self.assertEqual(testee, expect)