def valid_geolocation(lat, lon): if np.shape(lat) != np.shape(lon): return False idx = (ma.greater_equal(lat, -90) & ma.less_equal(lat, 90) & ma.greater_equal(lon, -180) & ma.less_equal(lon, 360)) return idx
def test_testUfuncs1(self): # Test various functions such as sin, cos. (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d assert_(eq(np.cos(x), cos(xm))) assert_(eq(np.cosh(x), cosh(xm))) assert_(eq(np.sin(x), sin(xm))) assert_(eq(np.sinh(x), sinh(xm))) assert_(eq(np.tan(x), tan(xm))) assert_(eq(np.tanh(x), tanh(xm))) with np.errstate(divide='ignore', invalid='ignore'): assert_(eq(np.sqrt(abs(x)), sqrt(xm))) assert_(eq(np.log(abs(x)), log(xm))) assert_(eq(np.log10(abs(x)), log10(xm))) assert_(eq(np.exp(x), exp(xm))) assert_(eq(np.arcsin(z), arcsin(zm))) assert_(eq(np.arccos(z), arccos(zm))) assert_(eq(np.arctan(z), arctan(zm))) assert_(eq(np.arctan2(x, y), arctan2(xm, ym))) assert_(eq(np.absolute(x), absolute(xm))) assert_(eq(np.equal(x, y), equal(xm, ym))) assert_(eq(np.not_equal(x, y), not_equal(xm, ym))) assert_(eq(np.less(x, y), less(xm, ym))) assert_(eq(np.greater(x, y), greater(xm, ym))) assert_(eq(np.less_equal(x, y), less_equal(xm, ym))) assert_(eq(np.greater_equal(x, y), greater_equal(xm, ym))) assert_(eq(np.conjugate(x), conjugate(xm))) assert_(eq(np.concatenate((x, y)), concatenate((xm, ym)))) assert_(eq(np.concatenate((x, y)), concatenate((x, y)))) assert_(eq(np.concatenate((x, y)), concatenate((xm, y)))) assert_(eq(np.concatenate((x, y, x)), concatenate((x, ym, x))))
def _make_continuous_partitions(shuffled_results: ShuffledResults, score_threshold: float, frame_rate: float) -> _PartitionedResults: time_window = max(1, int(frame_rate * CONTINOUS_SEGMENT_TIME_WINDOW_SEC)) min_segment_size = max(1, int(frame_rate * MIN_SEGMENT_SIZE_SEC)) partitioned_results = _PartitionedResults(shuffled_results) # discard low score frames early (use the maximum value of both scores for now) good_score_frames = np.where( ma.greater_equal(ma.max(shuffled_results.scores, axis=1), score_threshold))[0] for frame_index in good_score_frames: prev_theta = partitioned_results.theta[ frame_index - min(time_window, frame_index):frame_index, 0] # if there is a big gap > time_window we start a new partition, with a random value (0) if np.all(np.any(prev_theta.mask, axis=1)): partitioned_results.set_partition(frame_index=frame_index, partition=0, new_partition=True) # otherwise we look in the time_window close past the closest non nan frame see if we can continue the # partition as long as the values stay continuous else: last_valid_index = np.where( ~np.any(prev_theta.mask, axis=1))[0][-1] dists = [ angle_distance( shuffled_results.theta[frame_index, k, :], prev_theta[last_valid_index], ) for k in range(2) ] partition = int(np.argmin(dists)) if dists[partition] < CONTINUOUS_ANGLES_DIST_THRESHOLD: partitioned_results.set_partition(frame_index=frame_index, partition=partition) # discard short segments for cur_partition_indices in partitioned_results.get_segments(): if len(cur_partition_indices) < min_segment_size: partitioned_results.mask(cur_partition_indices) return partitioned_results
def test_testOddFeatures(self): # Test of other odd features x = arange(20) x = x.reshape(4, 5) x.flat[5] = 12 assert_(x[1, 0] == 12) z = x + 10j * x assert_(eq(z.real, x)) assert_(eq(z.imag, 10 * x)) assert_(eq((z * conjugate(z)).real, 101 * x * x)) z.imag[...] = 0.0 x = arange(10) x[3] = masked assert_(str(x[3]) == str(masked)) c = x >= 8 assert_(count(where(c, masked, masked)) == 0) assert_(shape(where(c, masked, masked)) == c.shape) z = where(c, x, masked) assert_(z.dtype is x.dtype) assert_(z[3] is masked) assert_(z[4] is masked) assert_(z[7] is masked) assert_(z[8] is not masked) assert_(z[9] is not masked) assert_(eq(x, z)) z = where(c, masked, x) assert_(z.dtype is x.dtype) assert_(z[3] is masked) assert_(z[4] is not masked) assert_(z[7] is not masked) assert_(z[8] is masked) assert_(z[9] is masked) z = masked_where(c, x) assert_(z.dtype is x.dtype) assert_(z[3] is masked) assert_(z[4] is not masked) assert_(z[7] is not masked) assert_(z[8] is masked) assert_(z[9] is masked) assert_(eq(x, z)) x = array([1., 2., 3., 4., 5.]) c = array([1, 1, 1, 0, 0]) x[2] = masked z = where(c, x, -x) assert_(eq(z, [1., 2., 0., -4., -5])) c[0] = masked z = where(c, x, -x) assert_(eq(z, [1., 2., 0., -4., -5])) assert_(z[0] is masked) assert_(z[1] is not masked) assert_(z[2] is masked) assert_(eq(masked_where(greater(x, 2), x), masked_greater(x, 2))) assert_(eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x, 2))) assert_(eq(masked_where(less(x, 2), x), masked_less(x, 2))) assert_(eq(masked_where(less_equal(x, 2), x), masked_less_equal(x, 2))) assert_(eq(masked_where(not_equal(x, 2), x), masked_not_equal(x, 2))) assert_(eq(masked_where(equal(x, 2), x), masked_equal(x, 2))) assert_(eq(masked_where(not_equal(x, 2), x), masked_not_equal(x, 2))) assert_(eq(masked_inside(list(range(5)), 1, 3), [0, 199, 199, 199, 4])) assert_(eq(masked_outside(list(range(5)), 1, 3), [199, 1, 2, 3, 199])) assert_(eq(masked_inside(array(list(range(5)), mask=[1, 0, 0, 0, 0]), 1, 3).mask, [1, 1, 1, 1, 0])) assert_(eq(masked_outside(array(list(range(5)), mask=[0, 1, 0, 0, 0]), 1, 3).mask, [1, 1, 0, 0, 1])) assert_(eq(masked_equal(array(list(range(5)), mask=[1, 0, 0, 0, 0]), 2).mask, [1, 0, 1, 0, 0])) assert_(eq(masked_not_equal(array([2, 2, 1, 2, 1], mask=[1, 0, 0, 0, 0]), 2).mask, [1, 0, 1, 0, 1])) assert_(eq(masked_where([1, 1, 0, 0, 0], [1, 2, 3, 4, 5]), [99, 99, 3, 4, 5])) atest = ones((10, 10, 10), dtype=np.float32) btest = zeros(atest.shape, MaskType) ctest = masked_where(btest, atest) assert_(eq(atest, ctest)) z = choose(c, (-x, x)) assert_(eq(z, [1., 2., 0., -4., -5])) assert_(z[0] is masked) assert_(z[1] is not masked) assert_(z[2] is masked) x = arange(6) x[5] = masked y = arange(6) * 10 y[2] = masked c = array([1, 1, 1, 0, 0, 0], mask=[1, 0, 0, 0, 0, 0]) cm = c.filled(1) z = where(c, x, y) zm = where(cm, x, y) assert_(eq(z, zm)) assert_(getmask(zm) is nomask) assert_(eq(zm, [0, 1, 2, 30, 40, 50])) z = where(c, masked, 1) assert_(eq(z, [99, 99, 99, 1, 1, 1])) z = where(c, 1, masked) assert_(eq(z, [99, 1, 1, 99, 99, 99]))
with Dataset2(tmp_rad_file.name, 'r') as f: SWdown_global = f.variables['SWdown_global'][:] Rad_Time = f.variables['time'][:] Rad_secs = mdate.epoch2num(Rad_Time) #Delete temporary file tmp_rad_file.delete = True tmp_rad_file.unlink(tmp_rad_file.name) except IndexError: pass #--------Umrechnung von Z in mm6 m-3 nach dBZ------------- print('Calculate dBZ') try: Z_dbz = np.empty(np.shape(Z)) # 2D-Array in der Groesse von Z erstellen Z_dbz = 10 * np.log10(Z) Z_dbz = np.where(ma.greater_equal(Z_dbz, 30), 30, Z_dbz) Z_dbz = np.where(ma.less_equal(Z_dbz, Filter), np.nan, Z_dbz) except: #Remove temp. folders if os.path.isfile(AllSky_file): try: shutil.rmtree(tmp_AllSky_folder) except: print("Temporary folder {0} could not found or deleted".format( tmp_AllSky_folder)) print('No animation created. Radar data missing') sys.exit() #----------Calculate Lifting Condensation Level----------------------------- try: LCL = np.empty(np.shape(Weather_temp))