def moments(self, unit="km/s", **kwargs): """ Return the moments of the spectrum. In order to assure that the 1st and 2nd moments are meaningful, a 'default' unit is set. If unit is not set, will use current unit. *Documentation imported from the moments module:* """ if unit is False or unit is None: return moments_module.moments(self.xarr, self.data, **kwargs) else: return moments_module.moments(self.xarr.as_unit(unit), self.data, **kwargs)
def moments(self, unit='km/s', **kwargs): """ Return the moments of the spectrum. In order to assure that the 1st and 2nd moments are meaningful, a 'default' unit is set. If unit is not set, will use current unit. *Documentation imported from the moments module:* """ if unit is False or unit is None: return moments_module.moments(self.xarr, self.data, **kwargs) else: return moments_module.moments(self.xarr.as_unit(unit), self.data, **kwargs)
def __init__(self, x, size, selectTrain, sess, toTarget=None, ts=0.001): self.sess = sess self.mean_x_train, self.variance_x_train = moments(x, [0]) #self.mean_x_ma, self.variance_x_ma = moments(self.x_splh, [0]) self.mean_x_ma = tf.Variable(tf.zeros([size])) self.variance_x_ma = tf.Variable(tf.ones([size])) self.update = tf.tuple( [ self.variance_x_ma.assign(0.95 * self.variance_x_ma + 0.05 * self.variance_x_train) ], control_inputs=[ self.mean_x_ma.assign(0.95 * self.mean_x_ma + 0.05 * self.mean_x_train) ])[0] self.mean_x_ma_update = tf.tuple([self.mean_x_train], control_inputs=[])[0] self.printUp = tf.Print(self.mean_x_ma_update, [selectTrain], message="selectTrain value : ") self.variance_x_ma_update = tf.tuple([self.variance_x_train], control_inputs=[])[0] def getxmau(): return self.mean_x_ma_update def getxma(): return self.mean_x_ma def getvxmau(): return self.variance_x_ma_update def getvxma(): return self.variance_x_ma self.mean_x = tf.cond(selectTrain, getxmau, getxma) self.variance_x = tf.cond(selectTrain, getvxmau, getvxma) self.beta = tf.Variable(tf.zeros([size])) self.gamma = tf.Variable(tf.ones([size])) #tfs.tfs.session.run(tf.initialize_variables([self.beta, self.gamma]))#, self.mean_x_ma, self.variance_x_ma])) self.xNorm = tf.reshape( tf.nn.batch_norm_with_global_normalization( tf.reshape(x, [-1, 1, 1, size]), self.mean_x, self.variance_x, self.beta, self.gamma, 0.01, True), [-1, size]) if toTarget != None: self.isTracking = toTarget self.updateBeta = self.beta.assign(self.beta * (1 - ts) + self.isTracking.beta * ts) self.updateGamma = self.gamma.assign(self.gamma * (1 - ts) + self.isTracking.gamma * ts) self.updateTarget = tf.group(self.updateBeta, self.updateGamma)
def get_focus_score(self, image): """Determine how well the image is focussed, and award a score""" hdul = HDUList(image) hdr = hdul[0].header data = hdul[0].data nrows = hdr['NAXIS1'] ncols = hdr['NAXIS2'] ns = 1 back = 400 imx = 512 jmx = 512 spix = 50 background = 360 from moments import moments fwhm = moments(data, imx, jmx, spix, nrows, ncols, background) print("FWHM = {}".format(fwhm)) return fwhm
def __init__(self, x, size, selectTrain, sess, toTarget=None, ts=0.001): self.sess = sess self.mean_x_train, self.variance_x_train = moments(x, [0]) #self.mean_x_ma, self.variance_x_ma = moments(self.x_splh, [0]) self.mean_x_ma = tf.Variable(tf.zeros([size])) self.variance_x_ma = tf.Variable(tf.ones([size])) self.update = tf.tuple([self.variance_x_ma.assign(0.95*self.variance_x_ma+ 0.05*self.variance_x_train)] , control_inputs=[self.mean_x_ma.assign(0.95*self.mean_x_ma+ 0.05*self.mean_x_train)])[0] self.mean_x_ma_update = tf.tuple([self.mean_x_train] , control_inputs=[])[0] self.printUp = tf.Print(self.mean_x_ma_update, [selectTrain], message="selectTrain value : ") self.variance_x_ma_update = tf.tuple([self.variance_x_train], control_inputs=[])[0] def getxmau(): return self.mean_x_ma_update def getxma(): return self.mean_x_ma def getvxmau(): return self.variance_x_ma_update def getvxma(): return self.variance_x_ma self.mean_x = tf.cond(selectTrain, getxmau, getxma) self.variance_x = tf.cond(selectTrain, getvxmau, getvxma) self.beta = tf.Variable(tf.zeros([size])) self.gamma = tf.Variable(tf.ones([size])) #tfs.tfs.session.run(tf.initialize_variables([self.beta, self.gamma]))#, self.mean_x_ma, self.variance_x_ma])) self.xNorm = tf.reshape(tf.nn.batch_norm_with_global_normalization(tf.reshape(x, [-1, 1, 1, size]), self.mean_x, self.variance_x, self.beta, self.gamma, 0.01, True), [-1, size]) if toTarget!=None: self.isTracking = toTarget self.updateBeta = self.beta.assign(self.beta*(1-ts)+self.isTracking.beta*ts) self.updateGamma = self.gamma.assign(self.gamma*(1-ts)+self.isTracking.gamma*ts) self.updateTarget = tf.group(self.updateBeta, self.updateGamma)
#print("map_A:\t", g.map_A) #print("p1:\t", g.p1) #print("p2:\t", g.p2) #print("q1:\t", g.q1) #print("q2:\t", g.q2) #print("idx2:\t", g.idx2) #print("idx2s:\t", g.idx2s) #print("d:\t", g.d) #print(check_measure_r(g, g.m_r, epsilon)) #print(check_measure_r(g, g.m_r1, epsilon)) #print(check_measure_s(g, g.m_s, epsilon)) #print(check_measure_s(g, g.m_s1, epsilon)) #print(check_measure(g, g.m_rs, epsilon)) # exp = ep.E_D(g) exp0 = mm.moments(0, g) exp1 = mm.moments(1, g) exp2 = mm.moments(2, g) var = exp2 - exp1**2 print(foldr(concat('\t'), ['total', exp0, exp1, exp2, var], '')) pLst = [0, 0.2, 0.4, 0.6, 0.85, 0.87, 0.89, 0.9, 0.92, 0.94, 0.96] # pLst = [0] e = list(g.edges())[0] for p in pLst: expc0 = mc.momentsCond(0, g, e, p) expc1 = mc.momentsCond(1, g, e, p) expc2 = mc.momentsCond(2, g, e, p) varc = expc2 - expc1**2