Esempio n. 1
0
 def test(self):
     result = ["A       b    ", "a       B    "]
     self.assertEqual(wave("a       b    "), result)
     result = ["This is a few words", "tHis is a few words", "thIs is a few words", "thiS is a few words", "this Is a few words", "this iS a few words", "this is A few words", "this is a Few words", "this is a fEw words", "this is a feW words", "this is a few Words", "this is a few wOrds", "this is a few woRds", "this is a few worDs", "this is a few wordS"]
     self.assertEqual(wave("this is a few words"), result)
     result = []
     self.assertEqual(wave(""), result)
     result = [" Gap ", " gAp ", " gaP "]
     self.assertEqual(wave(" gap "), result)
Esempio n. 2
0
File: mler.py Progetto: WEC-Sim/WDRT
    def __init__(self,H=None,T=None,numFreq=10001):
        self.sim   = simulation.simulation()
        self.waves = wave.wave(H,T,numFreq)

        self.desiredRespAmp     = 0.0                       # [-]   Desired response amplitude.  M_d in documentation.
        self.waveHeightDesired  = None                      # [m]   Height of wave desired if renormalizing amplitudes

        # calculated variables
        self._RAO               = None                      # [-]   Complex RAO array  N x 6
        self._RAOdataReadIn     = np.zeros(6,dtype=bool)    # [-]   What RAO dimensions did we read in?
        self._RAOdataFileName   = ['','','','','','']       # [-]   Name of the data file read in for RAO
        self._CoeffA_Rn         = None                      # [ ]   MLER coefficients A_{R,n}
        self._S                 = None                      # [m^2-s] Conditioned wave spectrum vector
        self._A                 = None                      # [m^2-s] 2*(conditioned wave spectrum vector)
        self._phase             = 0.0                       # [rad] Wave phase
        self._Spect             = None                      # [-]   Spectral info
        self._rescaleFact       = None                      # [-]   Rescaling factor for renormalizing the amplitude

        self._animation         = None                      #       Object storing animation information
        self._respExtremes      = None                      # [m]   Array containing min/max of the simulated response
Esempio n. 3
0
    def __init__(self,H=None,T=None,numFreq=10001):
        self.sim   = simulation.simulation()
        self.waves = wave.wave(H,T,numFreq)

        self.desiredRespAmp     = 0.0                       # [-]   Desired response amplitude.  M_d in documentation.
        self.waveHeightDesired  = None                      # [m]   Height of wave desired if renormalizing amplitudes

        # calculated variables
        self._RAO               = None                      # [-]   Complex RAO array  N x 6
        self._RAOdataReadIn     = np.zeros(6,dtype=bool)    # [-]   What RAO dimensions did we read in?
        self._RAOdataFileName   = ['','','','','','']       # [-]   Name of the data file read in for RAO
        self._CoeffA_Rn         = None                      # [ ]   MLER coefficients A_{R,n}
        self._S                 = None                      # [m^2-s] Conditioned wave spectrum vector
        self._A                 = None                      # [m^2-s] 2*(conditioned wave spectrum vector)
        self._phase             = 0.0                       # [rad] Wave phase
        self._Spect             = None                      # [-]   Spectral info
        self._rescaleFact       = None                      # [-]   Rescaling factor for renormalizing the amplitude

        self._animation         = None                      #       Object storing animation information
        self._respExtremes      = None                      # [m]   Array containing min/max of the simulated response
Esempio n. 4
0
def process_wave(filenames, classes, classes_io, classes_nums, fname_base_len, val=False):
    data_x = []
    data_y = []
    data_y_io = []

    for i, filename in enumerate(filenames):
        printProgressBar(i+1, len(filenames))
        img = cv2.imread(filename, 0)
        im = img.copy()
        h = wave.wave(im)
        index = classes.index(filename[fname_base_len:-13])
        data_x.append(h)
        if val:
            inout = int(classes_io[int(classes[i].split(" ")[1])])
            data_y.append(int(classes[i].split(" ")[1]))
            data_y_io.append(inout)
        else:
            data_y.append(int(classes_nums[index]))
            data_y_io.append(int(classes_io[index]))
    data_x_scaled = preprocessing.scale(data_x)
    return data_x_scaled, data_y, data_y_io         
Esempio n. 5
0
    def test_rand(self):
        from random import randint
        def wave2(str):
            result = []
            str = list(str)
            for b in range(0,len(str)):
                if str[b] != " ":
                    temp = []
                    for i in range(0, len(str)):
                        if i == b:
                            temp.append(str[i].upper())
                        else:
                            temp.append(str[i])
                    result.append("".join(temp))
            return result

        letters = list("abcd efghi jklmno pqrstu vwxyz")
        for _ in range (1,97):
            word = []
            for _ in range(0,randint(0,100)):
                word.append(letters[randint(0,len(letters)-1)])
            word = "".join(word)
            result = wave2(word)
            self.assertEqual(wave(word), result)
Esempio n. 6
0
    qNour = defaultFill(1,dtNourish,500,10*dtNourish,T+dtNourish)
    
    # initialize time steps
    # loop through and update wave accordingly
    t = 0
    while t<T:
        
        #interpolate waves
        hs = interpParam(t,Hs,dtWave)
        tp = interpParam(t,Tp,dtWave) 
        d = interpParam(t,D,dtWave)
        qN = interpParam(t,qNour,dtNourish)
        dStore.append(d)
#        print(d)
        #use the offshore contour to calculate wave refraction
        wv = wave(hs,tp,d,test.normalsOff)
        #wave angle relative to offshore contour
        wv.orient()
        #refract and shoal waves -> still need to add difraction
        hb = wv.iteration()
        #init morphology 
        bed = morph(test.x,test.y,test.yInit,test.xPoints,test.qPoints,test.swl,
                    test.yStr,test.xStr,hs,tp,1)
        #calculate potential LST
        Q = bed.CERC(wv.thetaB,hb,wv.Cgb,wv.sgn,rot,test.normals)
        #quantify erosion and accretion
        Q,qAn = bed.orient(wv.thetaB,test.normals,rot,Q,wv.sgn)
        #add source and sinks
        bed.source_sinks(qi=qN)
        Dg = bed.A*test.yAdd**(2/float(3))        
        dyPot,dy = bed.update(6,2,dt,Q,Q,hb,rot,d,Dg,0.8)
for t in test_names:
    fn = os.path.join(directory, t[7:])
    img = cv2.imread(fn)
    # print(fn)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # GBP
    start = time.time()
    gbp.gbp(gray)
    gbp_times.append(time.time() - start)

    # CENTRIST
    start = time.time()
    centrist.centrist_im(cl, gray)
    centrist_times.append(time.time() - start)

    # WHGO
    start = time.time()
    whgo.whgo(gray, 16)
    whgo_times.append(time.time() - start)

    # WAVE
    start = time.time()
    wave.wave(gray)
    wave_times.append(time.time() - start)

print("GBP time", np.mean(gbp_times))
print("CENTRIST time", np.mean(centrist_times))
print("WHGO time", np.mean(whgo_times))
print("WAVE time", np.mean(wave_times))
Esempio n. 8
0
#symulate full system
import wave as wv

wave = wv.wave(80000, 0.00001, 'results/solution.pvd',
               'meshes/cracked_beam.xml', "full", "dontcare", 80)
print('Initializing FEM...')
wave.initiate_fem()
print('Time integrating...')
wave.mid_point()
print('Genearting the weight matrix...')
wave.generate_X_matrix()
print('Saving snapshots...')
wave.save_snapshots()
print('complete.')

# genearate reduced basis
print('Generateing reduced basis...')
import mor as mr

mor = mr.Mor()
#mor.set_basis_size(100)
#mor.POD_energy()
mor.initiate_greedy()
mor.greedy(100, 100)
mor.save_basis()
print('complete.')

# simulate reduced system
print('simulating Iweighted reduced system...')
import wave as wv
Esempio n. 9
0
        frequency = 440.0 * STEP**note
        volume = volume_step * (MAX_VOLUME / 20)

        stdscr.addstr(1, 2, NOTES[note % 12] + ' ' * 80)
        stdscr.addstr(3, 2, str(score) + ' points')
        stdscr.addstr(4, 2, str(health) + ' health')

        stdscr.move(10, 2)

        if target_position >= TARGET_FRAMES:
            if frequency >= target_frequency / STEP and frequency <= target_frequency * STEP:
                score += 1
                wave_bytes, target_position, time = wave(frames=FRAMES * 2,
                                                         left=score_tones,
                                                         right=score_tones,
                                                         position=1,
                                                         max_position=1,
                                                         volume=MAX_VOLUME,
                                                         bitrate=BITRATE,
                                                         time=time)
            else:
                health -= 1
                wave_bytes, target_position, time = wave(
                    frames=FRAMES * 4,
                    left=health_tones[:health],
                    right=health_tones[:health],
                    position=1,
                    max_position=1,
                    volume=MAX_VOLUME,
                    bitrate=BITRATE,
                    time=time)
            target_frequency = 440.0 * STEP**random.randint(
Esempio n. 10
0
                              dsun_meters = i0.meta['dsun_obs'], 
                              occultation = True) for line in lonlatgc]

pxcoord = [np.array(np.round(np.nan_to_num(wcs.convert_data_to_pixel(line[0], line[1], 
                                                                     i0.scale.values(), i0.reference_pixel.values(), 
                                                                     [0,0]))), #i0.reference_coordinate.values()))),
                    dtype = np.int) for line in xycoord]
pxcoord_arr = np.array(pxcoord) # shape for default -> (360,2,180)
# Convert the values from physical to pixel values
deltaX = wcs.rsun_meters * np.deg2rad(step) / 1e3 # km
velocity_px = velocity / deltaX
deltaT = 1 / velocity_px # sec
cadencewave = int(cadence / deltaT)
front = int(150e3 / deltaX)
# Create the wave 
wavearr, tsteps = wave.wave(len(line[0]), velocity = velocity_px, cadence = cadencewave,
                            wave_func = wave.square, wave_args = {'size': front })

messa = \
"""The velocity used is: {velocity} km/s 
with a front size of: {front} km
and a cadence of: {cadence} s""".format(velocity = velocity, 
                                        front = front * deltaX, 
                                        cadence = cadencewave * deltaT)
print messa
# Create t-x-y array for all the images
mask_series = np.zeros((wavearr.shape[0],) + i0.shape)
time0 = stime.parse_time(i0.meta['date-obs'])
times_str = [(time0 + datetime.timedelta(0,deltaT * ts + cadence)).isoformat() for ts in tsteps]  # the first image is at dt = cadence from i0.

for ind, mask in enumerate(mask_series):
    for line in pxcoord_arr:
Esempio n. 11
0
 def test_string2(self):
     result = [
         "Codewars", "cOdewars", "coDewars", "codEwars", "codeWars",
         "codewArs", "codewaRs", "codewarS"
     ]
     self.assertEqual(wave("codewars"), result)
Esempio n. 12
0
 def test_string1(self):
     result = ["Hello", "hEllo", "heLlo", "helLo", "hellO"]
     self.assertEqual(wave("hello"), result)
Esempio n. 13
0
 def test_string5(self):
     result = [" Gap ", " gAp ", " gaP "]
     self.assertEqual(wave(" gap "), result)
Esempio n. 14
0
 def test_string4(self):
     result = [
         "Two words", "tWo words", "twO words", "two Words", "two wOrds",
         "two woRds", "two worDs", "two wordS"
     ]
     self.assertEqual(wave("two words"), result)
Esempio n. 15
0
 def test_string3(self):
     result = []
     self.assertEqual(wave(""), result)