text:
import numpy as np
import torch
import torch.nn as nn

cuda_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

def segment_max(logit, n_seg, seg_i, idx_j):
	max_seg_numel = idx_j.max().item() + 1
	seg_max = logit.new_full((n_seg, max_seg_numel), -np.inf)
	seg_max = seg_max.index_put_((seg_i, idx_j), logit).max(dim=1)[0]
	return seg_max[seg_i]

def segment_sum(logit, n_seg, seg_i):
	norm = logit.new_zeros(n_seg).index_add(0, seg_i, logit)
	return norm[seg_i]

def segment_softmax(logit, n_seg, seg_i, idx_j, temperature):
	logit_max = segment_max(logit, n_seg, seg_i, idx_j).detach()
	logit = torch.exp((logit - logit_max) / temperature)
	logit_norm = segment_sum(logit, n_seg, seg_i)
	prob = logit / (logit_norm + 1e-8)
	return prob

def segment_multihead_expand(seg_i, n_seg, n_head):
	i_head_shift = n_seg * seg_i.new_tensor(torch.arange(n_head))
	seg_i = (seg_i.view(-1, 1) + i_head_shift.view(1, -1)).view(-1)
	return seg_i

class CoAttention(nn.Module):
	def __init__(self,
			node_in_feat,
			node_out_feat,
			n_head=1,
			dropout=0.1):
		super().__init__()
		self.temperature = np.sqrt(node_in_feat)

		self.n_head = n_head
		self.multi_head = self.n_head > 1

		self.key_proj = nn.Linear(node_in_feat, node_in_feat * n_head, bias=False)
		self.val_proj = nn.Linear(node_in_feat, node_in_feat * n_head, bias=False)
		nn.init.xavier_normal_(self.key_proj.weight)
		nn.init.xavier_normal_(self.val_proj.weight)

		self.softmax = nn.Softmax(dim=1)

		self.out_proj = nn.Sequential(
			nn.Linear(node_in_feat * n_head, node_out_feat),
			nn.LeakyReLU())

	def forward(self, x1, masks1, x2, masks2, entropy=[]):

		h1 = self.key_proj(x1)
		h2 = self.key_proj(x2)

		e12 = torch.bmm(h1, torch.transpose(h2, -1, -2))
		e21 = torch.bmm(h2, torch.transpose(h1, -1, -2))

		a12 = self.softmax(e12 + (masks2.unsqueeze(1) - 1.0) * 1e9)
		a21 = self.softmax(e21 + (masks1.unsqueeze(1) - 1.0) * 1e9)

		#a12 = torch.ones_like(e12) * masks2.unsqueeze(1)
		#a21 = torch.ones_like(e21) * masks1.unsqueeze(1)

		n12 = torch.bmm(a12, self.val_proj(x2))
		n21 = torch.bmm(a21, self.val_proj(x1))

		# TODO!! Remove this while training, this is just for entropy.
		#translation = torch.ones_like(translation)

		# Entropy computation
		#ent1 = node1.new_zeros((n_seg1, 1)).index_add(0, seg_i1, torch.sum(node1_edge * torch.log(node1_edge + 1e-7), -1))
		#ent2 = node2.new_zeros((n_seg2, 1)).index_add(0, seg_i2, torch.sum(node2_edge * torch.log(node2_edge + 1e-7), -1))
		#entropy.append(ent1)
		#entropy.append(ent2)

		msg1 = self.out_proj(n12)
		msg2 = self.out_proj(n21)

		#Check if 1 -> 1 and 2 -> 2.
		return msg1, msg2, a12, a21

class MessagePassing(nn.Module):
	def __init__(self,
				 node_in_feat, # probably d_node
				 node_out_feat, # probably d_hid
				 dropout = 0.1):
		super(MessagePassing, self).__init__()

		self.node_proj = nn.Sequential(
			nn.Linear(node_in_feat, node_out_feat, bias=False))

	def compute_adj_mat(self, A):
		batch, N = A.shape[:2]
		A_hat = A
		I = torch.eye(N).unsqueeze(0).to(cuda_device)
		A_hat = A + I
		#D_hat = (torch.sum(A_hat, 1) + 1e-5) ** (-0.5)
		#L = D_hat.view(batch, N, 1) * A_hat * D_hat.view(batch, 1, N)
		return A_hat

	def forward(self, x, A, mask):
		# print('in', x.shape, torch.sum(torch.abs(torch.sum(x, 2)) > 0))
		if len(A.shape) == 3:
			A = A.unsqueeze(3)

		new_A = self.compute_adj_mat(A[:, :, :, 0]) #only one relation type
		x = self.node_proj(x)
		x = torch.bmm(new_A, x)

		if len(mask.shape) == 2:
			mask = mask.unsqueeze(2)
		x = x * mask  # to make values of dummy nodes zeros again, otherwise the bias is added after applying self.fc which affects node embeddings in the following layers
		return x

class CoAttentionMessagePassingNetwork(nn.Module):
	def __init__(self,
		hidden_dim, #d_node, # filters
		n_prop_step, #n_prop_step
		n_head=1,
		dropout=0.1,
		update_method='res'):

		super().__init__()

		self.n_prop_step = n_prop_step

		self.update_method = update_method

		self.mps = nn.ModuleList([
			MessagePassing(
				node_in_feat=hidden_dim,
				node_out_feat=hidden_dim, dropout=dropout)
			for step_i in range(n_prop_step)])

		self.coats = nn.ModuleList([
			CoAttention(
				node_in_feat=hidden_dim,
				node_out_feat=hidden_dim, n_head=n_head, dropout=dropout)
			for step_i in range(n_prop_step)])

		self.pre_readout_proj = nn.Sequential(
			nn.Linear(hidden_dim, hidden_dim),
			nn.LeakyReLU())

		self.fc = nn.Linear(3*hidden_dim, hidden_dim)

	def forward(
			self,
			x1, A1, masks1,
			x2, A2, masks2,
			entropies=[]):
		for step_i in range(self.n_prop_step):
			#if step_i >= len(entropies):
			#	entropies.append([])
			inner_msg1 = self.mps[step_i](x1, A1, masks1)
			inner_msg2 = self.mps[step_i](x2, A2, masks2)
			#outer_msg1, outer_msg2 = self.coats[step_i](
			#	x1, masks1,
			#	x2, masks2, [])
				# node2, out_seg_i2, out_idx_j2, entropies[step_i])

			if self.update_method == "res":
				x1 = x1 + inner_msg1 #+ outer_msg1
				x2 = x2 + inner_msg2 #+ outer_msg2
			else:
				x1 = self.fc(torch.cat([x1, inner_msg1, outer_msg1], -1))
				x2 = self.fc(torch.cat([x2, inner_msg2, outer_msg2], -1))

		g1_vec = self.readout(x1, masks1)
		g2_vec = self.readout(x2, masks2)

		return g1_vec, g2_vec

	def readout(self, node, mask):
		#print(node.shape)
		node = self.pre_readout_proj(node)
		if len(mask.shape) == 2:
			mask = mask.unsqueeze(2)
		node = node * mask
		mask = mask.squeeze()
		readout = torch.mean(node, 1) / torch.mean(mask, 1, keepdim=True)
		return readout

class GraphGraphInteractionNetwork(nn.Module):
	def __init__(
			self,
			in_features, #d_atom_feat,
			out_features,
			hidden_dim, #d_node, # filters
			n_prop_step, #n_hidden
			n_head=1,
			dropout=0.1,
			update_method='res'):

		super().__init__()

		self.atom_proj = nn.Linear(in_features, hidden_dim)

		self.encoder = CoAttentionMessagePassingNetwork(
			hidden_dim=hidden_dim,
			n_prop_step=n_prop_step, n_head=n_head,
			update_method=update_method, dropout=dropout)
		self.lbl_predict = nn.Linear(hidden_dim, out_features)

	def forward(self, data1, data2, entropies=[]):
		x1, A1, masks1 = data1[:3]
		x2, A2, masks2 = data2[:3]
		#print(x1.shape)

		x1 = self.atom_proj(x1)
		x2 = self.atom_proj(x2)

		d1_vec, d2_vec = self.encoder(x1, A1, masks1,
		 	x2, A2, masks2, entropies)

		pred1 = self.lbl_predict(d1_vec)
		pred2 = self.lbl_predict(d2_vec)
		return pred1, pred2


text:
 # ------------------------------------------------------------------------------
# Benchmark against real beam (3cm x 3cm x 10cm) - Load 1
# ------------------------------------------------------------------------------
### Import some useful functions
import sys
sys.path.append('../')

from pathlib import Path
import time
import os
import numpy as np

from py_diff_pd.common.common import ndarray, create_folder, print_info,delete_folder
from py_diff_pd.common.project_path import root_path
from py_diff_pd.common.renderer import PbrtRenderer
from py_diff_pd.core.py_diff_pd_core import StdRealVector, HexMesh3d, HexDeformable, TetMesh3d, TetDeformable
from py_diff_pd.common.hex_mesh import generate_hex_mesh, voxelize, hex2obj
from py_diff_pd.common.display import render_hex_mesh, export_gif, export_mp4

# Utility functions
from utils import read_measurement_data, plots_A, create_combined_video

### Import the simulation scene
from Environments.beam_env import BeamEnv

### MAIN
if __name__ == '__main__':
    seed = 42
    np.random.seed(seed)
    folder = Path('Numerical_Damping_Case_A-1')

    ### Material and simulation parameters
    # Varying the parameter dt=h will lead to different damping ratios
    dt = [0.25e-2, 0.5e-2, 1e-2,2e-2]
    frame_num = [320,160,80,40]

    # Material parameters: Dragon Skin 10
    youngs_modulus = 263824 # Optimized value
    poissons_ratio = 0.499
    density = 1.07e3

    # Gravity
    state_force = [0, 0, -9.80709]

    # Create simulation scene
    hex_params = {
        'density': density,
        'youngs_modulus': youngs_modulus,
        'poissons_ratio': poissons_ratio,
        'state_force_parameters': state_force,
        'mesh_type': 'hex',
        'refinement': 2.35
    }

    hex_env = BeamEnv(seed, folder, hex_params,0,'A-1')
    hex_deformable = hex_env.deformable()

    # Simulation parameters
    methods = ('pd_eigen', )
    thread_ct = 8
    opts = (
        { 'max_pd_iter': 5000, 'max_ls_iter': 10, 'abs_tol': 1e-9, 'rel_tol': 1e-4, 'verbose': 0, 'thread_ct': thread_ct, 'use_bfgs': 1, 'bfgs_history_size': 10 },
    )

    ### Simulation and plots
    print_info(f"DoF: {hex_deformable.dofs()} Hex")

    frame_num_idx=0

    # Open a plot
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots(figsize=(12,8))

    for time_step in dt:

        for method, opt in zip(methods, opts):

            # Hexahedral simulation
            print_info(f"Simulation for a time step of h={time_step}s ...")

            _, info_hex = hex_env.simulate(time_step, frame_num[frame_num_idx], method, opt, require_grad=False,
                verbose=1
            )

            print_info(f"Total for {frame_num[frame_num_idx]} frames took {info_hex['forward_time']:.2f}s for Hexahedral {method}")
            print_info(f"Time per frame: {1000*info_hex['forward_time']/frame_num[frame_num_idx]:.2f}ms")

            qs_hex = info_hex['q']

            z_hex = []

            for i in range(frame_num[frame_num_idx]+1):
                z_hex_i = qs_hex[i].reshape(-1,3).take(hex_env.target_idx_tip_left, axis=0)[:,2]
                z_hex.append(z_hex_i)

            time = []
            for i in range(frame_num[frame_num_idx]+1):
                time.append([np.array(i*time_step)])

            # Plot
            ax.plot(time,z_hex, marker='o', markersize=4, label='h = {}'.format(time_step))

            # Save the values of z_hex
            np.savetxt(f"{folder}/point_left_z_hex_{hex_deformable.dofs()}_{time_step}.csv", z_hex, delimiter =",",fmt ='% s')
            frame_num_idx=frame_num_idx+1

    major_ticks = np.arange(0, 0.8, 0.2)
    minor_ticks = np.arange(0, 0.8, 0.04)
    ax.set_xticks(major_ticks)
    ax.set_xticks(minor_ticks, minor=True)

    major_ticks_y = np.arange(0.0100, 0.026, 0.0025)
    minor_ticks_y = np.arange(0.0100, 0.026, 0.0005)
    ax.set_yticks(major_ticks_y)
    ax.set_yticks(minor_ticks_y, minor=True)
    plt.xticks(fontsize=22)
    plt.yticks(fontsize=22)

    ax.grid(which='minor', alpha=0.2)
    ax.grid(which='major', alpha=0.5)

    ax.set_title("Hexahedral z Position of Left Tip Point for different time steps h", fontsize=24)
    ax.set_xlabel("Time [s]", fontsize=24)
    ax.set_ylabel("z Position [m]", fontsize=24)
    ax.title.set_position([.5, 1.03])
    ax.legend(loc="lower center", bbox_to_anchor=(0.5, -0.30), ncol= 2, prop={'size': 20})

    fig.savefig(f"{folder}/z_position_point_left_{hex_deformable.dofs()}.png", bbox_inches='tight')
    plt.close()

ext: py

reason: import numpy


text:
import numpy as np
import scipy as sp
from sklearn.linear_model import orthogonal_mp_gram
from .range_finder import RandomizedRangeFinder
from .svd import DirectSVD

from abc import ABC, abstractmethod

def rsvd(A, k, p=10, q=0):
    r = RandomizedRangeFinder(A, k=k, p=p, q=q, debug=False)
    rsvd = DirectSVD(r.Q, A=A, eigh=False)
    return rsvd.U, rsvd.D, rsvd.Vh

class AbstractKSVD(ABC):
    def __init__(self, n_components, max_iter=10, tol=1e-6,
                 transform_n_nonzero_coefs=None):
        """
        Parameters
        ----------
        n_components:
            Number of dictionary elements

        max_iter:
            Maximum number of iterations

        tol:
            tolerance for error

        transform_n_nonzero_coefs:
            Number of nonzero coefficients to target
        """
        self.components_ = None
        self.max_iter = max_iter
        self.tol = tol
        self.n_components = n_components
        self.transform_n_nonzero_coefs = transform_n_nonzero_coefs
        self.error_norm = []

    @abstractmethod
    def update_dict(self):
        pass

    def _initialize(self, X):
        """Initialize dictionary D

        Problem is posed as find X, D such that min{Y - X D}.

        We know that X D is of rank n_components hence we find SVD of Y and return
        right singular vectors scaled with singular values.

        Note that this representation is transposed to match the sklearn representation
        of data matrix. Much more natural view of this problem is find

        Y = D X where D acts on X and not the other way around.

        Parameters
        ----------

        X: ndarray of shape (n_samples, n_features)
            Data matrix.
        """

        if min(X.shape) < self.n_components:
            D = np.random.randn(self.n_components, X.shape[1])
        else:
            u, s, vt = sp.sparse.linalg.svds(X, k=self.n_components)
            D = np.dot(np.diag(s), vt)
        # normalize each sample
        D /= np.linalg.norm(D, axis=1)[:, np.newaxis]
        return D

    def _transform(self, D, X):
        gram = D.dot(D.T)
        Xy = D.dot(X.T)

        n_nonzero_coefs = self.transform_n_nonzero_coefs
        if n_nonzero_coefs is None:
            n_nonzero_coefs = int(0.1 * X.shape[1])

        return orthogonal_mp_gram(gram, Xy, n_nonzero_coefs=n_nonzero_coefs).T

    def fit(self, X):
        """
        Parameters
        ----------
        X: shape = [n_samples, n_features]
        """
        D = self._initialize(X)
        for i in range(self.max_iter):
            gamma = self._transform(D, X)
            e = np.linalg.norm(X - gamma.dot(D))
            self.error_norm.append(e)
            if e < self.tol:
                print ("Number of iterations: {}", i)
                break
            D, gamma = self.update_dict(X, D, gamma)
            #assert np.all(np.isclose(np.linalg.norm(D, axis=1), 1))
        self.components_ = D
        return self

    def transform(self, X):
        return self._transform(self.components_, X)

class ClassicKSVD(AbstractKSVD):
    def __init__(self, n_components, max_iter=10, tol=1e-6,
                 transform_n_nonzero_coefs=None):
        super().__init__(n_components, max_iter, tol, transform_n_nonzero_coefs)

    def update_dict(self, X, D, gamma):
        for j in range(self.n_components):
            # index set of all the elems in the j-th row that are nonzero
            #I = gamma[:, j] > 0
            I = np.flatnonzero(gamma[:, j])
            if len(I) == 0:
                continue

            # zero out j-th row of dictionary and compute error matrix E
            # This is error without d_j
            D[j, :] = 0
            E = X[I, :] - gamma[I, :].dot(D)

            # compute rank-1 approximation of E
            u, d, vh = np.linalg.svd(E, full_matrices=False)

            D[j, :] = vh[0]
            gamma[I, j] = d[0] * u[:, 0]
        return D, gamma

class RandomizedKSVD(AbstractKSVD):
    def __init__(self, n_components, max_iter=10, tol=1e-6,
                 transform_n_nonzero_coefs=None):
        super().__init__(n_components, max_iter, tol, transform_n_nonzero_coefs)

    def update_dict(self, X, D, gamma):
        for j in range(self.n_components):
            # index set of all the elems in the j-th row that are nonzero
            #I = gamma[:, j] > 0
            I = np.flatnonzero(gamma[:, j])
            if len(I) == 0:
                continue

            # zero out j-th row of dictionary and compute error matrix E
            # This is error without d_j
            D[j, :] = 0
            E = X[I, :] - gamma[I, :].dot(D)

            # compute rank-1 approximation of E

            u, d, vh = rsvd(E, k=1, p=2, q=1)
            # Fine tuning code
            #u_, d_, vh_ = np.linalg.svd(E, full_matrices=False)

            #E_rsvd = d[0] * np.outer(u[:, 0], vh[0])
            #E_full = d_[0] * np.outer(u_[:, 0], vh_[0])

            #print (np.linalg.norm(E - E_rsvd), np.linalg.norm(E - E_full))

            D[j, :] = vh[0]
            gamma[I, j] = d[0] * u[:, 0]
        return D, gamma

class ApproximateKSVD(AbstractKSVD):
    def __init__(self, n_components, max_iter=10, tol=1e-6,
                 transform_n_nonzero_coefs=None):
        super().__init__(n_components, max_iter, tol, transform_n_nonzero_coefs)

    def update_dict(self, X, D, gamma):
        for j in range(self.n_components):
            # index map of all the atom indices in sparse representation
            #I = gamma[:, j] > 0
            I = np.flatnonzero(gamma[:, j])
            if len(I) == 0:
                continue

            D[j, :] = 0
            # approximate SVD with power method
            g = gamma[I, j].T
            r = X[I, :] - gamma[I, :].dot(D)

            d = r.T.dot(g)
            d /= np.linalg.norm(d)
            g = r.dot(d)

            # insert new column and row
            D[j, :] = d
            gamma[I, j] = g.T

        return D, gamma

reason: import numpy,import scipy


text:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  4 09:10:23 2019

@author: Oyeyemi Damilola
"""

import os
import numpy as np
#from models.model import Model       # this the first version of model designed
from PyQt5 import QtCore, QtGui, QtWidgets
from models.model_v2 import SambaModel
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from models.exceptions import IncompleteInitialParameters,InvalidExtensionError,InvalidInputs,InvalidModelFile

class Figure_Canvas(FigureCanvas):
    def __init__(self,parent=None, width= 6 , height = 5 ,dpi= 100):
        fig = Figure(figsize=(width,height),dpi = 100 )
        FigureCanvas.__init__(self,fig)
        self.setParent(parent)
        self.axes = fig.add_subplot(111)

    def display_plot(self,data):

        """
        Generates the plots/visualizations
        @params

            params : a dict that contains the variables to plotted
        """

        if data['visualization_type'] == 'Evapotranspiration':

            self.axes.plot(data['julian_days'],data['eto'],label='ETo')
            self.axes.plot(data['julian_days'],data['pe'],label='PE')
            self.axes.plot(data['julian_days'],data['ae'],label='AE')
            self.axes.set_xlabel('Julian Days')
            self.axes.set_ylabel('ETo, PE, AE (mm/day)')
            self.axes.grid(b=True,which='major')
            self.axes.legend()

            #self.self.axesaxes.plot(x, y)

        elif data['visualization_type'] == 'SMD':

            self.axes.plot(data['julian_days'],data['runoff'],label='Runoff')
            self.axes.plot(data['julian_days'],data['taw'],label='TAW')
            self.axes.plot(data['julian_days'],data['smd'],label='SMD')
            self.axes.plot(data['julian_days'],data['rainfall'],label='Rainfall')
            self.axes.grid(which='both')
            self.axes.set_xlabel('Julian Days')
            self.axes.set_ylabel('Rain, Runoff, SMD, TAW (mm)')
            self.axes.legend()

        elif data['visualization_type'] == 'Monthly precipitation':

            self.axes.bar(data['y_pos'],data['monthly_precipitation'].values(),align='center',alpha=0.5)
            self.axes.set_xticks(data['y_pos'])
            self.axes.set_xticklabels(data['months'])
            self.axes.set_ylabel('Monthly Precipitation')
            self.axes.grid()

        elif data['visualization_type'] == 'Recharge/Runoff':

            total_runoff = round( sum(data['runoff']) , 3)
            total_recharge = round( sum(data['recharge']) , 3 )
            self.axes.plot(data['julian_days'],data['runoff'],label='Runoff,Total:'+str(total_runoff))
            self.axes.plot(data['julian_days'],data['recharge'],label='Recharge,Total:'+ str(total_recharge))
            self.axes.grid(which='both')
            self.axes.set_xlabel('Julian Days')
            self.axes.set_ylabel('Runoff, Recharge')
            self.axes.legend()

class Ui_SambaMainWindow(object):

    model = None

    def get_model(self):
        if self.model is not None:
            return self.model
        else:
            self.error_dialog.showMessage('No Model Generated')

    def setupUi(self, SambaMainWindow):
        SambaMainWindow.setObjectName("SambaMainWindow")
        SambaMainWindow.resize(950, 700)
        SambaMainWindow.setMinimumSize(QtCore.QSize(950, 700))
        SambaMainWindow.setMaximumSize(QtCore.QSize(1000, 700))
        self.centralwidget = QtWidgets.QWidget(SambaMainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.soilBox = QtWidgets.QGroupBox(self.centralwidget)
        self.soilBox.setGeometry(QtCore.QRect(10, 10, 261, 51))
        self.soilBox.setObjectName("soilBox")
        self.layoutWidget = QtWidgets.QWidget(self.soilBox)
        self.layoutWidget.setGeometry(QtCore.QRect(10, 20, 221, 22))
        self.layoutWidget.setObjectName("layoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.layoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label = QtWidgets.QLabel(self.layoutWidget)
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        self.fpInput = QtWidgets.QLineEdit(self.layoutWidget)
        self.fpInput.setObjectName("fpInput")
        self.horizontalLayout.addWidget(self.fpInput)
        self.label_2 = QtWidgets.QLabel(self.layoutWidget)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout.addWidget(self.label_2)
        self.wpInput = QtWidgets.QLineEdit(self.layoutWidget)
        self.wpInput.setObjectName("wpInput")
        self.horizontalLayout.addWidget(self.wpInput)
        self.cropCoeffBox = QtWidgets.QGroupBox(self.centralwidget)
        self.cropCoeffBox.setGeometry(QtCore.QRect(10, 70, 261, 139))
        self.cropCoeffBox.setObjectName("cropCoeffBox")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.cropCoeffBox)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.label_4 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_4.setObjectName("label_4")
        self.horizontalLayout_2.addWidget(self.label_4)
        self.cropCoeff_Initial = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropCoeff_Initial.setObjectName("cropCoeff_Initial")
        self.horizontalLayout_2.addWidget(self.cropCoeff_Initial)
        self.label_19 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_19.setObjectName("label_19")
        self.horizontalLayout_2.addWidget(self.label_19)
        self.cropDuration_Init = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropDuration_Init.setObjectName("cropDuration_Init")
        self.horizontalLayout_2.addWidget(self.cropDuration_Init)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.label_5 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_5.setObjectName("label_5")
        self.horizontalLayout_3.addWidget(self.label_5)
        self.cropCoeff_Middle = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropCoeff_Middle.setObjectName("cropCoeff_Middle")
        self.horizontalLayout_3.addWidget(self.cropCoeff_Middle)
        self.label_21 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_21.setObjectName("label_21")
        self.horizontalLayout_3.addWidget(self.label_21)
        self.cropDuration_Dev = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropDuration_Dev.setObjectName("cropDuration_Dev")
        self.horizontalLayout_3.addWidget(self.cropDuration_Dev)
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        self.label_6 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_6.setObjectName("label_6")
        self.horizontalLayout_4.addWidget(self.label_6)
        self.cropCoeff_End = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropCoeff_End.setObjectName("cropCoeff_End")
        self.horizontalLayout_4.addWidget(self.cropCoeff_End)
        self.label_22 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_22.setObjectName("label_22")
        self.horizontalLayout_4.addWidget(self.label_22)
        self.cropDuration_Mid = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropDuration_Mid.setObjectName("cropDuration_Mid")
        self.horizontalLayout_4.addWidget(self.cropDuration_Mid)
        self.verticalLayout.addLayout(self.horizontalLayout_4)
        self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.label_7 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_7.setObjectName("label_7")
        self.horizontalLayout_5.addWidget(self.label_7)
        self.cropCoeff_bs = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropCoeff_bs.setObjectName("cropCoeff_bs")
        self.horizontalLayout_5.addWidget(self.cropCoeff_bs)
        self.label_23 = QtWidgets.QLabel(self.cropCoeffBox)
        self.label_23.setObjectName("label_23")
        self.horizontalLayout_5.addWidget(self.label_23)
        self.cropDuration_Late = QtWidgets.QLineEdit(self.cropCoeffBox)
        self.cropDuration_Late.setObjectName("cropDuration_Late")
        self.horizontalLayout_5.addWidget(self.cropDuration_Late)
        self.verticalLayout.addLayout(self.horizontalLayout_5)
        self.cropStagesBox = QtWidgets.QGroupBox(self.centralwidget)
        self.cropStagesBox.setGeometry(QtCore.QRect(10, 210, 261, 161))
        self.cropStagesBox.setObjectName("cropStagesBox")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.cropStagesBox)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.label_8 = QtWidgets.QLabel(self.cropStagesBox)
        self.label_8.setObjectName("label_8")
        self.horizontalLayout_6.addWidget(self.label_8)
        self.cropStages_Planting = QtWidgets.QLineEdit(self.cropStagesBox)
        self.cropStages_Planting.setObjectName("cropStages_Planting")
        self.horizontalLayout_6.addWidget(self.cropStages_Planting)
        self.verticalLayout_2.addLayout(self.horizontalLayout_6)
        self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.label_9 = QtWidgets.QLabel(self.cropStagesBox)
        self.label_9.setObjectName("label_9")
        self.horizontalLayout_7.addWidget(self.label_9)
        self.cropStages_Development = QtWidgets.QLineEdit(self.cropStagesBox)
        self.cropStages_Development.setObjectName("cropStages_Development")
        self.horizontalLayout_7.addWidget(self.cropStages_Development)
        self.verticalLayout_2.addLayout(self.horizontalLayout_7)
        self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.label_10 = QtWidgets.QLabel(self.cropStagesBox)
        self.label_10.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
        self.label_10.setObjectName("label_10")
        self.horizontalLayout_8.addWidget(self.label_10)
        self.cropStages_Middle = QtWidgets.QLineEdit(self.cropStagesBox)
        self.cropStages_Middle.setObjectName("cropStages_Middle")
        self.horizontalLayout_8.addWidget(self.cropStages_Middle)
        self.verticalLayout_2.addLayout(self.horizontalLayout_8)
        self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_9.setObjectName("horizontalLayout_9")
        self.label_11 = QtWidgets.QLabel(self.cropStagesBox)
        self.label_11.setObjectName("label_11")
        self.horizontalLayout_9.addWidget(self.label_11)
        self.cropStages_Late = QtWidgets.QLineEdit(self.cropStagesBox)
        self.cropStages_Late.setObjectName("cropStages_Late")
        self.horizontalLayout_9.addWidget(self.cropStages_Late)
        self.verticalLayout_2.addLayout(self.horizontalLayout_9)
        self.horizontalLayout_10 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_10.setObjectName("horizontalLayout_10")
        self.label_18 = QtWidgets.QLabel(self.cropStagesBox)
        self.label_18.setObjectName("label_18")
        self.horizontalLayout_10.addWidget(self.label_18)
        self.cropStages_Harvest = QtWidgets.QLineEdit(self.cropStagesBox)
        self.cropStages_Harvest.setObjectName("cropStages_Harvest")
        self.horizontalLayout_10.addWidget(self.cropStages_Harvest)
        self.verticalLayout_2.addLayout(self.horizontalLayout_10)
        self.runOffMatrix = QtWidgets.QGroupBox(self.centralwidget)
        self.runOffMatrix.setEnabled(True)
        self.runOffMatrix.setGeometry(QtCore.QRect(10, 380, 261, 201))
        self.runOffMatrix.setObjectName("runOffMatrix")
        self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.runOffMatrix)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
        self.gridLayout.setContentsMargins(9, 11, 20, 19)
        self.gridLayout.setHorizontalSpacing(31)
        self.gridLayout.setVerticalSpacing(24)
        self.gridLayout.setObjectName("gridLayout")
        self.lineEdit_3 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.gridLayout.addWidget(self.lineEdit_3, 1, 3, 1, 1)
        self.lineEdit_12 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_12.setObjectName("lineEdit_12")
        self.gridLayout.addWidget(self.lineEdit_12, 1, 2, 1, 1)
        self.lineEdit_17 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_17.setObjectName("lineEdit_17")
        self.gridLayout.addWidget(self.lineEdit_17, 3, 1, 1, 1)
        self.lineEdit_13 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_13.setObjectName("lineEdit_13")
        self.gridLayout.addWidget(self.lineEdit_13, 1, 1, 1, 1)
        self.lineEdit_16 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_16.setObjectName("lineEdit_16")
        self.gridLayout.addWidget(self.lineEdit_16, 2, 3, 1, 1)
        self.label_3 = QtWidgets.QLabel(self.runOffMatrix)
        self.label_3.setObjectName("label_3")
        self.gridLayout.addWidget(self.label_3, 1, 0, 1, 1)
        self.lineEdit_18 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_18.setObjectName("lineEdit_18")
        self.gridLayout.addWidget(self.lineEdit_18, 3, 2, 1, 1)
        self.lineEdit_14 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_14.setObjectName("lineEdit_14")
        self.gridLayout.addWidget(self.lineEdit_14, 2, 1, 1, 1)
        self.label_16 = QtWidgets.QLabel(self.runOffMatrix)
        self.label_16.setObjectName("label_16")
        self.gridLayout.addWidget(self.label_16, 2, 0, 1, 1)
        self.lineEdit_15 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_15.setObjectName("lineEdit_15")
        self.gridLayout.addWidget(self.lineEdit_15, 2, 2, 1, 1)
        self.lineEdit_19 = QtWidgets.QLineEdit(self.runOffMatrix)
        self.lineEdit_19.setObjectName("lineEdit_19")
        self.gridLayout.addWidget(self.lineEdit_19, 3, 3, 1, 1)
        self.label_17 = QtWidgets.QLabel(self.runOffMatrix)
        self.label_17.setObjectName("label_17")
        self.gridLayout.addWidget(self.label_17, 3, 0, 1, 1)
        self.label_15 = QtWidgets.QLabel(self.runOffMatrix)
        self.label_15.setInputMethodHints(QtCore.Qt.ImhMultiLine)
        self.label_15.setObjectName("label_15")
        self.gridLayout.addWidget(self.label_15, 0, 0, 1, 1)
        self.label_14 = QtWidgets.QLabel(self.runOffMatrix)
        self.label_14.setObjectName("label_14")
        self.gridLayout.addWidget(self.label_14, 0, 3, 1, 1)
        self.label_13 = QtWidgets.QLabel(self.runOffMatrix)
        self.label_13.setObjectName("label_13")
        self.gridLayout.addWidget(self.label_13, 0, 2, 1, 1)
        self.label_12 = QtWidgets.QLabel(self.runOffMatrix)
        self.label_12.setObjectName("label_12")
        self.gridLayout.addWidget(self.label_12, 0, 1, 1, 1)
        self.verticalLayout_3.addLayout(self.gridLayout)
        self.layoutWidget_5 = QtWidgets.QWidget(self.centralwidget)
        self.layoutWidget_5.setGeometry(QtCore.QRect(20, 590, 251, 22))
        self.layoutWidget_5.setObjectName("layoutWidget_5")
        self.horizontalLayout_19 = QtWidgets.QHBoxLayout(self.layoutWidget_5)
        self.horizontalLayout_19.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_19.setObjectName("horizontalLayout_19")
        self.label_35 = QtWidgets.QLabel(self.layoutWidget_5)
        self.label_35.setObjectName("label_35")
        self.horizontalLayout_19.addWidget(self.label_35)
        self.ze = QtWidgets.QLineEdit(self.layoutWidget_5)
        self.ze.setObjectName("ze")
        self.horizontalLayout_19.addWidget(self.ze)

        self.initial_smd_label = QtWidgets.QLabel(self.layoutWidget_5)
        self.initial_smd_label.setObjectName("Initial SMD")
        self.initial_smd_label.setText('Initial SMD')
        self.horizontalLayout_19.addWidget(self.initial_smd_label)

        self.initial_smd = QtWidgets.QLineEdit(self.layoutWidget_5)
        self.initial_smd.setObjectName("intial_smd")
        self.horizontalLayout_19.addWidget(self.initial_smd)
        self.layoutWidget_6 = QtWidgets.QWidget(self.centralwidget)
        self.layoutWidget_6.setGeometry(QtCore.QRect(20, 620, 251, 22))
        self.layoutWidget_6.setObjectName("layoutWidget_6")
        self.horizontalLayout_20 = QtWidgets.QHBoxLayout(self.layoutWidget_6)
        self.horizontalLayout_20.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_20.setObjectName("horizontalLayout_20")
        self.label_36 = QtWidgets.QLabel(self.layoutWidget_6)
        self.label_36.setObjectName("label_36")
        self.horizontalLayout_20.addWidget(self.label_36)
        self.depletionFactor = QtWidgets.QLineEdit(self.layoutWidget_6)
        self.depletionFactor.setObjectName("depletionFactor")
        self.horizontalLayout_20.addWidget(self.depletionFactor)
        self.nss_fraction_label = QtWidgets.QLabel(self.layoutWidget_6)
        self.nss_fraction_label.setObjectName("NSS Fraction")
        self.nss_fraction_label.setText('NSS Fraction')
        self.horizontalLayout_20.addWidget(self.nss_fraction_label)
        self.nss_fraction = QtWidgets.QLineEdit(self.layoutWidget_6)
        self.nss_fraction.setObjectName("nss_fraction")
        self.horizontalLayout_20.addWidget(self.nss_fraction)
        self.layoutWidget_7 = QtWidgets.QWidget(self.centralwidget)
        self.layoutWidget_7.setGeometry(QtCore.QRect(20, 650, 251, 22))
        self.layoutWidget_7.setObjectName("layoutWidget_7")
        self.horizontalLayout_21 = QtWidgets.QHBoxLayout(self.layoutWidget_7)
        self.horizontalLayout_21.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_21.setObjectName("horizontalLayout_21")
        self.label_37 = QtWidgets.QLabel(self.layoutWidget_7)
        self.label_37.setObjectName("label_37")
        self.horizontalLayout_21.addWidget(self.label_37)
        self.maxRootDepth = QtWidgets.QLineEdit(self.layoutWidget_7)
        self.maxRootDepth.setObjectName("maxRootDepth")
        self.horizontalLayout_21.addWidget(self.maxRootDepth)
        self.visualizationBox = QtWidgets.QGroupBox(self.centralwidget)
        self.visualizationBox.setGeometry(QtCore.QRect(280, 50, 651, 591))
        self.visualizationBox.setObjectName("visualizationBox")
        self.visualizationGraphicsView = QtWidgets.QGraphicsView(self.visualizationBox)
        self.visualizationGraphicsView.setGeometry(QtCore.QRect(10, 20, 631, 561))
        self.visualizationGraphicsView.setObjectName("visualizationGraphicsView")
        self.graphicScene = QtWidgets.QGraphicsScene()
        self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(280, 10, 651, 31))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout_34 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout_34.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_34.setObjectName("horizontalLayout_34")
        self.searchInput = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
        self.searchInput.setReadOnly(True)
        self.searchInput.setObjectName("searchInput")
        self.horizontalLayout_34.addWidget(self.searchInput)
        self.selectModel = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.selectModel.setObjectName("selectModel")
        self.horizontalLayout_34.addWidget(self.selectModel)
        self.generateModel = QtWidgets.QPushButton(self.horizontalLayoutWidget)
        self.generateModel.setObjectName("generateModel")
        self.horizontalLayout_34.addWidget(self.generateModel)
        self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget)
        self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(280, 650, 651, 25))
        self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
        self.horizontalLayout_35 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2)
        self.horizontalLayout_35.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_35.setObjectName("horizontalLayout_35")
        self.selectPlot = QtWidgets.QComboBox(self.horizontalLayoutWidget_2)
        self.selectPlot.setObjectName("selectPlot")
        self.selectPlot.addItems(['                       --Select plot --                ',
                                  'SMD',
                                  'Monthly precipitation',
                                  'Evapotranspiration',
                                  'Recharge/Runoff'])
        self.horizontalLayout_35.addWidget(self.selectPlot)
        self.displayPlot = QtWidgets.QPushButton(self.horizontalLayoutWidget_2)
        self.displayPlot.setObjectName("displayPlot")
        self.horizontalLayout_35.addWidget(self.displayPlot)

        self.horizontalLayout_35.addWidget(self.displayPlot)

        self.label_20 = QtWidgets.QLabel(self.centralwidget)
        self.label_20.setGeometry(QtCore.QRect(740, 630, 47, 20))
        self.label_20.setObjectName("label_20")
        SambaMainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(SambaMainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 950, 21))
        self.menubar.setObjectName("menubar")
        SambaMainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(SambaMainWindow)
        self.statusbar.setObjectName("statusbar")
        SambaMainWindow.setStatusBar(self.statusbar)
        self.error_dialog = QtWidgets.QErrorMessage()
        self.msg_dialog = QtWidgets.QMessageBox()
        self.msg_dialog.setIcon(self.msg_dialog.Information)

        self.retranslateUi(SambaMainWindow)
        QtCore.QMetaObject.connectSlotsByName(SambaMainWindow)

        """
        Controllers
        """

        self.selectModel.clicked.connect(self.get_model_file)
        self.generateModel.setEnabled(False)
        self.generateModel.clicked.connect(self.load_model)
        self.displayPlot.clicked.connect(self.show)

    def retranslateUi(self, SambaMainWindow):
        _translate = QtCore.QCoreApplication.translate
        SambaMainWindow.setWindowTitle(_translate("SambaMainWindow", "MainWindow"))
        self.soilBox.setTitle(_translate("SambaMainWindow", "SOIL"))
        self.label.setText(_translate("SambaMainWindow", "FC"))
        self.label_2.setText(_translate("SambaMainWindow", "WP"))
        self.cropCoeffBox.setTitle(_translate("SambaMainWindow", "CROP COEFFICIENT/ CROP DURATION"))
        self.label_4.setText(_translate("SambaMainWindow", "Initial  "))
        self.label_19.setText(_translate("SambaMainWindow", "Init"))
        self.label_5.setText(_translate("SambaMainWindow", "Middle "))
        self.label_21.setText(_translate("SambaMainWindow", "Dev"))
        self.label_6.setText(_translate("SambaMainWindow", "  End   "))
        self.label_22.setText(_translate("SambaMainWindow", "Mid"))
        self.label_7.setText(_translate("SambaMainWindow", "  BS     "))
        self.label_23.setText(_translate("SambaMainWindow", "Late"))
        self.cropStagesBox.setTitle(_translate("SambaMainWindow", "CROP STAGES"))
        self.label_8.setText(_translate("SambaMainWindow", "Planting"))
        self.label_9.setText(_translate("SambaMainWindow", "Development"))
        self.label_10.setText(_translate("SambaMainWindow", "Middle"))
        self.label_11.setText(_translate("SambaMainWindow", " Late   "))
        self.label_18.setText(_translate("SambaMainWindow", "Harvest"))
        self.runOffMatrix.setTitle(_translate("SambaMainWindow", "RUN-OFF MATRIX"))
        self.label_3.setText(_translate("SambaMainWindow", "   0-20"))
        self.label_16.setText(_translate("SambaMainWindow", "20-50"))
        self.label_17.setText(_translate("SambaMainWindow", "  >50"))
        self.label_15.setText(_translate("SambaMainWindow", "R.I/SMD"))
        self.label_14.setText(_translate("SambaMainWindow", "  >50"))
        self.label_13.setText(_translate("SambaMainWindow", "20-50"))
        self.label_12.setText(_translate("SambaMainWindow", "  0-20"))
        self.label_35.setText(_translate("SambaMainWindow", "Z E"))
        self.label_36.setText(_translate("SambaMainWindow", "Depletion Factor"))
        self.label_37.setText(_translate("SambaMainWindow", "Maximum Root Depth"))
        self.visualizationBox.setTitle(_translate("SambaMainWindow", "VISUALIZATION"))
        self.selectModel.setText(_translate("SambaMainWindow", "Select Model File"))
        self.generateModel.setText(_translate("SambaMainWindow", "Generate Model"))
        self.displayPlot.setText(_translate("SambaMainWindow", "Display Plot"))

        """
        Controller functions
        """

    def get_model_file(self):

        '''
        to retrieve the model file from the local drive
        '''
        filename, _ = QtWidgets.QFileDialog.getOpenFileName(None,'Select Model File',os.getcwd())
        self.searchInput.setText(filename)
        self.generateModel.setEnabled(True)
        self.graphicScene.clear()
        return filename

    def show(self):

        '''
        to display the figure selected on the canvas / graphic scene
        '''
        model = self.get_model()
        dr = Figure_Canvas()
        dr.display_plot(model.load_visualization(self.selectPlot.currentText()))

       # graphicscene = QtWidgets.QGraphicsScene()
       # graphicscene.addWidget(dr)
        self.graphicScene.addWidget(dr)

        self.visualizationGraphicsView.setScene(self.graphicScene)
        self.visualizationGraphicsView.show()

    def get_crop_duration(self):

        '''

        to retrieve the user's defined input for the duration of crops
        '''

        crop_duration = {}
        try:
            crop_duration['initial'] = float(self.cropDuration_Init.text())
            crop_duration['development'] = float(self.cropDuration_Dev.text())
            crop_duration['middle'] = float(self.cropDuration_Mid.text())
            crop_duration['late'] = float(self.cropDuration_Late.text())
        except Exception:
            raise InvalidInputs('Invalid Inputs')
        else:
            return crop_duration

    def get_run_off_matrix(self):

        '''

        to retrieve the user's defined input for the runoff matrix
        '''

        run_off_matrix = np.empty((3,3))

        try:
            # first row
            run_off_matrix[0,0] = float(self.lineEdit_13.text())
            run_off_matrix[0,1] = float(self.lineEdit_12.text())
            run_off_matrix[0,2] = float(self.lineEdit_3.text())

            #second row
            run_off_matrix[1,0] = float(self.lineEdit_14.text())
            run_off_matrix[1,1] = float(self.lineEdit_15.text())
            run_off_matrix[1,2] = float(self.lineEdit_16.text())

            #third row
            run_off_matrix[2,0] = float(self.lineEdit_17.text())
            run_off_matrix[2,1] = float(self.lineEdit_18.text())
            run_off_matrix[2,2] = float(self.lineEdit_19.text())

        except Exception:
            raise InvalidInputs('Invalid Inputs')
        else:
            return run_off_matrix

    def get_soil_parameters(self):

        '''

        to retrieve the user's defined input for the soil parameters
        '''

        soil_params = {}
        try:
            soil_params['FC'] = float(self.fpInput.text())
            soil_params['WP'] = float(self.wpInput.text())
        except Exception:
            raise InvalidInputs('Invalid Inputs')
        else:
            return soil_params

    def get_crop_coefficient(self):

        '''

        to retrieve the user's defined input for the crop coefficient
        '''

        crop_coefficient = {}
        try:
            crop_coefficient['initial'] = float(self.cropCoeff_Initial.text())
            crop_coefficient['middle'] = float(self.cropCoeff_Middle.text())
            crop_coefficient['end'] = float(self.cropCoeff_End.text())
            crop_coefficient['bs'] = float(self.cropCoeff_bs.text())
        except Exception:
            raise InvalidInputs('Invalid Inputs')
        else:
            return crop_coefficient

    def get_crop_stages(self):

        '''

        to retrieve the user's defined input for the crop stages
        '''

        crop_stages = {}
        try:
            crop_stages['planting'] = float(self.cropStages_Planting.text())
            crop_stages['development'] = float(self.cropStages_Development.text())
            crop_stages['middle'] = float(self.cropStages_Middle.text())
            crop_stages['late'] = float(self.cropStages_Late.text())
            crop_stages['harvest'] = float(self.cropStages_Harvest.text())
        except Exception:
            raise InvalidInputs('Invalid Inputs')
        else:
            return crop_stages
    def get_model_constant_params(self):

        '''

        to retrieve the user's defined input for the constant parameters
        '''

        model_constant_params = {}
        try:
             model_constant_params['Ze'] = float(self.ze.text())
             model_constant_params['depletion_factor'] = float(self.depletionFactor.text())
             model_constant_params['initial_smd'] = float(self.initial_smd.text())
             model_constant_params['nss_fraction'] = float(self.nss_fraction.text())
        except Exception:
             raise InvalidInputs('Invalid Inputs')
        else:
             return model_constant_params
    def get_max_root_depth(self):

        '''

        to retrieve the user's defined input for the maximum root depth
        '''

        try:
            max_root_depth = float(self.maxRootDepth.text())
        except Exception:
            raise InvalidInputs('Invalid Inputs')
        else:
            return max_root_depth
    def load_model(self):

        # clear plot on the graphic scene
        self.graphicScene.clear()

        try:
            RUN_OFF_MATRIX = self.get_run_off_matrix()
            SOIL = self.get_soil_parameters()
            MODEL_CONSTANT_PARAMS = self.get_model_constant_params()
            CROP_COEFF = self.get_crop_coefficient()
            CROP_STAGES = self.get_crop_stages()
            MAX_ROOT_DEPTH = self.get_max_root_depth()
            MODEL_FILE = self.searchInput.text()
            CROP_DURATION = self.get_crop_duration()
            model = SambaModel(model_path = MODEL_FILE,
                          crop_stages = CROP_STAGES,
                          soil = SOIL,
                          crop_coefficient = CROP_COEFF,
                          run_off_matrix = RUN_OFF_MATRIX,
                          model_constant_params = MODEL_CONSTANT_PARAMS,
                          max_root_depth = MAX_ROOT_DEPTH,
                          crop_duration =  CROP_DURATION)
            self.model = model
            self.model.generate_model()
        except (InvalidExtensionError,InvalidInputs,IncompleteInitialParameters,InvalidModelFile) as e:
                self.error_dialog.showMessage(str(e))
        else:
             self.msg_dialog.setInformativeText('Model\nGenerated')
             self.msg_dialog.exec_()

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    SambaMainWindow = QtWidgets.QMainWindow()
    ui = Ui_SambaMainWindow()
    ui.setupUi(SambaMainWindow)
    SambaMainWindow.show()
    sys.exit(app.exec_())

max_stars_repo_name: oyeyemidamilola/samba-model

max_issues_repo_name: oyeyemidamilola/samba-model

max_forks_repo_name: oyeyemidamilola/samba-model


text:
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 23 16:24:15 2020

@authors: Intentodemusico
"""
#Scraping distribui2
from mpi4py import MPI
from bs4 import BeautifulSoup
import json, urllib.request
import numpy as np
def getGoogle(x,letra):
    global rank
    #Es necesario pasar un User-Agent en la cabecera para evitar errores con los controles de seguridad de ciertas páginas
    query="https://www.google.com/search?q="+letra
    url = urllib.request.Request(query, headers={'User-Agent': 'Mozilla/5.0'})
    req = urllib.request.urlopen(url)
    page = req.read()
    print(rank,letra,x)
    #Escogemos el encoder que vamos a usar
    scraping = BeautifulSoup(page,features="html.parser")
    #Al encontrar la etiqueta que queremos, podemos obtener subetiquetas (en este caso div) y el texto que se encuentra en ellas
    title = scraping.findAll("a")[x+17].div.get_text()
    #Con parent podemos referenciar a la etiqueta padre de la que estamos seleccionando
    #Podemos navegar entre las etiquetas hermanas (las que están al mismo nivel) con next_sibling y previous_sibling
    summary=scraping.findAll("a")[x+17].parent.next_sibling.next_sibling.get_text()
    #Podemos obtener propiedades específicas de una etiqueta
    link="https://google.com"+str(scraping.findAll("a")[x+17].get('href'))

    return title, summary, link

jsonArray=[]

def getTen(myArr):
    jsonA=[]
    for letra in myArr:
        for x in range(10):
            t,s,l=getGoogle(x,letra.replace(" ","+"))
            jsonA.append({'query':letra, 'title': t, 'summary': s,'link': l})
    return jsonA
def getArray(r,a):
    return np.split(a,3)[r]

#%%
comm = MPI.COMM_WORLD
size=comm.Get_size()
rank=comm.Get_rank()
nodes=3
#%%
array=np.array(['fraude ingreso solidario']*36)
myArray=getArray(rank,array)

jsonArray=getTen(myArray)

########

if rank == 0:
    data=comm.gather(jsonArray,root=0)

if rank==0:
    f=open("googleJSON.json","w")

    json.dump(data,f, sort_keys=True, indent=4,ensure_ascii=False)
    print("Fin")
    f.close()

max_stars_repo_name: intentodemusico/Atribunet

max_issues_repo_name: intentodemusico/Atribunet

max_forks_repo_name: intentodemusico/Atribunet


text:
########################################################
# Rodrigo Leite - drigols                              #
# Last update: 17/12/2021                              #
########################################################

def create_df(**df):
  my_df = {}
  import pandas as pd
  my_df = pd.DataFrame(df)
  return my_df

if __name__ =='__main__':

  import matplotlib.pyplot as plt
  import scipy.stats as stats

  students = {
    'Name': ['Dan', 'Joann', 'Pedro', 'Rosie', 'Ethan', 'Vicky', 'Frederic'],
    'Hours':[41, 40, 36, 30, 35, 39, 40]
  }

  my_df = create_df(**students)
  hours = my_df['Hours'] # Pega as horas trabalhadas por semana de cada aluno.
  density = stats.gaussian_kde(hours) # Pega a densidade das horas.

  # Cria o plot/gráfico.
  n, x, _ = plt.hist(hours, histtype='step', density=True, bins=25) # Cria o Histograma.
  plt.plot(x, density(x)*7) # Cria a linha de densidade no plot.
  plt.axvline(hours.mean(), color='magenta', linestyle='dashed', linewidth=2) # Adiciona mean() lane no plot.
  plt.axvline(hours.median(), color='green', linestyle='dashed', linewidth=2) # Adiciona median() lane no plot.
  plt.savefig('../images/density-02.png', format='png')
  plt.show()

max_stars_repo_name: drigols/Studies

max_issues_repo_name: drigols/Studies

max_forks_repo_name: drigols/Studies

reason: import scipy


text:
import cv2 # computer vision library
import helpers # helper functions

import random
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg # for loading in images

# IMAGE_DIR_TRAINING = "images/traffic-light/training/"
# IMAGE_DIR_TEST = "images/traffic-light/testing/"

pics = [
"images/traffic-light/testing/green/1d5a9390-81dd-4f09-9c32-4436cb90bb95.jpg",
"images/traffic-light/testing/green/7bfade00-0869-4482-8b9a-1028910397d1.jpg",
"images/traffic-light/testing/green/6e33a55e-8f13-46d0-bd82-0a4d021e05e3.jpg",
"images/traffic-light/testing/green/0b3606b7-bf9e-49d8-8de8-801bb8374b2d.jpg",
"images/traffic-light/testing/green/3a134375-f8d2-4fb9-bd8b-e76e8c1d9305.jpg",
"images/traffic-light/testing/green/0be91609-32ba-4b7b-b460-cc47dd62b740.jpg",
"images/traffic-light/testing/yellow/3b9d130d-3725-440d-867a-7e8a04603a97.jpg",
"images/traffic-light/testing/green/1e3af45f-6fd3-4c8b-9c9e-f8e504b868d7.jpg",
"images/traffic-light/testing/green/2e368899-ff57-48f9-ae8c-4bd35cf6c402.jpg"

]

# Using the load_dataset function in helpers.py
# Load training data
# IMAGE_LIST = helpers.load_traffic_dataset(IMAGE_DIR_TRAINING)
def crop_image(image):
    row_crop = 4
    col_crop = 12
    return image[row_crop:-row_crop,col_crop:-col_crop,:]

def testHSV(rgb_image):

    cropped_img = crop_image(rgb_image)
    # Convert to HSV
    hsv  = cv2.cvtColor(cropped_img, cv2.COLOR_RGB2HSV)

    # HSV channels
    h = hsv[:,:,0]
    s = hsv[:,:,1]
    v = hsv[:,:,2]

    sum_brightness = np.sum(hsv[:,:,2])
    area = h.shape[0]*h.shape[1]  # pixels

    # find the avg
    # create a mask using v channel
    lower_v = sum_brightness/area
    upper_v = 255
    print("lower:", lower_v, ", ",upper_v)
    mask = cv2.inRange(v, lower_v, upper_v)

    # Mask the image to let the color show through
    masked_image = np.copy(v)
    masked_image[mask != 255] = 0

    # Plot the original image and the three channels
    f, [(ax1, ax2, ax3), (ax4,ax5,ax6)]  = plt.subplots(2, 3, figsize=(20,10))

    ax1.set_title('cropped image')
    ax1.imshow(cropped_img)
    ax2.set_title('H channel')
    ax2.imshow(h, cmap='gray')
    ax3.set_title('S channel')
    ax3.imshow(s, cmap='gray')
    ax4.set_title('V channel')
    ax4.imshow(v, cmap='gray')
    ax5.set_title('Mask')
    ax5.imshow(mask, cmap='gray')
    ax6.set_title('V Mask')
    ax6.imshow(masked_image, cmap='gray')

# Classify image using HSV channel
def classify_image(rgb_image):
    hsv = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2HSV)
    # HSV channels
    h = hsv[:,:,0] #0-180
    s = hsv[:,:,1] #0-255
    v = hsv[:,:,2] #0-255

    sum_brightness = np.sum(hsv[:,:,2])
    area = h.shape[0]*h.shape[1]  # pixels

    # find the avg
    # create a mask using v channel
    lower_v = sum_brightness/area
    upper_v = 255
    # print("lower:", lower_v, ", ",upper_v)
    mask = cv2.inRange(v, lower_v, upper_v)

    # Mask the image to let the color show through
    masked_image = np.copy(v)
    masked_image[mask != 255] = 0

    # drawMask(rgb_image,v,masked_image)

    RH1,RH2,RS,RV = range(160,181),range(0,10),range(43,256),range(46,256)
    YH, YS, YV = range(10,60),range(43,256),range(45,256)
    GH, GS, GV = range(70,100),range(43,256),range(46,256)

    red = 0
    yellow = 0
    green = 0

    h,w = masked_image.shape
    for i in range(h):
        for j in range(w):
            if masked_image[i][j] != 0:
                h = hsv[i][j][0]
                s = hsv[i][j][1]
                v = hsv[i][j][2]
                if (h in RH1 or h in RH2) and (s in RS) and (v in RV):
                    red += 1
                if (h in YH) and (s in YS) and (v in YV):
                    yellow += 1
                if (h in GH) and (s in GS) and (v in GV):
                    green += 1

    print("red", red)
    print("green", green)
    print("yellow", yellow)

    if red > green and red > yellow:
        return [1,0,0]
    if green > red and green > yellow:
        return [0,0,1]
    if yellow > red and yellow > green:
        return [0,1,0]

    return [1,0,0]

def estimate_label(rgb_image):
    return classify_image(crop_image(rgb_image))

# for url in pics:
# print(len(pics))
image = helpers.load_image(pics[0])
standard_im = np.copy(image)
standard_im = cv2.resize(standard_im,(32,32))
result = estimate_label(image)
print(str(result))
testHSV(standard_im)
plt.show()


text:
from __future__ import print_function
import argparse
from pydoc import locate
import constrained_opt
import cv2
import numpy as np

def parse_args():
    parser = argparse.ArgumentParser(description='iGAN: Interactive Visual Synthesis Powered by GAN')
    parser.add_argument('--model_name', dest='model_name', help='the model name', default='outdoor_64', type=str)
    parser.add_argument('--model_type', dest='model_type', help='the generative models and its deep learning framework', default='dcgan_theano', type=str)
    parser.add_argument('--framework', dest='framework', help='deep learning framework', default='theano')
    parser.add_argument('--input_color', dest='input_color', help='input color image', default='./pics/input_color.png')
    parser.add_argument('--input_color_mask', dest='input_color_mask', help='input color mask', default='./pics/input_color_mask.png')
    parser.add_argument('--input_edge', dest='input_edge', help='input edge image', default='./pics/input_edge.png')
    parser.add_argument('--output_result', dest='output_result', help='output_result', default='./pics/script_result.png')
    parser.add_argument('--batch_size', dest='batch_size', help='the number of random initializations', type=int, default=64)
    parser.add_argument('--n_iters', dest='n_iters', help='the number of total optimization iterations', type=int, default=100)
    parser.add_argument('--top_k', dest='top_k', help='the number of the thumbnail results being displayed', type=int, default=16)
    parser.add_argument('--model_file', dest='model_file', help='the file that stores the generative model', type=str, default=None)
    parser.add_argument('--d_weight', dest='d_weight', help='captures the visual realism based on GAN discriminator', type=float, default=0.0)
    args = parser.parse_args()
    return args

def preprocess_image(img_path, npx):
    im = cv2.imread(img_path, 1)
    if im.shape[0] != npx or im.shape[1] != npx:
        out = cv2.resize(im, (npx, npx))
    else:
        out = np.copy(im)

    out = cv2.cvtColor(out, cv2.COLOR_BGR2RGB)
    return out

if __name__ == '__main__':
    args = parse_args()
    if not args.model_file:  # if the model_file is not specified
        args.model_file = './models/%s.%s' % (args.model_name, args.model_type)

    for arg in vars(args):
        print('[%s] =' % arg, getattr(args, arg))

    # initialize model and constrained optimization problem
    model_class = locate('model_def.%s' % args.model_type)
    model = model_class.Model(model_name=args.model_name, model_file=args.model_file)
    opt_class = locate('constrained_opt_%s' % args.framework)
    opt_solver = opt_class.OPT_Solver(model, batch_size=args.batch_size, d_weight=args.d_weight)
    img_size = opt_solver.get_image_size()
    opt_engine = constrained_opt.Constrained_OPT(opt_solver, batch_size=args.batch_size, n_iters=args.n_iters, topK=args.top_k)
    # load user inputs
    npx = model.npx
    im_color = preprocess_image(args.input_color, npx)
    im_color_mask = preprocess_image(args.input_color_mask, npx)
    im_edge = preprocess_image(args.input_edge, npx)
    # run the optimization
    opt_engine.init_z()
    constraints = [im_color, im_color_mask[..., [0]], im_edge, im_edge[..., [0]]]
    for n in range(args.n_iters):
        opt_engine.update_invert(constraints=constraints)
    results = opt_engine.get_current_results()
    final_result = np.concatenate(results, 1)
    # combine input and output
    final_vis = np. hstack([im_color, im_color_mask, im_edge, final_result])
    final_vis = cv2.cvtColor(final_vis, cv2.COLOR_RGB2BGR)
    final_vis = cv2.resize(final_vis, (0, 0), fx=2.0, fy=2.0)
    # save
    cv2.imwrite(args.output_result, final_vis)

max_stars_repo_name: CosmosHua/iGAN

max_issues_repo_name: CosmosHua/iGAN

max_forks_repo_name: CosmosHua/iGAN


text:
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.patches as patches
# from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
# from mpl_toolkits.axes_grid1.inset_locator import mark_inset
import os
import numpy as np

plt.style.use('paper/figstyle.mpl')
dpi = 300

import sys
sys.path += ["python"]
from figure_util import shift_legend, cm2inch

speedac = pd.read_csv("paper/maximum_out_S4_R3/Bimol_1.speedtime", sep="\t")
speedac["N"] = speedac["i0"] + speedac["i1"]
N = 50
one_N = speedac[speedac["N"] == N].copy()

fig, ax = plt.subplots(1, 3)

plot_settings = {
                "linestyle" : "-",
                "marker" : "o",
                "markersize" : 3,
                "linewidth" : 0.5,
                "markerfacecolor" : "none",
                "markeredgewidth" : 0.5}

for i in one_N["i0"].unique():
    one_run = one_N[one_N["i0"] == i]
    one_run = one_run.sort_values(by="r0")
    ax[0].loglog(one_run["r0"], one_run["score"],
                 label="A = {0}".format(int(i)),
                 **plot_settings)

    ax[1].loglog(one_run["r0"], one_run["opt_time"]*N,
                 label="A = {0}".format(int(i)),
                 **plot_settings)

ax[0].set_xlabel("Ratio of slow/fast reaction rates")
ax[0].set_ylabel("Accuracy")
#ax[0].legend(loc="lower center")

ax[1].set_xlabel("Ratio of slow/fast reaction rates")
ax[1].set_ylabel("Expected halt time")
leg = ax[1].legend()
leg, ax[1] = shift_legend(ax[1], leg, yshift=0.1)

#####################
### Accuracy decrease with moleucles
#############
acc_down = pd.read_csv("paper/maximum_out_S4_R3/Bimol_1_tf10000.tsv", sep="\t", names=["N", "opt_score", "one_score"])
ax[2].plot(acc_down["N"], acc_down["opt_score"],**plot_settings)
ax[2].set_xscale('log')
ax[2].set_ylim(0, 1.1)
#cycler = matplotlib.rcParams['axes.color_cycle']
ax[2].axvline(100, color="gray", linewidth=0.5)
ax[2].set_xlabel("Total molecules ($n$)")
ax[2].set_ylabel("Accuracy")

ly = 0.92
ax[0].text(0.01, ly, "a", transform=fig.transFigure, fontsize=10)
ax[1].text(0.35,  ly, "b", transform=fig.transFigure, fontsize=10)
ax[1].text(0.69,  ly, "c", transform=fig.transFigure, fontsize=10)

fig.set_size_inches(cm2inch(12, 3.5))

#fig.tight_layout()
fig.subplots_adjust(left= 0.10,  # the left side of the subplots of the figure
                   right = 0.99,   # the right side of the subplots of the figure
                   bottom = 0.3,   # the bottom of the subplots of the figure
                   top = 0.85,      # the top of the subplots of the figure
                   wspace = 0.5,   # the amount of width reserved for blank space between subplots,
                                  # expressed as a fraction of the average axis width
                   hspace = 0.2)   # the amount of height reserved for white space between subplots,

fig.savefig("max_speedac.pdf", dpi=dpi)#bbox_inches="tight")
fig.savefig("max_speedac.png", dpi=dpi)#bbox_inches="tight")

max_stars_repo_name: npmurphy/CRNSynthesisFigures

max_issues_repo_name: npmurphy/CRNSynthesisFigures

max_forks_repo_name: npmurphy/CRNSynthesisFigures


text:
###############################################################################
#
# File: rotation_translation_image_warp.py
#
# Warp an image by a rotation.
# This is a first order approximation, the instantaneous flow due
# to rotation of an observer is used to derive the flow field by
# which the image is warped.
#
# History:
# 07-28-20 - Levi Burner - Created file
#
###############################################################################

from scipy import ndimage
import numpy as np
import cv2

# Calculate an optical flow field due to a body rate rotation
def discrete_optical_flow_due_to_rotation(yaw, pitch, roll, focal_length, grid_size):
    a = pitch
    b = yaw
    g = roll
    f = focal_length

    (x, y) = np.meshgrid(np.arange(0, grid_size[1], dtype=np.float32) - grid_size[1]/2.0 + 0.5,
                         np.arange(0, grid_size[0], dtype=np.float32) - grid_size[0]/2.0 + 0.5)

    # Equations 1 and 2 from page 3 of Passive Navigation as a Pattern Recognition Problem
    u_rot = a*x*y/f - b*(x*x/f + f) + g*y
    v_rot = a*(y*y/f+f) - b*x*y/f - g*x

    # Channels first format
    return np.dstack((u_rot, v_rot))

# Calculate an optical flow field due to a translation in XY plane
# Assumes constant depth of Z = focal_length
def discrete_optical_flow_due_to_2D_translation(u, v, grid_size):
    (uu, vv) = np.meshgrid(np.repeat(v, grid_size[1]),
                           np.repeat(u, grid_size[0]))
    return np.dstack((uu, vv))

def image_warp(image, flow):
    # Need to switch to channels first for handling color images
    # Use atleast_3d to also handle grayscale
    image_rolled = np.moveaxis(np.atleast_3d(image), 2, 0)

    x = np.arange(0, image.shape[1], 1, dtype=np.float32)
    y = np.arange(0, image.shape[0], 1, dtype=np.float32)
    xv, yv = np.meshgrid(x, y)
    coords = np.array((xv, yv))

    flow_rolled = np.moveaxis(flow, 2, 0)

    # Warp is in the reverse direction so take negative of flow
    mapping = -flow_rolled + coords

    mapping_swapped = np.array((mapping[1, :, :], mapping[0, :, :]))

    image_warped_rolled = np.array([ndimage.map_coordinates(channel, mapping_swapped)
                                       for channel in image_rolled])

    image_warped = np.moveaxis(image_warped_rolled, 0, 2)

    if len(image.shape) == 2:
        image_warped = image_warped.reshape(image.shape)

    return image_warped

reason: import numpy,from scipy


text:
# -*- coding: utf-8 -*-

"""PSMF Experiment 3 - Shared functionality

This file is part of the PSMF codebase.
See the LICENSE file for copyright and licensing information.

"""

import argparse
import hashlib
import json
import numpy as np
import os
import safer
import socket

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-i", "--input", help="Input CSV file with pollutants", required=True
    )
    parser.add_argument(
        "-o", "--output", help="Output JSON file", required=True
    )
    parser.add_argument(
        "-p",
        "--percentage",
        help="Missing percentage (0-100)",
        type=int,
        required=True,
    )
    parser.add_argument(
        "-s", "--seed", help="Random seed", type=int, default=42
    )
    parser.add_argument(
        "-r", "--repeats", help="Number of MC repeats", type=int, default=1000
    )
    parser.add_argument(
        "-f",
        "--fancy",
        help="Show fancy progress bar (suppress other printing)",
        action="store_true",
    )

    return parser.parse_args()

def prepare_missing(Ymiss, missRatio, misSeg=20):
    """Prepare the data by generating a random missing mask

    Ymiss : (copy of) the input data (d x n)
    missRatio : fraction in [0, 1] of the amount of missing data we want
    misSeg : length of consecutive missing data segments

    Returns

    ratio : actually achieved ratio of missingness (close to desired)
    Mmiss : missing mask (missing set to 1)

    """
    d, n = Ymiss.shape
    NumMissDefault = np.sum(np.isnan(Ymiss))
    Mmiss = np.zeros_like(Ymiss)
    ratio = NumMissDefault / (d * n)
    while ratio < missRatio:
        for i in range(0, d):
            mStart = np.random.randint(1, n - misSeg)
            for j in range(mStart, mStart + misSeg):
                if not np.isnan(Ymiss[i, j]):
                    Ymiss[i, j] = np.nan
                    Mmiss[i, j] = 1
        ratio = (NumMissDefault + np.sum(Mmiss)) / (d * n)

    return ratio, Mmiss

def RMSEM(Y1, Y2, M):
    nMissing = np.sum(M)
    Y1m = np.multiply(Y1, M)
    Y2m = np.multiply(Y2, M)
    R2 = (1 / nMissing) * np.sum(np.power(Y1m - Y2m, 2))
    return np.sqrt(R2)

def compute_number_inside_bars(Mmiss, m, n, Yorg, YrecL, YrecH):
    TotalNum = 0
    for i in range(m):
        for j in range(n):
            if Mmiss[i, j] == 1:
                if Yorg[i, j] < YrecH[i, j] and YrecL[i, j] < Yorg[i, j]:
                    TotalNum += 1
    return TotalNum / np.sum(Mmiss)

def sha1sum(filename):
    blocksize = 1 << 16
    hasher = hashlib.sha1()
    with open(filename, "rb") as fp:
        buf = fp.read(blocksize)
        while len(buf) > 0:
            hasher.update(buf)
            buf = fp.read(blocksize)
    return hasher.hexdigest()

def matrix_hash(A):
    b2b = hashlib.blake2b(digest_size=16)
    b2b.update(A.tobytes())
    return b2b.hexdigest()

def prepare_output(
    input_filename,
    script_filename,
    params,
    hashes,
    results,
    seed,
    percentage,
    missRatio,
    method,
):
    out = {}

    out["method"] = method
    out["seed"] = seed
    out["missing_percentage"] = percentage
    out["missing_ratio"] = missRatio
    out["parameters"] = params
    out["hashes"] = hashes
    out["results"] = results

    # hostname of the machine that created the result
    out["hostname"] = socket.gethostname()

    # save the full path of the script and its sha1
    out["script"] = script_filename
    out["script_sha1"] = sha1sum(script_filename)

    # save the full path of the data file and its sha1
    dataset_filename = os.path.abspath(os.path.realpath(input_filename))
    out["dataset"] = dataset_filename
    out["dataset_sha1"] = sha1sum(dataset_filename)

    return out

def dump_output(output, filename):
    with safer.open(filename, "w") as fp:
        json.dump(output, fp, indent="\t", sort_keys=True)

max_stars_repo_name: vishalbelsare/rPSMF

max_issues_repo_name: vishalbelsare/rPSMF

max_forks_repo_name: vishalbelsare/rPSMF


text:
import math

import numpy as np
from tensorflow.keras.utils import Sequence

class BatchIndexer:
    def __init__(self, length: int, batch_size: int, seed=None, shuffle=True):
        assert batch_size > 0
        assert length > 0

        if not shuffle:
            assert seed is None

        self.batch_size = batch_size
        self.batch_count = int(math.ceil(length / self.batch_size))
        self.indices = np.arange(0, length)
        self.shuffle = shuffle

        if shuffle:
            self.random = np.random.RandomState(seed)
            self.random.shuffle(self.indices)

    def get_indices(self, start, end):
        return self.indices[start:end]

    def reset(self):
        if self.shuffle:
            self.random.shuffle(self.indices)

    def __len__(self):
        return self.batch_count

class BatchGenerator(Sequence):
    def __init__(self, length: int, batch_size: int, seed=None, shuffle=True):
        self.indexer = BatchIndexer(length, batch_size, seed, shuffle)

    @property
    def batch_size(self):
        return self.indexer.batch_size

    def load_sample(self, index):
        raise NotImplementedError()

    def __len__(self):
        return len(self.indexer)

    def on_epoch_end(self):
        self.indexer.reset()

    def __getitem__(self, index):
        xs = []
        ys = []

        start = index * self.batch_size
        end = start + self.batch_size
        for index in self.indexer.get_indices(start, end):
            x, y = self.load_sample(index)
            xs.append(x)
            ys.append(y)

        return np.array(xs), np.array(ys)

class EagerGenerator(BatchGenerator):
    """Preloads all samples from the given sequence and keeps them in memory"""

    def __init__(self, sequence: Sequence, batch_size: int, seed=None, shuffle=True):
        self.samples = get_all_samples(sequence)
        super().__init__(len(self.samples), batch_size, seed, shuffle)

    def load_sample(self, index):
        return self.samples[index]

def get_all_samples(generator):
    samples = []
    for batch in generator:
        samples.extend(zip(*batch))
    return samples

class SequenceWrapper(Sequence):
    """Wraps a sequence and delegates everything to it."""

    def __init__(self, sequence: Sequence):
        self.sequence = sequence

    def __len__(self):
        return len(self.sequence)

    def __getitem__(self, item):
        return self.sequence[item]

    def on_epoch_end(self):
        self.sequence.on_epoch_end()

class MappingSequence(SequenceWrapper):
    """Sequence that wraps another sequence and applies a function to its batches"""

    def __init__(self, sequence: Sequence, map_x, map_y=None):
        super().__init__(sequence)
        self.map_x = map_x
        self.map_y = map_y if map_y else identity

    def __getitem__(self, item):
        xs, ys = self.sequence[item]
        return (self.map_x(xs), self.map_y(ys))

def identity(x):
    return x

max_stars_repo_name: vojtechcima/kitt

max_issues_repo_name: vojtechcima/kitt

max_forks_repo_name: vojtechcima/kitt


text:
import numpy as np
import matplotlib.pylab as plt

def sigmoid(x):
    return 1 / (1 + np.exp(-x))

if __name__ == "__main__":
    x = np.arange(-5.0, 5.0, 0.1)
    y = sigmoid(x)
    print(y)
    plt.plot(x, y)
    plt.ylim(-0.1, 1.1)
    plt.show()

max_stars_repo_path: Deep Learning from Scratch/03/3_2_4.py

max_stars_repo_name: skysign/public

max_issues_repo_path: Deep Learning from Scratch/03/3_2_4.py

max_issues_repo_name: skysign/public

max_forks_repo_path: Deep Learning from Scratch/03/3_2_4.py

max_forks_repo_name: skysign/public


text:
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-3, 3, 50)
y1 = 2*x + 1
y2 = x ** 2

# Create a figure
plt.figure()

plt.xlim( (-1, 2) )
plt.ylim( (-2, 3) )

# Set new sticks
new_sticks = np.linspace(-1, 2, 5)
plt.xticks( new_sticks )

# Set tick labels
plt.yticks( [-2, -1.8, -1, 1.22, 3],
            [ r'$too\ bad$', r'$bad$', r'$normal$', r'$good$', r'$very good$'] )

# Set line style
line_1 = plt.plot(x, y1, label='linear line')
line_2 = plt.plot(x, y2, color='red', linewidth=1.0, linestyle='--', label='square line')

# Set legend render mode
plt.legend(loc='upper right')

# render figure
plt.show()

max_stars_repo_name: brianchiang-tw/Python

max_issues_repo_name: brianchiang-tw/Python

max_forks_repo_name: brianchiang-tw/Python


text:
import AsianOptions
import StandardEuropeanOptions
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')
from collections import defaultdict
import numpy as np

def different_volatilities(volatilities: list, interest_rate=0.05,
                           time_to_maturity=1, strike_price=12, initial_price=10):
    if not isinstance(volatilities, list):
        raise ValueError(f'"volatilities" is not of type list!')

    prices = defaultdict(list)
    for vol in volatilities:
        # Call options for different volatilities
        asian_call = AsianOptions.AsianCallOption(initial_price=initial_price,
                                                  strike_price=strike_price,
                                                  interest_rate=interest_rate,
                                                  volatility=vol,
                                                  time_to_maturity=time_to_maturity,
                                                  time_partition_size=100,
                                                  spatial_partition_size=500)

        standard_call = StandardEuropeanOptions.StandardCallOption(initial_price=initial_price,
                                                                   strike_price=strike_price,
                                                                   interest_rate=interest_rate,
                                                                   volatility=vol,
                                                                   time_to_maturity=time_to_maturity)
        asian_call_price = asian_call.solve()
        standard_call_price = standard_call.compute()

        # Put options for different volatilities
        asian_put = AsianOptions.AsianPutOption(initial_price=initial_price,
                                                  strike_price=strike_price,
                                                  interest_rate=interest_rate,
                                                  volatility=vol,
                                                  time_to_maturity=time_to_maturity,
                                                  time_partition_size=100,
                                                  spatial_partition_size=500)
        standard_put = StandardEuropeanOptions.StandardPutOption(initial_price=initial_price,
                                                                   strike_price=strike_price,
                                                                   interest_rate=interest_rate,
                                                                   volatility=vol,
                                                                   time_to_maturity=time_to_maturity)

        asian_put_price = asian_put.solve()
        standard_put_price = standard_put.compute()

        # Store prices
        prices["Asian call"].append(asian_call_price)
        prices["Asian put"].append(asian_put_price)
        prices["Standard call"].append(standard_call_price)
        prices["Standard put"].append(standard_put_price)

    return prices

def different_initial_prices(initial_prices: list, strike_price, interest_rate=0.05,
                             time_to_maturity=1,  volatility=0.5):
    if not isinstance(initial_prices, list):
        raise ValueError(f'"initial_prices" is not of type list!')

    prices = defaultdict(list)
    for pr_idx, init_pr in enumerate(initial_prices):
        # Call options for different volatilities
        asian_call = AsianOptions.AsianCallOption(initial_price=init_pr,
                                                  strike_price=strike_price,
                                                  interest_rate=interest_rate,
                                                  volatility=volatility,
                                                  time_to_maturity=time_to_maturity,
                                                  time_partition_size=100,
                                                  spatial_partition_size=500)

        standard_call = StandardEuropeanOptions.StandardCallOption(initial_price=init_pr,
                                                                  strike_price=strike_price,
                                                                  interest_rate=interest_rate,
                                                                  volatility=volatility,
                                                                  time_to_maturity=time_to_maturity)
        asian_call_price = asian_call.solve()
        standard_call_price = standard_call.compute()

        # Put options for different volatilities
        asian_put = AsianOptions.AsianPutOption(initial_price=init_pr,
                                                  strike_price=strike_price,
                                                  interest_rate=interest_rate,
                                                  volatility=volatility,
                                                  time_to_maturity=time_to_maturity,
                                                  time_partition_size=100,
                                                  spatial_partition_size=500)
        standard_put = StandardEuropeanOptions.StandardPutOption(initial_price=init_pr,
                                                                  strike_price=strike_price,
                                                                  interest_rate=interest_rate,
                                                                  volatility=volatility,
                                                                  time_to_maturity=time_to_maturity)

        asian_put_price = asian_put.solve()
        standard_put_price = standard_put.compute()

        # Store prices
        prices["Asian call"].append(asian_call_price)
        prices["Asian put"].append(asian_put_price)
        prices["Standard call"].append(standard_call_price)
        prices["Standard put"].append(standard_put_price)

    return prices

def put_call_parity(initial_price=20, strike_price=12, interest_rate=0.05,
                    volatility=0.5, time_to_maturity=1, confidence=0.05):

    # Numerical prices
    asian_call = AsianOptions.AsianCallOption(initial_price=initial_price,
                                              strike_price=strike_price,
                                              interest_rate=interest_rate,
                                              volatility=volatility,
                                              time_to_maturity=time_to_maturity,
                                              time_partition_size=100,
                                              spatial_partition_size=500)
    asian_put = AsianOptions.AsianPutOption(initial_price=initial_price,
                                              strike_price=strike_price,
                                              interest_rate=interest_rate,
                                              volatility=volatility,
                                              time_to_maturity=time_to_maturity,
                                              time_partition_size=100,
                                              spatial_partition_size=500)
    asian_call_price = asian_call.solve()
    asian_put_price = asian_put.solve()

    numerical_pcp = asian_call_price - asian_put_price

    # Analytical formula
    analytical_pcp = initial_price / (interest_rate * time_to_maturity) * \
                     (1 - np.exp(-interest_rate * time_to_maturity)) - strike_price * np.exp(-interest_rate*time_to_maturity)

    ratio = 1 - numerical_pcp / analytical_pcp

    if ratio <= confidence:
        print(f'Put-call parity ratio is within confidence! ({ratio:.4f} < {confidence})')
    else:
        print(f'Put-call parity not fulfilled, ratio is outside of confidence! ({ratio:.4f} > {confidence})')

def plot_prices(prices: defaultdict, x_values: list, varying_factor: str, strike_price=None):
    asian_call_prices = prices["Asian call"]
    asian_put_prices = prices["Asian put"]
    standard_call_prices = prices["Standard call"]
    standard_put_prices = prices["Standard put"]

    plt.figure(figsize=(14, 10))
    plt.plot(x_values, asian_call_prices, color='#b00b69', label='Asian Call')
    plt.plot(x_values, asian_put_prices, color='#b00b69', linestyle='--', label='Asian Put')
    plt.plot(x_values, standard_call_prices, color='#5c04a5', label='Standard Call')
    plt.plot(x_values, standard_put_prices, color='#5c04a5', linestyle='--', label='Standard Put')
    if varying_factor.lower() in ['volatility', 'vol', 'sigma']:
        plt.xlabel(r'$\sigma$', fontsize=14)
    elif varying_factor.lower() in ['s0', 'initial_stock_price', 'initial_price', 'initial price', 'initial stock price']:
        plt.xlabel(r'$S_0$', fontsize=14)
        if strike_price:
            plt.vlines(strike_price, 0, 0.75*max(standard_call_prices), linestyles='dashed')
            plt.text(x=strike_price, y=0.8*max(standard_call_prices), s='At the money (S = K)', ha='center', va='center')
            plt.text(x=0.6*strike_price, y=0.8 * max(standard_call_prices), s='Out of the money (OTM) for call', ha='center', va='center')
            plt.text(x=0.6 * strike_price, y=0.7 * max(standard_call_prices), s='In the money (ITM) for put', ha='center', va='center')
            plt.text(x=1.4 * strike_price, y=0.8 * max(standard_call_prices), s='In of the money (ITM) for call', ha='center', va='center')
            plt.text(x=1.4 * strike_price, y=0.7 * max(standard_call_prices), s='Out of the money (OTM) for put', ha='center', va='center')
    plt.title(f'Comparison between Asian options and Standard European options for different {varying_factor}')
    plt.legend()
    plt.ylabel(r'Price function $\Pi(0)$')
    plt.savefig(f'./Results/comparison_{varying_factor.split(" ")[0]}.png')
    plt.show()

if __name__ == '__main__':
    vol_prices = different_volatilities([0+0.2*i for i in range(50)], interest_rate=0.05,
                           time_to_maturity=1, strike_price=12, initial_price=10)
    s0_prices = different_initial_prices([10+i*5 for i in range(18)], strike_price=50,
                             interest_rate=0.05, time_to_maturity=1,  volatility=0.5)
    plot_prices(vol_prices, [0+0.2*i for i in range(50)], 'volatility')
    plot_prices(s0_prices, [10+i*5 for i in range(18)], 'initial price', strike_price=50)
    put_call_parity()


text:
from collections import deque

import cv2
import multiprocessing
import numpy as np
import os

from multiprocessing import Process

from cvutils import CVVideoCapture, CVFrame, CVAcceptanceTest
from cvutils.cvmisc import generate_multiprocessing_final_pass_ranges
from cvutils.cvprogresstracker import CVProgressTracker
from utils import stats, RepeatingTimer, first_occurrence_index, \
    last_occurrence_index

def _test_optical_flow_capture_worker(worker_frame_start,
                                      worker_frame_end,
                                      frame_start, frame_count, batch_size,
                                      distance_limit,
                                      feature_params,
                                      lucas_kanade_params,
                                      frame_acceptance_ctype,
                                      file_handle,
                                      progress_value,
                                      lock_video_capture,
                                      gray_scale_conversion_code,
                                      skip_window_both_end=0
                                      ):
    if worker_frame_start > worker_frame_end:
        return
    video_capture = CVVideoCapture(file_handle)
    video_capture.set_position_frame(worker_frame_start)
    buffer = deque()
    current_frame = worker_frame_start
    need_more_frame = True
    worker_last_candidate = None
    while True:
        if need_more_frame:
            # read in until the end
            if current_frame < worker_frame_end:
                amount_load = int(
                    min(batch_size, worker_frame_end - current_frame))
                with lock_video_capture:
                    print('[OpticalFlow] Process %d - Reading %d frames from '
                          '%d' % (os.getpid(), amount_load, current_frame))
                    buffer += [video_capture.read() for i in
                               range(0, amount_load)]
                current_frame += amount_load
                need_more_frame = False
            else:
                # no more frame
                break

        # purge buffer until we find a possible list
        while True:
            if len(buffer) == 0:
                need_more_frame = True
                break
            if frame_acceptance_ctype[
                int(buffer[0].position_frame - frame_start)]:
                worker_last_candidate = buffer[0]
                break
            else:
                buffer.popleft()

        if need_more_frame:
            continue

        # greedy
        iter_buffer = iter(buffer)
        frame_initial = next(iter_buffer)  # type: CVFrame
        frame_initial_gray = frame_initial.get_cv_mat_grayscale(
            gray_scale_conversion_code)
        previous_frame_gray = frame_initial_gray.copy()
        previous_frame_features = cv2.goodFeaturesToTrack(previous_frame_gray,
                                                          mask=None,
                                                          **feature_params)

        integral_mean_distance = 0
        frame_candidate = None
        frame_candidate_distance = None
        frame_last_candidate = frame_initial
        frame_last_candidate_distance = 0
        for frame_i in iter_buffer:  # type: CVFrame
            frame_i_gray = frame_i.get_cv_mat_grayscale(
                gray_scale_conversion_code)
            frame_i_features, feature_status, err = \
                cv2.calcOpticalFlowPyrLK(previous_frame_gray, frame_i_gray,
                                         previous_frame_features,
                                         None,
                                         **lucas_kanade_params)

            num_features_left = feature_status.sum()

            if num_features_left == 0:
                # we are lost
                # set the last accept frame to get maximum distance
                frame_candidate = frame_last_candidate
                break

            good_previous_features = previous_frame_features[
                feature_status == 1]
            good_i_features = frame_i_features[feature_status == 1]

            immediate_displacement = (
                                     good_i_features - good_previous_features) ** 2
            immediate_distance = np.sqrt(np.sum(immediate_displacement, axis=1))
            mean_immediate_distance = stats.trimboth(immediate_distance,
                                                     0.1).mean()
            integral_mean_distance += mean_immediate_distance

            # print('optical flow process [%d] matching %d[%d] -> %d[%d], int distance '
            #      '= %d' %
            #      (os.getpid(),
            #       int(frame_initial.position_frame),
            #       frame_acceptance_ctype[int(frame_initial.position_frame - frame_start)],
            #       int(frame_i.position_frame),
            #       frame_acceptance_ctype[int(frame_i.position_frame - frame_start)],
            #       integral_mean_distance))

            if frame_acceptance_ctype[int(frame_i.position_frame - frame_start)]:
                # we need to maintain the last accepted one as candidate
                # and the corresponding skip count till that candidate
                # skipped_frame_count += int(frame_i.position_frame - frame_last_candidate.position_frame)
                frame_last_candidate = frame_i
                frame_last_candidate_distance = integral_mean_distance

            previous_frame_gray = frame_i_gray.copy()
            previous_frame_features = good_i_features.reshape(-1, 1, 2)

            if integral_mean_distance < distance_limit:
                continue

            if not frame_acceptance_ctype[int(frame_i.position_frame - frame_start)]:
                # only select accepted ones as candidate
                frame_candidate = frame_last_candidate
                frame_candidate_distance = frame_last_candidate_distance
            else:
                frame_candidate = frame_i
                frame_candidate_distance = integral_mean_distance
            break

        # found the frame?
        if frame_candidate is None:
            need_more_frame = True
            continue

        worker_last_candidate = frame_candidate
        skipped_count = int(frame_candidate.position_frame - frame_initial.position_frame)

        # matched
        # logging.info('proc [%d] matched %d -> %d' %
        #              (os.getpid(), int(template.position_frame), int(image.position_frame)))
        print('optical flow process [%d] matched %d -> %d, skipped %d, int distance = %d' %
            (os.getpid(), int(frame_initial.position_frame),
             int(frame_candidate.position_frame),
             skipped_count,
             frame_candidate_distance))

        # we don't want to reject the initial frame
        buffer.popleft()
        # remove unmatched
        for i in range(0, skipped_count - 1):
            f = buffer.popleft()  # type: CVFrame
            # special handling for greedy algorithm
            if (f.position_frame < (worker_frame_start + skip_window_both_end)) or \
                    (f.position_frame > (worker_frame_end - skip_window_both_end)):
                # skip first and last frame_rate frames on each worker
                continue
            frame_acceptance_ctype[int(f.position_frame) - frame_start] = False

        with progress_value.get_lock():
            progress_value.value += skipped_count / (worker_frame_end - worker_frame_start)

    # purge the last bit of the acceptance array
    print('last candidate %d' % worker_last_candidate.position_frame)
    for i in range(int(worker_last_candidate.position_frame + 1),
                   worker_frame_end - skip_window_both_end):
        # since we are not able to find a matching frame with last candidate
        # among this range, these frames are not possible for a valid candidate
        # hence, no need to check
        frame_acceptance_ctype[i - frame_start] = False

    with lock_video_capture:
        video_capture.release()

class CVOpticalFlow(CVAcceptanceTest):
    def __init__(self, feature_params, lucas_kanade_params):
        super(CVOpticalFlow, self).__init__('opticalflow')
        self.feature_params = feature_params
        self.lucas_kanade_params = lucas_kanade_params
        pass

    def test_optical_flow_video_capture(self,
                                        cv_video_capture: CVVideoCapture,
                                        distance_limit,
                                        frame_acceptance_np: np.ndarray,
                                        frame_start=0, frame_end=None,
                                        batch_size=200,
                                        gray_scale_conversion_code=cv2.COLOR_BGR2GRAY,
                                        progress_tracker: CVProgressTracker = None):
        frame_count = int(cv_video_capture.get_frame_count())
        if frame_end:
            cv_video_capture.set_position_frame(frame_start)
            frame_count = min(frame_end - frame_start, frame_count)
            frame_count = max(frame_count, 0)

        if progress_tracker:
            progress_tracker.running = True

        frame_acceptance_ctype = \
            multiprocessing.Array('b', frame_acceptance_np.tolist())

        progress_value = multiprocessing.Value('d')
        progress_value.value = 0
        lock_video_capture = multiprocessing.RLock()

        skip_window_both_end = int(cv_video_capture.get_frame_rate())
        # worker_count = 1
        worker_count = multiprocessing.cpu_count()
        task_per_worker = int(frame_count / worker_count)
        args_list = [(task_per_worker * i, task_per_worker * (i + 1),
                      frame_start, frame_count, batch_size,
                      distance_limit,
                      self.feature_params,
                      self.lucas_kanade_params,
                      frame_acceptance_ctype,
                      cv_video_capture.file_handle,
                      progress_value,
                      lock_video_capture,
                      gray_scale_conversion_code,
                      skip_window_both_end
                      )
                     for i in range(0, worker_count - 1)]
        args_list.append((task_per_worker * (worker_count - 1), frame_count,
                          frame_start, frame_count, batch_size,
                          distance_limit,
                          self.feature_params,
                          self.lucas_kanade_params,
                          frame_acceptance_ctype,
                          cv_video_capture.file_handle,
                          progress_value,
                          lock_video_capture,
                          gray_scale_conversion_code,
                          skip_window_both_end
                          ))

        processes = [Process(target=_test_optical_flow_capture_worker,
                             args=arg_tuple) for arg_tuple in args_list]

        def update_progress_tracker():
            progress_tracker.progress = progress_value.value / worker_count * 0.7

        progress_timer = RepeatingTimer(0.1, update_progress_tracker)

        if progress_tracker:
            progress_timer.start()

        if progress_tracker:
            progress_tracker.running = True
        for p in processes:
            p.start()
        for p in processes:
            p.join()

        print('[OpticalFlow] final pass')

        final_pass_ranges = generate_multiprocessing_final_pass_ranges \
            (frame_acceptance_ctype, frame_count, task_per_worker, worker_count, skip_window_both_end)

        final_pass_arg_list = [(range_i[0], range_i[1],
                                frame_start, frame_count, batch_size,
                                distance_limit,
                                self.feature_params,
                                self.lucas_kanade_params,
                                frame_acceptance_ctype,
                                cv_video_capture.file_handle,
                                progress_value,
                                lock_video_capture,
                                gray_scale_conversion_code)
                               for range_i in final_pass_ranges]

        final_pass_processes = [
            Process(target=_test_optical_flow_capture_worker,
                    args=arg_tuple) for arg_tuple in final_pass_arg_list]

        def update_progress_tracker_final_pass():
            progress_tracker.progress = 0.7 + progress_value.value / worker_count * 0.3

        progress_value.value = 0
        if progress_tracker:
            progress_timer.function = update_progress_tracker_final_pass

        for p in final_pass_processes:
            p.start()
        # for p in final_pass_processes:
            p.join()

        if progress_tracker:
            progress_timer.cancel()
            progress_tracker.complete()

        return np.array(frame_acceptance_ctype, dtype=np.bool_).copy()
        pass

max_stars_repo_name: njzhangyifei/keyframe

max_issues_repo_name: njzhangyifei/keyframe

max_forks_repo_name: njzhangyifei/keyframe