item['fields']['path'] = nhl_path

with open(f"{cwd}/scoreboard/fixtures/teams.json", "w") as json_out:
    json.dump(loading_data, json_out, indent=2)
    json_out.close()

print(
    f"INFO: Capstone.settings.NHL_SCOREBOARD_PATH has been configured to: `{nhl_path}`."
)
print(f"INFO: Capstone.settings.GUI_PATH has been configured to: `{cwd}`.\n")

# Prompt for additional boards
questions = [
    inquirer.Checkbox(
        'boards',
        message="Select additional boards (use space to select)",
        choices=['MLB-LED-Scoreboard', 'NFL-LED-Scoreboard'],
    ),
]
answers = inquirer.prompt(questions)

# Update MLB BoardType.path
if "MLB-LED-Scoreboard" in answers["boards"]:
    print('Enter the full path to `MLB-LED-Scoreboard`. ')
    mlb_path = input(print('Leave blank for "/home/pi/mlb-led-scoreboard": '))
    if mlb_path == "":
        mlb_path = "/home/pi/mlb-led-scoreboard"
    else:
        mlb_path = path_verify(mlb_path)
    print(f"INFO: MLB BoardType.path has been configured to: `{mlb_path}`.")
Example #2
0
from pprint import pprint

import inquirer
import yaml
import subprocess

with open('setup.yaml') as f:
    config = yaml.safe_load(f.read())[0]

questions = [
    inquirer.Text('host', message='Enter host'),
    inquirer.Text('user',
                  message='Enter username',
                  default=config['vars']['ansible_user']),
    inquirer.Text('proxy', message='Enter proxy'),
    inquirer.Checkbox('roles', message='Select roles', choices=config['roles'])
]

answers = inquirer.prompt(questions)

config['vars']['ansible_user'] = answers['user']
config['vars']['http_proxy'] = answers['proxy']
config['roles'] = answers['roles']

with open('setup.rendered.yaml', 'w') as f:
    f.write(yaml.safe_dump([config]))

command = 'ansible-playbook -i {}, setup.rendered.yaml'.format(answers['host'])

print(command)
process = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE)
Example #3
0
def process(data_file, error_apriori, units):
    '''
    Given a .csv data file in the format of (time, x, y, z) applies both filters, generates a filtered.csv data
    file, prints out the final keplerian elements computed from both Lamberts and Interpolation and finally plots
    the initial, filtered data set and the final orbit.

    Args:
        data_file (string): The name of the .csv file containing the positional data
        error_apriori (float): apriori estimation of the measurements error in km

    Returns:
        Runs the whole process of the program
    '''

    # First read the csv file called "orbit" with the positional data
    data = read_data.load_data(data_file)

    if (units == 'm'):
        # Transform m to km
        data[:, 1:4] = data[:, 1:4] / 1000

    print(
        "***********Choose filter(s) in desired order of application***********"
    )
    print(
        "(SPACE to toggle, UP/DOWN to navigate, RIGHT/LEFT to select/deselect and ENTER to submit)"
    )
    print(
        "*if nothing is selected, Triple Moving Average followed by Savitzky Golay will be applied"
    )
    questions = [
        inquirer.Checkbox(
            'filter',
            message="Select filter(s)",
            choices=[
                'None', 'Savitzky Golay Filter',
                'Triple Moving Average Filter', 'Wiener Filter'
            ],
        ),
    ]
    choices = inquirer.prompt(questions)
    data_after_filter = data

    if (len(choices['filter']) == 0):
        print("Applying Triple Moving Average followed by Savitzky Golay...")
        # Apply the Triple moving average filter with window = 3
        data_after_filter = triple_moving_average.generate_filtered_data(
            data_after_filter, 3)

        # Use the golay_window.py script to find the window for the Savitzky Golay filter based on the error you input
        window = golay_window.window(error_apriori, data_after_filter)

        # Apply the Savitzky Golay filter with window = window (51 for orbit.csv) and polynomial order = 3
        data_after_filter = sav_golay.golay(data_after_filter, window, 3)

    else:
        for index, choice in enumerate(choices['filter']):
            if (choice == 'None'):
                print("Using the original data...")
                # no filter is applied
                data_after_filter = data_after_filter

            elif (choice == 'Savitzky Golay Filter'):
                print("Applying Savitzky Golay Filter...")
                # Use the golay_window.py script to find the window for the Savitzky Golay filter
                # based on the error you input
                window = golay_window.window(error_apriori, data_after_filter)

                # Apply the Savitzky Golay filter with window = window (51 for orbit.csv) and polynomial order = 3
                data_after_filter = sav_golay.golay(data_after_filter, window,
                                                    3)

            elif (choice == 'Wiener Filter'):
                print("Applying Wiener Filter...")
                # Apply the Wiener filter
                data_after_filter = wiener.wiener_new(data_after_filter, 3)

            else:
                print("Applying Triple Moving Average Filter...")
                # Apply the Triple moving average filter with window = 3
                data_after_filter = triple_moving_average.generate_filtered_data(
                    data_after_filter, 3)

    # Compute the residuals between filtered data and initial data and then the sum and mean values of each axis
    res = data_after_filter[:, 1:4] - data[:, 1:4]
    sums = np.sum(res, axis=0)
    print("\nDisplaying the sum of the residuals for each axis")
    print(sums, "\n")

    means = np.mean(res, axis=0)
    print("Displaying the mean of the residuals for each axis")
    print(means, "\n")

    # Save the filtered data into a new csv called "filtered"
    np.savetxt("filtered.csv", data_after_filter, delimiter=",")

    print("***********Choose Method(s) for Orbit Determination***********")
    print(
        "(SPACE to toggle, UP/DOWN to navigate, RIGHT/LEFT to select/deselect and ENTER to submit)"
    )
    print(
        "*if nothing is selected, Cubic Spline Interpolation will be used for Orbit Determination"
    )
    questions = [
        inquirer.Checkbox(
            'method',
            message="Select Method(s)",
            choices=[
                'Lamberts Kalman', 'Cubic Spline Interpolation',
                'Ellipse Best Fit', 'Gibbs 3 Vector'
            ],
        ),
    ]
    choices = inquirer.prompt(questions)
    kep_elements = {}

    if (len(choices['method']) == 0):
        # Apply the interpolation method
        kep_inter = interpolation.main(data_after_filter)
        # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
        # We set an estimate of measurement variance R = 0.01 ** 2
        kep_final_inter = lamberts_kalman.kalman(kep_inter, 0.01**2)
        kep_final_inter = np.transpose(kep_final_inter)
        kep_final_inter = np.resize(kep_final_inter, ((7, 1)))
        kep_final_inter[6, 0] = sgp4.rev_per_day(kep_final_inter[0, 0])
        kep_elements['Cubic Spline Interpolation'] = kep_final_inter

    else:
        for index, choice in enumerate(choices['method']):
            if (choice == 'Lamberts Kalman'):
                # Apply Lambert Kalman method for the filtered data set

                #previously, all data...
                #kep_lamb = lamberts_kalman.create_kep(data_after_filter)

                # only three (3) observations from half an orbit.
                # also just two (2) observations are fine for lamberts.
                data = np.array([
                    data_after_filter[:, :][0],
                    data_after_filter[:, :][len(data_after_filter) // 2],
                    data_after_filter[:, 0:][-1]
                ])

                kep_lamb = lamberts_kalman.create_kep(data)

                # Determination of orbit period
                semimajor_axis = kep_lamb[0][0]
                T_orbitperiod = oe.T_orbitperiod(semimajor_axis=semimajor_axis)
                timestamps = data_after_filter[:, 0]
                runtime = np.subtract(timestamps, np.min(timestamps))
                index = np.argmax(
                    runtime >= T_orbitperiod //
                    2) - 1  # only half orbit is good for Gibbs method

                if index < 2:
                    # in case there are not enough points to have the result at index point at 2
                    # or the argmax search does not find anything and sets index = 0.
                    index = len(timestamps) - 1

                # enough data for half orbit
                data = np.array([
                    data_after_filter[:, :][0],
                    data_after_filter[:, :][index // 2],
                    data_after_filter[:, :][index]
                ])

                kep_lamb = lamberts_kalman.create_kep(data)

                # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
                # We set an estimate of measurement variance R = 0.01 ** 2
                kep_final_lamb = lamberts_kalman.kalman(kep_lamb, 0.01**2)
                kep_final_lamb = np.transpose(kep_final_lamb)
                kep_final_lamb = np.resize(kep_final_lamb, ((7, 1)))
                kep_final_lamb[6, 0] = sgp4.rev_per_day(kep_final_lamb[0, 0])
                kep_elements['Lamberts Kalman'] = kep_final_lamb

            elif (choice == 'Cubic Spline Interpolation'):
                # Apply the interpolation method
                kep_inter = interpolation.main(data_after_filter)
                # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
                # We set an estimate of measurement variance R = 0.01 ** 2
                kep_final_inter = lamberts_kalman.kalman(kep_inter, 0.01**2)
                kep_final_inter = np.transpose(kep_final_inter)
                kep_final_inter = np.resize(kep_final_inter, ((7, 1)))
                kep_final_inter[6, 0] = sgp4.rev_per_day(kep_final_inter[0, 0])
                kep_elements['Cubic Spline Interpolation'] = kep_final_inter

            elif (choice == 'Ellipse Best Fit'):
                # Apply the ellipse best fit method
                kep_ellip = ellipse_fit.determine_kep(data_after_filter[:,
                                                                        1:])[0]
                kep_final_ellip = np.transpose(kep_ellip)
                kep_final_ellip = np.resize(kep_final_ellip, ((7, 1)))
                kep_final_ellip[6, 0] = sgp4.rev_per_day(kep_final_ellip[0, 0])
                kep_elements['Ellipse Best Fit'] = kep_final_ellip

            else:
                # Apply the Gibbs method

                # first only with first, middle and last measurement
                R = np.array([
                    data_after_filter[:, 1:][0],
                    data_after_filter[:, 1:][len(data_after_filter) // 2],
                    data_after_filter[:, 1:][-1]
                ])

                kep_gibbs = gibbs_method.gibbs_get_kep(R)

                # Determination of orbit period
                semimajor_axis = kep_gibbs[0][0]
                T_orbitperiod = oe.T_orbitperiod(semimajor_axis=semimajor_axis)
                timestamps = data_after_filter[:, 0]
                runtime = np.subtract(timestamps, np.min(timestamps))
                index = np.argmax(
                    runtime >= T_orbitperiod //
                    2) - 1  # only half orbit is good for Gibbs method

                if index < 2:
                    # in case there are not enough points to have the result at index point at 2
                    # or the argmax search does not find anything and sets index = 0.
                    index = len(timestamps) - 1

                # enough data for half orbit
                R = np.array([
                    data_after_filter[:, 1:][0],
                    data_after_filter[:, 1:][index // 2],
                    data_after_filter[:, 1:][index]
                ])

                kep_gibbs = gibbs_method.gibbs_get_kep(R)

                # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
                # We set an estimate of measurement variance R = 0.01 ** 2
                kep_final_gibbs = lamberts_kalman.kalman(kep_gibbs, 0.01**2)

                kep_final_gibbs = np.transpose(kep_final_gibbs)
                kep_final_gibbs = np.resize(kep_final_gibbs, ((7, 1)))
                kep_final_gibbs[6, 0] = sgp4.rev_per_day(kep_final_gibbs[0, 0])
                kep_elements['Gibbs 3 Vector'] = kep_final_gibbs

    kep_final = np.zeros((7, len(kep_elements)))
    order = []
    for index, key in enumerate(kep_elements):
        kep_final[:, index] = np.ravel(kep_elements[key])
        order.append(str(key))

    # Print the final orbital elements for all solutions
    kep_elements = [
        "Semi major axis (a)(km)", "Eccentricity (e)", "Inclination (i)(deg)",
        "Argument of perigee (ω)(deg)",
        "Right acension of ascending node (Ω)(deg)", "True anomaly (v)(deg)",
        "Frequency (f)(rev/day)"
    ]

    for i in range(0, len(order)):
        print("\n******************Output for %s Method******************\n" %
              order[i])
        for j in range(0, 7):
            print("%s: %.16f" % (kep_elements[j], kep_final[j, i]))

    print("\nShow plots? [y/n]")
    user_input = input()

    if (user_input == "y" or user_input == "Y"):
        for j in range(0, len(order)):
            # Plot the initial data set, the filtered data set and the final orbit
            # First we transform the set of keplerian elements into a state vector
            state = kep_state.kep_state(np.resize(kep_final[:, j], (7, 1)))

            # Then we produce more state vectors at varius times using a Runge Kutta algorithm
            keep_state = np.zeros((6, 150))
            ti = 0.0
            tf = 1.0
            t_hold = np.zeros((150, 1))
            x = state
            h = 0.1
            tetol = 1e-04
            for i in range(0, 150):
                keep_state[:,
                           i] = np.ravel(rkf78.rkf78(6, ti, tf, h, tetol, x))
                t_hold[i, 0] = tf
                tf = tf + 1

            positions = keep_state[0:3, :]

            ## Finally we plot the graph
            mpl.rcParams['legend.fontsize'] = 10
            fig = plt.figure()
            ax = fig.gca(projection='3d')
            ax.plot(data[:, 1],
                    data[:, 2],
                    data[:, 3],
                    ".",
                    label='Initial data ')
            ax.plot(data_after_filter[:, 1],
                    data_after_filter[:, 2],
                    data_after_filter[:, 3],
                    "k",
                    linestyle='-',
                    label='Filtered data')
            ax.plot(positions[0, :],
                    positions[1, :],
                    positions[2, :],
                    "r-",
                    label='Orbit after %s method' % order[j])
            ax.legend()
            ax.can_zoom()
            ax.set_xlabel('x (km)')
            ax.set_ylabel('y (km)')
            ax.set_zlabel('z (km)')
            plt.show()
Example #4
0
import os
import sys
from pprint import pprint
import inquirer

sys.path.append(os.path.realpath('.'))

questions = [
    inquirer.Checkbox('interests',
                      message="What are you interested in?",
                      choices=[
                          'October', 'Books', 'Science', 'Nature', 'Fantasy',
                          'History'
                      ],
                      default=['October']),
]

answers = inquirer.prompt(questions)

pprint(answers)
Example #5
0
# Get all the instance types using the new DescribeInstanceTypeOfferings API
instance_types = paginate(To
                          operation='describe_instance_type_offerings',
                          key='InstanceTypeOfferings')

# Set up a Map of attributes a user can request to compare
# Also allows us to provide "Friendly" table headers later
attribute_map = {'Hibernation Supported': 'HibernationSupported', 'Hypervisor': 'Hypervisor', 'Free Tier': 'FreeTierEligible', 'Current Generation': 'CurrentGeneration',
                 'Bare Metal': 'BareMetal'
                 }

# Using inquirer, setup a checkbox selection from the instance types we got back
# Our choices will be only the InstanceType key from every result, sorted.
questions = [
    inquirer.Checkbox(
        'i_types', "What Types do you want to know more about?", choices=sorted([x['InstanceType'] for x in instance_types])),
    inquirer.Checkbox(
        'attributes', "Which Attributes would you like to compare?", choices=sorted(attribute_map.keys())
    )
]

# Get the Input from a user
answers = inquirer.prompt(questions)

# Get All the extra info about the selected instances using the new DescribeInstanceTypes API
extra_info = paginate('describe_instance_types', 'InstanceTypes', args={
    'InstanceTypes': answers['i_types']
})

# Create the table rows based on the user input
rows = []
Example #6
0
import os
import sys
from pprint import pprint

sys.path.append(os.path.realpath("."))
import inquirer  # noqa

questions = [
    inquirer.Checkbox(
        "interests",
        message="What are you interested in?",
        choices=[
            ("Computers", "c"),
            ("Books", "b"),
            ("Science", "s"),
            ("Nature", "n"),
            ("Fantasy", "f"),
            ("History", "h"),
        ],
        default=["c", "b"],
    ),
]

answers = inquirer.prompt(questions)

pprint(answers)
if __name__ == '__main__':

    # Options for questions.
    output_choices = [
        'I want to display the results directly.',
        'I want the results to be saved to output directory only.',
        'I want both.']
    figure_choices = ['Figure 2', 'Table 3', 'Figure 3', 'Figure 4',
                      'Figure 5', 'Figure 6']

    # Questions to select the data and methods.
    questions = [
        inquirer.Checkbox(
            'figure',
            message="What figure are you interested in?",
            choices=figure_choices,
            validate=non_empty_validation,
            ),
        inquirer.List(
            'output',
            message="How do you want the results to be generated?",
            choices=output_choices
            ),
    ]
    answers = inquirer.prompt(questions)

    produce_output(
        answers['figure'],
        output_choices.index(answers['output'])
    )
Example #8
0
    file_handler = FileHandler(out_file_path, 'a')
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(LoggingConfig.formatter)
    log.addHandler(file_handler)

    banner(log)
    if not is_arguments_valid(log, root, out_dir, timezone):
        log.info("[+] Mac Ripper Cli finished.")
        sys.exit(1)
    log.info("[+] EVIDENCE ROOT PATH : " + root)
    log.info("[+] OUTPUT PATH : " + out_dir)
    log.info("[+] TIMEZONE : " + timezone)

    q = [
        inquirer.Checkbox(
            'parsers',
            message="実行モジュールを選択して下さい(右矢印キーで選択、左矢印キーで解除)",
            choices=['Plist', 'Mru', 'Sqlite', 'Unified log', 'Spotlight'])
    ]
    selected_parser_names = inquirer.prompt(q)["parsers"]
    print(selected_parser_names)
    parsers = []
    for selected in selected_parser_names:
        if selected == "Plist":
            parsers.append(CliPlist(log))
        elif selected == "Mru":
            parsers.append(CliMru(log))
        elif selected == "Sqlite":
            parsers.append(CliSqlite(log))
        elif selected == "Unified log":
            parsers.append(CliUnifiedLogs(log))
        elif selected == "Spotlight":
Example #9
0
def process(data_file, error_apriori, units):
    '''
    Given a .csv data file in the format of (time, x, y, z) applies both filters, generates a filtered.csv data
    file, prints out the final keplerian elements computed from both Lamberts and Interpolation and finally plots
    the initial, filtered data set and the final orbit.

    Args:
        data_file (string): The name of the .csv file containing the positional data
        error_apriori (float): apriori estimation of the measurements error in km

    Returns:
        Runs the whole process of the program
    '''

    # First read the csv file called "orbit" with the positional data
    print("Imported file format is:",
          read_data.detect_file_format(data_file)["file"])
    print("")
    data = read_data.load_data(data_file)

    if (units == 'm'):
        # Transform m to km
        data[:, 1:4] = data[:, 1:4] / 1000

    print(
        "***********Choose filter(s) in desired order of application***********"
    )
    print(
        "(SPACE to toggle, UP/DOWN to navigate, RIGHT/LEFT to select/deselect and ENTER to submit)"
    )
    print(
        "*if nothing is selected, Triple Moving Average followed by Savitzky Golay will be applied"
    )
    questions = [
        inquirer.Checkbox(
            'filter',
            message="Select filter(s)",
            choices=[
                'None', 'Savitzky Golay Filter',
                'Triple Moving Average Filter', 'Wiener Filter'
            ],
        ),
    ]
    choices = inquirer.prompt(questions)
    data_after_filter = data

    if (len(choices['filter']) == 0):
        print("Applying Triple Moving Average followed by Savitzky Golay...")
        # Apply the Triple moving average filter with window = 3
        data_after_filter = triple_moving_average.generate_filtered_data(
            data_after_filter, 3)

        # Use the golay_window.py script to find the window for the Savitzky Golay filter based on the error you input
        window = golay_window.window(error_apriori, data_after_filter)

        polyorder = 3
        if polyorder < window:
            # Apply the Savitzky Golay filter with window = window (51 for example_data/orbit.csv) and polynomial order = 3
            data_after_filter = sav_golay.golay(data_after_filter, window,
                                                polyorder)

    else:
        for index, choice in enumerate(choices['filter']):
            if (choice == 'None'):
                print("Using the original data...")
                # no filter is applied
                data_after_filter = data_after_filter

            elif (choice == 'Savitzky Golay Filter'):
                print("Applying Savitzky Golay Filter...")
                # Use the golay_window.py script to find the window for the Savitzky Golay filter
                # based on the error you input
                window = golay_window.window(error_apriori, data_after_filter)

                polyorder = 3
                if polyorder < window:
                    # Apply the Savitzky Golay filter with window = window (51 for example_data/orbit.csv) and polynomial order = 3
                    data_after_filter = sav_golay.golay(
                        data_after_filter, window, polyorder)

            elif (choice == 'Wiener Filter'):
                print("Applying Wiener Filter...")
                # Apply the Wiener filter
                data_after_filter = wiener.wiener_new(data_after_filter, 3)

            else:
                print("Applying Triple Moving Average Filter...")
                # Apply the Triple moving average filter with window = 3
                data_after_filter = triple_moving_average.generate_filtered_data(
                    data_after_filter, 3)

    # Compute the residuals between filtered data and initial data and then the sum and mean values of each axis
    res = data_after_filter[:, 1:4] - data[:, 1:4]
    sums = np.sum(res, axis=0)
    print("\nDisplaying the sum of the residuals for each axis")
    print(sums, "\n")

    means = np.mean(res, axis=0)
    print("Displaying the mean of the residuals for each axis")
    print(means, "\n")

    # Save the filtered data into a new csv called "filtered"
    np.savetxt("filtered.csv", data_after_filter, delimiter=",")

    print("***********Choose Method(s) for Orbit Determination***********")
    print(
        "(SPACE to toggle, UP/DOWN to navigate, RIGHT/LEFT to select/deselect and ENTER to submit)"
    )
    print(
        "*if nothing is selected, Cubic Spline Interpolation will be used for Orbit Determination"
    )
    questions = [
        inquirer.Checkbox(
            'method',
            message="Select Method(s)",
            choices=[
                'Lamberts Kalman', 'Cubic Spline Interpolation',
                'Ellipse Best Fit', 'Gibbs 3 Vector', 'Gauss 3 Vector',
                'MCMC (exp.)'
            ],
        ),
    ]
    choices = inquirer.prompt(questions)
    kep_elements = {}

    if (len(choices['method']) == 0):
        # Apply the interpolation method
        kep_inter = interpolation.main(data_after_filter)
        # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
        # We set an estimate of measurement variance R = 0.01 ** 2
        kep_final_inter = lamberts_kalman.kalman(kep_inter, 0.01**2)
        kep_final_inter = np.transpose(kep_final_inter)
        kep_final_inter = np.resize(kep_final_inter, ((7, 1)))
        kep_final_inter[6, 0] = sgp4.rev_per_day(kep_final_inter[0, 0])
        kep_elements['Cubic Spline Interpolation'] = kep_final_inter

    else:
        for index, choice in enumerate(choices['method']):
            if (choice == 'Lamberts Kalman'):
                # Apply Lambert Kalman method for the filtered data set

                #previously, all data...
                #kep_lamb = lamberts_kalman.create_kep(data_after_filter)

                # only three (3) observations from half an orbit.
                # also just two (2) observations are fine for lamberts.
                data = np.array([
                    data_after_filter[:, :][0],
                    data_after_filter[:, :][len(data_after_filter) // 2],
                    data_after_filter[:, :][-1]
                ])

                kep_lamb = lamberts_kalman.create_kep(data)

                # Determination of orbit period
                semimajor_axis = kep_lamb[0][0]
                timestamps = data_after_filter[:, 0]

                index = get_timestamp_index_by_orbitperiod(
                    semimajor_axis, timestamps)

                # enough data for half orbit
                data = np.array([
                    data_after_filter[:, :][0],
                    data_after_filter[:, :][index // 2],
                    data_after_filter[:, :][index]
                ])

                kep_lamb = lamberts_kalman.create_kep(data)

                # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
                # We set an estimate of measurement variance R = 0.01 ** 2
                kep_final_lamb = lamberts_kalman.kalman(kep_lamb, 0.01**2)
                kep_final_lamb = np.transpose(kep_final_lamb)
                kep_final_lamb = np.resize(kep_final_lamb, ((7, 1)))
                kep_final_lamb[6, 0] = sgp4.rev_per_day(kep_final_lamb[0, 0])
                kep_elements['Lamberts Kalman'] = kep_final_lamb

            elif (choice == 'Cubic Spline Interpolation'):
                # Apply the interpolation method
                kep_inter = interpolation.main(data_after_filter)
                # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
                # We set an estimate of measurement variance R = 0.01 ** 2
                kep_final_inter = lamberts_kalman.kalman(kep_inter, 0.01**2)
                kep_final_inter = np.transpose(kep_final_inter)
                kep_final_inter = np.resize(kep_final_inter, ((7, 1)))
                kep_final_inter[6, 0] = sgp4.rev_per_day(kep_final_inter[0, 0])
                kep_elements['Cubic Spline Interpolation'] = kep_final_inter

            elif (choice == 'Ellipse Best Fit'):
                # Apply the ellipse best fit method
                kep_ellip = ellipse_fit.determine_kep(data_after_filter[:,
                                                                        1:])[0]
                kep_final_ellip = np.transpose(kep_ellip)
                kep_final_ellip = np.resize(kep_final_ellip, ((7, 1)))
                kep_final_ellip[6, 0] = sgp4.rev_per_day(kep_final_ellip[0, 0])
                kep_elements['Ellipse Best Fit'] = kep_final_ellip

            elif (choice == 'Gibbs 3 Vector'):
                # Apply the Gibbs method

                # first only with first, middle and last measurement
                R = np.array([
                    data_after_filter[:, 1:][0],
                    data_after_filter[:, 1:][len(data_after_filter) // 2],
                    data_after_filter[:, 1:][-1]
                ])

                kep_gibbs = gibbs_method.gibbs_get_kep(R)

                # Determination of orbit period
                semimajor_axis = kep_gibbs[0][0]
                timestamps = data_after_filter[:, 0]

                index = get_timestamp_index_by_orbitperiod(
                    semimajor_axis, timestamps)

                # enough data for half orbit
                R = np.array([
                    data_after_filter[:, 1:][0],
                    data_after_filter[:, 1:][index // 2],
                    data_after_filter[:, 1:][index]
                ])

                kep_gibbs = gibbs_method.gibbs_get_kep(R)

                # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
                # We set an estimate of measurement variance R = 0.01 ** 2
                kep_final_gibbs = lamberts_kalman.kalman(kep_gibbs, 0.01**2)
                kep_final_gibbs = np.transpose(kep_final_gibbs)
                kep_final_gibbs = np.resize(kep_final_gibbs, ((7, 1)))
                kep_final_gibbs[6, 0] = sgp4.rev_per_day(kep_final_gibbs[0, 0])
                kep_elements['Gibbs 3 Vector'] = kep_final_gibbs

            elif (choice == 'Gauss 3 Vector'):
                # Apply the Gauss method

                # first only with first, middle and last measurement
                R = np.array([
                    data_after_filter[:, 1:][0],
                    data_after_filter[:, 1:][len(data_after_filter) // 2],
                    data_after_filter[:, 1:][-1]
                ])

                t1 = data_after_filter[:, 0][0]
                t2 = data_after_filter[:, 0][len(data_after_filter) // 2]
                t3 = data_after_filter[:, 0][-1]

                v2 = gauss_method.gauss_method_get_velocity(
                    R[0], R[1], R[2], t1, t2, t3)

                # Determination of orbit period
                semimajor_axis = oe.semimajor_axis(R[0], v2)
                timestamps = data_after_filter[:, 0]

                index = get_timestamp_index_by_orbitperiod(
                    semimajor_axis, timestamps)

                # enough data for half orbit
                R = np.array([
                    data_after_filter[:, 1:][0],
                    data_after_filter[:, 1:][index // 2],
                    data_after_filter[:, 1:][index]
                ])

                t1 = data_after_filter[:, 0][0]
                t2 = data_after_filter[:, 0][index // 2]
                t3 = data_after_filter[:, 0][index]

                v2 = gauss_method.gauss_method_get_velocity(
                    R[0], R[1], R[2], t1, t2, t3)

                semimajor_axis = oe.semimajor_axis(R[0], v2)
                ecc = oe.eccentricity_v(R[1], v2)
                ecc = np.linalg.norm(ecc)
                inc = oe.inclination(R[1], v2) * 180.0 / np.pi
                AoP = oe.AoP(R[1], v2) * 180.0 / np.pi
                raan = oe.raan(R[1], v2) * 180.0 / np.pi
                true_anomaly = oe.true_anomaly(R[1], v2) * 180.0 / np.pi
                T_orbitperiod = oe.T_orbitperiod(semimajor_axis=semimajor_axis)
                n_mean_motion_perday = oe.n_mean_motion_perday(T_orbitperiod)

                kep_gauss = np.array([[
                    semimajor_axis, ecc, inc, AoP, raan, true_anomaly,
                    n_mean_motion_perday
                ]])

                # Apply Kalman filters to find the best approximation of the keplerian elements for all solutions
                # We set an estimate of measurement variance R = 0.01 ** 2
                kep_final_gauss = lamberts_kalman.kalman(kep_gauss, 0.01**2)
                kep_final_gauss = np.transpose(kep_final_gauss)
                kep_final_gauss = np.resize(kep_final_gauss, ((7, 1)))
                kep_final_gauss[6, 0] = sgp4.rev_per_day(kep_final_gauss[0, 0])
                kep_elements['Gauss 3 Vector'] = kep_final_gauss

            else:
                # apply mcmc method, a real optimizer

                # all data
                timestamps = data_after_filter[:, 0]
                R = np.array(data_after_filter[:, 1:])

                # all data can make the MCMC very slow. so we just pick a few in random, but in order.
                timestamps_short = []
                R_short = []
                if len(timestamps) > 25:
                    print(
                        "Too many positions for MCMC. Just 25 positons are selected"
                    )

                    # pick randomly, but in order and no duplicates
                    l = list(
                        np.linspace(0,
                                    len(timestamps) - 1,
                                    num=len(timestamps)))
                    select_index = sorted(random.sample(list(l)[1:-1], k=23))
                    print(select_index)

                    timestamps_short.append(timestamps[0])
                    R_short.append(R[0])

                    for select in range(len(select_index)):
                        timestamps_short.append(timestamps[int(
                            select_index[select])])
                        R_short.append(R[int(select_index[select])])

                    timestamps_short.append(timestamps[-1])
                    R_short.append(R[-1])

                else:
                    timestamps_short = timestamps
                    R_short = R

                parameters = with_mcmc.fromposition(timestamps_short, R_short)

                r_a = parameters["r_a"]
                r_p = parameters["r_p"]
                AoP = parameters["AoP"]
                inc = parameters["inc"]
                raan = parameters["raan"]
                tp = parameters["tp"]

                semimajor_axis = (r_p + r_a) / 2.0
                ecc = (r_a - r_p) / (r_a + r_p)
                T_orbitperiod = oe.T_orbitperiod(semimajor_axis=semimajor_axis)
                true_anomaly = tp / T_orbitperiod * 360.0
                n_mean_motion_perday = oe.n_mean_motion_perday(T_orbitperiod)

                kep_mcmc = np.array([[
                    semimajor_axis, ecc, inc, AoP, raan, true_anomaly,
                    n_mean_motion_perday
                ]])

                kep_elements['MCMC (exp.)'] = kep_mcmc

    kep_final = np.zeros((7, len(kep_elements)))
    order = []
    for index, key in enumerate(kep_elements):
        kep_final[:, index] = np.ravel(kep_elements[key])
        order.append(str(key))

    # Print the final orbital elements for all solutions
    kep_elements = [
        "Semi major axis (a)(km)", "Eccentricity (e)", "Inclination (i)(deg)",
        "Argument of perigee (ω)(deg)",
        "Right acension of ascending node (Ω)(deg)", "True anomaly (v)(deg)",
        "Frequency (f)(rev/day)"
    ]

    for i in range(0, len(order)):
        print("\n******************Output for %s Method******************\n" %
              order[i])
        for j in range(0, 7):
            print("%s: %.16f" % (kep_elements[j], kep_final[j, i]))

    print("\nShow plots? [y/n]")
    user_input = input()

    if (user_input == "y" or user_input == "Y"):
        for j in range(0, len(order)):
            # Plot the initial data set, the filtered data set and the final orbit
            # First we transform the set of keplerian elements into a state vector
            state = kep_state.kep_state(np.resize(kep_final[:, j], (7, 1)))

            # Then we produce more state vectors at varius times using a Runge Kutta algorithm
            keep_state = np.zeros((6, 150))
            ti = 0.0
            tf = 1.0
            t_hold = np.zeros((150, 1))
            x = state
            h = 0.1
            tetol = 1e-04
            for i in range(0, 150):
                keep_state[:,
                           i] = np.ravel(rkf78.rkf78(6, ti, tf, h, tetol, x))
                t_hold[i, 0] = tf
                tf = tf + 1

            positions = keep_state[0:3, :]

            ## Finally we plot the graph
            mpl.rcParams['legend.fontsize'] = 10
            fig = plt.figure()
            ax = plt.axes(projection='3d')
            ax.plot(data[:, 1],
                    data[:, 2],
                    data[:, 3],
                    ".",
                    label='Initial data ')
            ax.plot(data_after_filter[:, 1],
                    data_after_filter[:, 2],
                    data_after_filter[:, 3],
                    "k",
                    linestyle='-',
                    label='Filtered data')
            ax.plot(positions[0, :],
                    positions[1, :],
                    positions[2, :],
                    "r-",
                    label='Orbit after %s method' % order[j])
            ax.legend()
            ax.can_zoom()
            ax.set_xlabel('x (km)')
            ax.set_ylabel('y (km)')
            ax.set_zlabel('z (km)')
            plt.show()
Example #10
0
def main():
    '''
    Create Gitlab issues from terminal.
    Gitlab access token is required and a environment var must be exported:
    export GL_ACCESS_TOKEN='YOUR_GITLAB_ACCESS_TOKEN_HERE'

    To commit to BdiL project directly, export the following environment vars:
    export GL_SKIP_REPO_TYPES='True'
    export GL_GROUP='stoqtech'
    export GL_PROJECT='private/bdil'
    '''

    access_token = os.getenv("GL_ACCESS_TOKEN")
    assert access_token, access_token

    if os.getenv("GL_SKIP_REPO_TYPES"):
        repo_type = 'group'
    else:
        repo_types = ['personal', 'group']
        questions = [
            inquirer.List('repo type',
                          message="Repository type",
                          choices=repo_types)
        ]
        repo_type = list(inquirer.prompt(questions).values())[0]

    # Group or user
    if repo_type == 'group':
        group = os.getenv("GL_GROUP")
        if group is None:
            print("What's the group?")
            group = ''
            while group == '':
                group = prompt('>')
    else:
        user = os.getenv("GL_USER")
        if user is None:
            print("What's the user?")
            user = ''
            while user == '':
                user = prompt('>')

    # Project
    project = os.getenv("GL_PROJECT")
    if project is None:
        print("What's the project? (If it's private, start with private/")
        project = ''
        while project == '':
            project = prompt('>')

    repo_formatted = ''
    if repo_type == 'group':
        repo_formatted = (group + '/' + project).replace('/', '%2F')
    else:
        repo_formatted = (user + '/' + project).replace('/', '%2F')

    # Labels
    print('Getting labels...')
    if repo_type == 'group':
        labels_url = "https://gitlab.com/api/v4/groups/{}/labels/".format(
            group)
    else:
        labels_url = "https://gitlab.com/api/v4/projects/{}/labels/".format(
            repo_formatted)
    params = dict(per_page='100')
    result = requests.get(
        labels_url,
        headers={"Private-Token": os.getenv("GL_ACCESS_TOKEN")},
        params=params)
    labels_list = []
    for label in result.json():
        labels_list.append(label['name'])

    # Members
    members = get_members(repo_formatted)
    members_name = []
    for member in members:
        members_name.append(member['name'])

    print("\nWhat's the title?")
    title = ''
    while title == '':
        title = prompt('>')

    print("\nWhat's the description?")
    description = ''
    while description == '':
        description = prompt('>')

    print("\nWho is the assignee?")
    questions = [
        inquirer.List('members',
                      message="Selected assignee",
                      choices=members_name)
    ]
    assignee = list(inquirer.prompt(questions).values())[0]
    user_id = ''
    for member in members:
        if member['name'] == assignee:
            user_id = member['id']
            break

    print("\nWhich labels should it contain? (Press space to select)")
    questions = [
        inquirer.Checkbox('labels',
                          message="Selected labels",
                          choices=labels_list)
    ]
    labels = inquirer.prompt(questions)
    labels_value = ''
    for val in list(labels.values())[0]:
        labels_value += val + ','

    params = dict(
        title=title,
        description=description,
        labels=labels_value,
        assignee_ids=[user_id],
    )

    gitlab_url = "https://gitlab.com/api/v4/projects/{}/issues/".format(
        repo_formatted)
    new_issue = requests.post(
        gitlab_url,
        headers={"Private-Token": os.getenv("GL_ACCESS_TOKEN")},
        params=params)
    web_url = new_issue.json()['web_url']
    pyperclip.copy(web_url)
    print(web_url)
Example #11
0
def prompt_targets(question,
                   targets=None,
                   instances=None,
                   multiple=True,
                   config=None):
    if targets == None and instances == None or targets != None and instances != None:
        raise RuntimeError(
            "Provide exactly one of either 'targets' or 'instances'")

    if targets:
        instances = inventory.search(config, targets)

    if len(instances) == 0:
        return []

    if len(instances) == 1:
        return instances

    display_instances = collections.OrderedDict()
    # TODO: fix cap'd length... it's pretty arbitraty
    maxLen = min(max([len(instance.name) for instance in instances]), 55)
    for instance in sorted(instances):
        display = str("%-" + str(maxLen + 3) + "s (%s)") % (instance.name,
                                                            instance.address)
        display_instances[display] = instance

    questions = []

    if multiple:
        question = inquirer.Checkbox(
            'instance',
            message="%s%s%s (space to multi-select, enter to finish)" %
            (utils.term.bold + utils.term.underline, question,
             utils.term.normal),
            choices=list(display_instances.keys()) + ['all'],
            # default='all'
        )
    else:
        question = inquirer.List(
            'instance',
            message="%s%s%s (enter to select)" %
            (utils.term.bold, question, utils.term.normal),
            choices=list(display_instances.keys()),
        )
    questions.append(question)

    answers = None
    try:
        answers = inquirer.prompt(questions,
                                  theme=THEMER,
                                  raise_keyboard_interrupt=True)
    except KeyboardInterrupt:
        logger.error("Cancelled by user")
        sys.exit(1)

    if 'all' in answers["instance"]:
        selected_hosts = instances
    else:
        selected_hosts = []
        if not multiple:
            answers["instance"] = [answers["instance"]]
        for answer in answers["instance"]:
            selected_hosts.append(display_instances[answer])

    return selected_hosts
Example #12
0
import inquirer

if __name__ == '__main__':
    questions = [
        inquirer.Text('user', message='Please enter your github username', validate=lambda _, x: x != '.'),
        inquirer.Password('password', message='Please enter your password'),
        inquirer.Text('repo', message='Please enter the repo name', default='default'),
        inquirer.Checkbox('topics', message='Please define your type of project?',
                          choices=['common', 'backend', 'frontend'], ),
        inquirer.Text('organization',
                      message='If this is a repo from a organization please enter the organization name, if not just leave this blank'),
        inquirer.Confirm('correct', message='This will delete all your current labels and create a new ones. Continue?',
                         default=False),
    ]

    answers = inquirer.prompt(questions)

    print(answers)
Example #13
0
password_box.send_keys('PASS')

driver.find_element_by_class_name('btn-submit').click()

driver.get('https://mess.iiit.ac.in/mess/web/student_cancel.php')

today = date.today()
datelist = ['TODAY']
for i in range(1, 8):
    date = today + timedelta(days=i)
    datelist.append(str(date))
datelist += dayes
date = [
    inquirer.Checkbox(
        'dates',
        message=color.BOLD + color.CYAN + 'SELECT THE DATE'.center(40, "*") +
        color.END,
        choices=datelist,
    ),
]
dat = inquirer.prompt(date)
alldates = dat.get('dates')

meals = [
    inquirer.Checkbox(
        'interests',
        message=color.BOLD + color.CYAN + "SELECT MEALS".center(40, "*") +
        color.END + "---using space",
        choices=['breakfast', 'lunch', 'dinner', 'uncancel'],
    ),
]
check = inquirer.prompt(meals)
Example #14
0
    try:
        int(current)
        return True
    except ValueError:
        raise errors.ValidationError(
            '', reason='Provided value is not an integer!')


questions = [
    inquirer.Text(
        'college',
        message='Keywords to find in college name (Leave blank for all)?',
        default=''),
    inquirer.Checkbox(
        'quota',
        message=
        'Quota? (Use space to deselect, X = selected, O = not selected)',
        choices=data["values"]["quota"],
        default=["AI", "OS"]),
    inquirer.Checkbox('category',
                      message='Category?',
                      choices=data["values"]["category"],
                      default=[
                          x for x in data["values"]["category"]
                          if ("gen" in x.lower() or "obc" in x.lower())
                          and "pwd" not in x.lower()
                      ]),
    inquirer.Checkbox('seat_pool',
                      message='Seat Pool?',
                      choices=data["values"]["seat_pool"],
                      default=["Gender-Neutral"]),
    inquirer.Text(
Example #15
0
# for i in binFileNames:
#     baseName = os.path.basename(i)
#     # print(i)
#     binFileJustNames.append(baseName)

binFileJustNames.sort()

chosenBinFiles = []

if len(binFileNames) != 0:
    if bl_update == "1":
        chosenBinFiles.append("02_m3_fw.bin")
    else :
        questions = [
          inquirer.Checkbox('interests',
                            message="Use UP/DOWN keys and use SPACEBAR to select or deselect the files to be downloaded",
                            choices=binFileJustNames,
                            ),
        ]
        answers = inquirer.prompt(questions)
        chosenBinFiles = answers['interests']

        print(chosenBinFiles)
    name = ""

    for x in range(len(chosenBinFiles)): 
        name = name + " " + filePath + "/" +chosenBinFiles[x]
        # print("name ", name)

    # print("Files downloaded : ", name)

    if bl_update == "1":
Example #16
0
    f"{url}/api/scanreporttablesfilter/?scan_report=317&fields=id,name",
    headers=headers)
tables = response.json()


def get_fields(table_id):
    response = requests.get(
        f"{url}/api/scanreportfieldsfilter/?scan_report_table={table_id}&fields=id,name",
        headers=headers)
    fields = response.json()
    return fields


questions = [
    inquirer.Checkbox('tables',
                      message=f"Which tables to process?",
                      choices=tables)
]
answers = inquirer.prompt(questions)

tables = answers['tables']

for obj in tables:
    table_id = obj['id']
    fields = get_fields(table_id)

    questions = [
        inquirer.Checkbox('fields',
                          message=f"{obj['name']}: Which fields to process?",
                          choices=fields)
    ]
Example #17
0
        port = get_port()
        tvasion(ip, port, "FUD reverse shell", "")
    elif encrypted_item == "msf":
        msf_item = select_item(msf, msf_size)
        if msf_item == "windows/x64/exec":
            tvasion("", "", "msf", msf_item)
        elif msf_item == "windows/x64/meterpreter/reverse_tcp":
            ip = get_ip()
            port = get_port()
            tvasion(ip, port, "msf", msf_item)
elif os_item == "install scripts":
    items = []
    questions = [
        inquirer.Checkbox(
            'scripts',
            message="use space to select tool(s) and press enter for install ",
            choices=['smb-login-brute.sh', 'oneliner.py', 'basic-web-enum.py'],
        )
    ]
    answers = inquirer.prompt(questions)
    if len(answers['scripts']) == 0:
        print(Fore.RED + "[-] No script selected !")
        exit()
    else:
        items = list(answers.values())
        for i in items[0]:
            install_script(i)
            print(Fore.GREEN + "[+] " + str(i) +
                  " is installed. You can run " + str(i) +
                  " directly from your terminal !")
elif os_item == "install third-party apps":
Example #18
0
import json
with open("p.json") as pfile:
    p = json.load(pfile)
    p_r = {}
    for i, x in enumerate(p):
        p_r[x] = i

import inquirer
questions = [
    inquirer.Checkbox(
        'interests',
        message="What are you interested in?",
        choices=p,
    ),
    inquirer.Checkbox(
        'are',
        message="What are you?",
        choices=p,
    ),
]
answers = inquirer.prompt(questions)
a_i = [p_r[x] for x in answers["interests"]]
a_a = [p_r[x] for x in answers["are"]]
c = {"i": a_i, "a": a_a}

with open("config.json", "w") as cfile:
    json.dump(c, cfile)

print("config written")
Example #19
0
def install():
    preflight_checks()

    questions = [
        inquirer.Text('cluster-name', message="Name of the cluster"),
        inquirer.List(
            'cluster-provider',
            message="On which provider should we create the kubernetes cluster",
            choices=CLUSTER_PROVIDERS,
        ),
        inquirer.List(
            'infrabox-version',
            message="Which version of InfraBox do you want to install",
            choices=['1.1.4'],
        ),
        inquirer.Text('admin-email', message="Admin email"),
        inquirer.Checkbox(
            'components',
            message="Which component would you like to configure",
            choices=['Github'],
        ),
    ]
    config = inquirer.prompt(questions)

    if 'Github' in config['components']:
        questions = [
            inquirer.Text('github-client-id', message="Github Client ID"),
            inquirer.Text('github-client-secret',
                          message="Github Client Secret"),
            inquirer.Text(
                'github-allowed-orgs',
                message=
                "Comma separated list of Github Organizations allowed to login"
            ),
        ]

        answers = inquirer.prompt(questions)
        config.update(answers)

    questions = [
        inquirer.List(
            'start',
            message="Select yes to start installation",
            choices=['no', 'yes'],
        ),
    ]

    answers = inquirer.prompt(questions)
    if answers['start'] != 'yes':
        return

    config['admin-password'] = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(10))

    if config['cluster-provider'] == CLUSTER_PROVIDERS[0]:
        create_gke_cluster(config['cluster-name'])

    config['workdir'] = '/tmp/install-infrabox/%s' % config['cluster-name']

    create_namespaces()
    install_helm()
    install_postgres()
    install_minio()
    install_nginx_ingress()
    config['host'] = get_host()
    install_certificates(config)
    clone_repo(config)
    generate_keys(config)
    helm_install_infrabox(config)

    print("Your InfraBox is ready: https://%s" % config['host'])
    print()

    if 'Github' in config['components']:
        print(
            "IMPORTANT: Update your Github callback url to: https://%s/github/auth/callback"
            % config['host'])
        print()

    print("The configuration has been stored here: %s" % config['workdir'])
    print("Please keep a backup of it at a secure place.")
    print(
        "It contains secret data like the encryption key and your admin password."
    )
Example #20
0
def ask_questions():
    model_name_question = [
        inquirer.Text(name='value', message='your model name ()')
    ]
    model_name = prompt(model_name_question)

    task_type_question = [
        inquirer.List(name='value',
                      message='choose task type',
                      choices=task_type_choices)
    ]
    task_type = prompt(task_type_question)

    network_name_question = [
        inquirer.List(name='value',
                      message='choose network',
                      choices=network_name_choices(task_type))
    ]
    network_name = prompt(network_name_question)

    dataset_format_question = [
        inquirer.List(name='value',
                      message='choose dataset format',
                      choices=dataset_format_choices(task_type))
    ]
    dataset_format = prompt(dataset_format_question)

    enable_data_augmentation = [
        inquirer.Confirm(name='value',
                         message='enable data augmentation?',
                         default=True)
    ]

    train_dataset_path_question = [
        inquirer.Text(name='value', message='training dataset path')
    ]
    train_path = prompt(train_dataset_path_question)

    enable_test_dataset_path_question = [
        inquirer.List(
            name='value',
            message='set validation dataset?'
            ' (if answer no, the dataset will be separated for training and validation'
            ' by 9:1 ratio.)',
            choices=['yes', 'no'])
    ]
    enable_test_dataset_path = prompt(enable_test_dataset_path_question)

    test_dataset_path_question = [
        inquirer.Text(name='value', message='validation dataset path')
    ]
    if enable_test_dataset_path == 'yes':
        test_path = prompt(test_dataset_path_question)
    else:
        test_path = None

    batch_size_question = [
        inquirer.Text(name='value',
                      message='batch size (integer)',
                      default=default_batch_size(task_type),
                      validate=integer_validate)
    ]
    batch_size = prompt(batch_size_question)

    image_size_question = [
        inquirer.Text(name='value',
                      message='image size (integer x integer)',
                      default='128x128',
                      validate=generate_image_size_validate(network_name))
    ]
    image_size = image_size_filter(prompt(image_size_question))

    training_epochs_question = [
        inquirer.Text(name='value',
                      message='how many epochs do you run training (integer)',
                      default='100',
                      validate=integer_validate)
    ]
    training_epochs = prompt(training_epochs_question)

    training_optimizer_question = [
        inquirer.List(name='value',
                      message='select optimizer',
                      choices=['Momentum', 'Adam'],
                      default='Momentum')
    ]
    training_optimizer = prompt(training_optimizer_question)

    initial_learning_rate_value_question = [
        inquirer.Text(name='value',
                      message='initial learning rate',
                      default='0.001')
    ]
    initial_learning_rate_value = prompt(initial_learning_rate_value_question)

    # learning rate schedule
    learning_rate_schedule_question = [
        inquirer.List(
            name='value',
            message='choose learning rate schedule'
            ' ({{epochs}} is the number of training epochs you entered before)',
            choices=list(learning_rate_schedule_map.values()),
            default=learning_rate_schedule_map["constant"])
    ]
    _tmp_learning_rate_schedule = prompt(learning_rate_schedule_question)
    for key, value in learning_rate_schedule_map.items():
        if value == _tmp_learning_rate_schedule:
            learning_rate_schedule = key

    data_augmentation = {}
    if prompt(enable_data_augmentation):
        all_augmentor = {}
        checkboxes = []
        for name, obj in inspect.getmembers(augmentor):
            if inspect.isclass(obj) and issubclass(obj, Processor):
                argspec = inspect.getfullargspec(obj)
                # ignore self
                args = argspec.args[1:]
                defaults = argspec.defaults
                if len(args) == len(defaults):
                    default_val = [(arg, default)
                                   for arg, default in zip(args, defaults)]
                    default_str = " (default: {})".format(", ".join(
                        ["{}={}".format(a, d) for a, d in default_val]))
                else:
                    defaults = ("# Please fill a value.", ) * (
                        len(args) - len(defaults)) + defaults
                    default_val = [(arg, default)
                                   for arg, default in zip(args, defaults)]
                    default_str = " (**caution**: No default value is provided, \
please modify manually after config exported.)"

                all_augmentor[name + default_str] = {
                    "name": name,
                    "defaults": default_val
                }
                checkboxes.append(name + default_str)
        data_augmentation_question = [
            inquirer.Checkbox(name='value',
                              message='Please choose augmentors',
                              choices=checkboxes)
        ]
        data_augmentation_res = prompt(data_augmentation_question)
        if data_augmentation_res:
            for v in data_augmentation_res:
                data_augmentation[all_augmentor[v]
                                  ["name"]] = all_augmentor[v]["defaults"]

    quantize_first_convolution_question = [
        inquirer.Confirm(name='value',
                         message='apply quantization at the first layer?',
                         default=True)
    ]
    quantize_first_convolution = prompt(quantize_first_convolution_question)

    return {
        'model_name': model_name,
        'task_type': task_type,
        'network_name': network_name,
        'network': {
            'quantize_first_convolution': quantize_first_convolution,
        },
        'dataset': {
            'format': dataset_format,
            'train_path': train_path,
            'test_path': test_path,
        },
        'trainer': {
            'batch_size': int(batch_size),
            'epochs': int(training_epochs),
            'optimizer': training_optimizer,
            'learning_rate_schedule': learning_rate_schedule,
            'initial_learning_rate': float(initial_learning_rate_value),
            'save_checkpoint_steps': 1000,
            'keep_checkpoint_max': 5,
        },
        'common': {
            'image_size': [int(val) for val in image_size],
            'pretrain_model': False,
            'dataset_prefetch': True,
            'data_augmentation': data_augmentation,
        },
    }
Example #21
0
    )

    if response.status_code == 201:
        return response.json()["app_url"]
    else:
        print(
            f"Unable to create a ticket: {name} Response code: {response.status_code} Response text: {response.text}"
        )


github_services = GITHUB_SERVICE_OWNERS.keys()

question = {
    inquirer.Checkbox(
        "selected_services",
        message="Create a clubhouse ticket for the following services:",
        choices=github_services,
    )
}

answers = inquirer.prompt(question)

selected_services = answers["selected_services"]

for service in selected_services:

    owner = GITHUB_SERVICE_OWNERS.get(service)
    clubhouse_member_id = CLUBHOUSE_MEMBERS.get(owner)

    for project in CLUBHOUSE_PROJECTS:
        if service in project["services"]:
Example #22
0
def change_tags(**kwargs):
    reviews = sorted(
        load_reviews(),
        key=lambda r:
        (r.metadata["book"]["author"], r.metadata["book"]["title"]),
    )
    tags = sorted(list(load_tags().keys()))

    answers = inquirer.prompt([
        inquirer.List(
            name="tag",
            message="Which tag do you want to work on?",
            choices=tags,
            carousel=True,
        ),
        inquirer.Checkbox(
            name="include",
            message="Show only books with these tags (empty for all)",
            choices=tags + ["no tags"],
        ),
        inquirer.Checkbox(
            name="exclude",
            message="Exclude books with these tags",
            choices=tags,
        ),
    ])

    tag = answers["tag"]
    include = answers["include"]
    exclude = answers["exclude"]

    if include:
        include_empty = "no tags" in include
        reviews = [
            r for r in reviews
            if (include_empty and not r.metadata["book"].get("tags")) or any(
                tag in include for tag in r.metadata["book"].get("tags", []))
        ]

    if exclude:
        reviews = [
            r for r in reviews
            if not any(tag in exclude
                       for tag in r.metadata["book"].get("tags", []))
        ]

    longest_author = max(len(r.metadata["book"]["author"])
                         for r in reviews) + 2
    longest_title = max(len(r.metadata["book"]["title"]) for r in reviews) + 2

    def review_string(r):
        result = r.metadata["book"]["author"].ljust(
            longest_author) + r.metadata["book"]["title"].ljust(longest_title)
        tags = r.metadata["book"].get("tags")
        if tags:
            tag_string = "".join([f"[{tag}]" for tag in tags])
            result = f"{result} {tag_string}"
        return result

    tagged = inquirer.prompt([
        inquirer.Checkbox(
            name="tagged",
            message=f"Books tagged as {tag}",
            choices=[(review_string(r), r) for r in reviews],
            default=[
                r for r in reviews
                if tag in r.metadata["book"].get("tags", [])
            ],
        )
    ])["tagged"]

    for review in reviews:
        if review in tagged:
            review.add_tag(tag)
        else:
            review.remove_tag(tag)
Example #23
0
def confirm_overlap(x, fragments, viewer=None):
    """Show dialogs to confirm overlapping fragments."""
    print('{}: {} overlapping fragments found'.format(x.name, len(fragments)))
    if fragments:
        fragments.sort_values('n_nodes')
        # Have user inspect fragments
        # Show larger fragments in 3d viewer
        if any(fragments.n_nodes > 10):
            # Generate a summary
            large_frags = fragments[fragments.n_nodes > 10]
            s = large_frags.summary(add_props=['overlap_score', 'id'])[[
                'name', 'id', 'n_nodes', 'n_connectors', 'overlap_score'
            ]]
            # Show and let user decide which ones to merge
            if not viewer:
                viewer = navis.Viewer(title='Check overlap')
            # Make sure viewer is actually visible and cleared
            viewer.show()
            viewer.clear()
            # Add original skeleton
            viewer.add(x, color='w')
            viewer.add(large_frags)
            viewer.picking = True
            viewer._picking_text.visible = True
            viewer.show_legend = True

            # Print summary
            print('Large (>10 nodes) overlapping fragments:')
            print(s.to_string(index=False, show_dimensions=False))

            msg = """
            Please check these large fragments for overlap and deselect
            neurons that you DO NOT want to have merged by clicking on
            their names in the legend.
            Hit ENTER when you are ready to proceed or CTRL-C to cancel.
            """

            try:
                _ = input(msg)
            except KeyboardInterrupt:
                raise KeyboardInterrupt('Merge process aborted by user.')
            except BaseException:
                raise

            # Remove deselected fragments
            # Mind you not all fragments are on viewer - this is why we remove
            # neurons that has been hidden
            fragments = fragments[~np.isin(fragments.id, viewer.invisible)]

    # Now ask for smaller fragments via CLI
    if fragments:
        s = fragments.summary(
            add_props=['overlap_score', 'sampler_count', 'id'])[[
                'name', 'id', 'n_nodes', 'n_connectors', 'sampler_count',
                'overlap_score'
            ]]

        # Ask user which neuron should be merged
        msg = """
        Please check the fragments that potentially overlap with the input neuron (white).
        Deselect those that should NOT be merged using the arrows keys.
        Hit ENTER when you are ready to proceed or CTRL-C to abort
        """
        print(msg)

        msg = s.to_string(index=False).split('\n')[0]

        s_str = s.to_string(index=False, show_dimensions=False, header=False)
        choices = [(v, i) for i, v in enumerate(s_str.split('\n'))]
        q = [
            inquirer.Checkbox(name='selection',
                              message=msg,
                              choices=choices,
                              default=list(range(len(choices))))
        ]

        # Ask the question
        selection = inquirer.prompt(q, theme=GreenPassion()).get('selection')

        if isinstance(selection, type(None)):
            raise SystemExit('Merge process aborted by user.')

        # Remove fragments that are not selected
        if selection:
            fragments = fragments[selection]
        else:
            # If no selection, remove all neurons from the list
            fragments = fragments[:0]

    # If no overlapping fragments (either none from the start or all removed
    # during filtering) ask if just proceed with upload
    if not fragments:
        print('No overlapping fragments to be merged into in target instance.')
        msg = 'Proceed with just uploading this neuron?'
        q = [inquirer.Confirm(name='confirm', message=msg)]
        confirm = inquirer.prompt(q, theme=GreenPassion()).get('confirm')

        if not confirm:
            raise SystemExit('Merge process aborted by user.')

        base_neuron = None
    # If any fragments left, ask for base neuron
    else:
        # Ask user which neuron to use as merge target
        s = fragments.summary(
            add_props=['overlap_score', 'sampler_count', 'id'])[[
                'name', 'id', 'n_nodes', 'n_connectors', 'sampler_count',
                'overlap_score'
            ]]

        msg = """
        Above fragments and your input neuron will be merged into a single neuron.
        All annotations will be preserved but only the neuron used as merge target
        will keep its name and skeleton ID.
        Please select the neuron you would like to use as merge target!
        """ + s.to_string(index=False).split('\n')[0]
        print(msg)

        s_str = s.to_string(index=False, show_dimensions=False, header=False)
        choices = [(v, i) for i, v in enumerate(s_str.split('\n'))]
        q = [
            inquirer.List(name='base_neuron',
                          message='Choose merge target',
                          choices=choices)
        ]
        # Ask the question
        bn = inquirer.prompt(q, theme=GreenPassion()).get('base_neuron')

        if isinstance(bn, type(None)):
            raise ValueError("Merge aborted by user")

        base_neuron = fragments[bn]

        # Some safeguards:
        # Check if we would delete any samplers
        cond1 = s.id != base_neuron.id
        cond2 = s.sampler_count > 0
        has_sampler = s[cond1 & cond2]
        if not has_sampler.empty:
            print("Merging selected fragments would delete reconstruction "
                  "samplers on the following neurons:")
            print(has_sampler)
            q = [inquirer.Confirm(name='confirm', message='Proceed anyway?')]
            confirm = inquirer.prompt(q, theme=GreenPassion())['confirm']

            if not confirm:
                raise SystemExit('Merge process aborted by user.')

        # Check if we would generate any 2-soma neurons
        has_soma = [not isinstance(s, type(None)) for s in fragments.soma]
        if sum(has_soma) > 1:
            print('Merging the selected fragments would generate a neuron  '
                  'with two somas!')
            q = [inquirer.Confirm(name='confirm', message='Proceed anyway?')]
            confirm = inquirer.prompt(q, theme=GreenPassion())['confirm']

            if not confirm:
                raise SystemExit('Merge process aborted by user.')

    return fragments, base_neuron
Example #24
0
def process(data_file, error_apriori, units):
    '''
    Given a .csv data file in the format of (time, x, y, z) applies both filters, generates a filtered.csv data
    file, prints out the final keplerian elements computed from both Lamberts and Interpolation and finally plots
    the initial, filtered data set and the final orbit.

    Args:
        data_file (string): The name of the .csv file containing the positional data
        error_apriori (float): apriori estimation of the measurements error in km

    Returns:
        Runs the whole process of the program
    '''
    # First read the csv file called "orbit" with the positional data
    data = read_data.load_data(data_file)

    if (units == 'm'):
        # Transform m to km
        data[:, 1:4] = data[:, 1:4] / 1000

    print("Choose filter(s) in the order you want to apply them")
    print(
        "(SPACE to change, UP/DOWN to navigate, RIGHT/LEFT to Select/Deselect and ENTER to Submit)"
    )
    print("*if nothing is selected program will run without applying filters")
    questions = [
        inquirer.Checkbox(
            'filter',
            message="Select filters",
            choices=[
                'Savintzky Golay Filter', 'Tripple Moving Average Filter'
            ],
        ),
    ]
    choices = inquirer.prompt(questions)
    data_after_filter = data

    if (len(choices['filter']) == 0):
        print("No filter selected, continuing without applying filter")
    else:
        for index, choice in enumerate(choices['filter']):

            if (choice == 'Savintzky Golay Filter'):
                print("Applying Savintzky Golay Filter")
                # Use the golay_window.py script to find the window for the savintzky golay filter based on the error you input
                window = golay_window.window(error_apriori, data_after_filter)

                # Apply the Savintzky - Golay filter with window = 31 and polynomail parameter = 6
                data_after_filter = sav_golay.golay(data_after_filter, window,
                                                    3)
            else:
                print("Applying Triple Moving Average Filter")
                # Apply the Triple moving average filter with window = 3
                data_after_filter = triple_moving_average.generate_filtered_data(
                    data_after_filter, 3)

    # Compute the residuals between filtered data and initial data and then the sum and mean values of each axis
    res = data_after_filter[:, 1:4] - data[:, 1:4]
    sums = np.sum(res, axis=0)
    print("\nDisplaying the sum of the residuals for each axis")
    print(sums)

    means = np.mean(res, axis=0)
    print("Displaying the mean of the residuals for each axis")
    print(means, "\n")

    # Save the filtered data into a new csv called "filtered"
    np.savetxt("filtered.csv", data_after_filter, delimiter=",")

    print("Choose Methods for Orbit Determination")
    print(
        "(SPACE to change, UP/DOWN to navigate, RIGHT/LEFT to Select/Deselect and ENTER to Submit)"
    )
    print(
        "*if nothing is selected program will determine orbit using Cubic Spline Interpolation"
    )
    questions = [
        inquirer.Checkbox(
            'method',
            message="Select Methods",
            choices=[
                'Lamberts Kalman Solutions', 'Cubic Spline Interpolation',
                'Ellipse Best Fit'
            ],
        ),
    ]
    choices = inquirer.prompt(questions)
    kep_elements = {}

    if (len(choices['method']) == 0):
        # Apply the interpolation method
        kep_inter = interpolation.main(data_after_filter)
        # Apply Kalman filters, estimate of measurement variance R = 0.01 ** 2
        kep_final_inter = lamberts_kalman.kalman(kep_inter, 0.01**2)
        kep_elements['Interpolation'] = np.transpose(kep_final_inter)
    else:
        for index, choice in enumerate(choices['method']):
            if (choice == 'Lamberts Kalman Solutions'):
                # Apply Lambert's solution for the filtered data set
                kep_lamb = lamberts_kalman.create_kep(data_after_filter)
                # Apply Kalman filters, estimate of measurement variance R = 0.01 ** 2
                kep_final_lamb = lamberts_kalman.kalman(kep_lamb, 0.01**2)
                kep_elements['Lambert'] = np.transpose(kep_final_lamb)

            elif (choice == 'Cubic Spline Interpolation'):
                # Apply the interpolation method
                kep_inter = interpolation.main(data_after_filter)
                # Apply Kalman filters, estimate of measurement variance R = 0.01 ** 2
                kep_final_inter = lamberts_kalman.kalman(kep_inter, 0.01**2)
                kep_elements['Interpolation'] = np.transpose(kep_final_inter)
            elif (choice == 'Ellipse Best Fit'):
                # Fitting an ellipse on filtered data
                kep_elements['Ellipse-Fit'] = (ellipse_fit.determine_kep(
                    data_after_filter[:, 1:]))[0]

    kep_final = np.zeros((6, len(kep_elements)))
    order = []
    for index, key in enumerate(kep_elements):
        kep_final[:, index] = np.ravel(kep_elements[key])
        order.append(str(key))

    # Print the final orbital elements for both solutions
    print(
        "Displaying the final keplerian elements with methods in column order: {}"
        .format(", ".join(order)))
    print(kep_final)
    print("\n")

    # Plot the initial data set, the filtered data set and the final orbit

    # First we transform the set of keplerian elements into a state vector
    state = kep_state.kep_state(kep_elements[order[0]])

    # Then we produce more state vectors at varius times using a Runge Kutta algorithm
    keep_state = np.zeros((6, 150))
    ti = 0.0
    tf = 1.0
    t_hold = np.zeros((150, 1))
    x = state
    h = 0.1
    tetol = 1e-04
    for i in range(0, 150):
        keep_state[:, i] = np.ravel(rkf78.rkf78(6, ti, tf, h, tetol, x))
        t_hold[i, 0] = tf
        tf = tf + 1

    positions = keep_state[0:3, :]

    ## Finally we plot the graph
    mpl.rcParams['legend.fontsize'] = 10
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.plot(data[:, 1], data[:, 2], data[:, 3], ".", label='Initial data ')
    ax.plot(data_after_filter[:, 1],
            data_after_filter[:, 2],
            data_after_filter[:, 3],
            "k",
            linestyle='-',
            label='Filtered data')
    ax.plot(positions[0, :],
            positions[1, :],
            positions[2, :],
            "r-",
            label='Orbit after {} method'.format(order[0]))
    ax.legend()
    ax.can_zoom()
    ax.set_xlabel('x (km)')
    ax.set_ylabel('y (km)')
    ax.set_zlabel('z (km)')
    plt.show()
import os
import sys
import re
sys.path.append(os.path.realpath('.'))
from pprint import pprint

import inquirer

questions = [
    inquirer.Checkbox('interests',
                      message="What are you interested in?",
                      choices=['Choice %s' % i for i in range(40)],
                      default=['Choice 2', 'Choice 10']),
]

answers = inquirer.prompt(questions)

pprint(answers)
Example #26
0
#this file is for testing new methods before putting them into the offical checklist file 
import inquirer

questions = [
          inquirer.Checkbox('interests',
                                  message="What are you interested in?",
                                                      choices=['Computers', 'Books', 'Science', 'Nature', 'Fantasy', 'History'],
                                                                          ),
          ]
answers = inquirer.prompt(questions)
print(answers)
Example #27
0
def sync():
    with pocket_casts() as api:
        # Get all podcast titles
        titles_by_uuid: t.Dict[str, str] = api.podcasts()

        # Get list of episodes in "up next"
        episodes_from_pocketcasts: t.List[Episode] = api.up_next()
        selected_episodes = inquirer.prompt([
            inquirer.Checkbox(
                name='episodes',
                message='Select episodes to download:',
                default=[
                    episode.uuid for episode in episodes_from_pocketcasts[1:]
                ],
                choices=[(episode.title, episode.uuid)
                         for episode in episodes_from_pocketcasts],
            )
        ])

        pocketcasts_by_uuid: t.Dict[str, Episode] = {
            episode.uuid: episode
            for episode in episodes_from_pocketcasts
            if episode.uuid in selected_episodes['episodes']
        }

        # Get previously-downloaded files
        ipod_by_uuid: t.Dict[str, Path] = {}
        playlist_path = MUSIC_DIR
        playlist_path.mkdir(parents=True, exist_ok=True)
        filename_regex = re.compile(r"([a-f0-9-]+)\..+")
        for file in playlist_path.iterdir():
            filename_match = filename_regex.match(file.name)
            if not filename_match:
                log.error("Cannot parse filename %s", file)
                continue
            ipod_by_uuid[filename_match.group(1)] = file

        uuids_on_ipod = set(ipod_by_uuid.keys())
        uuids_from_pocketcasts = set(pocketcasts_by_uuid.keys())

        uuids_to_delete = uuids_on_ipod - uuids_from_pocketcasts
        uuids_to_download = uuids_from_pocketcasts - uuids_on_ipod

        for uuid in uuids_to_delete:
            ipod_by_uuid[uuid].unlink()

        episodes_to_download = [
            pocketcasts_by_uuid[uuid] for uuid in uuids_to_download
        ]

        if episodes_to_download:
            log.info("Downloading %r",
                     [episode.title for episode in episodes_to_download])
        with ThreadPool() as pool:
            for success, episode in pool.imap_unordered(
                    download_episode, episodes_to_download):
                if success:
                    log.info("Downloaded %s: %s", episode.title,
                             episode.filename)
                    try:
                        tags = EasyID3(episode.path)
                        tags["title"] = episode.title
                        tags["genre"] = "Podcast"
                        try:
                            tags["album"] = titles_by_uuid[episode.podcast]
                        except KeyError:
                            tags["album"] = "Mystery podcast"
                        tags.save()
                    except Exception:
                        log.exception("Could not rename %r", episode)

        return pocketcasts_by_uuid
Example #28
0
import inquirer

if __name__ == "__main__":

    questions = [
        inquirer.Text("user",
                      message="Please enter your github username",
                      validate=lambda _, x: x != "."),
        inquirer.Password("password", message="Please enter your password"),
        inquirer.Text("repo",
                      message="Please enter the repo name",
                      default="default"),
        inquirer.Checkbox(
            "topics",
            message="Please define your type of project?",
            choices=["common", "backend", "frontend"],
        ),
        inquirer.Text(
            "organization",
            message=
            ("If this is a repo from a organization please enter the organization name,"
             " if not just leave this blank"),
        ),
        inquirer.Confirm(
            "correct",
            message=
            "This will delete all your current labels and create a new ones. Continue?",
            default=False,
        ),
    ]
Example #29
0
		message="Which year are you in?",
		choices=["First Year", "Second Year", "Third Year", "Fourth Year"],
	)
]

personalAnswers = inquirer.prompt(personalQuestions, theme=GreenPassion())

print("\n\nPlease join our community at https://bit.ly/dscbvppune\n\n")
fun(f)
clear()
print(f.renderText('DSC BVP Pune'))
print(f.renderText("Teams"))

domainRelatedQuestions = [
	inquirer.Checkbox('domains',
		message="Select the domains you would like to be a part of (Press space to select, enter to submit)",
		choices=['Technical Team', 'Designing Team', 'Content Team', 'Management and Publicity Team'],
	),
]

domainChoiceAnswers = inquirer.prompt(domainRelatedQuestions, theme=GreenPassion())

clear()
print(f.renderText('DSC BVP Pune'))
print("\n\n\n")
print(f.renderText("Your skills"))
print("Please enter your skills either technical or non technical => ")
print("""Input should be in the form of 'Flutter', 'Django', 'Google Cloud', 'Content Writer' """)

skills = [x.replace("'", "").lstrip(" ") for x in input("Your skills => ").split(',')]

clear()
Example #30
0
# -----------------------------------------------
# Select hostnames
# -----------------------------------------------
hostname_list = yaml_config[cluster_name]
hostname_list = list(filter(None, hostname_list))
hostname_list = wrapper.natural_sort(hostname_list)
for hostname in hostname_list:
    hostname = hostname.rstrip(" ")
    if not is_valid_hostname(hostname) or hostname[-1] == ".":
        sys.exit(f"Illegal hostname: '{hostname}'")

questions = [
    inquirer.Checkbox(
        "selected",
        message=f"Select server(s). Use spacebar",
        choices=hostname_list,
    ),
]

answers = inquirer.prompt(questions)

selected_hostnames = []

# select multiple
if isinstance(answers["selected"], list):
    selected_hostnames = answers["selected"]
else:
    selected_hostnames.append(answers["selected"])

if not len(selected_hostnames):