def miller(self, psinorm=None, rova=None, omt_factor=None): """ Calculate Miller quantities. Args: psinorm (float, default 0.8): psi-norm for Miller quantities (overrides rova) rova (float, default None): r/a for Miller quantities (ignored if psinorm evals to True) omt_factor (float, default 0.2): sets omt = omp * omt_factor and omn = omp * (1-omt_factor) Returns: dictionary with Miller quantities and reference values for GENE simulation """ output = {} if psinorm is None and rova is None: psinorm = 0.8 if omt_factor is None: omt_factor = 0.2 # r and psi splines psi_grid_spl = US(self.r_minor_fs, self.psi_grid, k=self.io, s=self.s) r_min_spl = US(self.psi_grid, self.r_minor_fs, k=self.io, s=self.s) if psinorm: print('using `psinorm`, ignoring `rova`') self.psinorm = psinorm psi_poi = self.psinorm * (self.psisep - self.psiax) + self.psiax r_poi = r_min_spl(psi_poi)[()] self.rova = r_poi / self.a_lcfs else: print('using `rova`, ignoring `psinorm`') self.rova = rova r_poi = self.rova * self.a_lcfs # r = r/a * a; FS minor radius psi_poi = psi_grid_spl(r_poi)[()] # psi at FS self.psinorm = (psi_poi - self.psiax) / (self.psisep - self.psiax ) # psi-norm at FS output['gfile'] = self.gfile output['psinorm'] = self.psinorm output['rova'] = self.rova R0_spl = US(self.r_minor_fs, self.R_major_fs, k=self.io, s=self.s) R0_poi = R0_spl(r_poi)[()] # R_maj of FS q_spl = US(self.r_minor_fs, self.qpsi_fs, k=self.io, s=self.s) #q_spl_psi = US(self.psi_grid, self.qpsi_fs, k=self.io, s=self.s) q_poi = q_spl(r_poi)[()] drdpsi_poi = float(r_min_spl.derivatives(psi_poi)[1]) eps_poi = r_poi / R0_poi if not self.quiet: print('\n*** Flux surfance ***') print('r_min/a = {:.3f}'.format(self.rova)) print('psinorm = {:.3f}'.format(self.psinorm)) print('r_min = {:.3f} m'.format(r_poi)) print('R_maj = {:.3f} m'.format(R0_poi)) print('eps = {:.3f}'.format(eps_poi)) print('q = {:.3f}'.format(q_poi)) print('psi = {:.3e} Wb/rad'.format(psi_poi)) print('dr/dpsi = {:.3g} m/(Wb/rad)'.format(drdpsi_poi)) F_spl = US(self.r_minor_fs, self.F_fs, k=self.io, s=self.s) F_poi = F_spl(r_poi)[()] # F of FS Bref_poi = F_poi / R0_poi p_spl = US(self.r_minor_fs, self.p_fs, k=self.io, s=self.s) p_poi = p_spl(r_poi)[()] t_poi = self.ti n_poi = p_poi / (t_poi * 1e3 * 1.602e-19) / 1e19 output['Lref'] = self.a_lcfs output['Bref'] = Bref_poi output['pref'] = p_poi output['Tref'] = t_poi output['nref'] = n_poi beta = 403.e-5 * n_poi * self.ti / (Bref_poi**2) coll = 2.3031e-5 * (24-np.log(np.sqrt(n_poi*1e13)/(1e3*t_poi))) \ * self.a_lcfs * n_poi / (t_poi**2) output['beta'] = beta output['coll'] = coll if not self.quiet: print('\n*** Reference values ***') print('Lref = {:.3g} m ! for Lref=a convention'.format( self.a_lcfs)) print('Bref = {:.3g} T'.format(Bref_poi)) print('pref = {:.3g} Pa'.format(p_poi)) print('Tref = {:.3g} keV'.format(t_poi)) print('nref = {:.3g} 1e19/m^3'.format(n_poi)) print('beta = {:.3g}'.format(beta)) print('coll = {:.3g}'.format(coll)) pprime_spl = US(self.r_minor_fs, self.pprime_fs, k=self.io, s=1e-4) pprime_poi = pprime_spl(r_poi)[()] pm_poi = Bref_poi**2 / (2 * 4 * 3.14e-7) dpdr_poi = pprime_poi / drdpsi_poi dpdx_pm = -dpdr_poi / pm_poi omp_poi = -(self.a_lcfs / p_poi) * dpdr_poi output['dpdx_pm'] = dpdx_pm output['omp'] = omp_poi if not self.quiet: print('\n*** Pressure gradients ***') print('dp/dpsi = {:.3g} Pa/(Wb/rad)'.format(pprime_poi)) print('p_m = 2mu/Bref**2 = {:.3g} Pa'.format(pm_poi)) print('-(dp/dr)/p_m = {:.3g} 1/m'.format(dpdx_pm)) print('omp = a/p * dp/dr = {:.3g} ! with Lref=a'.format(omp_poi)) omt = omp_poi * omt_factor omn = omp_poi * (1 - omt_factor) output['omt'] = omt output['omt_factor'] = omt_factor output['omn'] = omn if not self.quiet: print('\n*** Temp/dens gradients ***') print('omt_factor = {:.3g}'.format(omt_factor)) print('omt = a/T * dT/dr = {:.3g}'.format(omt)) print('omn = a/n * dn/dr = {:.3g}'.format(omn)) sgstart = self.nw // 10 subgrid = np.arange(sgstart, self.nw) nsg = subgrid.size # calc symmetric R/Z on psi/theta grid kappa = np.empty(nsg) delta = np.empty(nsg) zeta = np.empty(nsg) drR = np.empty(nsg) amhd = np.empty(nsg) bp = np.empty(nsg) bt = np.empty(nsg) b = np.empty(nsg) theta_tmp = np.linspace(-2. * np.pi, 2 * np.pi, 2 * self.ntheta - 1) stencil_width = self.ntheta // 10 for i, isg in enumerate(subgrid): R_extended = np.empty(2 * self.ntheta - 1) Z_extended = np.empty(2 * self.ntheta - 1) R_extended[0:(self.ntheta - 1) // 2] = self.R_ftgrid[isg, (self.ntheta + 1) // 2:-1] R_extended[(self.ntheta - 1) // 2:(3 * self.ntheta - 3) // 2] = self.R_ftgrid[isg, :-1] R_extended[(3 * self.ntheta - 3) // 2:] = self.R_ftgrid[isg, 0:(self.ntheta + 3) // 2] Z_extended[0:(self.ntheta - 1) // 2] = self.Z_ftgrid[isg, (self.ntheta + 1) // 2:-1] Z_extended[(self.ntheta - 1) // 2:(3 * self.ntheta - 3) // 2] = self.Z_ftgrid[isg, :-1] Z_extended[(3 * self.ntheta - 3) // 2:] = self.Z_ftgrid[isg, 0:(self.ntheta + 3) // 2] theta_mod_ext = np.arctan2(Z_extended - self.Z_avg_fs[isg], R_extended - self.R_major_fs[isg]) # introduce 2pi shifts to theta_mod_ext for ind in range(self.ntheta): if theta_mod_ext[ind + 1] < 0. \ and theta_mod_ext[ind] > 0. \ and abs(theta_mod_ext[ind + 1] - theta_mod_ext[ind]) > np.pi: lshift_ind = ind if theta_mod_ext[-ind - 1] > 0. \ and theta_mod_ext[-ind] < 0. \ and abs(theta_mod_ext[-ind - 1] - theta_mod_ext[-ind]) > np.pi: rshift_ind = ind theta_mod_ext[-rshift_ind:] += 2. * np.pi theta_mod_ext[:lshift_ind + 1] -= 2. * np.pi theta_int = interp1d(theta_mod_ext, theta_tmp, kind=self.io) R_int = interp1d(theta_mod_ext, R_extended, kind=self.io) Z_int = interp1d(theta_mod_ext, Z_extended, kind=self.io) R_tm = R_int(self.theta_grid) Z_tm = Z_int(self.theta_grid) Z_sym = 0.5 * (Z_tm[:] - Z_tm[::-1]) + self.Z_avg_fs[isg] R_sym = 0.5 * (R_tm[:] + R_tm[::-1]) delta_ul = np.empty(2) for o in range(2): if o: ind = np.argmax(Z_sym) section = np.arange(ind + stencil_width // 2, ind - stencil_width // 2, -1) else: ind = np.argmin(Z_sym) section = np.arange(ind - stencil_width // 2, ind + stencil_width // 2) x = R_sym[section] y = Z_sym[section] y_int = interp1d(x, y, kind=self.io) x_fine = np.linspace(np.amin(x), np.amax(x), stencil_width * 100) y_fine = y_int(x_fine) if o: x_at_extremum = x_fine[np.argmax(y_fine)] Z_max = np.amax(y_fine) else: x_at_extremum = x_fine[np.argmin(y_fine)] Z_min = np.amin(y_fine) delta_ul[o] = (self.R_major_fs[isg] - x_at_extremum) \ / self.r_minor_fs[isg] kappa[i] = (Z_max - Z_min) / 2. / self.r_minor_fs[isg] delta[i] = delta_ul.mean() # calc zeta zeta_arr = np.empty(4) for o in range(4): if o == 0: val = np.pi / 4 searchval = np.cos(val + np.arcsin(delta[i]) / np.sqrt(2)) searcharr = (R_sym - self.R_major_fs[isg]) / self.r_minor_fs[isg] elif o == 1: val = 3 * np.pi / 4 searchval = np.cos(val + np.arcsin(delta[i]) / np.sqrt(2)) searcharr = (R_sym - self.R_major_fs[isg]) / self.r_minor_fs[isg] elif o == 2: val = -np.pi / 4 searchval = np.cos(val - np.arcsin(delta[i]) / np.sqrt(2)) searcharr = (R_sym - self.R_major_fs[isg]) / self.r_minor_fs[isg] elif o == 3: val = -3 * np.pi / 4 searchval = np.cos(val - np.arcsin(delta[i]) / np.sqrt(2)) searcharr = (R_sym - self.R_major_fs[isg]) / self.r_minor_fs[isg] else: raise ValueError('out of range') if o in [0, 1]: searcharr2 = searcharr[self.ntheta // 2:] ind = self._find(searchval, searcharr2) + self.ntheta // 2 else: searcharr2 = searcharr[0:self.ntheta // 2] ind = self._find(searchval, searcharr2) section = np.arange(ind - stencil_width // 2, ind + stencil_width // 2) theta_sec = self.theta_grid[section] if o in [0, 1]: theta_int = interp1d(-searcharr[section], theta_sec, kind=self.io) theta_of_interest = theta_int(-searchval) else: theta_int = interp1d(searcharr[section], theta_sec, kind=self.io) theta_of_interest = theta_int(searchval) Z_sec = Z_sym[section] Z_sec_int = interp1d(theta_sec, Z_sec, kind=self.io) Z_val = Z_sec_int(theta_of_interest) zeta_arg = (Z_val - self.Z_avg_fs[isg] ) / kappa[i] / self.r_minor_fs[isg] if abs(zeta_arg) >= 1: zeta_arg = 0.999999 * np.sign(zeta_arg) zeta_arr[o] = np.arcsin(zeta_arg) zeta_arr[1] = np.pi - zeta_arr[1] zeta_arr[3] = -np.pi - zeta_arr[3] zeta[i] = 0.25 * (np.pi + zeta_arr[0] - zeta_arr[1] - zeta_arr[2] + zeta_arr[3]) # calc dr/dR, amhd, and derivs amhd[i] = -self.qpsi_fs[isg]**2 * self.R_major_fs[isg] * self.pprime_fs[isg] * \ 8 * np.pi * 1e-7 / Bref_poi**2 / \ r_min_spl.derivatives(self.psi_grid[isg])[1] drR[i] = R0_spl.derivatives(self.r_minor_fs[isg])[1] R = self.R_major_fs[isg] + self.r_minor_fs[isg] Z = self.Z_avg_fs[isg] Br = -self.psi_spl(Z, R, dx=1, dy=0) / R Bz = self.psi_spl(Z, R, dx=0, dy=1) / R bp[i] = np.sqrt(Br**2 + Bz**2) bt[i] = self.F_fs[isg] / R b[i] = np.sqrt(bp[i]**2 + bt[i]**2) amhd_spl = US(self.r_minor_fs[sgstart:], amhd, k=self.io, s=1e-3) drR_spl = US(self.r_minor_fs[sgstart:], drR, k=self.io, s=self.s) b_spl = US(self.psinorm_grid[sgstart:], b, k=self.io, s=self.s) # calc derivatives for kappa, delta, zeta s_kappa = np.empty(nsg) s_delta = np.empty(nsg) s_zeta = np.empty(nsg) kappa_spl = US(self.r_minor_fs[sgstart:], kappa, k=self.io, s=self.s) delta_spl = US(self.r_minor_fs[sgstart:], delta, k=self.io, s=self.s) zeta_spl = US(self.r_minor_fs[sgstart:], zeta, k=self.io, s=self.s) for i, isg in enumerate(subgrid): s_kappa[i] = kappa_spl.derivatives(self.r_minor_fs[isg])[1] \ * self.r_minor_fs[isg] / kappa[i] s_delta[i] = delta_spl.derivatives(self.r_minor_fs[isg])[1] \ * self.r_minor_fs[isg] / np.sqrt(1 - delta[i]**2) s_zeta[i] = zeta_spl.derivatives(self.r_minor_fs[isg])[1] \ * self.r_minor_fs[isg] output['trpeps'] = eps_poi output['q0'] = q_poi output['shat'] = (r_poi / q_poi) * q_spl.derivatives(r_poi)[1] output['amhd'] = amhd_spl(r_poi)[()] output['drR'] = drR_spl(r_poi)[()] output['kappa'] = kappa_spl(r_poi)[()] output['s_kappa'] = kappa_spl.derivatives( r_poi)[1] * r_poi / kappa_spl(r_poi)[()] output['delta'] = delta_spl(r_poi)[()] output['s_delta'] = delta_spl.derivatives(r_poi)[1] * r_poi \ / np.sqrt(1 - delta_spl(r_poi)[()]**2) output['zeta'] = zeta_spl(r_poi)[()] output['s_zeta'] = zeta_spl.derivatives(r_poi)[1] * r_poi output['minor_r'] = 1.0 output['major_R'] = R0_poi / self.a_lcfs if not self.quiet: print( '\n\nShaping parameters for flux surface r=%9.5g, r/a=%9.5g:' % (r_poi, self.rova)) print('Copy the following block into a GENE parameters file:\n') print('trpeps = %9.5g' % (eps_poi)) print('q0 = %9.5g' % q_poi) print('shat = %9.5g !(defined as r/q*dq_dr)' % (r_poi / q_poi \ * q_spl.derivatives(r_poi)[1])) print('amhd = %9.5g' % amhd_spl(r_poi)) print('drR = %9.5g' % drR_spl(r_poi)) print('kappa = %9.5g' % kappa_spl(r_poi)) print('s_kappa = %9.5g' % (kappa_spl.derivatives(r_poi)[1] \ * r_poi / kappa_spl(r_poi))) print('delta = %9.5g' % delta_spl(r_poi)) print('s_delta = %9.5g' % (delta_spl.derivatives(r_poi)[1] \ * r_poi / np.sqrt(1 - delta_spl(r_poi)**2))) print('zeta = %9.5g' % zeta_spl(r_poi)) print('s_zeta = %9.5g' % (zeta_spl.derivatives(r_poi)[1] * r_poi)) print('minor_r = %9.5g' % (1.0)) print('major_R = %9.5g' % (R0_poi / self.a_lcfs)) if self.plot: plt.figure(figsize=(6, 8)) plt.subplot(4, 2, 1) plt.plot(self.psinorm_grid[sgstart:], kappa) plt.title('Elongation') plt.ylabel(r'$\kappa$', fontsize=14) plt.subplot(4, 2, 2) plt.plot(self.psinorm_grid[sgstart:], s_kappa) plt.title(r'$r/\kappa*(d\kappa/dr)$') plt.ylabel(r'$s_\kappa$', fontsize=14) plt.subplot(4, 2, 3) plt.plot(self.psinorm_grid[sgstart:], delta) plt.title('Triangularity') plt.ylabel(r'$\delta$', fontsize=14) plt.subplot(4, 2, 4) plt.plot(self.psinorm_grid[sgstart:], s_delta) plt.title(r'$r/\delta*(d\delta/dr)$') plt.ylabel(r'$s_\delta$', fontsize=14) plt.subplot(4, 2, 5) plt.plot(self.psinorm_grid[sgstart:], zeta) plt.title('Squareness') plt.ylabel(r'$\zeta$', fontsize=14) plt.subplot(4, 2, 6) plt.plot(self.psinorm_grid[sgstart:], s_zeta) plt.title(r'$r/\zeta*(d\zeta/dr)$') plt.ylabel(r'$s_\zeta$', fontsize=14) plt.subplot(4, 2, 7) plt.plot(self.psinorm_grid[sgstart:], b) plt.plot(self.psinorm_grid[sgstart:], bp) plt.plot(self.psinorm_grid[sgstart:], bt) plt.title('|B|') plt.ylabel(r'|B|', fontsize=14) plt.subplot(4, 2, 8) plt.plot(self.psinorm_grid[sgstart:], b_spl(self.psinorm_grid[sgstart:], nu=1)) plt.title('|B| deriv.') plt.ylabel(r'$d|B|/d\Psi_N$', fontsize=14) for ax in plt.gcf().axes: ax.set_xlabel(r'$\Psi_N$', fontsize=14) ax.axvline(self.psinorm, 0, 1, ls='--', color='k', lw=2) plt.tight_layout(pad=0.3) return output
qpsi_lowres[i * 5:i * 5 + n_entries] = [ float(eqdsk_lowres[i + start_line][j * entrylength:(j + 1) * entrylength]) for j in range(n_entries) ] start_line = i + start_line + 1 #linear grid of psi, on which all 1D fields are defined linpsi_lowres = linspace(psiax_lowres, psisep_lowres, nw_lowres) #create rho_tor_lowres grid x_fine_lowres = linspace(psiax_lowres, psisep_lowres, nw_lowres * 10) phi_fine_lowres = empty((nw_lowres * 10), dtype=float) phi_fine_lowres[0] = 0. #spline of q for rhotor grid interpol_order = 3 q_spl_psi_lowres = US(linpsi_lowres, qpsi_lowres, k=interpol_order, s=1e-5) for i in range(1, nw_lowres * 10): x = x_fine_lowres[:i + 1] y = q_spl_psi_lowres(x) phi_fine_lowres[i] = trapz(y, x) rho_tor_fine_lowres = sqrt(phi_fine_lowres / phi_fine_lowres[-1]) rho_tor_spl_lowres = US(x_fine_lowres, rho_tor_fine_lowres, k=interpol_order, s=1e-5) rho_tor_lowres = empty(nw_lowres, dtype=float) for i in range(nw_lowres): rho_tor_lowres[i] = rho_tor_spl_lowres(linpsi_lowres[i]) rho_pol_fine_lowres = np.zeros(len(x_fine_lowres))
n_entries = len(eqdsk[i + start_line]) / entrylength qpsi[i * 5:i * 5 + n_entries] = [ float(eqdsk[i + start_line][j * entrylength:(j + 1) * entrylength]) for j in range(n_entries) ] start_line = i + start_line + 1 #linear grid of psi, on which all 1D fields are defined linpsi = linspace(psiax, psisep, nw) #create rho_tor grid x_fine = linspace(psiax, psisep, nw * 10) phi_fine = empty((nw * 10), dtype=float) phi_fine[0] = 0. #spline of q for rhotor grid interpol_order = 3 q_spl_psi = US(linpsi, qpsi, k=interpol_order, s=1e-5) for i in range(1, nw * 10): x = x_fine[:i + 1] y = q_spl_psi(x) phi_fine[i] = trapz(y, x) rho_tor_fine = sqrt(phi_fine / phi_fine[-1]) rho_tor_spl = US(x_fine, rho_tor_fine, k=interpol_order, s=1e-5) rho_tor = empty(nw, dtype=float) for i in range(nw): rho_tor[i] = rho_tor_spl(linpsi[i]) rho_pol_fine = np.zeros(len(x_fine)) for i in range(len(x_fine)): rho_pol_fine[i] = sqrt((x_fine[i] - psiax) / (psisep - psiax))
def model_read(fname,LOGGS,IntInds): '''Routine to read in the YREC models and create a coarser grid. fname = the location of the YREC track. LOGGS = every logg value where a grid point is desired. IntInds = all of the indices in the YREC file that we wish to capure. ''' ## Collect the rows that we want to use for our downsampled grid. logg_is = find_loggs(fname,LOGGS) ## Some models will be empty...for some reason. If you encounter this, just ## return a string, which will be be interpreted as "do not make model." if len(logg_is) == 0: return 'fail!' ## Make a vector for saving active values. active = [] ## Create empty vectors to save the interpolation products. TEFFS = [] for II in IntInds: vars()['ALL_'+str(II[0])+'_'+str(II[1])] = [] ## Run back through the file to collect the desired rows. In actuality, ## we will read the four rows surrounded the desired logg point and ## interpolate cubically between them. with open(fname) as f: for j, line in enumerate(f): ## First check if any new triggers have gone off. if j+2 in logg_is: ## yes!! ## Collect the index of this number. k = str(logg_is.index(j+2)) ## Make the new storage vectors for logg, teff, and others. vars()['gravs_'+k] = [] vars()['teffs_'+k] = [] for II in IntInds: vars()[str(II[0])+'_'+str(II[1])+'_'+k] = [] ## Make this index active. active.append(k) ## Check if any counters have reached 0. If so, do the ## interpolation, and save the results. if j-2 in logg_is: ## Determine how many points can be interpolated ## from this vector. k = str(logg_is.index(j-2)) num = logg_is.count(j-2) ## Do the interpolation for each in turn. for n in xrange(num): ## Collect the vectors. gravs = vars()['gravs_'+k][::-1] teffs = vars()['teffs_'+k][::-1] ## Interpolate to Teff. Make sure to use LOGGS[k+n], to ## account for the possibility of multiple interpolations ## with the same vectors. TEFF = US(gravs[::-1],teffs[::-1],k=3,s=0)(LOGGS[int(k)+n]) TEFFS.append(10.**float(TEFF)) ## Interpolate to the other variables. for II in IntInds: vect = vars()[str(II[0])+'_'+str(II[1])+'_'+k][::-1] #print IntInds.index(II), gravs,vect Val = US(gravs,vect,k=3,s=0)(LOGGS[int(k)+n]) vars()['ALL_'+str(II[0])+'_'+str(II[1])].append(float(Val)) ## Make this index inactive. del active[active.index(k)] ## Check if we have any active indicies. If so, read the ## values out of the line, and same them to vectors. if len(active) > 0: for k in active: vars()['gravs_'+k].append(float(line[67:81])) vars()['teffs_'+k].append(float(line[83:97])) for II in IntInds: i1, i2 = II[0], II[1] name = str(i1)+'_'+str(i2)+'_'+k vars()[name].append(float(line[i1:i2])) ## Check if we've reached the end. If so, quit. if len(TEFFS) == len(logg_is): break ## Return a vector of vectors. AllReturn = [] AllReturn.append(TEFFS) for II in IntInds: VECT = vars()['ALL_'+str(II[0])+'_'+str(II[1])] AllReturn.append(VECT) return AllReturn
R_ped = interp(psip_n_obmp, R_obmp, psi_ped) Bp_ped = interp(psip_n_obmp, B_pol, psi_ped) omega_tor = Er_ped / R_ped / Bp_ped rhot_ped = rho_tor_spl(psi_ped * (psisep - psiax) + psiax) omega_tor_full = interp(rhot_ped, omega_tor, rhot0) #plt.plot(rhot0,omega_tor_full,'+-',label='omega_tor') #plt.plot(rhot_ped,omega_tor,'+-',label='omega_tor_ped') #plt.legend(loc=2) #plt.grid() #plt.axis((0.95,1.,-1.5E5,100.)) #plt.show() rhot1 = np.linspace(rhot_ped[0], rhot_ped[-1], 300) omega_tor_spl = US(rhot_ped, omega_tor) q_ped = interp(psip_n, qpsi, psi_ped) te_ped = interp(psi0, te, psi_ped) q_rhot_spl = US(rhot_ped, q_ped) te_rhot_spl = US(rhot_ped, te_ped) omega_t = np.sqrt(te_rhot_spl(rhot1) * 1E3 * e / M) / a plt.plot(rhot1, omega_t, '+-', label='omega_t') plt.legend() plt.grid() plt.show() Er_rhot_spl = US(rhot_ped, Er_ped) Bt_ped = interp(psip_n_obmp, B_tor, psi_ped) B_ped = np.sqrt(Bt_ped**2 + Bp_ped**2) B_rhot_spl = US(rhot_ped, B_ped)
#spline hill climb algo import pymongo import numpy as np import datetime from scipy.interpolate import UnivariateSpline as US #database config settings connection = pymongo.MongoClient('localhost:27017') db = connection.StockMarketDB col = db.hourlyStatistics #this is where you select the table (to be redone) prices = [] time = [] for doc in col.find().sort('date', pymongo.ASCENDING): prices.append(doc['low']) time.append(doc['date']) xaxis = np.linspace(0, lin(time), 1) spl = US(time, prices) ##Useful loop for debugging #for i in range(1,len(prices)): # print(prices[i]) # print(timep[i])
def setup_xarray(scan_list, scan_list2, scan_range, scan_range2, log, log2, precis, precis2, scan_type): if scan_type == '1d': #for scanning a predefined list of numbers if scan_list != []: #interpolate to prescribed length l1_spl = US(range(len(scan_list)), scan_list) XARRAY = l1_spl(np.linspace(0, len(scan_list) - 1, precis)) X2ARRAY = None #for having a second simultaneously varying variable if scan_list2 != []: #interpolate to prescribed length l2_spl = US(scan_list, scan_list2) X2ARRAY = l2_spl(XARRAY) #log- or linearly spaced 1d scan if (scan_list == [] and scan_list2 == []): X2ARRAY = None #np.empty(1,dtype=np.float) if log: XARRAY = np.logspace(np.log10(scan_range[0]), np.log10(scan_range[1]), precis) else: XARRAY = np.linspace(scan_range[0], scan_range[1], precis) elif scan_type == '2d': #for scanning a predefined list of numbers if scan_list != []: #interpolate to prescribed length l1_spl = US(range(len(scan_list)), scan_list) XARRAY = np.tile( l1_spl(np.linspace(0, len(scan_list) - 1, precis)), precis).flatten() #for having a second simultaneously varying variable if scan_list2 != []: #interpolate to prescribed length l2_spl = US(scan_list, scan_list2) X2ARRAY = np.repeat(l2_spl(XARRAY), precis) else: exit('Error: need to specify two scan_lists for 2d scan!') #log- or linearly spaced 2d scan if (scan_list == [] and scan_list2 == []): if log: XARRAY = np.tile( np.logspace(np.log10(scan_range[0]), np.log10(scan_range[1]), precis), precis2).flatten() else: XARRAY = np.tile( np.linspace(scan_range[0], scan_range[1], precis), precis2).flatten() if log2: X2ARRAY = np.repeat( np.logspace(np.log10(scan_range2[0]), np.log10(scan_range2[1]), precis2), precis).flatten() else: X2ARRAY = np.repeat( np.linspace(scan_range2[0], scan_range2[1], precis2), precis).flatten() return XARRAY, X2ARRAY