def get_SED_points(self, log_log=False, lin_nu=None,interp='linear'): size = self._blob_object.nu_grid_size x = zeros(size) y = zeros(size) for i in range(size): x[i] = BlazarSED.get_spectral_array(self.nu_ptr, self._blob_object, i) y[i] = BlazarSED.get_spectral_array(self.nuFnu_ptr, self._blob_object, i) msk_nan = np.isnan(x) msk_nan += np.isnan(y) x[msk_nan] = 0. y[msk_nan] = self.get_emiss_lim() msk = y < self.get_emiss_lim() y[msk] = self.get_emiss_lim() if lin_nu is not None: #f_interp=interpolate.Akima1DInterpolator(log10(x), log10(y)) f_interp = interpolate.interp1d(log10(x), log10(y), bounds_error=False, kind=interp) y = np.power(10., f_interp(log10(lin_nu))) x=lin_nu msk_nan = np.isnan(y) y[msk_nan] = self.get_emiss_lim() if log_log == True: msk = y <= 0. y[msk] = self.get_emiss_lim() x = log10(x) y = log10(y) return x, y
def update(self): size = self._blob.nu_grid_size x = zeros(size) y = zeros(size) for i in range(size): x[i] = BlazarSED.get_spectral_array(self.nu_ptr, self._blob, i) y[i] = BlazarSED.get_spectral_array(self.nuFnu_ptr, self._blob, i)
def predict_proba(self, examples: List[IT]) -> Sequence[float]: predictions = self.predict(examples) indices = [p.value - 1 if isinstance(p, Enum) else p for p in predictions] proba = zeros((len(examples), self.n_classes)) proba[(range(len(predictions)), indices)] = 1 return proba
def sine_model(time, period, phase, amplitudes): npv = period.size npt = time.size nsn = amplitudes.shape[1] bl = zeros((npv, npt)) for i in range(npv): for j in range(nsn): bl[i, :] += amplitudes[i, j] * sin(2 * pi * (time - phase[i] * period[i]) / (period[i] / (j + 1))) return bl
def get_spectral_points(self,log_log=False,emiss_lim=0): #try: size=self._blob_object.nu_grid_size x=zeros(size) y=zeros(size) for i in range(size): x[i]=BlazarSED.get_spectral_array(self.nu_ptr,self._blob_object,i) y[i]=BlazarSED.get_spectral_array(self.n_ptr,self._blob_object,i) #print("->%e %e"%(x[i],y[i])) msk_nan=np.isnan(x) msk_nan+=np.isnan(y) #print('emiss lim',self.get_emiss_lim()) x[msk_nan]=0. y[msk_nan]=emiss_lim msk=y<emiss_lim y[msk]=emiss_lim if log_log==True: msk = y <= 0. y[msk] = emiss_lim #x=x[msk] # y=y[msk] x=log10(x) y=log10(y) return x,y
def load_mask(self, image_id: int): # Получаем параметры изображения boxes, w, h = self.extract_boxes(image_id) # create one array for all masks, each on a different channel masks = zeros([h, w, len(boxes)], dtype='uint8') # create masks class_ids = list() for i in range(len(boxes)): box = boxes[i] row_s, row_e = box[1], box[3] col_s, col_e = box[0], box[2] masks[row_s:row_e, col_s:col_e, i] = 1 class_ids.append(box[4]) # Pack instance masks into an array if class_ids: # mask = np.stack(instance_masks, axis=2).astype(np.bool) class_ids = np.array(class_ids, dtype=np.int32) else: # Call super class to return an empty mask masks = np.empty([0, 0, 0]) class_ids = np.empty([0], np.int32) return masks, class_ids
def __call__(self, npop: int = 40, de_niter: int = 1000, mcmc_niter: int = 200, mcmc_repeats: int = 3, initialize_only: bool = False): self.logger = getLogger(f"{self.name}:{self.ts.name.lower().replace('_','-')}") self.logger.info(f"Fitting {self.mode} transits") self.ts.transit_fits[self.mode] = self epochs = epoch(self.ts.time, self.ts.zero_epoch, self.ts.period) if self.mode == 'all': mask = ones(self.ts.time.size, bool) elif self.mode == 'even': mask = epochs % 2 == 0 elif self.mode == 'odd': mask = epochs % 2 == 1 else: raise NotImplementedError mask &= abs(self.ts.phase - 0.5*self.ts.period) < 4 * 0.5 * self.ts.duration self.ts.transit_fit_masks[self.mode] = self.mask = mask self.epochs = epochs = epochs[mask] self.time = self.ts.time[mask] self.fobs = self.ts.flux[mask] tref = floor(self.time.min()) tm = QuadraticModelCL(klims=(0.01, 0.60)) if self.use_opencl else QuadraticModel(interpolate=False) self.lpf = lpf = SearchLPF(times=self.time, fluxes=self.fobs, epochs=epochs, tm=tm, nsamples=self.nsamples, exptimes=self.exptime, tref=tref) # TODO: V-shaped transits are not always modelled well. Need to set smarter priors (or starting population) # for the impact parameter and stellar density. lpf.set_prior('rho', 'UP', 0.01, 25) if self.mode == 'all': d = min(self.ts.depth, 0.75) lpf.set_prior('tc', 'NP', self.ts.zero_epoch, 0.01) lpf.set_prior('p', 'NP', self.ts.period, 0.001) lpf.set_prior('k2', 'UP', max(0.01**2, 0.5*d), min(max(0.08**2, 4*d), 0.75**2)) else: pr = self.ts.tf_all.parameters lpf.set_prior('tc', 'NP', pr.tc.med, 5*pr.tc.err) lpf.set_prior('p', 'NP', pr.p.med, pr.p.err) lpf.set_prior('k2', 'UP', max(0.01**2, 0.5 * pr.k2.med), max(0.08**2, min(0.6**2, 2 * pr.k2.med))) lpf.set_prior('q1', 'NP', pr.q1.med, pr.q1.err) lpf.set_prior('q2', 'NP', pr.q2.med, pr.q2.err) # TODO: The limb darkening table has been computed for TESS. Needs to be made flexible. if self.ts.teff is not None: ldcs = Table.read(Path(__file__).parent / "data/ldc_table.fits").to_pandas() ip = interp1d(ldcs.teff, ldcs[['q1', 'q2']].T) q1, q2 = ip(clip(self.ts.teff, 2000., 12000.)) lpf.set_prior('q1', 'NP', q1, 1e-5) lpf.set_prior('q2', 'NP', q2, 1e-5) if initialize_only: return else: lpf.optimize_global(niter=de_niter, npop=npop, use_tqdm=self.use_tqdm, plot_convergence=False) lpf.sample_mcmc(mcmc_niter, repeats=mcmc_repeats, use_tqdm=self.use_tqdm, leave=False) df = lpf.posterior_samples(derived_parameters=True) df = pd.DataFrame((df.median(), df.std()), index='med err'.split()) pv = lpf.posterior_samples(derived_parameters=False).median().values self.phase = fold(self.time, pv[1], pv[0], 0.5) * pv[1] - 0.5 * pv[1] self.fmod = lpf.flux_model(pv) self.ftra = lpf.transit_model(pv) self.fbase = lpf.baseline(pv) # Calculate the per-orbit log likelihood differences # -------------------------------------------------- ues = unique(epochs) lnl = zeros(ues.size) err = 10 ** pv[7] def lnlike_normal(o, m, e): npt = o.size return -npt * log(e) - 0.5 * npt * log(2. * pi) - 0.5 * sum((o - m) ** 2 / e ** 2) for i, e in enumerate(ues): m = epochs == e lnl[i] = lnlike_normal(self.fobs[m], self.fmod[m], err) - lnlike_normal(self.fobs[m], 1.0, err) self.parameters = df self.dll_epochs = ues self.dll_values = lnl self.zero_epoch = df.tc.med self.period = df.p.med self.duration = df.t14.med self.depth = df.k2.med if self.mode == 'all': self.delta_bic = self.ts.dbic = delta_bic(lnl.sum(), 0, 9, self.time.size) self.ts.update_ephemeris(self.zero_epoch, self.period, self.duration, self.depth)
# 读取csv至字典 import csv from numpy.core._multiarray_umath import zeros import matplotlib.pyplot as plt csvFile = open("导出沉船报警记录.csv", "r", encoding='utf-8-sig') reader = csv.reader(csvFile) lonlat = zeros((2848, 2)) for item in reader: # 忽略第一行 if reader.line_num == 1: continue # 计算网格号 lonlat[reader.line_num, 0] = item[4] lonlat[reader.line_num, 1] = item[5] csvFile.close() # citys csvFile = open("浙江省市经纬度.csv", "r", encoding='utf-8-sig') reader = csv.reader(csvFile) citys = zeros((100, 2)) for item in reader: # 忽略第一行 if reader.line_num == 1: continue # 计算网格号