Example #1
0
def main(options):

    global program
    program = propyte.Program(
        options = options,
        name    = name,
        version = version,
        logo    = logo
    )
    global log
    from propyte import log

    log.info("")

    input_data_filename = options["--data"]

    log.info("input data file: {filename}".format(
        filename = input_data_filename
    ))

    log.debug("start to print log messages at various levels")

    log.debug("message at level DEBUG")
    log.info("message at level INFO")
    log.warning("message at level WARNING")
    log.error("message at level ERROR")
    log.critical("message at level CRITICAL")

    log.debug("stop printing log messages at various levels")

    function_1()

    log.info("")

    program.terminate()
Example #2
0
def main(options):

    global program
    program = propyte.Program(options=options,
                              name=name,
                              version=version,
                              logo=logo)
    global log
    from propyte import log

    log.info("")

    input_data_filename = options["--data"]

    log.info(
        "input data file: {filename}".format(filename=input_data_filename))

    log.debug("start to print log messages at various levels")

    log.debug("message at level DEBUG")
    log.info("message at level INFO")
    log.warning("message at level WARNING")
    log.error("message at level ERROR")
    log.critical("message at level CRITICAL")

    log.debug("stop printing log messages at various levels")

    function_1()

    log.info("")

    program.terminate()
Example #3
0
File: spin.py Project: Ciemaar/spin
 def display_orientation(self, orientation=None):
     if orientation in ["left", "right", "inverted", "normal"]:
         log.info("change display to {orientation}".format(
             orientation=orientation))
         engage_command(
             "xrandr -o {orientation}".format(orientation=orientation))
     else:
         log.error("unknown display orientation \"{orientation}\" "
                   "requested".format(orientation=orientation))
         sys.exit()
def main(options):

    global program
    program = propyte.Program(options=options,
                              name=name,
                              version=version,
                              logo=logo)
    global log
    from propyte import log

    print("")

    filename_ROOT = options["--fileroot"]
    name_tree = options["--tree"]

    if not os.path.isfile(os.path.expandvars(filename_ROOT)):
        log.error("file {filename} not found".format(filename=filename_ROOT))
        program.terminate()

    file_ROOT = abstraction.open_ROOT_file(filename_ROOT)
    tree = file_ROOT.Get(name_tree)

    number_entries = tree.GetEntries()
    names_variables = [
        variable.GetName() for variable in tree.GetListOfBranches()
    ]
    names_variables = shijian.natural_sort(names_variables)
    names_objects = [key.GetName() for key in file_ROOT.GetListOfKeys()]
    names_objects = shijian.natural_sort(names_objects)

    log.info(
        textwrap.dedent("""
        input ROOT file:   {filename_ROOT}
        number of entries: {number_entries}
        """.format(filename_ROOT=filename_ROOT,
                   number_entries=number_entries)))

    log.info("variables:")
    print("")
    for name_variable in names_variables:
        log.info("    " + name_variable)

    print("")
    log.info("objects:")
    print("")
    for name_object in names_objects:
        log.info("    " + name_object)

    #print("")
    #log.info("tree printout:")
    #print("")
    #tree.Print()
    #print("")

    program.terminate()
Example #5
0
File: spin.py Project: Ciemaar/spin
 def acceleration_control_switch(self, status=None):
     if status == "on":
         log.info("change acceleration control to on")
         self.process_acceleration_control = multiprocessing.Process(
             target=self.acceleration_control)
         self.process_acceleration_control.start()
     elif status == "off":
         log.info("change acceleration control to off")
         self.process_acceleration_control.terminate()
     else:
         log.error("unknown acceleration control status \"{status}\" "
                   "requested".format(status=status))
         sys.exit()
Example #6
0
File: spin.py Project: Ciemaar/spin
 def stylus_proximity_control_switch(self, status=None):
     if status == "on":
         log.info("change stylus proximity control to on")
         self.process_stylus_proximity_control = multiprocessing.Process(
             target=self.stylus_proximity_control)
         self.process_stylus_proximity_control.start()
     elif status == "off":
         log.info("change stylus proximity control to off")
         self.process_stylus_proximity_control.terminate()
     else:
         log.error("unknown stylus proximity control status \"{status}\" "
                   "requested".format(status=status))
         sys.exit()
Example #7
0
File: spin.py Project: Ciemaar/spin
 def display_position_control_switch(self, status=None):
     if status == "on":
         log.info("change display position control to on")
         self.process_display_position_control = multiprocessing.Process(
             target=self.display_position_control)
         self.process_display_position_control.start()
     elif status == "off":
         log.info("change display position control to off")
         self.process_display_position_control.terminate()
     else:
         log.error(
             "unknown display position control status \"{orientation}\" "
             "requested".format(status=status))
         sys.exit()
Example #8
0
File: spin.py Project: Ciemaar/spin
 def nipple_switch(self, status=None):
     if "nipple" in self.names_devices:
         status_xinput = {"on": "enable", "off": "disable"}
         if status_xinput.has_key(status):
             log.info("change nipple to {status}".format(status=status))
             engage_command("xinput {status} \"{name_device}\"".format(
                 status=status_xinput[status],
                 name_device=self.names_devices["nipple"]))
         else:
             _message = "unknown nipple status \"{status}\" " +\
                        "requested"
             log.error(_message.format(status=status))
             sys.exit()
     else:
         log.debug("nipple status unchanged")
Example #9
0
def main(options):

    global program
    program = propyte.Program(options=options,
                              name=name,
                              version=version,
                              logo=logo)
    global log
    from propyte import log

    print("")

    filename_CSV_input = options["--infile"]
    filename_CSV_output = options["--outfile"]

    if not os.path.isfile(os.path.expandvars(filename_CSV_input)):
        log.error(
            "file {filename} not found".format(filename=filename_CSV_input))
        program.terminate()

    log.info("read CSV from {filename}".format(filename=filename_CSV_input))
    data = pd.read_csv(filename_CSV_input)

    scaler = sklearn.preprocessing.MinMaxScaler(feature_range=(-1, 1))

    number_of_columns = data.shape[1]
    indices_of_feature_columns = range(0, number_of_columns - 1)

    # scale feature columns
    log.info("scale features")
    data[indices_of_feature_columns] = scaler.fit_transform(
        data[indices_of_feature_columns])

    log.info(
        "save scaled CSV to {filename}".format(filename=filename_CSV_output))
    data.to_csv(
        filename_CSV_output,
        index=False,
        #header = False
    )

    print("")

    program.terminate()
Example #10
0
def main(options):

    filename_log = options["--logfile"]

    global program
    program = propyte.Program(options=options,
                              name=name,
                              version=version,
                              logo=logo,
                              filename_log=filename_log)
    global log
    from propyte import log

    log.debug("message at level DEBUG")
    log.info("message at level INFO")
    log.warning("message at level WARNING")
    log.error("message at level ERROR")
    log.critical("message at level CRITICAL")

    program.terminate()
Example #11
0
File: spin.py Project: Ciemaar/spin
 def engage_mode(self, mode=None):
     log.info("engage mode {mode}".format(mode=mode))
     if mode == "tablet":
         self.display_orientation(orientation="left")
         self.touchscreen_orientation(orientation="left")
         self.touchpad_switch(status="off")
         self.nipple_switch(status="off")
     elif mode == "laptop":
         self.display_orientation(orientation="normal")
         self.touchscreen_orientation(orientation="normal")
         self.touchscreen_switch(status="on")
         self.touchpad_orientation(orientation="normal")
         self.touchpad_switch(status="on")
         self.nipple_switch(status="on")
     elif mode in ["left", "right", "inverted", "normal"]:
         self.display_orientation(orientation=mode)
         self.touchscreen_orientation(orientation=mode)
         self.touchpad_orientation(orientation=mode)
     else:
         log.error("unknown mode \"{mode}\" requested".format(mode=mode))
         sys.exit()
def main(options):

    filename_log = options["--logfile"]

    global program
    program = propyte.Program(
        options      = options,
        name         = name,
        version      = version,
        logo         = logo,
        filename_log = filename_log
    )
    global log
    from propyte import log

    log.debug("message at level DEBUG")
    log.info("message at level INFO")
    log.warning("message at level WARNING")
    log.error("message at level ERROR")
    log.critical("message at level CRITICAL")

    program.terminate()
Example #13
0
File: spin.py Project: Ciemaar/spin
 def touchpad_orientation(self, orientation=None):
     if "touchpad" in self.names_devices:
         coordinate_transformation_matrix = {
             "left": "0 -1 1 1 0 0 0 0 1",
             "right": "0 1 0 -1 0 1 0 0 1",
             "inverted": "-1 0 1 0 -1 1 0 0 1",
             "normal": "1 0 0 0 1 0 0 0 1"
         }
         if coordinate_transformation_matrix.has_key(orientation):
             log.info("change touchpad to {orientation}".format(
                 orientation=orientation))
             engage_command(
                 "xinput set-prop \"{name_device}\" \"Coordinate "
                 "Transformation Matrix\" "
                 "{matrix}".format(
                     name_device=self.names_devices["touchpad"],
                     matrix=coordinate_transformation_matrix[orientation]))
         else:
             log.error("unknown touchpad orientation \"{orientation}\""
                       " requested".format(orientation=orientation))
             sys.exit()
     else:
         log.debug("touchpad orientation unchanged")
Example #14
0
def main(options):

    global program
    program = propyte.Program(options=options,
                              name=name,
                              version=version,
                              logo=logo)
    global log
    from propyte import log

    # access options and arguments
    expression = options["--expression"]
    word_vector_model = options["--wordvectormodel"]

    # Define a dictionary of natural language expressions and word vectors.
    stored_expressions = {
        "This is a test.":
        numpy.array([
            -0.3828682, -0.36397889, 0.46676171, 0.32530552, 0.20376287,
            -0.41326976, -0.58228827, 0.05073506, -0.29834735, 0.62523258,
            0.48247468, 0.63565594, 0.61466146, -0.05790123, 0.49383548,
            0.17871667, 0.26640224, -0.05172781, -0.43991241, 0.8027305,
            0.13174312, -0.70332521, -0.56575418, -0.21705133, -0.93002945,
            0.04151381, -0.15113404, 0.06264834, 0.03022593, -0.00822711,
            -0.23755306, -0.9215641, 0.21348992, 0.38396335, 0.3020944,
            -0.08034055, -0.36891997, -0.86551458, -1.02402425, 0.03633916,
            0.34436008, 0.43058148, -0.32728755, 0.50974292, -0.31518513,
            -0.63085675, -0.40564051, 0.30009648, -0.06426927, -0.6588546,
            0.06724164, 0.08611558, -0.13476974, 0.43107161, -0.26038069,
            0.03187743, 0.05931987, 0.28155532, 0.3636784, -0.76867509,
            -0.2253349, -0.77433741, 0.01924273, 0.63751495, 0.03874384,
            0.28651205, 0.14867969, -0.2256701, 0.23747981, 0.12383705,
            0.27097231, -0.06902695, 0.06664967, 0.05863822, -0.06882346,
            0.59539717, 0.08472043, -0.13579898, -0.31311297, -0.68136102,
            0.33296993, 0.26578408, -0.55723149, 0.38583612, -0.18033087,
            -0.50730389, 0.39173275, 0.57567608, -0.42063141, 0.22387385,
            0.473548, 0.41959459, 0.34881225, 0.1939103, -0.54997987,
            0.30737191, -0.6659264, 0.0437102, -0.11230323, -0.13493723
        ],
                    dtype=numpy.float32),
        "All those moments will be lost in time.":
        numpy.array([
            -1.19203818e+00, -2.22961619e-01, 6.69643760e-01, 3.70975524e-01,
            -6.15832031e-01, -4.36573088e-01, -6.77924156e-01, 6.26985192e-01,
            1.36510044e-01, 1.09196387e-01, 7.61598766e-01, 7.17226386e-01,
            -1.08178332e-01, -1.00655735e+00, 7.45964348e-01, 1.64966106e-01,
            5.85332870e-01, -3.83911550e-01, -6.85201228e-01, 1.31213856e+00,
            8.04567218e-01, -1.28810382e+00, -2.52677381e-01, -9.27993536e-01,
            -4.17307138e-01, -4.56952095e-01, -7.27599859e-01, 7.54008472e-01,
            6.67124987e-04, 2.75971144e-01, 2.75658131e-01, -6.79417193e-01,
            -1.73686996e-01, 8.78942013e-01, 4.39480424e-01, -6.37802243e-01,
            -6.99860230e-02, -7.99779966e-02, -7.58146644e-02, 8.09784770e-01,
            -3.71645451e-01, 1.04973994e-01, -1.34749603e+00, 2.96185315e-01,
            5.85593104e-01, -1.40544206e-01, -3.77467513e-01, 3.46597135e-01,
            2.56733745e-01, 4.04421866e-01, 1.57907709e-01, 3.00843865e-01,
            -5.41967154e-01, 5.51929235e-01, -1.69145897e-01, 4.42785203e-01,
            -2.69805342e-02, 1.31654418e+00, 3.19460958e-01, 5.08862257e-01,
            3.44371676e-01, -6.95496798e-01, 4.88163918e-01, 2.55316138e-01,
            5.03436685e-01, 9.24195647e-02, -2.38671958e-01, -8.97032142e-01,
            -3.73697281e-03, 2.99875826e-01, 1.65674359e-01, 2.01489821e-01,
            1.58179402e-02, 1.30668238e-01, -1.56954467e-01, -2.88258016e-01,
            6.76668346e-01, -3.77742261e-01, 2.20978767e-01, -6.34561360e-01,
            8.33457410e-01, -2.13193640e-01, -6.35235757e-02, 1.89480215e-01,
            6.02166615e-02, -6.64785147e-01, 1.07347333e+00, 6.22629285e-01,
            -4.63467717e-01, -1.13483839e-01, 3.43968630e-01, 2.75979757e-01,
            -1.28710240e-01, 1.50670230e+00, -3.10248852e-01, 3.29222828e-01,
            1.64443821e-01, -7.78683364e-01, -9.80837345e-02, -1.07415296e-01
        ],
                    dtype=numpy.float32),
        "All those moments were lost in time.":
        numpy.array([
            -0.94025505, -0.45476836, 0.41891485, 1.06683254, -0.49607083,
            -0.60043317, -0.55656326, 0.05368682, 0.20896676, 0.19261286,
            0.51067233, 0.01298623, -0.67276001, -0.51130211, 0.61433661,
            0.03579944, 0.4515644, -0.19222273, -0.3919456, 0.65209424,
            0.98329031, -0.78390068, -0.0611292, -0.88086104, 0.25153416,
            -0.16051427, -0.33223695, 0.86147106, -0.19569418, -0.21456225,
            0.27583197, -0.65764415, -0.76533222, 0.78306556, 0.84534264,
            -0.26408321, 0.04312199, -0.00636051, 0.1322974, 0.72321951,
            -0.01186696, 0.40505514, -0.87730938, 0.58147532, 0.89738142,
            -0.16748536, -0.38406748, -0.12007161, 0.49123141, 0.48998365,
            0.15616624, 0.52637529, -0.66329396, 0.10376941, -0.33025965,
            0.04188792, 0.30536407, 0.38240519, 0.01627355, 1.23012972,
            0.46352714, -0.74617827, 0.43505573, -0.16246299, 0.34668511,
            -0.02247265, -0.34742412, -0.64483654, -0.2243523, 0.04222834,
            0.42057285, 0.22310457, 0.36833102, -0.05716853, -0.44688487,
            -0.51298815, 0.61859602, -0.21154809, -0.08168469, -0.15004104,
            0.21371906, 0.21713886, 0.21935812, 0.04912762, 0.02854752,
            -0.55747426, 0.70036995, 0.20306921, -0.46556181, -0.10637223,
            0.60909081, 0.55366743, -0.22907487, 1.13089538, 0.34430629,
            0.35133895, 0.085365, -0.58662325, -0.13062993, -0.04200239
        ],
                    dtype=numpy.float32),
        "All those moments are lost in time.":
        numpy.array([
            -0.78943789, -0.30322614, 0.3780162, 0.80896467, -0.42042252,
            -0.64176518, -0.51211309, -0.1537444, -0.04233316, 0.07710438,
            0.66949254, 0.37771451, -0.74869132, -0.55132926, 0.53695548,
            -0.11229508, 0.6673997, -0.34724045, -0.42173663, 0.7451877,
            1.01433206, -0.85418928, -0.31583607, -0.6812892, 0.42722669,
            -0.43322188, -0.35293943, 0.7662127, -0.30090365, -0.13694993,
            -0.04172039, -0.65059775, -0.62617165, 0.71341687, 0.82349646,
            -0.31194365, 0.00356466, -0.32218212, 0.15857732, 0.82880032,
            0.0566355, 0.43106011, -1.01921201, 0.51658779, 0.8068108,
            -0.09396499, -0.37920368, -0.08726061, 0.29975161, 0.25999272,
            0.23571083, 0.24800834, -0.73045135, 0.19150458, -0.19696848,
            -0.11186107, 0.1336731, 0.33246318, 0.22474274, 1.15420532,
            0.39482915, -0.70385826, 0.54841375, -0.03638301, 0.54499787,
            0.02484709, -0.2070619, -0.69282937, -0.21465099, 0.11578664,
            0.22713676, 0.21237181, 0.2007356, 0.14489903, -0.37357002,
            -0.50091666, 0.59818357, -0.36113665, 0.06037673, -0.26377741,
            0.31544513, -0.23714744, -0.01429842, 0.17592101, -0.16280818,
            -0.58340323, 0.63590413, 0.31803992, -0.47035503, -0.17544734,
            0.66008455, 0.77849454, -0.04235193, 1.29202402, 0.12573826,
            0.20377615, -0.08164676, -0.41151166, -0.1280518, 0.02905136
        ],
                    dtype=numpy.float32),
    }

    model_word2vec = abstraction.load_word_vector_model(
        filename=word_vector_model)

    working_expression_NL = expression

    # Convert the expression to a word vector.
    working_expression_WV =\
        abstraction.convert_sentence_string_to_word_vector(
            sentence_string = working_expression_NL,
            model_word2vec  = model_word2vec
        )
    log.info(
        "word vector representation of expression \"{working_expression_NL}\":"
        "\n{working_expression_WV}".format(
            working_expression_NL=working_expression_NL,
            working_expression_WV=working_expression_WV))

    # Define table headings.
    table_contents = [[
        "working expression natural language",
        "stored expression natural language",
        "absolute magnitude difference between working amd stored expression "
        "word vectors",
        "angle between working and stored expression word vectors"
    ]]

    # Compare the expression word vector representation to existing word
    # vectors.
    magnitude_differences = []
    angles = []
    stored_expressions_NL_list = []
    magnitude_working_expression_WV = datavision.magnitude(
        working_expression_WV)
    for stored_expression_NL in stored_expressions:
        stored_expression_WV = stored_expressions[stored_expression_NL]
        magnitude_stored_expression_WV = datavision.magnitude(
            stored_expression_WV)
        magnitude_difference_working_expression_WV_stored_expression_WV = abs(
            magnitude_working_expression_WV - magnitude_stored_expression_WV)
        angle_working_expression_WV_stored_expression_WV = datavision.angle(
            working_expression_WV, stored_expression_WV)
        # Store comparison results in lists.
        magnitude_differences.append(
            magnitude_difference_working_expression_WV_stored_expression_WV)
        angles.append(angle_working_expression_WV_stored_expression_WV)
        stored_expressions_NL_list.append(stored_expression_NL)
        # Build table.
        table_contents.append([
            str(working_expression_NL),
            str(stored_expression_NL),
            str(magnitude_difference_working_expression_WV_stored_expression_WV
                ),
            str(angle_working_expression_WV_stored_expression_WV)
        ])

    # Record table.
    print(pyprel.Table(contents=table_contents))

    log.info("")

    index_minimum_magnitude_differences =\
        magnitude_differences.index(min(magnitude_differences))
    index_minimum_angles = angles.index(min(angles))
    index_minimum_match_width = len(angles) / 4
    if abs(index_minimum_magnitude_differences -
           index_minimum_angles) < index_minimum_match_width:
        log.info("translation: {translation_expression_NL}".format(
            translation_expression_NL =\
                stored_expressions_NL_list[index_minimum_angles]
        ))
    else:
        log.error("unable to translate")

    log.info("")

    program.terminate()
Example #15
0
def main(options):

    global program
    program = propyte.Program(options=options,
                              name=name,
                              version=version,
                              logo=logo)
    global log
    from propyte import log

    print("")

    filename_ROOT = options["--fileroot"]
    filename_CSV = options["--filecsv"]
    selection = options["--selection"]
    class_label = int(options["--classlabel"])
    name_tree = options["--tree"]
    maximum_number_of_events = None if options["--maxevents"].lower() == "none"\
                                  else int(options["--maxevents"])
    include_headings = options["--headings"].lower() == "true"

    if not os.path.isfile(os.path.expandvars(filename_ROOT)):
        log.error("file {filename} not found".format(filename=filename_ROOT))
        program.terminate()

    if os.path.isfile(os.path.expandvars(filename_CSV)):
        log.warning(
            "CSV file {filename} exists -- *append* data to file".format(
                filename=filename_CSV))
        print("")
        append = True
    else:
        append = False

    file_ROOT = abstraction.open_ROOT_file(filename_ROOT)
    tree = file_ROOT.Get(name_tree)
    number_of_events = tree.GetEntries()

    file_CSV = open(filename_CSV, "a")
    writer = csv.writer(file_CSV, delimiter=",")

    log.info(
        textwrap.dedent("""
        input ROOT file: {filename_ROOT}
        output CSV file: {filename_CSV}
        selection:       {selection}
        class label:     {class_label}
        """.format(filename_ROOT=filename_ROOT,
                   filename_CSV=filename_CSV,
                   selection=selection,
                   class_label=class_label)))

    print("")
    log.info("save variables of events to CSV {filename}".format(
        filename=filename_CSV))
    print("")

    progress = shijian.Progress()
    progress.engage_quick_calculation_mode()
    index_selected = 0
    detail = True
    for index, event in enumerate(tree):
        if select_event(event=event, selection=selection):
            index_selected = index_selected + 1
            if                                           \
                maximum_number_of_events is not None and \
                index_selected > maximum_number_of_events:
                break
            line = [
                #Variable_ttHbb(event = event, name = "Aplan_bjets"),
                Variable_ttHbb(event=event, name="Aplan_jets"),  #
                Variable_ttHbb(event=event, name="Centrality_all"),  #
                #Variable_ttHbb(event = event, name = "ClassifBDTOutput_6jsplit"),
                #Variable_ttHbb(event = event, name = "ClassifBDTOutput_basic"),
                #Variable_ttHbb(event = event, name = "ClassifBDTOutput_withReco_6jsplit"),
                #Variable_ttHbb(event = event, name = "ClassifBDTOutput_withReco_basic"),
                #Variable_ttHbb(event = event, name = "ClassifHPLUS_Semilep_HF_BDT200_Output"),
                Variable_ttHbb(event=event, name="dEtajj_MaxdEta"),  #
                Variable_ttHbb(event=event, name="dRbb_avg"),  #
                #Variable_ttHbb(event = event, name = "dRbb_MaxM"),
                Variable_ttHbb(event=event, name="dRbb_MaxPt"),  #
                #Variable_ttHbb(event = event, name = "dRbb_min"),
                #Variable_ttHbb(event = event, name = "dRbj_Wmass"),
                #Variable_ttHbb(event = event, name = "dRHl_MaxdR"),
                #Variable_ttHbb(event = event, name = "dRHl_MindR"),
                #Variable_ttHbb(event = event, name = "dRjj_min"),
                #Variable_ttHbb(event = event, name = "dRlepbb_MindR"),
                #Variable_ttHbb(event = event, name = "dRlj_MindR"),
                #Variable_ttHbb(event = event, name = "dRuu_MindR"),
                Variable_ttHbb(event=event, name="H1_all"),  #
                #Variable_ttHbb(event = event, name = "H4_all"),
                #Variable_ttHbb(event = event, name = "HhadT_nJets"),
                #Variable_ttHbb(event = event, name = "HiggsbbM"),
                #Variable_ttHbb(event = event, name = "HiggsjjM"),
                #Variable_ttHbb(event = event, name = "HT_all"),
                #Variable_ttHbb(event = event, name = "HT_jets"),
                #Variable_ttHbb(event = event, name = "Mbb_MaxM"),
                #Variable_ttHbb(event = event, name = "Mbb_MaxPt"),
                Variable_ttHbb(event=event, name="Mbb_MindR"),  #
                #Variable_ttHbb(event = event, name = "Mbj_MaxPt"),
                #Variable_ttHbb(event = event, name = "Mbj_MindR"),
                #Variable_ttHbb(event = event, name = "Mbj_Wmass"),
                #Variable_ttHbb(event = event, name = "met_met"),
                #Variable_ttHbb(event = event, name = "met_phi"),
                #Variable_ttHbb(event = event, name = "MHiggs"),
                #Variable_ttHbb(event = event, name = "Mjj_HiggsMass"),
                #Variable_ttHbb(event = event, name = "Mjjj_MaxPt"),
                #Variable_ttHbb(event = event, name = "Mjj_MaxPt"),
                #Variable_ttHbb(event = event, name = "Mjj_MindR"),
                #Variable_ttHbb(event = event, name = "Mjj_MinM"),
                #Variable_ttHbb(event = event, name = "mu"),
                #Variable_ttHbb(event = event, name = "Muu_MindR"),
                #Variable_ttHbb(event = event, name = "NBFricoNN_dil"),
                #Variable_ttHbb(event = event, name = "nBTags"),
                #Variable_ttHbb(event = event, name = "nBTags30"),
                #Variable_ttHbb(event = event, name = "nBTags50"),
                #Variable_ttHbb(event = event, name = "nBTags60"),
                #Variable_ttHbb(event = event, name = "nBTags70"),
                #Variable_ttHbb(event = event, name = "nBTags77"),
                #Variable_ttHbb(event = event, name = "nBTags80"),
                #Variable_ttHbb(event = event, name = "nBTags85"),
                #Variable_ttHbb(event = event, name = "nBTags90"),
                #Variable_ttHbb(event = event, name = "nBTagsFlatBEff_30"),
                #Variable_ttHbb(event = event, name = "nBTagsFlatBEff_40"),
                #Variable_ttHbb(event = event, name = "nBTagsFlatBEff_50"),
                #Variable_ttHbb(event = event, name = "nBTagsFlatBEff_60"),
                #Variable_ttHbb(event = event, name = "nBTagsFlatBEff_70"),
                #Variable_ttHbb(event = event, name = "nBTagsFlatBEff_77"),
                #Variable_ttHbb(event = event, name = "nBTagsFlatBEff_85"),

                #Variable_ttHbb(event = event, name = "nElectrons"),
                #Variable_ttHbb(event = event, name = "nHFJets"),
                Variable_ttHbb(event=event, name="NHiggs_30"),  #
                #Variable_ttHbb(event = event, name = "Njet_pt40"),
                #Variable_ttHbb(event = event, name = "Njet_pt40"),
                #Variable_ttHbb(event = event, name = "nJets"),
                #Variable_ttHbb(event = event, name = "nMuons"),
                #Variable_ttHbb(event = event, name = "nPrimaryVtx"),

                #Variable_ttHbb(event = event, name = "pT_jet3"),
                Variable_ttHbb(event=event, name="pT_jet5"),  #
                #Variable_ttHbb(event = event, name = "pTuu_MindR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_b1higgsbhadtop_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_bbhiggs_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_BDT_output"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_BDT_output_6jsplit"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_BDT_output_truthMatchPattern"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_BDT_withH_output"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_BDT_withH_output_6jsplit"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_BDT_withH_output_truthMatchPattern"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_hadWb1Higgs_mass"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgsbhadtop_withH_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgsbleptop_mass"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgsbleptop_withH_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgslep_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgsleptop_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgs_mass"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgsq1hadW_mass"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_higgsttbar_withH_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_leptophadtop_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_leptophadtop_withH_dR"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_Ncombinations"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_nuApprox_recoBDT"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_nuApprox_recoBDT_6jsplit"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_nuApprox_recoBDT_withH"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_nuApprox_recoBDT_withH_6jsplit"),
                #Variable_ttHbb(event = event, name = "semilepMVAreco_ttH_Ht_withH"),
                #Variable_ttHbb(event = event, name = "ttHF_mva_discriminant"),

                #Variable_ttHbb(event = event, name = "el_d0sig[0]"),
                #Variable_ttHbb(event = event, name = "el_delta_z0_sintheta[0]"),
                #Variable_ttHbb(event = event, name = "el_e[0]"),
                #Variable_ttHbb(event = event, name = "el_eta[0]"),
                #Variable_ttHbb(event = event, name = "el_phi[0]"),
                #Variable_ttHbb(event = event, name = "el_pt[0]"),
                #Variable_ttHbb(event = event, name = "el_topoetcone20[0]"),

                #Variable_ttHbb(event = event, name = "mu_d0sig[0]"),
                #Variable_ttHbb(event = event, name = "mu_delta_z0_sintheta[0]"),
                #Variable_ttHbb(event = event, name = "mu_e[0]"),
                #Variable_ttHbb(event = event, name = "mu_eta[0]"),
                #Variable_ttHbb(event = event, name = "mu_phi[0]"),
                #Variable_ttHbb(event = event, name = "mu_pt[0]"),
                #Variable_ttHbb(event = event, name = "mu_topoetcone20[0]"),

                #Variable_ttHbb(event = event, name = "jet_e[0]"),
                #Variable_ttHbb(event = event, name = "jet_eta[0]"),
                #Variable_ttHbb(event = event, name = "jet_jvt[0]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c10[0]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c20[0]"),
                #Variable_ttHbb(event = event, name = "jet_phi[0]"),
                #Variable_ttHbb(event = event, name = "jet_pt[0]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand[0]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand_6jsplit[0]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand[0]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[0]"),

                #Variable_ttHbb(event = event, name = "jet_e[1]"),
                #Variable_ttHbb(event = event, name = "jet_eta[1]"),
                #Variable_ttHbb(event = event, name = "jet_jvt[1]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c10[1]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c20[1]"),
                #Variable_ttHbb(event = event, name = "jet_phi[1]"),
                #Variable_ttHbb(event = event, name = "jet_pt[1]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand[1]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand_6jsplit[1]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand[1]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[1]"),

                #Variable_ttHbb(event = event, name = "jet_e[2]"),
                #Variable_ttHbb(event = event, name = "jet_eta[2]"),
                #Variable_ttHbb(event = event, name = "jet_jvt[2]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c10[2]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c20[2]"),
                #Variable_ttHbb(event = event, name = "jet_phi[2]"),
                #Variable_ttHbb(event = event, name = "jet_pt[2]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand[2]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand_6jsplit[2]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand[2]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[2]"),

                #Variable_ttHbb(event = event, name = "jet_e[3]"),
                #Variable_ttHbb(event = event, name = "jet_eta[3]"),
                #Variable_ttHbb(event = event, name = "jet_jvt[3]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c10[3]"),
                #Variable_ttHbb(event = event, name = "jet_mv2c20[3]"),
                #Variable_ttHbb(event = event, name = "jet_phi[3]"),
                #Variable_ttHbb(event = event, name = "jet_pt[3]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand[3]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_cand_6jsplit[3]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand[3]"),
                #Variable_ttHbb(event = event, name = "jet_semilepMVAreco_recoBDT_withH_cand_6jsplit[3]"),

                # large-R jets
                #Variable_ttHbb(event = event, name = "FirstLjetM"),
                #Variable_ttHbb(event = event, name = "FirstLjetPt"),
                #Variable_ttHbb(event = event, name = "HhadT_nLjets"),
                #Variable_ttHbb(event = event, name = "HT_ljets"),
                #Variable_ttHbb(event = event, name = "NBFricoNN_ljets"),
                #Variable_ttHbb(event = event, name = "nBjetOutsideLjet"),
                #Variable_ttHbb(event = event, name = "nJetOutsideLjet"),
                #Variable_ttHbb(event = event, name = "nLjet_m100"),
                #Variable_ttHbb(event = event, name = "nLjet_m50"),
                #Variable_ttHbb(event = event, name = "nLjets"),
                #Variable_ttHbb(event = event, name = "SecondLjetM"),
                #Variable_ttHbb(event = event, name = "SecondLjetPt"),
                #Variable_ttHbb(event = event, name = "ljet_C2[0]"),
                #Variable_ttHbb(event = event, name = "ljet_D2[0]"),
                #Variable_ttHbb(event = event, name = "ljet_e[0]"),
                #Variable_ttHbb(event = event, name = "ljet_eta[0]"),
                #Variable_ttHbb(event = event, name = "ljet_m[0]"),
                #Variable_ttHbb(event = event, name = "ljet_phi[0]"),
                #Variable_ttHbb(event = event, name = "ljet_pt[0]"),
                #Variable_ttHbb(event = event, name = "ljet_sd12[0]"),
                #Variable_ttHbb(event = event, name = "ljet_sd23[0]"),
                #Variable_ttHbb(event = event, name = "ljet_tau21[0]"),
                #Variable_ttHbb(event = event, name = "ljet_tau21_wta[0]"),
                #Variable_ttHbb(event = event, name = "ljet_tau32[0]"),
                #Variable_ttHbb(event = event, name = "ljet_tau32_wta[0]"),

                #rcjet_d12,
                #rcjet_d23,
                #rcjet_e,
                #rcjet_eta,
                #rcjet_phi,
                #rcjet_pt,
                Variable_ttHbb(name="class", value=class_label)
            ]
            if detail:
                log.info("event variable details:")
                log.info(
                    "\nnumber of variables: {number}".format(number=len(line)))
                table_contents = [["variable value", "variable type"]]
                for variable in line:
                    table_contents.append(
                        [str(variable.name()),
                         str(type(variable.value()))])
                print(pyprel.Table(contents=table_contents, ))
                detail = False
            if include_headings and not append:
                headings = [variable.name() for variable in line]
                writer.writerow(headings)
                include_headings = False
            values = [variable.value() for variable in line]
            writer.writerow(values)
        print(progress.add_datum(fraction=index / number_of_events))

    print("")
    log.info(
        "{number_selected} events of {number_total} passed selection".format(
            number_selected=index_selected, number_total=index))

    print("")

    program.terminate()
def main(options):

    global program
    program = propyte.Program(
        options = options,
        name    = name,
        version = version,
        logo    = logo
    )
    global log
    from propyte import log

    host = "127.0.0.1" # 10.0.0.41
    port_number = 2718

    filename_peers = options["--peersfile"]

    log.info("")

    # Read the local peers list.
    if not os.path.exists(filename_peers):
        log.error("file {filename} not found".format(
            filename = filename_peers
        ))
        program.terminate()
    peers_list_local = [line.rstrip("\n") for line in open(filename_peers)]
    peers_consensus = shijian.List_Consensus()
    peers_consensus.append(tuple(peers_list_local))
    log.debug("peers list local: {peers}".format(
        peers = peers_list_local
    ))
    log.debug("peers list consensus: {peers}".format(
        peers = peers_consensus.consensus()
    ))

    port           = int(str(port_number), 10)
    address_remote = (host, port)

    # Create a datagram socket for UDP.
    socket_UDP = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    # Set the socket to be reusable.
    socket_UDP.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    # Set the socket to accept incoming broadcasts.
    socket_UDP.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    # Disengage socket blocking.
    socket_UDP.setblocking(False)
    # Set the socket to accept connections on the port.
    socket_UDP.bind(("", port))

    # Communicate data in a loop.
    log.info("Ctrl c to exit")
    while True:
        # receive
        try:
            # buffer size: 8192
            message, address = socket_UDP.recvfrom(8192)
            message = message.rstrip("\n")
            if message:
                log.debug("{address}:{port_number}> {message}".format(
                    address     = address[0],
                    port_number = port_number,
                    message     = message
                ))

                # upcoming: message accept/reject procedure
                # Record the sender ID in order to limit the number of senders
                # such that scalability problems do not manifest.
                # Record the message ID in order to avoid parsing it again.

                # If a peers list is detected, parse it and add it to the
                # consensus.
                if "peers =" in message:
                    peers_list_remote = eval(message.lstrip("peers =").rstrip(";"))
                    peers_consensus.append(tuple(peers_list_remote))
                    if len(peers_consensus) >= 3:
                        peers_consensus_list = list(peers_consensus.consensus())
                        log.debug("consensus peers list: {peers_consensus_list}".format(
                            peers_consensus_list = peers_consensus_list
                        ))
                        log.debug("update local peers list with consensus peers list")
                        peers_list_local = peers_consensus_list
                # upcoming functionality
                # If a heartbeat is detected, send the local peers list.
                if "heartbeat" in message:
                    message_send = "peers = {peers_list_local};".format(
                        peers_list_local = peers_list_local
                    )
                    socket_UDP.sendto(message_send, address)

        except:
            pass
        # send
        message_send =\
        "message_text = heartbeat; message_ID = {message_ID};".format(
            message_ID = shijian.UID()
        )
        socket_UDP.sendto(message_send, address_remote)
        time.sleep(1)

    log.info("")

    program.terminate()
Example #17
0
def main(options):

    global program
    program = propyte.Program(
        options = options,
        name    = name,
        version = version,
        logo    = logo
    )
    global log
    from propyte import log

    print("")

    filename_CSV               = options["--infile"]
    make_histogram_comparisons = options["--histogramcomparisons"].lower() == "true"
    make_scatter_matrix        = options["--scattermatrix"].lower() == "true"
    make_event_images          = options["--eventimages"].lower() == "true"
    number_of_event_images     = int(options["--numberofeventimages"])
    directoryname_plots        = options["--directoryplots"]

    if not os.path.isfile(os.path.expandvars(filename_CSV)):
        log.error("file {filename} not found".format(
            filename = filename_CSV
        ))
        program.terminate()

    log.info("read CSV from {filename}".format(filename = filename_CSV))
    data = pd.read_csv(filename_CSV)

    number_of_columns          = data.shape[1]
    indices_of_feature_columns = range(0, number_of_columns -1)

    feature_names = list(data.columns)

    data_class_0 = data.loc[data["class"] == 0]
    data_class_1 = data.loc[data["class"] == 1]

    print("")
    log.info("basic feature characteristics")
    print("")

    table_contents = [[
        "feature",
        "minimum value in class 0",
        "minimum value in class 1",
        "maximum value in class 0",
        "maximum value in class 1",
        "mean value in class 0",
        "mean value in class 1"
    ]]

    for feature_name in feature_names:

        values_class_0 = list(data_class_0[feature_name])
        values_class_1 = list(data_class_1[feature_name])

        table_contents.append([
            feature_name,
            min(values_class_0),
            min(values_class_1),
            max(values_class_0),
            max(values_class_1),
            sum(values_class_0)/len(values_class_0),
            sum(values_class_1)/len(values_class_1)
        ])

    print(
        pyprel.Table(
            contents = table_contents
        )
    )

    if make_histogram_comparisons:

        for feature_name in feature_names:

            filename = shijian.propose_filename(
                filename = feature_name + "_ttbb_ttH.png"
            )
            log.info("save histogram {filename}".format(filename = filename))
            datavision.save_histogram_comparison_matplotlib(
                values_1      = list(data_class_0[feature_name]),
                values_2      = list(data_class_1[feature_name]),
                label_1       = "ttbb",
                label_2       = "ttH",
                label_ratio_x = "",
                label_y       = "",
                title         = feature_name,
                filename      = filename,
                directory     = directoryname_plots
            )

    if make_scatter_matrix:

        filename = "scatter_matrix_ttbb_ttH.jpg"
        log.info("save scatter matrix {filename}".format(filename = filename))
        scatter_matrix = pd.scatter_matrix(
            data,
            figsize  = [15, 15],
            marker   = ".",
            s        = 0.2,
            diagonal = "kde"
        )
        for ax in scatter_matrix.ravel():
            ax.set_xlabel(
                ax.get_xlabel(),
                fontsize = 15,
                rotation = 90
            )
            ax.set_ylabel(
                ax.get_ylabel(),
                fontsize = 15,
                rotation = 0,
                labelpad = 60
            )
            ax.get_xaxis().set_ticks([])
            ax.get_yaxis().set_ticks([])
        if not os.path.exists(directoryname_plots):
            os.makedirs(directoryname_plots)
        plt.savefig(
            directoryname_plots + "/" + filename,
            dpi = 700
        )

    if make_event_images:

        directoryname = "event_images"

        if not os.path.exists(directoryname):
            os.makedirs(directoryname)

        for class_label in [0, 1]:

            data_class = data.loc[data["class"] == class_label]

            for index, row in data_class[0:number_of_event_images].iterrows():
                image = datavision.NumPy_array_pad_square_shape(
                    array     = row.as_matrix(),
                    pad_value = -4
                )
                plt.imshow(
                    image,
                    cmap          = "Greys",
                    interpolation = "nearest"
                )
                filename = "event_image_class_" + str(class_label) + "_index_" + str(index) + ".png"
                log.info("save event image {filename}".format(filename = filename))
                plt.savefig(
                    directoryname + "/" + filename,
                    dpi = 200
                )

    print("")

    program.terminate()