def __init__(self, net, logger=None): super(pol_net, self).__init__() if logger is None: self.logger = get_logger('.log.txt') else: self.logger = logger self.net = net self.gamma = 1.0 self.lr = 0.001 ### HOW LONG ARE WE TRAINING FOR !!!!! CHANGE HERE DON'T HARDCODE ### self.num_trainings = 10 self.num_epochs = 15 self.num_batches = 10000 self.initialize_lstm() self.linear = nn.Linear(self.lstm_hidden_size, 1, bias=False) with torch.no_grad(): self.linear.weight.data.fill_(-0.1) self.log_std = nn.Parameter(torch.empty(1).fill_(-2)) self.saved_log_probs = [] self.optimizer = torch.optim.Adam(self.parameters(), lr=self.lr) self.color = cm.cool( np.linspace( 0, 1, self.num_batches * self.num_trainings // self.net.plot_freq + 2))
plt.plot(data_N200mln["B"], data_N200mln["exactPrice"], color="orchid", label="Exact price", marker="x", linewidth=1) plt.xlabel("$B$") plt.ylabel("Estimated Monte Carlo exact price [EUR]") plt.grid() plt.savefig(outputDirectory + "OptionPriceVsB_PriceVsB_N200mln.pdf", bbox_inches='tight') plt.close() ## Plot exact errors vs. N in log-log scale colorlist = iter(cm.cool(np.linspace(0, 1, len(BValues)))) for selectedB in BValues: mask = (data["B"] == selectedB) maskeddata = data[mask] maskeddata.sort("N") currentcolor = next(colorlist) if ((selectedB > 0.25) & (selectedB < 5)): plt.plot(maskeddata["N"], maskeddata["exactError"], color=currentcolor, marker="", label="B = " + str(selectedB), linewidth=1) plt.xscale("log")
def hro(Imap, Qmap, Umap, steps=10, hsize=15, minI=0., outh=[0, 4, 9]): # Calculates the relative orientation angle between the density structures and the magnetic field. # INPUTS # Imap - Intensity or column density map # Qmap - Stokes Q map # Upam - Stokes U map sz = np.shape(Imap) phi = roangles(Imap, Qmap, Umap) hist, bin_edges = np.histogram(Imap[(Imap > minI).nonzero()], bins=100 * sz[0]) bin_centre = 0.5 * (bin_edges[0:np.size(bin_edges) - 1] + bin_edges[1:np.size(bin_edges)]) chist = np.cumsum(hist) pitch = np.max(chist) / float(steps) hsteps = pitch * np.arange(0, steps + 1, 1) Isteps = np.zeros(steps + 1) for i in range(0, np.size(Isteps) - 1): good = np.logical_and(chist > hsteps[i], chist < hsteps[i + 1]).nonzero() Isteps[i] = np.min(bin_centre[good]) Isteps[np.size(Isteps) - 1] = np.max(Imap) hros = np.zeros([steps, hsize]) Smap = 0. * Imap xi = np.zeros(steps) prs = np.zeros(steps) s_prs = np.zeros(steps) cdens = np.zeros(steps) for i in range(0, np.size(Isteps) - 1): good = np.logical_and(Imap > Isteps[i], Imap < Isteps[i + 1]).nonzero() hist, bin_edges = np.histogram((180 / np.pi) * phi[good], bins=hsize, range=(-90., 90.)) bin_centre = 0.5 * (bin_edges[0:np.size(bin_edges) - 1] + bin_edges[1:np.size(bin_edges)]) hros[i, :] = hist cdens[i] = np.mean([Isteps[i], Isteps[i + 1]]) Smap[good] = i xi[i] = roparameter(bin_centre, hist) TEMPprs, TEMPs_prs = projRS(phi[good]) prs[i] = TEMPprs s_prs[i] = TEMPs_prs print(i) outsteps = np.size(outh) color = iter(cm.cool(np.linspace(0, 1, outsteps))) fig = plt.figure() for i in range(0, outsteps): c = next(color) labeltext = "%.2f" % Isteps[outh[ i]] + r' < $N_{\rm H}/$cm$^{-2}$ < ' + "%.2f" % Isteps[outh[i] + 1] plt.plot(bin_centre, hros[outh[i], :], '-', linewidth=2, c=c, label=labeltext) #drawstyle plt.xlabel(r'cos($\phi$)') plt.legend() plt.show() # -------------------------------------------------------------- fig = plt.figure() plt.plot(cdens, xi, '-', linewidth=2, c='red') plt.axhline(y=0., c='k', ls='--') plt.xlabel(r'log$_{10}$ ($N_{\rm H}/$cm$^{-2}$)') plt.ylabel(r'$\zeta$') plt.show() # -------------------------------------------------------------- fig = plt.figure() plt.plot(cdens, prs, '-', linewidth=2, c='blue') plt.errorbar(cdens, prs, yerr=s_prs, c='blue', fmt='o') plt.axhline(y=0., c='k', ls='--') plt.xlabel(r'log$_{10}$ ($N_{\rm H}/$cm$^{-2}$)') plt.ylabel(r'$Z_{x}$') plt.show() return Isteps, xi
def hro3D(dens, Bx, By, Bz, steps=10, hsize=21, mind=0, outh=[0,4,9]): """ Calculate the histogram of relative orientations (HRO) in three-dimensional data. Parameters ---------- dens : ... Bx,y,z : ... steps : ... hsize : ... mind : ... outh : ... Returns ------- hro : ... cdens : ... zeta : ... """ cosphi=roangles3D(dens, Bx, By, Bz) dsteps=equibins(dens, steps=steps, mind=mind) hros = np.zeros([steps,hsize]) cdens = np.zeros(steps) xi = np.zeros(steps) scube = 0.*dens for i in range(0, np.size(dsteps)-1): good = np.logical_and(dens>dsteps[i],dens<dsteps[i+1]).nonzero() hist, bin_edges = np.histogram(cosphi[good], bins=hsize, range=(-1.,1.)) bin_centre = 0.5*(bin_edges[0:np.size(bin_edges)-1]+bin_edges[1:np.size(bin_edges)]) hros[i,:] = hist scube[good] = i cdens[i] = np.mean([dsteps[i],dsteps[i+1]]) xi[i] = roparameter(bin_centre, hist) outsteps = np.size(outh) color = iter(cm.cool(np.linspace(0, 1, outsteps))) fig = plt.figure() for i in range(0, outsteps): c = next(color) labeltext = str(dsteps[outh[i]])+' < n < '+str(dsteps[outh[i]+1]) plt.plot(bin_centre, hros[outh[i],:], '-', linewidth=2, c=c, label=labeltext) #drawstyle plt.xlabel(r'cos($\phi$)') plt.legend() plt.show() fig=plt.figure() plt.plot(cdens, xi, '-', linewidth=2, c=c) plt.axhline(y=0., c='k', ls='--') plt.xlabel(r'log$_{10}$ ($n_{\rm H}/$cm$^{-3}$)') plt.ylabel(r'$\zeta$') #plt.savefig(prefix + '-' + 'ROvsLogNH' + 'Thres' + "%d" % (thr) + '.png') plt.show() # Do you mean xi or zeta? #return hros, cdens, zeta return hros, cdens, xi
dec = np.arange(-80, 90, 20) dec = np.append(dec, np.floor(lat / 5.) * 5) dec = np.append(dec, np.floor(lat / 5.) * 5 - 5) dec = np.append(dec, np.floor(lat / 5.) * 5 - 10) dec = np.append(dec, np.floor(lat / 5.) * 5 - 15) dec = np.append(dec, np.ceil(lat / 5.) * 5) dec = np.append(dec, np.ceil(lat / 5.) * 5 + 5) dec = np.append(dec, np.ceil(lat / 5.) * 5 + 10) dec = np.append(dec, np.ceil(lat / 5.) * 5 + 15) dec = np.unique(dec) dec = dec[np.abs(dec) <= 90] # http://matplotlib.org/examples/color/ # colormaps_reference.html color = iter(cm.cool(np.linspace(0, 1, len(dec)))) ''' equations: http://www.gb.nrao.edu/~rcreager/GBTMetrology/ 140ft/l0058/gbtmemo52/memo52.html ''' # parallactic angle fig = plt.figure() ax = fig.add_subplot(1, 1, 1) for d in range(dec.size): p = np.arctan2(np.sin(ha*15.*d2r) , \ (np.tan(lat*d2r)*np.cos(dec[d]*d2r) - \ np.sin(dec[d]*d2r)*np.cos(ha*15.*d2r)))/d2r el = np.arcsin(np.sin(dec[d]*d2r)*\