def activate(self, mode=None): """ If there are no analysis parameters given, eg no user input of mean or sigma, we will update those based on the activation function. """ if self.activation_function == 'gauss': if mode == 'mean': return np.mean(self.universe) if mode == 'sigma': return np.sigma(self.universe) elif self.activation_function == 'composite_gauss': if mode == 'mean': return np.mean(self.universe) if mode == 'sigma': return np.sigma(self.universe) else: raise Exception("Hey man you need a proper activation function here")
def generate_data(nbr_iterations): dims = (3, 1) start_positions = np.array(np.sigma(0, 0.5)) # Computing trajectory data = [start_positions] for iteration in range(nbr_iterations): previous_positions = data[-1] new_positions = np.array(sigma(iteration / (2 * np.pi), 0.5)) data.append(new_positions) return data
def cloudfilter(allprf, tarr, z, datestring): r""" Cloud filter This function computes the cloud filter equations described in [Teschke (2008),Garcia-Franco (2017), Garcia-Franco et.al. (2018)] **Parameters** **allprf**: `np.nadarray` backscattering matrix **tarr** : `np.array` Time-array, usually decimal hours. **z** : `np.array` Height-array usually length 500, start=10, end=5000, t_step=10 [m] **datestring** : `string` String for date, typically %Y%m%d, e.g., 20160305 :rtype: datetimearray, flag vector: temps returns all datetimes where cloud or precipitation has been found, flag vector is a numpy array with the dimensions of tarr where clouds are depicted as 1 and clear-sky conditions as 0. **Statistical filter** .. math:: \beta_\sigma (z,t)=B(z,t)\sigma(t) .. math:: \mu=\frac{1}{N_zN_t}\sum_z\sum_t\beta_\sigma(z,t) .. math:: \sum=\frac{1}{N_zN_t-1}\sum_z\sum_t[\beta_\sigma(z,t)-\mu]^2. .. math:: B_N=\mu+3\sqrt{\sum} * :math:`B(z,t)` Backscattering matrix * :math:`\sigma(t)` Variance over time $t$. * :math:`\mu` Global mean of \beta_\sigma(z,t) * :math:`\sum` Global variance of \beta_\sigma(z,t) * :math:`z_{max}` Maximum integration level [m] * :math:`B_N` Threshold for determining cloud or no cloud, function of both global mean and variance. `B_N` defines the threshold value used for determining whether or not a profile at time `t` presents cloud and precipiation or not. If B(z,t)>B_N then cloud and precipitation are present. Else, clear-sky conditions are considered. """ thrs = 1750.0 day = datestring dia = int(day[6:8]) year = int(day[0:4]) mes = int(day[4:6]) zi = np.where(z == 200.) zi = zi[0] zmax = np.where(z == 4000.) zmax = zmax[0] #print zi,zmax a = allprf[zi:zmax, :] nbs = [] tmps = [] sigma_t = np.sigma(tarr) count = len(tarr) * len(z[zi:zmax]) sumi = 0 for i, t in enumerate(tarr): for j, z1 in enumerate(z[zi:zmax]): try: sumi = sumi + a[j + zi, i] except IndexError: # print fl continue mu = sumi / count deviat = 0 for i, t in enumerate(tarr): for j, z1 in enumerate(z[zi:zmax]): try: deviat = deviat + ((a[j + zi, i] - mu)**2) except IndexError: continue sigma = deviat / (count - 1) ec = mu + (3 * np.sqrt(sigma)) # print 'media','sigma','3','s' # print mu,sigma,three,two #if ec > 1400: # print fl, ec for i, t in enumerate(tarr): cloud = False for j, z1 in enumerate(z[zi:zmax]): try: if a[j + zi, i] > ec or a[j + zi, i] > thrs: horas = int(math.floor(t)) minutos = int(round((t - horas) * 60, -1)) tim = datetime.datetime(year, mes, dia, horas, minutos) tmps.append(tim) #nbs.append(1) cloud = True break except IndexError: continue if cloud: nbs.append(1) else: nbs.append(0) # print tmps # print nbs return tmps, nbs