Пример #1
0
def banner():
    while True:
        print "1. Press 1 for running the tokenizer usually"
        print "2. Press 2 for creating the inverted index"
        print "3. Press 3 for creating the vectors for the documents"
        print "4. Press any other number to search"
        choice =  int(raw_input("$ "))
        if not os.path.exists(TEXT):
            print "No Data at All. No Valid Corpus. Please add something to\n" + str(TEXT)
        if not os.path.exists(DATA_PATH):
            print "No Data Existed, Path Created"
            os.mkdir(DATA)
        if not os.path.exists(TOKENS) or choice == 1:
            print "Creating tokens as they don't exist/You Chose To"
            os.mkdir(TOKENS)
            tokenizer()
        if not os.path.exists(INDICES) or choice == 2:
            print "Creating indices as they don't exist"
            os.mkdir(INDICES)
            counter()
        if not os.path.exists(SCORES) or choice == 3:
            print "Creating Vectors as they don't exist"
            os.mkdir(SCORES)
            score()
            mod()
        if choice > 3 or choice == 0:
            print "Search begins"
            break
Пример #2
0
    def test_mod_type(self):

        result = mod.mod(30, 4)
        self.assertIsInstance(result, int)

        result = mod.mod(10, 6)
        self.assertIsInstance(result, int)

        result = mod.mod(12, 6.5)
        self.assertFalse(type(result) is int)

        result = mod.mod(100, 2.5)
        self.assertFalse(type(result) is int)

        result = mod.mod(10, 1.5)
        self.assertFalse(type(result) is int)
    def addMod(self, fileList, modPath):
        m = mod.mod()
        m.open(os.path.join(modPath, mod.mod.MODCFG))

        pathLength = len(modPath)

        for f in fileList:
            alias = f[pathLength:]
            self.cur.execute("INSERT INTO files VALUES (?, ?, ?, ?)", (f, alias, m.name, m.version))
        
        self.cur.execute("INSERT INTO mods VALUES (?, ?, ?, ?, ?)", (modPath, m.name, m.version, m.author, m.description))
        self.con.commit()
Пример #4
0
class modHandler():

    modlist = []
    current_mod = mod()

    def __init__(self):
        # imports the available mods and sets the current mod to default
        modlist = self.importModList()

        # this will probably change
        current_mod = modlist[0]

    def importModList(self):
        #not done yet
        pass
Пример #5
0
    def test_mult_result(self):

        result = mod.mod(10, 4)
        self.assertEqual(result, 2)

        result = mod.mod(20, 8)
        self.assertEqual(result, 4)

        result = mod.mod(30, 11)
        self.assertEqual(result, 8)

        result = mod.mod(10, 3)
        self.assertNotEqual(result, 5)

        result = mod.mod(14, 3)
        self.assertNotEqual(result, 35)

        result = mod.mod(45, 4)
        self.assertNotEqual(result, 2)

        result = mod.mod(120, 25)
        self.assertNotEqual(result, 6)
Пример #6
0
def decrypt(x,gy,mgxy,g):
    gxyinvrs = mod.mod(gy,(p-1-x),p)
    return (mgxy*gxyinvrs)%p         
Пример #7
0
def genkey(x,p):    
    return mod.mod(long(g),x,p)
Пример #8
0
import multiplication
import addition
import division
import mod
import subtraction

x = 8
y = 5
result_of_subtraction = subtraction.sub(x, y)
result_of_addition = addition.add(x, y)
result_of_multiplication = multiplication.multiply(x, y)
result_of_division = division.divide(x, y)
result_of_mod = mod.mod(x, y)

print("X=8 and Y=5")
print("Result of subtraction: " + str(result_of_subtraction))
print("Result of addition: " + str(result_of_addition))
print("Result of multiplication: " + str(result_of_multiplication))
print("Result of division: " + str(result_of_division))
print("Result of mod: " + str(result_of_mod))
Пример #9
0
def encrypt(gy,p,gx,m,y):
    return (m*mod.mod(gx,y,p))%p    
Пример #10
0
def calculator():
    print('\tWELOCME TO OUR SCIENTIFIC CALCULATOR......')
    print('\t==========================================')
    print('''
1. Addition                   2. Subtraction                        3. Multiplication
4. Division                   5. Square                             6. Cube
7. Square root                8. Cube root                          9. log
10. Antilog                   11. Nth Root                          12. Nth Power
13. Factorial                 14. Matrix(2x2)                       15. Matrix(3x3)
16. ln                        17. Reciprocal                        18. Percentage
19. Exponential               20. Quadratic Equation                21. Sin()
22. Cos()                     23. Tan()                             24. Sinh
25. Cosh                      26. Tanh
27. Length Conversion       28.Temperature Conversion         29. Angle Conversion
30. Permutation                 31. Combination ''')

    #calculator()
    while True:
        choice = int(input('Please choose from the following given options!'))
        if choice == 1:
            import simple
            simple.add()
        elif choice == 2:
            import simple
            simple.subtract()
        elif choice == 3:
            import simple
            simple.multiply()
        elif choice == 4:
            import simple
            simple.divide()
        elif choice == 5:
            import Square
            Square.square()
        elif choice == 6:
            import Cube
            Cube.cube()
        elif choice == 7:
            import square_root
            square_root.square_root()
        elif choice == 8:
            import cube_root
            cube_root.cube_root()
        elif choice == 9:
            import log
            log.log()
        elif choice == 10:
            antilog.antilog()
        elif choice == 11:
            import nth_root
            nth_root.nth_root()
        elif choice == 12:
            import nth_power
            nth_power.nth_power()
        elif choice == 13:
            import factorial
            factorial.factorial()
        elif choice == 14:
            import matrix
            matrix.matrix()
        elif choice == 15:
            matrix_3()
        elif choice == 16:
            ln.ln()
        elif choice == 17:
            import reciprocal
            reciprocal.reciprocal()
        elif choice == 18:
            import Percentage
            Percentage.percentage()
        elif choice == 19:
            import exponential
            exponential.exponential()
        elif choice == 20:
            import quadratic_eq
            quadraric_eq.Quadratic()
        elif choice == 21:
            import sine
            sine.sin()
        elif choice == 22:
            import cosine
            cosine.cos()
        elif choice == 23:
            import tangent
            tangent.tan()
        elif choice == 24:
            import sinh
            sinh.sinh()
        elif choice == 25:
            import cosh
            cosh.cosh()
        elif choice == 26:
            import tanh
            tanh.tanh()
        elif choice == 27:
            import length_converter
            length_converter.length_converter()
        elif choice == 28:
            import Temp_converter
            Temp_converter.temperature_converter()
        elif choice == 29:
            import angle_converter
            angle_converter.rad()
            angle_converter.deg()
        elif choice == 30:
            import Combination
            Combination.npr(x, y)
        elif choice == 31:
            import Combination
            Combination.ncr(x, y)
        elif choice == 32:
            import mod
            mod.mod()
Пример #11
0
    return num1, num2


if command == 1:
    num1, num2 = takingInput()
    result = addition.add(num1, num2)
    print("Sum: ", result)

elif command == 2:
    num1, num2 = takingInput()
    result = sub.subtraction(num1, num2)
    print("Subtraction: ", result)

elif command == 3:
    num1, num2 = takingInput()
    result = divide.divide(num1, num2)
    print("Division: ", result)

elif command == 4:
    num1, num2 = takingInput()
    result = multiply.multiply(num1, num2)
    print("Multiplication: ", result)

elif command == 5:
    num1, num2 = takingInput()
    result = mod.mod(num1, num2)
    print("Remainder: ", result)

else:
    print("Invalid Command")
Пример #12
0
def ana_bfn(config,dict_obs=None, *args, **kwargs):
    """
    NAME
        ana_bfn

    DESCRIPTION
        Perform a BFN experiment on altimetric data and save the results on output directory
    
    """
    
    
    import bfn_functions as bfn

    # Flag initialization
    bfn_first_window = True
    bfn_last_window = False
    if dict_obs is None:
        call_obs_func = True
        import obs
    else:
        call_obs_func = False
    # BFN middle date initialization
    middle_bfn_date = config.init_date
    # In the case of Nudging (i.e. bfn_max_iteration=1), set the bfn window length as the entire period of the experience
    if config.bfn_max_iteration==1:
        print('bfn_max_iteration has been set to 1 --> '
              + 'Only one forth loop will be done on the entiere period of the experience')
        new_bfn_window_size = config.final_date - config.init_date
    else:
        new_bfn_window_size = config.bfn_window_size

    # Use temp_DA_path to save the projections
    if config.save_obs_proj:
        if config.path_save_proj is None:
            pathsaveproj = config.tmp_DA_path
        else:
            pathsaveproj = config.path_save_proj
    else:
        pathsaveproj = None

    # Main time loop
    while (middle_bfn_date <= config.final_date) and not bfn_last_window :
        print('\n*** BFN window ***')
        #############
        # 1. SET-UP #
        #############
        # BFN period
        init_bfn_date = max(config.init_date, middle_bfn_date - new_bfn_window_size/2)
        init_bfn_date += timedelta(seconds=(init_bfn_date - config.init_date).total_seconds()\
                         / config.bfn_propation_timestep.total_seconds()%1)
        middle_bfn_date = max(middle_bfn_date, config.init_date + new_bfn_window_size/2)
        if ((middle_bfn_date + new_bfn_window_size/2) >= config.final_date):
            bfn_last_window = True
            final_bfn_date = config.final_date
        else:
            final_bfn_date = init_bfn_date + new_bfn_window_size
        print('\nfrom ', init_bfn_date, ' to ', final_bfn_date)
        # propagation timestep
        one_time_step = config.bfn_propation_timestep
        # Initialize nc files
        if bfn_first_window:
            present_date_forward0 = init_bfn_date
            present_file_forward0 = config.tmp_DA_path + "/state_forward0.nc"
            present_file_backward0 = config.tmp_DA_path + "/state_backward0.nc"
            present_file_forward = config.tmp_DA_path + "/state_forward.nc"
            present_file_backward = config.tmp_DA_path + "/state_backward.nc"
        analyzed_vectors_names = config.tmp_DA_path + "/state_analyzed.nc"

        ########################
        # 2.READING STATE GRID #
        ########################
        print('\n* Reading state grid *')
         # Read box boundaries
        with xr.open_dataset(config.tmp_DA_path+config.name_init_file) as grd:
            lon = grd[config.name_mod_lon].values
            lat = grd[config.name_mod_lat].values
            if len(lon.shape)==1:
                ny,nx = lat.size,lon.size
            else:
                ny,nx = lon.shape

        ########################
        # 3. Create BFN object #
        ########################
        print('\n* Initialize BFN *')
        if config.name_model == 'QG1L':
            bfn_obj = bfn.bfn_qg1l(
                 init_bfn_date,
                 final_bfn_date,
                 config.assimilation_time_step,
                 one_time_step,
                 lon,
                 lat,
                 config.name_mod_var,
                 config.name_grd,
                 config.dist_scale,
                 pathsaveproj,
                 'projections_' + config.name_domain + '_' + '_'.join(config.satellite),
                 config.c,
                 config.flag_plot,
                 config.scalenudg)

        elif config.name_model == 'QGML':
            bfn_obj = bfn.bfn_qgml(
                 init_bfn_date,
                 final_bfn_date,
                 config.assimilation_time_step,
                 one_time_step,
                 lon,
                 lat,
                 config.name_mod_var,
                 config.name_grd,
                 config.dist_scale,
                 config.Rom,
                 config.Fr,
                 config.dh,
                 config.N,
                 config.L0,
                 pathsaveproj,
                 'projections_' + config.name_domain + '_' + '_'.join(config.satellite),
                 config.flag_plot,
                 config.scalenudg)

        else:
            print('Error: No BFN class implemented for', config.name_model, 'model')
            sys.exit()

        ######################################
        # 4. BOUNDARY AND INITIAL CONDITIONS #
        ######################################
        print("\n* Boundary and initial conditions *")
        # Boundary condition
        if config.flag_use_boundary_conditions:
            timestamps = np.arange(calendar.timegm(init_bfn_date.timetuple()),
                                   calendar.timegm(final_bfn_date.timetuple()),
                                   one_time_step.total_seconds())

            bc_field, bc_weight = grid.boundary_conditions(config.file_boundary_conditions,
                                                            config.lenght_bc,
                                                            config.name_var_bc,
                                                            timestamps,
                                                            lon,
                                                            lat,
                                                            config.flag_plot,
                                                            bfn_obj.sponge)

        else:
            bc_field = bc_weight = bc_field_t = None
        # Initial condition
        if bfn_first_window:
            # Use previous state as initialization
            init_file = config.path_save + config.name_exp_save\
                        + '_y' + str(init_bfn_date.year)\
                        + 'm' + str(init_bfn_date.month).zfill(2)\
                        + 'd' + str(init_bfn_date.day).zfill(2)\
                        + 'h' + str(init_bfn_date.hour).zfill(2)\
                        + str(init_bfn_date.minute).zfill(2) + '.nc'
            if not os.path.isfile(init_file) :
                restart = False
                print(init_file, " : Init file is not present for nudging."
                      + "We will use the current state vectors...")
                cmd = "cp "+ config.tmp_DA_path+config.name_init_file + " " +\
                    present_file_forward0
                os.system(cmd)
            else:
                restart = True
                print(init_file, " is used as initialization")
                cmd = "cp " + init_file + " " + present_file_forward0
                os.system(cmd)
        elif config.bfn_window_overlap:
            # Use last state from the last forward loop as initialization
            name_previous = config.name_exp_save\
                            + '_y' + str(init_bfn_date.year)\
                            + 'm' + str(init_bfn_date.month).zfill(2)\
                            + 'd' + str(init_bfn_date.day).zfill(2)\
                            + 'h' + str(init_bfn_date.hour).zfill(2)\
                            + str(init_bfn_date.minute).zfill(2) + '.nc'
            filename_forward = config.tmp_DA_path + '/BFN_forth_' + name_previous
            cmd = 'cp ' + filename_forward + ' ' + present_file_forward0
            os.system(cmd)

        ###################
        # 5. Observations #
        ###################
        # Selection
        print('\n* Select observations *')
        
        if call_obs_func:
            print('Calling obs_all_observationcheck function...')
            dict_obs_it = obs.obs(config)
            bfn_obj.select_obs(dict_obs_it)
            dict_obs_it.clear()
            del dict_obs_it
        else:
            bfn_obj.select_obs(dict_obs)

        # Projection
        print('\n* Project observations *')
        bfn_obj.do_projections()

        ###############
        # 6. BFN LOOP #
        ###############
        err_bfn0 = 0
        err_bfn1 = 0
        bfn_iter = 0
        Nold_t = None

        while bfn_iter==0 or\
             (bfn_iter < config.bfn_max_iteration
              and abs(err_bfn0-err_bfn1)/err_bfn1 > config.bfn_criterion):

            if bfn_iter>0:
                present_date_forward0 = init_bfn_date
                # Save last backward analysis as init forward file
                cmd0 = "cp " + present_file_backward0 + " " + present_file_forward0
                os.system(cmd0)

            err_bfn0 = err_bfn1
            bfn_iter += 1
            if bfn_iter == config.bfn_max_iteration:
                print('\nMaximum number of iterations achieved ('
                      + str(config.bfn_max_iteration)
                      + ') --> last Forth loop !!')

            ###################
            # 6.1. FORTH LOOP #
            ###################
            print("\n* Forward loop " + str(bfn_iter) + " *")
            while present_date_forward0 < final_bfn_date :

                #print('i = ' + str(bfn_iter) + ' forward : ' +str(present_date_forward0)  )
                # Retrieve corresponding time index for the forward loop
                iforward = int((present_date_forward0 - init_bfn_date)/one_time_step)

                # Get BC field
                if bc_field is not None:
                    bc_field_t = bc_field[iforward]

                # Propagate the state by nudging the model vorticity towards the 2D observations
                present_file_forward = mod.mod(config,
                                      state_vector0_name=present_file_forward0,
                                      present_date0=present_date_forward0,
                                      tint=+one_time_step.total_seconds(),
                                      Nudging_term=Nold_t,
                                      Hbc=bc_field_t,
                                      Wbc=bc_weight,
                                      state_vector_name=present_file_forward)


                # Time increment
                present_date_forward = present_date_forward0 + one_time_step

                # Get analysis
                analysis = tools.vectorize(present_file_forward,
                                         config.name_mod_var,
                                         )

                # Nudging term (next time step)
                N_t = bfn_obj.compute_nudging_term(
                        present_date_forward, analysis
                        )

                # Update model parameter
                if config.name_model == 'QG1L':
                    analysis_updated = bfn_obj.update_parameter(
                            analysis, Nold_t, N_t, bc_weight, way=1
                            )

                    if np.any(analysis_updated!=analysis):
                        tools.vector_save(
                                analysis_updated, lon, lat,
                                config.n_mod_var, config.name_mod_var,
                                config.name_mod_lon, config.name_mod_lat,
                                present_file_forward)

                # Save output every *saveoutput_time_step*
                if (((present_date_forward - config.init_date)/config.saveoutput_time_step)%1 == 0)\
                   & (present_date_forward>config.init_date) :
                        name_save = config.name_exp_save + '_' + str(iforward).zfill(5) + '.nc'
                        filename_forward = config.tmp_DA_path + '/BFN_forth_' + name_save
                        save_presentoutputs(present_file_forward,
                                            present_date_forward,
                                            filename=filename_forward)
                        if config.save_bfn_trajectory:
                            filename_traj = config.path_save + 'BFN_' + str(middle_bfn_date)[:10]\
                                       + '_forth_' + str(bfn_iter) + '/' + name_save

                            if not os.path.exists(os.path.dirname(filename_traj)):
                                os.makedirs(os.path.dirname(filename_traj))
                            save_presentoutputs(present_file_forward,
                                                present_date_forward,
                                                filename=filename_traj)

                # Save updated state vector as initial state vector
                cmd0 = "cp " + present_file_forward + " " + present_file_forward0
                os.system(cmd0)

                # Time update
                present_date_forward0 = present_date_forward
                Nold_t = N_t

            # Plot for debugging
            if config.flag_plot > 0:
                analysis = analysis.reshape((config.n_mod_var, ny, nx)) # SSH, PV
                fig, (ax1, ax2) = plt.subplots(1, 2, figsize=((10, 5)))
                p1 = ax1.pcolormesh(lon, lat, analysis[1],shading='auto')
                p2 = ax2.pcolormesh(lon, lat, analysis[0],shading='auto')
                plt.colorbar(p1, ax=ax1)
                plt.colorbar(p2, ax=ax2)
                ax1.set_title('Potential vorticity')
                ax2.set_title('SSH')
                plt.show()

            ##################
            # 6.2. BACK LOOP #
            ##################
            if  bfn_iter < config.bfn_max_iteration:
                print("\n* Backward loop " + str(bfn_iter) + " *")
                present_date_backward0 = final_bfn_date
                # Save last forward analysis as init backward file
                cmd0 = "cp " + present_file_forward0 + " " + present_file_backward0
                os.system(cmd0)

                while present_date_backward0 > init_bfn_date :
                    #print('i = ' + str(bfn_iter) + ' backward : ' +str(present_date_backward0)  )

                    # Retrieve corresponding time index for the backward loop
                    ibackward = int((present_date_backward0 - init_bfn_date)/one_time_step)

                    # Get BC field
                    if bc_field is not None:
                        bc_field_t = bc_field[ibackward-1]

                    # Propagate the state by nudging the model vorticity towards the 2D observations
                    present_file_backward = mod.mod(config,
                            state_vector0_name=present_file_backward0,
                            present_date0=present_date_backward0,
                            tint=-one_time_step.total_seconds(),
                            Nudging_term=Nold_t,
                            Hbc=bc_field_t,
                            Wbc=bc_weight,
                            state_vector_name=present_file_backward)
                    
                    
                    # Time increment
                    present_date_backward = present_date_backward0 - one_time_step

                    # Get analysis
                    analysis = tools.vectorize(present_file_backward,
                                             config.name_mod_var)

                    # Nudging term (next time step)
                    N_t = bfn_obj.compute_nudging_term(
                            present_date_backward,
                            analysis
                            )

                    # Update model parameter
                    if config.name_model == 'QG1L':
                        analysis_updated = bfn_obj.update_parameter(
                            analysis, Nold_t, N_t, bc_weight, way=-1
                            )

                        if np.any(analysis_updated!=analysis):
                            tools.vector_save(
                                    analysis_updated, lon, lat,
                                    config.n_mod_var, config.name_mod_var,
                                    config.name_mod_lon, config.name_mod_lat,
                                    present_file_backward)

                    # Save output every *saveoutput_time_step*
                    if (((present_date_backward - config.init_date)/config.saveoutput_time_step)%1 == 0)\
                       & (present_date_backward>=config.init_date) :
                            name_save = config.name_exp_save + '_' + str(ibackward).zfill(5) + '.nc'
                            filename_backward = config.tmp_DA_path + '/BFN_back_' + name_save
                            save_presentoutputs(present_file_backward,
                                                present_date_backward,
                                                filename=filename_backward)
                            if config.save_bfn_trajectory:
                                filename_traj = config.path_save + 'BFN_' + str(middle_bfn_date)[:10]\
                                           + '_back_' + str(bfn_iter) + '/' + name_save

                                if not os.path.exists(os.path.dirname(filename_traj)):
                                    os.makedirs(os.path.dirname(filename_traj))
                                save_presentoutputs(present_file_backward,
                                                    present_date_backward,
                                                    filename=filename_traj)

                    # Save updated state vector as initial state vector
                    cmd0 = "cp " + present_file_backward + " " + present_file_backward0
                    os.system(cmd0)

                    # Time update
                    present_date_backward0 = present_date_backward
                    Nold_t = N_t

                if config.flag_plot > 0:
                    analysis = analysis.reshape((config.n_mod_var, ny, nx))  # SSH, PV
                    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=((10, 5)))
                    p1 = ax1.pcolormesh(lon, lat, analysis[1],shading='auto')
                    p2 = ax2.pcolormesh(lon, lat, analysis[0],shading='auto')
                    plt.colorbar(p1, ax=ax1)
                    plt.colorbar(p2, ax=ax2)
                    ax1.set_title('Potential vorticity')
                    ax2.set_title('SSH')
                    plt.show()

            #########################
            # 6.3. CONVERGENCE TEST #
            #########################
            if bfn_iter < config.bfn_max_iteration:
                print('\n* Convergence test *')
                err_bfn1 = bfn_obj.convergence(
                                        path_forth=config.tmp_DA_path + '/BFN_forth_',
                                        path_back=config.tmp_DA_path + '/BFN_back_'
                                        )


        print("\n* End of the BFN loop after " + str(bfn_iter) + " iterations *")

        #####################
        # 7. SAVING OUTPUTS #
        #####################
        print('\n* Saving last forth loop as outputs for the following dates : *')
        # Set the saving temporal window
        if config.bfn_max_iteration==1:
            write_date_min = init_bfn_date
            write_date_max = final_bfn_date
        elif bfn_first_window:
            write_date_min = init_bfn_date
            write_date_max = init_bfn_date + new_bfn_window_size/2 + config.bfn_window_output/2
        elif bfn_last_window:
            write_date_min = middle_bfn_date - config.bfn_window_output/2
            write_date_max = final_bfn_date
        else:
            write_date_min = middle_bfn_date - config.bfn_window_output/2
            write_date_max = middle_bfn_date + config.bfn_window_output/2
        # Write outputs in the saving temporal window

        present_date = init_bfn_date
        while present_date < final_bfn_date :
            present_date += one_time_step
            if (present_date > write_date_min) & (present_date <= write_date_max) :
                # Save output every *saveoutput_time_step*
                if (((present_date - config.init_date).total_seconds()
                   /config.saveoutput_time_step.total_seconds())%1 == 0)\
                   & (present_date>config.init_date)\
                   & (present_date<=config.final_date) :
                    print(present_date, end=' / ')                
                    # Read current converged state
                    iforward = int((present_date - init_bfn_date)/one_time_step) - 1
                    name_save = config.name_exp_save + '_' + str(iforward).zfill(5) + '.nc'
                    current_file = config.tmp_DA_path + '/BFN_forth_' + name_save
                    vars_current = tools.vectorize(current_file,
                                                 config.name_mod_var,
                                                )
                    # Smooth with previous BFN window
                    if config.bfn_window_overlap and (not bfn_first_window or restart):
                        # Read previous output at this timestamp
                        previous_file = config.path_save + config.name_exp_save\
                                        + '_y'+str(present_date.year)\
                                        + 'm'+str(present_date.month).zfill(2)\
                                        + 'd'+str(present_date.day).zfill(2)\
                                        + 'h'+str(present_date.hour).zfill(2)\
                                        + str(present_date.minute).zfill(2) + \
                                            '.nc'
                        if os.path.isfile(previous_file):
                            vars_previous = tools.vectorize(previous_file,
                                                                   config.name_mod_var
                                                                )
                            # weight coefficients
                            W1 = max((middle_bfn_date - present_date)
                                     / (config.bfn_window_output/2), 0)
                            W2 = min((present_date - write_date_min)
                                     / (config.bfn_window_output/2), 1)
                            analysis = W1*vars_previous + W2*vars_current
                        else:
                            analysis = vars_current
                    else:
                        analysis = vars_current
                    tools.vector_save(analysis, lon, lat,
                                    config.n_mod_var,
                                    config.name_mod_var,
                                    config.name_mod_lon,
                                    config.name_mod_lat,
                                    analyzed_vectors_names,
                                    date=present_date)
                    # Save output
                    if config.saveoutputs:
                        save_presentoutputs(analyzed_vectors_names,present_date,
                                            name_exp=config.name_experiment,
                                            path=config.path_save)
        print()
        ########################
        # 8. PARAMETERS UPDATE #
        ########################
        if config.bfn_window_overlap:
            window_lag = config.bfn_window_output/2
        else:
            window_lag = config.bfn_window_output

        if bfn_first_window:
            middle_bfn_date = config.init_date + new_bfn_window_size/2 + window_lag
            bfn_first_window = False
        else:
            middle_bfn_date += window_lag

    ###############
    # 9. CLEANING #
    ###############
    print("Cleaning")
    # Remove state file
    cmd = "rm " + present_file_forward + " " + present_file_forward0\
          + " " + present_file_backward + " " + present_file_backward0\
          + " " + analyzed_vectors_names
    os.system(cmd)
Пример #13
0
def test_mod_20_6():
    line = '20,6\n'
    expected = 20 % 6
    actual = mod(line)
    assert actual == expected
Пример #14
0
def test_mod_2_3():
    line = '2,3\n'
    expected = 2 % 3
    actual = mod(line)
    assert actual == expected
Пример #15
0
def keygen(g,p,y):
    return mod.mod(g,y,p)
Пример #16
0
    def test_endpoint(self):

        #assign the x, y and modulus url variables
        x_arg = '?x='
        y_arg = '&y='
        modURL = 'http://mod.40175607.qpc.hal.davecutting.uk/'  #internal private cloud endpoint

        #set the x and y values and the expected result from their mod calculation
        x_string = '100'
        y_string = '11'
        expected_result = mod.mod(100, 11)

        #combine the above variables into one url string
        http_output = modURL + x_arg + x_string + y_arg + y_string

        #use the urllib module to call the mod url and parse the result value from the json object
        url_output = urlopen(http_output)
        json_obj = url_output.read()
        json_data = json.loads(json_obj)
        result = json_data['answer']

        #assert that the produced result == expected_result
        self.assertEqual(result, expected_result)

        x_string = '10'
        y_string = '6'
        expected_result = mod.mod(10, 6)
        http_output = modURL + x_arg + x_string + y_arg + y_string

        url_output = urlopen(http_output)
        json_obj = url_output.read()
        json_data = json.loads(json_obj)
        result = json_data['answer']

        self.assertEqual(result, expected_result)

        x_string = '39'
        y_string = '26'
        expected_result = mod.mod(39, 26)
        http_output = modURL + x_arg + x_string + y_arg + y_string

        url_output = urlopen(http_output)
        json_obj = url_output.read()
        json_data = json.loads(json_obj)
        result = json_data['answer']

        self.assertEqual(result, expected_result)

        x_string = '59'
        y_string = '3'
        expected_result = mod.mod(59, 14)
        http_output = modURL + x_arg + x_string + y_arg + y_string

        url_output = urlopen(http_output)
        json_obj = url_output.read()
        json_data = json.loads(json_obj)
        result = json_data['answer']

        self.assertNotEqual(result, expected_result)

        x_string = '400'
        y_string = '9'
        expected_result = mod.mod(400, 21)
        http_output = modURL + x_arg + x_string + y_arg + y_string

        url_output = urlopen(http_output)
        json_obj = url_output.read()
        json_data = json.loads(json_obj)
        result = json_data['answer']

        self.assertNotEqual(result, expected_result)

        x_string = '22'
        y_string = '10'
        expected_result = mod.mod(22, 8)
        http_output = modURL + x_arg + x_string + y_arg + y_string

        url_output = urlopen(http_output)
        json_obj = url_output.read()
        json_data = json.loads(json_obj)
        result = json_data['answer']

        self.assertNotEqual(result, expected_result)
Пример #17
0
import mod

mod.mod()
mod.fn()