Best Python code snippet using tavern
report.py
Source:report.py
...7# resected = [node.center_coordinates for node in subject.nodes if node.type == 'resected']8#9# if subject.data['resec_mni']:10# resection = read['resec_mni'](subject.data['resec_mni'])11# display.add_markers(resection, marker_color="violet", marker_size=1)12# display.add_markers(np.array(spared), marker_color="yellow", marker_size=100)13# display.add_markers(np.array(resected), marker_color="red", marker_size=250)14# # plt.show()15## label time cources comparison16# plt.plot(np.arange(401), label_ts[0][10].T, np.arange(401), label_ts[0][36].T)17# plt.show()18# plt.plot(np.arange(401), label_ts[1][10].T, np.arange(401), label_ts[1][36].T)19# plt.show()20# plt.plot(np.arange(401), label_ts[2][10].T, np.arange(401), label_ts[2][36].T)21# plt.show()22# plt.plot(np.arange(401), label_ts[3][10].T, np.arange(401), label_ts[3][36].T)23# plt.show()24## connectivity representation25# for i in range(67):26# print((conmat[:, i]))27## nodes strength28# plt.plot(n_strength, 'o')29# plt.title('Node Strength')30# plt.xlabel('node: number')31# plt.ylabel('node: strength')32# plt.show()33## compute roc curve34# resected_nodes = 1535#36# label_ind = np.zeros(len(n_strength))37# label_ind[0:resected_nodes] = True38# label_ind[resected_nodes+1:] = False39# Drs = roc_auc_score(label_ind, n_strength)40## example how to get freesurf_dict41# vertexes = [mne.vertex_to_mni(42# label.vertices,43# hemis=0 if label.hemi == 'lh' else 1,44# subject=subject, subjects_dir=subjects_dir45# )for label in labels]46# freesurf_dict_sample = {l[0].name: np.mean(l[1], axis=0) for l in zip(labels, vertexes)}47## show one label48# nplt.plot_markers(np.zeros(vertexes[0].shape[0]), vertexes[0])49# nplt.show()50## show one node51# nplt.plot_markers(np.array([0, 0]), np.array([52# np.mean(vertexes[0], axis=0),53# np.array([1000, 1000, 1000]) ## plot markers does not work with one node54# ]))55# nplt.show()56## show resection + resected nodes + spared nodes57# fig, ax = plt.subplots(figsize=(15,15))58#59# display = nplt.plot_glass_brain(None, display_mode='lyrz', figure=fig, axes=ax)60#61# display.add_markers(resec_coordinates, marker_color="violet", marker_size=1)62#63# display.add_markers(node_coordinates, marker_color="yellow", marker_size=30)64# spared = list()65# resected = list()66#67# for node_coordinate in node_coordinates:68# for resec_coordinate in resec_coordinates:69# diff = node_coordinate - resec_coordinate70# dist = np.sqrt(diff[0]**2 + diff[1]**2 + diff[2]**2)71# if dist <= 1 and not node_coordinate in np.array(resected):72# resected.append(node_coordinate)73# else:74# spared.append(node_coordinate)75#76# fig, ax = plt.subplots(figsize=(15,15))77#78#79# display = nplt.plot_glass_brain(80# None, display_mode='lyrz', figure=fig, axes=ax)81# display.add_markers(resec_coordinates, marker_color="violet", marker_size=1)82# display.add_markers(np.array(spared), marker_color="yellow", marker_size=100)83# display.add_markers(np.array(resected), marker_color="red", marker_size=250)84## pearson and plv nodes85# %%86# if os.path.isfile(res_pearson_nodes_file):87# print('Reading nodes...')88# nodes = pickle.load(open(res_pearson_nodes_file, 'rb'))89#90# else:91# print('PIPELINE: Pearson\'s Nodes file not found, create a new one')92#93# if not os.path.exists(res_nodes_folder):94# mkdir(res_nodes_folder)95#96# nodes = []97# n_strength, pearson_connectome = nodes_strength(label_ts, 'pearson')...
plots.py
Source:plots.py
1#!/usr/bin/env python32from volley_elo import team_elo_df3from elo import brier_score4def plot_elo(match_df, ax, elo_name="elo", teams=None, add_markers=True):5 """Plot an Elo time-series on the given axis for the given teams.6 :match_df: A match dataframe.7 :ax: Matplotlib axis.8 :elo_name: Name that the elo columns in `match_df`.9 :teams: A list of team names to plot, or None if all teams should be plotted.10 :add_markers: Add postseason and average markers.11 `add_markers` is useful if you want to plot multiple versions of Elo in the12 same plot. You wouldn't want duplicate labels of the postseason and average13 markers cluttering up the legend. (There are other solutions, but now you14 can use this one if you like.)15 """16 year = match_df.iloc[0].date.year17 df = team_elo_df(match_df, elo_name=elo_name)18 if teams:19 df = df[teams]20 df.plot(marker="o", lw=3, ax=ax, legend=False)21 ax.set_title("Elo rankings for {}-{} season".format(year, year + 1))22 if add_markers:23 ax.axhline(1500, color="k", linestyle="--", label='"Average"')24 postseason_df = match_df[match_df.postseason]25 if not postseason_df.empty:26 ax.axvline(postseason_df.iloc[0].date, color="k", label="Postseason")27def plot_brier(df, result_col, predict_col, ax):28 """Plot Brier scores and a moving average for the given dataframe.29 :year: TODO30 :returns: TODO31 """32 col = brier_score(df, result_col, predict_col)33 col.cumsum().plot(label=predict_col, ax=ax, lw=3, marker="o")34 col.cumsum().rolling(7).mean().plot(label=predict_col + " rolling average", ax=ax, lw=3, alpha=0.8)35if __name__ == "__main__":36 import volley_elo37 import matplotlib.pyplot as plt38 dfs = {year: volley_elo.get_historical_df(year) for year in range(12, 20)}39 volley_elo.record_seasons(list(dfs.values()))40 volley_elo.record_seasons(list(dfs.values()), K=100, elo_name="big-elo")41 plt.figure()42 plot_elo(dfs[19], plt.gca(), "elo", ["Birmingham-Southern"], add_markers=False)43 plot_elo(dfs[19], plt.gca(), "big-elo", ["Birmingham-Southern"], ["Big Elo BSC"])44 plt.legend(["Elo BSC", "Big Elo BSC", "Average", "Postseason"])...
map.py
Source:map.py
1import folium2def add_markers(dictionary):3 """4 (dict) -> <class 'folium.map.FeatureGroup'>5 Returns loactions to add it to the map6 """7 friends = folium.FeatureGroup("Friends Locations")8 for name in dictionary:9 points = dictionary[name][0]10 if friends:11 icon = folium.features.CustomIcon(dictionary[name][1],12 icon_size=(35, 35))13 friends.add_child(folium.Marker(location=[points[0],14 points[1]],15 popup=name,16 icon=icon))17 return friends18def create_map(dictionary, name):19 """20 (None) -> None21 Creates a map with folium in HTML file22 """23 map = folium.Map()24 # ADD MARKERS25 friends = add_markers(dictionary)26 map.add_child(friends)27 map.add_child(folium.LayerControl())...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!