Ejemplo n.º 1
0
    def main(self):
        #1) basic initialization
        pygame.init()

        #so that key holds can be recognized.
        pygame.key.set_repeat(17, 17)

        self.screen = pygame.display.set_mode(self.size)
        pygame.display.set_caption('Smoothie Maker')
        #counter of ticks
        self.current_ticks = 0

        #2 set up game objects
        self.clock = pygame.time.Clock()

        #create the blender object that represents you
        self.blender = Blender(self,
                               hspeed=7.0,
                               playerNumber=self.playerNumber,
                               playerType='user')

        opponentPlayerNumber = 1
        if self.playerNumber == 1:
            opponentPlayerNumber = 2

        #create the blender object that represents your opponent
        self.opponent = Blender(self,
                                hspeed=7.0,
                                playerNumber=opponentPlayerNumber,
                                playerType='opponent')

        self.scoreLabel = ScoreLabel(self, playerType='user')
        self.scoreLabelOpponent = ScoreLabel(self, playerType='opponent')

        self.youLabel = PlayerLabel(self,
                                    textLabel="You",
                                    xpos=self.width / 4,
                                    ypos=40,
                                    size=50)
        self.oppLabel = PlayerLabel(self,
                                    textLabel="Opponent",
                                    xpos=3 * self.width / 4,
                                    ypos=40,
                                    size=50)

        self.gameObjectsList = list()
        self.gameObjectsList.append(self.blender)
        self.gameObjectsList.append(self.opponent)

        self.gameLabels = list()
        self.gameLabels.append(self.scoreLabel)
        self.gameLabels.append(self.scoreLabelOpponent)
        self.gameLabels.append(self.youLabel)
        self.gameLabels.append(self.oppLabel)
Ejemplo n.º 2
0
    def __init__(self, args):

        self.blender = Blender('vitamix')
        # initialized, to be defined later
        #
        self.data_multibar = None
        self.data_stackedarea = None
        self.data_pie = None
        self.data_scatter_continuous = None
        self.all_plot_types = None
        self.difference_domains_multibar = None
        self.warning_multibar = None
        self.warning_stackedarea = None
        self.line_data = None

        # first to be initialized
        self.new_variable = None
        self.variable_list_string = None
        self.number_of_variables = None

        self.unique_plottypes = None

        # err msgs
        self.error_found = False
        self.err_msg = None

        self.calculate_stats(args)
Ejemplo n.º 3
0
def step(context, thing):
    context.blender = Blender()
    context.blender.add(thing)
Ejemplo n.º 4
0
def step_1(context, browser_page):
    #context.browser.get("https://crash-stats.mozilla.com/")
    context.blender = Blender()
    #context.blender.add(browser_page)
    context.browser.get(browser_page)
Ejemplo n.º 5
0
def step_given_put_thing_into_blender(context, thing):
    context.blender = Blender()
    context.blender.add(thing)
Ejemplo n.º 6
0
from blender import Blender
from improc_utils import *
from mask_generator import MaskGenerator

if __name__ == '__main__':
    pyr_blender = Blender(kernel_size=5)
    mask_gen = MaskGenerator()

    im1 = open_image('d:/lenna.png', rgb=False)
    im2 = open_image('d:/face.jpg', rgb=False)
    mask = mask_gen.split(0.5, 'h', shaped_like=im1)

    blended = pyr_blender.blend(im1, im2, mask)
    mixed = pyr_blender.mix(im1, im2, mask)

    display_many([blended, mixed])

Ejemplo n.º 7
0
    def do_fit(self):

        _, _, _, blend_valuelist, blend_frequencylist = blendframe.blendlist
        subblend_valuelist = blend_valuelist[subblendframe.selected_subblend]
        subblend_frequencylist = blend_frequencylist[
            subblendframe.selected_subblend]

        listsize = len(subblend_valuelist)
        self.rangelist = self.get_range()
        lowerx, upperx = self.rangelist

        index = listsize - 1
        while index > -1 and not subblend_valuelist[index] < lowerx:
            index = index - 1
        index = index + 1
        lowerindex = index
        index = 0
        while index < listsize and not subblend_valuelist[index] > upperx:
            index = index + 1
        index = index - 1
        upperindex = index

        indexlist = [lowerindex, upperindex]

        self.boolfit = False
        if not len(blendframe.blendlist) > 0:
            print("There is not a blend selected.")
            return

        self.listboxsize = listboxframe.listbox.size()
        if not self.listboxsize > 0:
            print("There is not a coke added.")
            return

        lowerconstraintlist = []
        upperconstraintlist = []
        for listindex in range(self.listboxsize):
            listboxitem = listboxframe.listbox.get(listindex)
            splitlist = listboxitem.split('[')
            splitlist = splitlist[1].split(']')
            constraint = splitlist[0]
            splitlist = constraint.split("≤")
            lowerconstraintlist.append(float(splitlist[0].strip()))
            upperconstraintlist.append(float(splitlist[2].strip()))
        constraintlist = [lowerconstraintlist, upperconstraintlist]
        blender = Blender(blendframe.blendlist, cokeframe.allcokelist,
                          subblendframe.selected_subblend, constraintlist,
                          indexlist)

        fitchoicevalue = self.fitchoicevar.get()
        if fitchoicevalue == 0:
            blender.qp_fit()
        else:
            blender.grid_fit(int(self.spacevar.get()))

        self.volumelist = blender.volumelist
        self.fit_frequencylist = [0.0] * 256
        for listindex in range(self.listboxsize):
            _, _, _, _, coke_frequencylist = cokeframe.allcokelist[listindex]
            subcoke_frequencylist = coke_frequencylist[
                subblendframe.selected_subblend]
            for k in range(256):
                self.fit_frequencylist[
                    k] = self.fit_frequencylist[k] + self.volumelist[
                        listindex] / 100.0 * subcoke_frequencylist[k]

        self.sumerror = 0.0
        for k in range(lowerindex, upperindex + 1, 1):
            self.sumerror = self.sumerror + (self.fit_frequencylist[k] -
                                             subblend_frequencylist[k])**2

        self.plot_fit()
        self.show_fit()
        self.boolfit = True
print "Shape: ", test_data.shape
#get training_data

training_data = pandas.load("../TrainingData.pickle")
print "Training data in."
#training_location_data = training_data[ ['LATITUDE', 'LONGITUDE' ] ]
#training_response = training_data['Mail_Return_Rate_CEN_2010']
#training_weights = training_data['weight']
training_data, training_location_data, training_response, training_weights = preprocess_dataframe(
    training_data)

print "Shape: ", training_data.shape

### CREATE MODEL ###
bl = Blender(verbose=True, training_fraction=0.95)

bl.add_model(
    lclR.LocalRegression(k=500, regressor=SmartSVR, params={'gamma': 0.0001}),
    "SmrtSVR")
bl.add_model(
    lclR.LocalRegression(k=500,
                         regressor=SmartSVR,
                         params={
                             'gamma': 0.001,
                             "C": 50
                         }), "LooseSmrtSVR")
bl.add_model(
    lclR.LocalRegression(k=500,
                         regressor=sklm.ElasticNet,
                         params={
Ejemplo n.º 9
0
                ------------------------
                """)
                choice = input("Enter choice: ")

                if choice == EXIT:
                    break

                elif choice == CREATE_OBJECT:
                    print("All data is optional")

                    manufacturer = input(
                        "Enter the manufacturer of the blender: ")

                    blender_type = input("Enter the blender type: ")

                    blender = Blender(manufacturer=manufacturer,
                                      blender_type=blender_type)

                    print(blender)
                    input("Press Enter to continue...")

                elif choice == PRINT_OBJECT:
                    try:
                        print(blender)
                    except NameError:
                        print("Error: Please create the object of the blender")
                    input("Press Enter to continue...")

                elif choice == EDIT_FIELDS:
                    try:
                        blender.manufacturer = input(
                            f"Enter the manufacturer of the blender ({blender.manufacturer} - default): "
Ejemplo n.º 10
0
def main(n_blends, excluded_type, mag_low, mag_high, mag_diff, rad_diff,
         test_ratio, datapath, seed):
    """
    Produce stamps of CANDELS blended galaxies with their individual masks
    """
    # Define the various paths and create directories
    cwd = Path.cwd()
    datapath = cwd / datapath
    input_stamps = datapath / "candels_img.npy"
    input_segmaps = datapath / "candels_seg.npy"
    input_catalog = datapath / "candels_cat.csv"

    outdir = cwd / f"output-s_{seed}-n_{n_blends}"
    if not outdir.exists():
        outdir.mkdir()
    outlog = outdir / "candels-blender.log"

    logging.basicConfig(
        filename=outlog,
        level=logging.INFO,
        format="%(asctime)s [ %(levelname)s ] : %(message)s",
    )

    blender = Blender(
        input_stamps,
        input_segmaps,
        input_catalog,
        train_test_ratio=test_ratio,
        magdiff=mag_diff,
        raddiff=rad_diff,
        seed=seed,
    )

    logger = logging.getLogger(__name__)
    logger.info(
        "\n"
        "Configuration\n"
        "=============\n"
        f"Number of blends: {n_blends}\n"
        f"Seed: {seed}\n"
        "\n"
        "Catalog cuts\n"
        "------------\n"
        f"Excluded galaxy types: {excluded_type}\n"
        f"Lowest magnitude: {mag_low}\n"
        f"Highest magnitude: {mag_high}\n"
        "\n"
        "Blend properties\n"
        "----------------\n"
        f"Top difference in magnitude between galaxies: {mag_diff}\n"
        f"Top distance between galaxies as a fraction of radius: {rad_diff}\n")

    # Apply cuts to the galaxy catalog
    click.echo(
        f"Selecting galaxies in the magnitude range {mag_low} < m < {mag_high}"
    )
    blender.make_cut(blender.cat.mag > mag_low)
    blender.make_cut(blender.cat.mag < mag_high)
    for galtype in set(excluded_type):
        click.echo(f"Excluding {galtype} galaxies")
        blender.make_cut(blender.cat.galtype != galtype)

    click.echo(
        f"After the cuts, there are {blender.n_gal} individual galaxies "
        "left in the catalog.")

    # Compute the train/test splits
    n_test = int(test_ratio * n_blends)
    n_train = n_blends - n_test

    create_image_set(blender, n_train, outdir)
    create_image_set(blender, n_test, outdir, test_set=True)

    click.echo(message=f"Images stored in {outdir}")