-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsweep.py
265 lines (187 loc) · 8.18 KB
/
sweep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import sys
sys.path.append('/Users/natj/projects/arcmancer/lib/')
import pyarcmancer as pyac
from img import Imgplane
from visualize_polar import Visualize
from lineprofile import *
import units
import numpy as np
import matplotlib as mpl
from pylab import *
import os
from matplotlib import cm
import scipy.interpolate as interp
#from joblib import Parallel, delayed
#import multiprocessing
outdir = 'out/lines2/'
##################################################
# Set up figure & layout
fig = figure(figsize=(6,10))
mpl.rc('font', family='serif')
mpl.rc('xtick', labelsize='x-small')
mpl.rc('ytick', labelsize='x-small')
mpl.rcParams['image.cmap'] = 'inferno'
#num_cores = multiprocessing.cpu_count()
#print "num of cores {}", num_cores
#Setup pyarcmancer
##################################################
conf = pyac.Configuration()
conf.absolute_tolerance = 1e-12
conf.relative_tolerance = 1e-12
conf.henon_tolerance = 1e-8
conf.sampling_interval = 1e-3
conf.minimum_stepsize = 1e-10
conf.maximum_steps = 10000
conf.enforce_maximum_stepsize = False
conf.enforce_minimum_stepsize = True
conf.enforce_maximum_steps = True
conf.store_only_endpoints = True
#pyac.Log.set_console()
pyac.Log.set_file()
##################################################
# Star parameters
#R = 12.0
#M = 1.6
freq = 700.0
#incl = 15.0
#for M in [1.5, 1.1, 1.8]:
for M in [1.4]:
print "##################################################"
print "M = ", M
for R in [10.0]:
print "##################################################"
print " R = ", R
#for incl in [90, 80, 70, 60, 50, 40, 30, 20, 15, 10, 5, 1]:
#for incl in [9, 8, 7, 6, 4, 3, 2, 0.5]:
for incl in [20.0]:
print "##################################################"
print " i = ",incl
fname = 'neutronstar_f{:03d}_bb_r{:02d}_m{:03.1f}_i{:02d}.png'.format( np.int(freq), np.int(R), M, np.int(incl))
if os.path.isfile( outdir+fname ):
continue
# Variables in units of solar mass are derived here
# and typically presented with full name
mass = M
radius = R * units.solar_mass_per_km / mass
angvel = freq * 2.0*np.pi / units.solar_mass_per_s * mass
imgscale = (mass/units.solar_mass_per_km*1.0e5)**2 #cm^2/Msun
compactness = np.sqrt(1 - 2/radius) #isotropic radius compactness
conf.absolute_tolerance = 1e-12 * radius
conf.minimum_stepsize = 1e-10 * radius
##################################################
#Define metric and surfaces of the spacetime
#S+D
metric = pyac.AGMMetric(radius, 1.0, angvel, pyac.AGMMetric.MetricType.agm_no_quadrupole)
ns_surface = pyac.AGMSurface(radius, 1.0, angvel, pyac.AGMSurface.SurfaceType.spherical)
#Oblate Sch #WORKS
#metric = pyac.AGMMetric(radius, 1.0, angvel, pyac.AGMMetric.MetricType.agm_no_quadrupole)
#ns_surface = pyac.AGMSurface(radius, 1.0, angvel, pyac.AGMSurface.SurfaceType.agm_no_quadrupole)
#Full AGM + oblate
#metric = pyac.AGMMetric(radius, 1.0, angvel, pyac.AGMMetric.MetricType.agm_standard)
#ns_surface = pyac.AGMSurface(radius, 1.0, angvel, pyac.AGMSurface.SurfaceType.agm)
surfaces = [ ns_surface ]
# Build and configure image plane by hand
img = Imgplane(conf, metric, surfaces)
img.verbose = 1
img.incl = np.deg2rad(incl) #set inclination
img.distance = 100000.0*mass #set distance
#Locate star edges
img.find_boundaries(Nedge=50, reltol=1.0e-4, max_iterations=30)
#Build internal coarse grid for the interpolation routines
img.generate_internal_grid(Nrad = 80, Nchi = 50 )
img.dissect_geos()
#Construct output xy image plane from img object
##################################################
ion()
visz = Visualize()
visz.gs.update(hspace = 0.5)
visz.compactness = compactness
visz.plot(img)
#prepare line profile axis object
visz.axs[6] = subplot( visz.gs[3,:] )
visz.axs[6].minorticks_on()
visz.axs[6].set_xlabel(r'Energy')
visz.axs[6].set_ylabel(r'Flux')
#Construct image
#visz.star(img, spot)
#visz.polar(img, spot)
visz.dissect(img)
visz.star_plot(0.0)
visz.polar_dissect(img)
visz.polar_plot(0.0)
##################################################
# Compute line profile
es, yy2 = lineprofile(visz.redshift**4, visz.redshift)
dE = np.max( np.abs(es[0] - compactness), np.abs(compactness - es[-1]))
##################################################
#Save redshift into a file
fname = 'reds_f{:03d}_bb_r{:02d}_m{:03.1f}_i{:02d}.csv'.format(
np.int(freq),
np.int(R),
M,
np.int(incl),
)
print 'Saving to a file: '+fname
np.savetxt(outdir+fname,
visz.redshift.flatten(),
delimiter=',',
fmt = '%10.9e'
)
#Save thetas into a file
fname = 'thetas_f{:03d}_bb_r{:02d}_m{:03.1f}_i{:02d}.csv'.format(
np.int(freq),
np.int(R),
M,
np.int(incl),
)
print 'Saving to a file: '+fname
np.savetxt(outdir+fname,
visz.thetas.flatten(),
delimiter=',',
fmt = '%10.9e'
)
#Save phi into a file
fname = 'phis_f{:03d}_bb_r{:02d}_m{:03.1f}_i{:02d}.csv'.format(
np.int(freq),
np.int(R),
M,
np.int(incl),
)
print 'Saving to a file: '+fname
np.savetxt(outdir+fname,
visz.phis.flatten(),
delimiter=',',
fmt = '%10.9e'
)
#redshift limits
vmin = compactness - dE
vmax = compactness + dE
# Line profile
##################################################
#ax = subplot(gs[2,2])
#ax.set_xlim(0.8, 1.2)
visz.axs[6].plot(es, yy2, "b-")
pause(1.0)
fname = 'neutronstar_f{:03d}_bb_r{:02d}_m{:03.1f}_i{:02d}.png'.format(
np.int(freq),
np.int(R),
M,
np.int(incl),
)
savefig(outdir+fname)
#save lineprofile
##################################################
#Finally save to file
fname = 'lineprofile_f{:03d}_bb_r{:02d}_m{:03.1f}_i{:02d}.csv'.format(
np.int(freq),
np.int(R),
M,
np.int(incl),
)
print 'Saving to a file: '+fname
np.savetxt(outdir+fname,
np.vstack((es, yy2)).T,
delimiter=',',
fmt = '%10.9e',
header='Energy, pdf'
)