コード例 #1
0
    def process(self):
        if self.label[0].endswith('Hz'):
            self.x_value = range(10, 90, 10)
            self.label_x = language('频率 / MHz', 'Frequency (MHz)')
        elif self.label[0].startswith('ec') or self.label[0].startswith('lc'):
            self.x_value = range(32, 32 * 9, 32)
            self.label_x = language('阵元数目', 'Number of Elements')
        elif self.label[0].startswith('rc'):
            self.x_value = range(512, 256 * 9, 256)
            self.label_x = language('图像行数', 'Number of Rows')
        else:
            pass

        if self.maximum > 10000:
            for line in self.lines:
                line['line'] = [num / 1000 for num in line['line']]
            self.label_y = language('时间 / 秒', 'Time (s)')
        else:
            self.label_y = language('时间 / 毫秒', 'Time (ms)')

        self.update()
コード例 #2
0
def main():
    try:
        if len(sys.argv) == 2:
            extension = (sys.argv[1]).split(".")
            if extension[len(extension) - 1] == "C" or extension[
                    len(extension) - 1] == 'c' or extension[len(extension) -
                                                            1] == 'cpp':
                with open(sys.argv[1], "r") as File:
                    from C import C_Keywords, C_Punctuation, C_Comment
                    lang = language(C_Keywords, C_Punctuation, "#", C_Comment,
                                    "C")
                    SyntaxParser(lang, File.read())
            else:
                with open(sys.argv[1], "r") as File:
                    print(File.read())
        else:
            print("No arguments passed!")
    except FileNotFoundError as error:
        print(error)
コード例 #3
0
ファイル: plumber.py プロジェクト: ideoforms/subvertle
	def __init__(self,pipelist):
		self.pipeline = None
		for pipe in pipelist:
			print pipe
			if (pipe=="expletive"):
				self.pipeline = expletive({}, self.pipeline)
			elif (pipe=="cockney"):
				self.pipeline = swap({'map':'cockney'}, self.pipeline)
			elif (pipe=="lolspeak"):
				self.pipeline = swap({'map':'lolspeak'}, self.pipeline)
			elif (pipe=="piglatin"):
				self.pipeline = piglatin({}, self.pipeline)
			elif (pipe=="opera"):
				self.pipeline = opera({}, self.pipeline)
			#elif (pipe=="language"):
				# need something pretty clever here for efficiency
				# there should be caching and the like
				#print "Error: Not done yet"
				#self.pipeline = language(, self.pipeline)
			else:
				self.pipeline = language({'languages':pipe}, self.pipeline)
コード例 #4
0
ファイル: quality.py プロジェクト: nlroel/field-ii-python
w = widgets.QualityChart()
if 'SA' in configs[0]:
    w.method = 'SA'
    w.reversed_method = 'RSA'
else:
    w.method = 'DAS'
    w.reversed_method = 'RDAS'

for device_name, value in results.items():
    value.sort()
    l = list(map(lambda v: v.split('_'), value))
    label, nums = zip(*l)
    nums = list(map(float, nums))
    print(label, nums)

    depth, name = device_name[:4], device_name[5:]
    is_dash = name == 'NRDAS' or name == 'reversed_synthetic_aperture'

    shape = 'circle' if depth == '25mm' else 'square'
    w.add_line(label, nums, shape, is_dash)

if 'contrast' in configs[0]:
    w.label_y = language('对比度', 'Contrast')
else:
    w.label_y = language('半峰全宽 / mm', 'FWHM (mm)')
w.process()

w.export_to_image(output_filename)
if show:
    w.exec()
コード例 #5
0
    def paint(self, painter: Painter):
        painter.setFont(QFont(language('SimSun', 'Times New Roman'), 12))

        w = self.width()
        h = self.height()
        text_width = int(30 * scaling.ratio)
        text_height = int(20 * scaling.ratio)

        painter.drawText(QRect(0, h - text_height, w, text_height),
                         Qt.AlignCenter, self.label_x)
        # translate and rotate for paint vertical text
        painter.save()
        painter.translate(0, h)
        painter.rotate(-90)
        painter.drawText(QRect(0, 0, h, text_height), Qt.AlignCenter,
                         self.label_y)
        painter.restore()

        # calculate min and max values #
        x_min = min(self.x_value)
        x_max = max(self.x_value)

        y_min = math.floor(self.minimum / 100) * 100
        y_max = math.ceil(self.maximum / 100) * 100

        horizontal_min = text_height + text_width
        horizontal_max = w - text_width / 2
        vertical_min = h - text_height * 2
        vertical_max = text_height

        # draw text on axis #
        horizontal_labels = list(map(str, self.x_value))
        horizontal_values = list(
            np.linspace(horizontal_min, horizontal_max,
                        len(horizontal_labels)))
        for horizontal_x, label in zip(horizontal_values, horizontal_labels):
            if label == horizontal_labels[0] or label == horizontal_labels[-1]:
                painter.setPen(
                    Pen(QBrush(Qt.black), 1.5, Qt.SolidLine, Qt.RoundCap,
                        Qt.RoundJoin))
            else:
                painter.setPen(
                    Pen(QBrush(Qt.black), 0.8, Qt.DotLine, Qt.RoundCap,
                        Qt.RoundJoin))

            current_point = PointF(horizontal_x, vertical_min)
            painter.draw_text_bottom(current_point, label, margin=2)
            painter.drawLine(current_point, PointF(horizontal_x, vertical_max))

        interval = (y_max - y_min) / 10
        vertical_labels = list(
            map(lambda v: '{:.0f}'.format(v),
                np.arange(y_min, y_max + 1, interval)))
        vertical_values = list(
            np.linspace(vertical_min, vertical_max, len(vertical_labels)))
        for vertical_pos, label in zip(vertical_values, vertical_labels):
            if label == vertical_labels[0] or label == vertical_labels[-1]:
                painter.setPen(
                    Pen(QBrush(Qt.black), 1.5, Qt.SolidLine, Qt.RoundCap,
                        Qt.RoundJoin))
            else:
                painter.setPen(
                    Pen(QBrush(Qt.black), 0.8, Qt.DotLine, Qt.RoundCap,
                        Qt.RoundJoin))

            current_point = PointF(horizontal_min, vertical_pos)

            if label != vertical_labels[0]:
                painter.draw_text_left(current_point, label)
            painter.drawLine(current_point, PointF(horizontal_max,
                                                   vertical_pos))

        for line in self.lines:
            previous_point = None
            nums = line['line']

            shape = line['shape']
            shape_func = getattr(self, 'draw_{}'.format(shape))
            l = Qt.DotLine if line['is_dash'] else Qt.SolidLine

            for x, y in zip(self.x_value, nums):
                percent_x = (x - x_min) / (x_max - x_min)
                percent_y = (y - y_min) / (y_max - y_min)
                horizontal_pos = horizontal_max * percent_x + horizontal_min * (
                    1 - percent_x)
                vertical_pos = vertical_max * percent_y + vertical_min * (
                    1 - percent_y)
                current_point = PointF(horizontal_pos, vertical_pos)

                shape_func(painter, current_point)
                if previous_point:
                    painter.setPen(
                        Pen(QBrush(Qt.black), 1.5, l, Qt.RoundCap,
                            Qt.RoundJoin))
                    painter.drawLine(previous_point, current_point)
                previous_point = current_point

        left_top = PointF(horizontal_min, vertical_max) + SizeF(5, 5)
        painter.setBrush(Qt.white)
        painter.setPen(
            Pen(Qt.black, 1.0, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawRect(QRectF(left_top, SizeF(162, 50)))

        current = left_top + SizeF(10, 10)
        painter.setPen(
            Pen(QBrush(Qt.black), 1.5, Qt.SolidLine, Qt.RoundCap,
                Qt.RoundJoin))
        painter.drawLine(current - SizeF(7, 0), current + SizeF(7, 0))
        self.draw_square(painter, current)
        painter.draw_text_right(current,
                                '{}-{}'.format(self.method,
                                               language('设备1', 'i7')),
                                margin=12)

        current += SizeF(0, 15)
        painter.drawLine(current - SizeF(7, 0), current + SizeF(7, 0))
        self.draw_triangle(painter, current)
        painter.draw_text_right(current,
                                '{}-{}'.format(self.method,
                                               language('设备2', 'i5')),
                                margin=12)

        current += SizeF(0, 15)
        painter.drawLine(current - SizeF(7, 0), current + SizeF(7, 0))
        self.draw_circle(painter, current)
        painter.draw_text_right(current,
                                '{}-{}'.format(self.method,
                                               language('设备3', 'TX1')),
                                margin=12)

        current = left_top + SizeF(90, 10)
        painter.setPen(
            Pen(QBrush(Qt.black), 1.5, Qt.DotLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(current - SizeF(7, 0), current + SizeF(7, 0))
        self.draw_square(painter, current)
        painter.draw_text_right(current,
                                '{}-{}'.format(self.reversed_method,
                                               language('设备1', 'i7')),
                                margin=12)

        current += SizeF(0, 15)
        painter.setPen(
            Pen(QBrush(Qt.black), 1.5, Qt.DotLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(current - SizeF(7, 0), current + SizeF(7, 0))
        self.draw_triangle(painter, current)
        painter.draw_text_right(current,
                                '{}-{}'.format(self.reversed_method,
                                               language('设备2', 'i5')),
                                margin=12)

        current += SizeF(0, 15)
        painter.setPen(
            Pen(QBrush(Qt.black), 1.5, Qt.DotLine, Qt.RoundCap, Qt.RoundJoin))
        painter.drawLine(current - SizeF(7, 0), current + SizeF(7, 0))
        self.draw_circle(painter, current)
        painter.draw_text_right(current,
                                '{}-{}'.format(self.reversed_method,
                                               language('设备3', 'TX1')),
                                margin=12)

        painter.end()
コード例 #6
0
import etl
import helpers
import random
import time
import torch
import torch.nn as nn
import torch.optim as optim
from torch.autograd import Variable
import math
from attention_decoder import AttentionDecoderRNN
from encoder import EncoderRNN
import language
import os

language = 'insta_hashtag'
helpers.validate - language(language)

teacher_forcing_ratio = 0.5
clip = 5
device = torch.device('cuda:0')


def train(input_var, target_var, encode, decoder, encoder_opt, decoder_opt,
          criterion):
    encoder_opt.zero_grad()
    decoder_opt.zero_grad()
    loss = 0

    target_length = target_var.size()[0]

    encoder_hidden = encoder.init_hidden()
コード例 #7
0
import utils
from parser import *
from compiler import *
from language import *

if __name__ == "__main__":
    string = utils.load_file("code.txt")
    data = parse(string)

    s = []
    for my_node in data:
        s.append(str(my_node))

    print("[" + ", ".join(s) + "]")
    print()

    lang = input("language: ")

    my_language = language("languages/" + lang + ".txt")
    my_compiler = compiler(my_language)
    out = my_compiler.get_code(data)
    print(out)

    utils.save_file("output" + my_language.data["file_ending"], out)
コード例 #8
0
    def paint(self, painter: Painter):
        font_size = language(47, 32)
        painter.setFont(QFont(language('SimSun', 'Times New Roman'),
                              font_size))
        if self.u_image is None:
            return

        w, h = self.size
        text_size = (95 * font_size // 40, 45 * font_size // 40)
        text_width, text_height = text_size
        image_width, image_height = self.u_image.size

        expected_h = int(w / image_width * image_height)
        if expected_h > h:
            expected_w = int(h / image_height * image_width)
            painter.translate((w - expected_w) // 2, 0)
            w = expected_w
        else:
            painter.translate(0, (h - expected_h) // 2)
            h = expected_h

        painter.save()
        painter.translate(0, h)
        painter.rotate(-90)
        painter.drawText(QRect(0, 0, h, text_height), Qt.AlignCenter,
                         language('深度 / mm', 'Axial distance (mm)'))
        painter.restore()
        w -= text_width
        h -= text_height * 2
        painter.translate(text_width, text_height / 3)

        half_image_width = image_width / 2
        for x in np.arange(0, half_image_width + 1e-5, 10):
            percent = (half_image_width + x) / image_width

            painter.drawLine(PointF(w * percent, h),
                             PointF(w * percent, h + 4))
            painter.draw_text_bottom(PointF(w * percent, h),
                                     "{}".format(int(x)),
                                     margin=5,
                                     background_color=Qt.transparent)

            if x == 0:
                painter.draw_text_bottom(PointF(w * percent, h),
                                         language("宽度 / mm",
                                                  "Lateral distance (mm)"),
                                         margin=8 + text_height,
                                         background_color=Qt.transparent)
            else:
                percent = 1 - percent
                painter.drawLine(PointF(w * percent, h),
                                 PointF(w * percent, h + 4))
                painter.draw_text_bottom(PointF(w * percent, h),
                                         "{}".format(-int(x)),
                                         margin=5,
                                         background_color=Qt.transparent)

        z_start = self.u_image.z_start
        for y in np.arange(0, image_height + 1e-5, 10):
            percent = y / image_height

            painter.drawLine(PointF(0, h * percent), PointF(-4, h * percent))
            painter.draw_text_left(PointF(0, h * percent),
                                   "{}".format(int(y + z_start)),
                                   margin=8,
                                   background_color=Qt.transparent)

        painter.drawLine(PointF(0, 0), PointF(0, h))
        painter.drawLine(PointF(0, 0), PointF(w, 0))

        painter.drawImage(QRect(0, 0, w, h), self.qim)