MapLine 1.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.1
2
+ Name: MapLine
3
+ Version: 1.0.3
4
+ Summary: A Python implementation of the 3D emission line fitting code
5
+ Home-page: https://github.com/hjibarram/Map_line
6
+ Download-URL: https://github.com/hjibarram/Map_line/archive/refs/tags/v1.0.3.tar.gz
7
+ Author: hjibarram
8
+ Author-email: hjibarram@gmail.com
9
+ License: MIT
10
+ Keywords: galaxies
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: astropy
17
+ Requires-Dist: matplotlib
18
+ Requires-Dist: numpy
19
+ Requires-Dist: scipy
20
+ Requires-Dist: cloup
21
+
22
+ This is an empty readme file
@@ -0,0 +1,18 @@
1
+ README.md
2
+ setup.py
3
+ MapLine.egg-info/PKG-INFO
4
+ MapLine.egg-info/SOURCES.txt
5
+ MapLine.egg-info/dependency_links.txt
6
+ MapLine.egg-info/not-zip-safe
7
+ MapLine.egg-info/requires.txt
8
+ MapLine.egg-info/top_level.txt
9
+ MapLines/__init__.py
10
+ MapLines/common/__init__.py
11
+ MapLines/common/constants.py
12
+ MapLines/tools/__init__.py
13
+ MapLines/tools/line_fit.py
14
+ MapLines/tools/mcmc.py
15
+ MapLines/tools/models.py
16
+ MapLines/tools/priors.py
17
+ MapLines/tools/tools.py
18
+ bin/run_mapline
@@ -0,0 +1,5 @@
1
+ astropy
2
+ matplotlib
3
+ numpy
4
+ scipy
5
+ cloup
@@ -0,0 +1 @@
1
+ MapLines
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env python
2
+ # encoding: utf-8
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env python
2
+ # encoding: utf-8
@@ -0,0 +1,7 @@
1
+ import numpy as np
2
+ """This module contains definition of MapLine.common.constants to be used
3
+ globally across the MapLine modules
4
+ """
5
+
6
+ __version__ = 'MapLine v1.0.3'
7
+
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env python
2
+ # encoding: utf-8
@@ -0,0 +1,461 @@
1
+ #!/usr/bin/env python
2
+ import numpy as np
3
+ import MapLines.tools.models as mod
4
+ import MapLines.tools.mcmc as mcm
5
+ import MapLines.tools.tools as tol
6
+ import MapLines.tools.priors as pri
7
+ from astropy.io import fits
8
+ #from progressbar import ProgressBar
9
+ from astropy.io import fits
10
+ import os.path as ptt
11
+ import sys
12
+ from tqdm import tqdm
13
+
14
+ def line_fit(file1,file2,file3,file_out,file_out2,name_out2,z=0.05536,j_t=0,i_t=0,lA1=6450.0,lA2=6850.0,skew=False,error_c=True,test=False,plot_f=True,ncpu=10,pgr_bar=True,single=False,flux_f=1.0,erft=0.75,dv1t=200,sim=False,cont=False,hbfit=False):
15
+ [pdl_cube, hdr]=fits.getdata(file1, 0, header=True)
16
+ if error_c:
17
+ pdl_cubeE =fits.getdata(file1, 1, header=False)
18
+ pdl_cubeE=pdl_cubeE*flux_f*erft
19
+ nz,nx,ny=pdl_cube.shape
20
+ pdl_cube=pdl_cube*flux_f
21
+ if ptt.exists(file3):
22
+ mask =fits.getdata(file3, 0, header=False)
23
+ nxt,nyt=mask.shape
24
+ if nxt != nx and nyt != ny:
25
+ mask=np.zeros([nx,ny])
26
+ mask[:,:]=1
27
+ else:
28
+ mask=np.zeros([nx,ny])
29
+ mask[:,:]=1
30
+ crpix=hdr["CRPIX3"]
31
+ try:
32
+ cdelt=hdr["CD3_3"]
33
+ except:
34
+ cdelt=hdr["CDELT3"]
35
+ crval=hdr["CRVAL3"]
36
+ wave=crval+cdelt*(np.arange(nz)+1-crpix)
37
+ wave_f=wave/(1+z)
38
+ nw=np.where((wave_f >= lA1) & (wave_f <= lA2))[0]
39
+ wave_i=wave_f[nw]
40
+ model_all=np.zeros([len(nw),nx,ny])
41
+ model_Blue=np.zeros([len(nw),nx,ny])
42
+ model_Red=np.zeros([len(nw),nx,ny])
43
+ model_Broad=np.zeros([len(nw),nx,ny])
44
+ if single:
45
+ if cont:
46
+ if skew:
47
+ model_param=np.zeros([12,nx,ny])
48
+ else:
49
+ model_param=np.zeros([10,nx,ny])
50
+ else:
51
+ if skew:
52
+ model_param=np.zeros([11,nx,ny])
53
+ else:
54
+ model_param=np.zeros([9,nx,ny])
55
+ else:
56
+ if cont:
57
+ if skew:
58
+ model_param=np.zeros([17,nx,ny])
59
+ else:
60
+ model_param=np.zeros([15,nx,ny])
61
+ else:
62
+ if skew:
63
+ model_param=np.zeros([16,nx,ny])
64
+ else:
65
+ model_param=np.zeros([14,nx,ny])
66
+ model_param[:,:,:]=np.nan
67
+ Loiii1=4960.36
68
+ LnrHb=4862.68
69
+ Loiii2=5008.22
70
+ Lnii2=6585.278
71
+ LnrHa=6564.632
72
+ Lnii1=6549.859
73
+ if hbfit:
74
+ lfac12=3.0
75
+ L1wave=Loiii1
76
+ L2wave=Loiii2
77
+ LHwave=LnrHb
78
+ LHBwave=LnrHb
79
+ else:
80
+ lfac12=2.93
81
+ L1wave=Lnii1
82
+ L2wave=Lnii2
83
+ LHwave=LnrHa
84
+ LHBwave=LnrHa
85
+ hdr["CRVAL3"]=wave_i[0]
86
+ try:
87
+ hdr["CD3_3"]=cdelt
88
+ except:
89
+ hdr["CDELT3"]=cdelt/(1+z)
90
+ if pgr_bar:
91
+ pbar=tqdm(total=nx*ny)
92
+ for i in range(0, nx):
93
+ for j in range(0, ny):
94
+ val=mask[i,j]
95
+ #val=1
96
+ if test:
97
+ if j_t*i_t == 0:
98
+ j_t=int(ny/2)
99
+ i_t=int(nx/2)
100
+ i=i_t
101
+ j=j_t
102
+ print('testing spaxel '+str(i)+' , '+str(j))
103
+ if val == 1:
104
+ fluxt=pdl_cube[nw,i,j]
105
+ if error_c:
106
+ fluxtE=pdl_cubeE[nw,i,j]
107
+ else:
108
+ fluxtE=tol.step_vect(fluxt,sp=50)
109
+ if cont:
110
+ if hbfit:
111
+ nwt=np.where((wave_f[nw] >= 5035.0) & (wave_f[nw] <= 5055.0))[0]
112
+ else:
113
+ nwt=np.where((wave_f[nw] >= 6380.0) & (wave_f[nw] <= 6400.0))[0]
114
+ fluxpt=np.nanmean(fluxt[nwt])
115
+ fluxt=fluxt-fluxpt
116
+ if hbfit:
117
+ nwt=np.where((wave_f[nw] >= 4880.0) & (wave_f[nw] <= 4890.0))[0]
118
+ else:
119
+ nwt=np.where((wave_f[nw] >= 6569.0) & (wave_f[nw] <= 6572.0))[0]
120
+ fluxp=np.nanmean(fluxt[nwt])
121
+ fluxe_t=np.nanmean(fluxtE)
122
+ if fluxp < 0:
123
+ fluxp=0.0001
124
+ data = (fluxt, fluxtE, wave_i, L2wave, LHwave, L1wave, fluxp, dv1t, sim, lfac12, single, skew)
125
+ nwalkers=240
126
+ niter=1024
127
+ if single:
128
+ if skew:
129
+ initial = np.array([0.04, 0.09, -20.0, 150.0, 1000.0, fluxp, 0.0, 0.0, 0.0])
130
+ else:
131
+ initial = np.array([0.04, 0.09, -20.0, 150.0, 1000.0, fluxp, 0.0])
132
+ else:
133
+ if skew:
134
+ initial = np.array([0.04, 0.09, 6.0, -80.0, -500.0, 150.0, 1000.0, fluxp, 0.0, 0.0, 0.0])
135
+ else:
136
+ initial = np.array([0.04, 0.09, 6.0, -80.0, -500.0, 150.0, 1000.0, fluxp, 0.0])
137
+ ndim = len(initial)
138
+ p0 = [np.array(initial) + 1e-5 * np.random.randn(ndim) for i in range(nwalkers)]
139
+ if plot_f:
140
+ tim=True
141
+ else:
142
+ tim=False
143
+ sampler, pos, prob, state = mcm.mcmc(p0,nwalkers,niter,ndim,pri.lnprob_gauss_Lin,data,tim=tim,ncpu=ncpu)
144
+ samples = sampler.flatchain
145
+ theta_max = samples[np.argmax(sampler.flatlnprobability)]
146
+ if single:
147
+ if skew:
148
+ A1_f,A3_f,dv1_f,fwhm1_f,fwhm2_f,A7_f,dv3_f,alph1_f,alphB_f=theta_max
149
+ else:
150
+ A1_f,A3_f,dv1_f,fwhm1_f,fwhm2_f,A7_f,dv3_f=theta_max
151
+ model,m2B,mHB,m1B,mHBR=mod.line_model(theta_max, x=wave_i, xo1=L2wave, xo2=LHwave, xo3=L1wave, ret_com=True, lfac12=lfac12, single=single, skew=skew)
152
+ model_all[:,i,j]=model
153
+ model_Blue[:,i,j]=m2B+m1B+mHB
154
+ model_Broad[:,i,j]=mHBR
155
+ model_param[0,i,j]=A1_f
156
+ model_param[1,i,j]=A1_f/lfac12
157
+ model_param[2,i,j]=A3_f
158
+ model_param[3,i,j]=A7_f
159
+ model_param[4,i,j]=dv1_f
160
+ model_param[5,i,j]=dv3_f
161
+ model_param[6,i,j]=fwhm1_f
162
+ model_param[7,i,j]=fwhm2_f
163
+ model_param[8,i,j]=fluxe_t
164
+ if cont:
165
+ model_param[9,i,j]=fluxpt
166
+ ind=9
167
+ else:
168
+ ind=8
169
+ if skew:
170
+ model_param[ind+1,i,j]=alph1_f
171
+ model_param[ind+2,i,j]=alphB_f
172
+ else:
173
+ if skew:
174
+ A1_f,A3_f,fac_f,dv1_f,dv2_f,fwhm1_f,fwhm2_f,A7_f,dv3_f,alph1_f,alphB_f=theta_max
175
+ else:
176
+ A1_f,A3_f,fac_f,dv1_f,dv2_f,fwhm1_f,fwhm2_f,A7_f,dv3_f=theta_max
177
+ if dv2_f < dv1_f:
178
+ fac_f=1/fac_f
179
+ dt=np.copy(dv2_f)
180
+ dv2_f=np.copy(dv1_f)
181
+ dv1_f=dt
182
+ A1_f=A1_f*fac_f
183
+ A3_f=A3_f*fac_f
184
+ if skew:
185
+ theta_max=A1_f,A3_f,fac_f,dv1_f,dv2_f,fwhm1_f,fwhm2_f,A7_f,dv3_f,alph1_f,alphB_f
186
+ else:
187
+ theta_max=A1_f,A3_f,fac_f,dv1_f,dv2_f,fwhm1_f,fwhm2_f,A7_f,dv3_f
188
+ model,m2B,m2R,mHB,mHR,m1B,m1R,mHBR=mod.line_model(theta_max, x=wave_i, xo1=L2wave, xo2=LHwave, xo3=L1wave, ret_com=True, lfac12=lfac12, single=single, skew=skew)
189
+ model_all[:,i,j]=model
190
+ model_Blue[:,i,j]=m2B+m1B+mHB
191
+ model_Red[:,i,j]=m2R+m1R+mHR
192
+ model_Broad[:,i,j]=mHBR
193
+ model_param[0,i,j]=A1_f
194
+ model_param[1,i,j]=A1_f/lfac12
195
+ model_param[2,i,j]=A3_f
196
+ model_param[3,i,j]=A7_f
197
+ model_param[4,i,j]=fac_f
198
+ model_param[5,i,j]=A1_f/fac_f
199
+ model_param[6,i,j]=A1_f/fac_f/lfac12
200
+ model_param[7,i,j]=A3_f/fac_f
201
+ model_param[8,i,j]=dv1_f
202
+ model_param[9,i,j]=dv2_f
203
+ model_param[10,i,j]=dv3_f
204
+ model_param[11,i,j]=fwhm1_f
205
+ model_param[12,i,j]=fwhm2_f
206
+ model_param[13,i,j]=fluxe_t
207
+ if cont:
208
+ model_param[14,i,j]=fluxpt
209
+ ind=14
210
+ else:
211
+ ind=13
212
+ if skew:
213
+ model_param[ind+1,i,j]=alph1_f
214
+ model_param[ind+2,i,j]=alphB_f
215
+ if plot_f:
216
+ import matplotlib.pyplot as plt
217
+ fig = plt.figure(figsize=(7,5))
218
+ ax1 = fig.add_subplot(1,1,1)
219
+ ax1.plot(wave_i,fluxt,linewidth=1,color='black',label=r'Spectrum')
220
+ ax1.plot(wave_i,fluxtE,linewidth=0.5,color='grey',label=r'$1\sigma$ Error')
221
+ ax1.plot(wave_i,model,linewidth=1,color='green',label=r'Model')
222
+ if single:
223
+ if hbfit:
224
+ ax1.plot(wave_i,mHBR,linewidth=1,color='red',label=r'Hb_n_BR')
225
+ ax1.plot(wave_i,m2B,linewidth=1,color='blue',label=r'OIII_2_NR')
226
+ ax1.plot(wave_i,mHB,linewidth=1,color='blue',label=r'Hb_n_NR')
227
+ ax1.plot(wave_i,m1B,linewidth=1,color='blue',label=r'OIII_1_NR')
228
+ else:
229
+ ax1.plot(wave_i,mHBR,linewidth=1,color='red',label=r'Hb_n_BR')
230
+ ax1.plot(wave_i,m2B,linewidth=1,color='blue',label=r'NII_2_NR')
231
+ ax1.plot(wave_i,mHB,linewidth=1,color='blue',label=r'Ha_n_NR')
232
+ ax1.plot(wave_i,m1B,linewidth=1,color='blue',label=r'NII_1_NR')
233
+ else:
234
+ if hbfit:
235
+ ax1.plot(wave_i,mHBR,linewidth=1,color='red',label=r'Hb_n_BR')
236
+ ax1.plot(wave_i,m2B,linewidth=1,color='blue',label=r'OIII_2_b')
237
+ ax1.plot(wave_i,m2R,linewidth=1,color='red',label=r'OIII_2_r')
238
+ ax1.plot(wave_i,mHB,linewidth=1,color='blue',label=r'Hb_n_b')
239
+ ax1.plot(wave_i,mHR,linewidth=1,color='red',label=r'Hb_n_r')
240
+ ax1.plot(wave_i,m1B,linewidth=1,color='blue',label=r'OIII_1_b')
241
+ ax1.plot(wave_i,m1R,linewidth=1,color='red',label=r'OIII_1_r')
242
+ else:
243
+ ax1.plot(wave_i,mHBR,linewidth=1,color='red',label=r'Ha_n_BR')
244
+ ax1.plot(wave_i,m2B,linewidth=1,color='blue',label=r'NII_2_b')
245
+ ax1.plot(wave_i,m2R,linewidth=1,color='red',label=r'NII_2_r')
246
+ ax1.plot(wave_i,mHB,linewidth=1,color='blue',label=r'Ha_n_b')
247
+ ax1.plot(wave_i,mHR,linewidth=1,color='red',label=r'Ha_n_r')
248
+ ax1.plot(wave_i,m1B,linewidth=1,color='blue',label=r'NII_1_b')
249
+ ax1.plot(wave_i,m1R,linewidth=1,color='red',label=r'NII_1_r')
250
+ fontsize=14
251
+ ax1.set_title("Observed Spectrum Input",fontsize=fontsize)
252
+ ax1.set_xlabel(r'$\lambda$ ($\rm{\AA}$)',fontsize=fontsize)
253
+ ax1.set_ylabel(r'$f_\lambda$ (10$^{-16}$erg cm$^{-2}$ s$^{-1}$ $\rm{\AA}^{-1}$)',fontsize=fontsize)
254
+ ax1.legend(fontsize=fontsize)
255
+ plt.tight_layout()
256
+ plt.show()
257
+ if single:
258
+ if skew:
259
+ labels = ['A1','A3','dv1','FWHM_N',"FWHM_B","A7","dv3", "alph1", "alphB"]
260
+ else:
261
+ labels = ['A1','A3','dv1','FWHM_N',"FWHM_B","A7","dv3"]
262
+ if hbfit:
263
+ if skew:
264
+ labels2 = [r'$A_{OIII}$',r'$A_{H\beta}$',r'$\Delta v$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$',r'$\alpha_n$',r'$\alpha_b$']
265
+ else:
266
+ labels2 = [r'$A_{OIII}$',r'$A_{H\beta}$',r'$\Delta v$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$']
267
+ else:
268
+ if skew:
269
+ labels2 = [r'$A_{NII}$',r'$A_{H\alpha}$',r'$\Delta v$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$',r'$\alpha_n$',r'$\alpha_b$']
270
+ else:
271
+ labels2 = [r'$A_{NII}$',r'$A_{H\alpha}$',r'$\Delta v$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$']
272
+ else:
273
+ if skew:
274
+ labels = ['A1','A3','fac','dv1','dv2','FWHM',"FWHM_B","A7","dv3", "alph1", "alphB"]
275
+ else:
276
+ labels = ['A1','A3','fac','dv1','dv2','FWHM',"FWHM_B","A7","dv3"]
277
+ if hbfit:
278
+ if skew:
279
+ labels2 = [r'$A_{OIII,b}$',r'$A_{H\beta,b}$',r'$f_c$',r'$\Delta v_b$',r'$\Delta v_r$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$',r'$\alpha_n$',r'$\alpha_b$']
280
+ else:
281
+ labels2 = [r'$A_{OIII,b}$',r'$A_{H\beta,b}$',r'$f_c$',r'$\Delta v_b$',r'$\Delta v_r$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$']
282
+ else:
283
+ if skew:
284
+ labels2 = [r'$A_{NII,b}$',r'$A_{H\alpha,b}$',r'$f_c$',r'$\Delta v_b$',r'$\Delta v_r$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$',r'$\alpha_n$',r'$\alpha_b$']
285
+ else:
286
+ labels2 = [r'$A_{NII,b}$',r'$A_{H\alpha,b}$',r'$f_c$',r'$\Delta v_b$',r'$\Delta v_r$',r'$FWHM_n$',r'$FWHM_b$',r'$A_{b}$',r'$\Delta v_{br}$']
287
+ import corner
288
+ fig = corner.corner(samples[:,0:len(labels2)],show_titles=True,labels=labels2,plot_datapoints=True,quantiles=[0.16, 0.5, 0.84],title_kwargs={"fontsize": 12},label_kwargs={"fontsize": 16})
289
+ fig.set_size_inches(15.8*len(labels2)/8.0, 15.8*len(labels2)/8.0)
290
+ fig.savefig('corners_NAME.pdf'.replace('NAME',name_out2))
291
+
292
+
293
+ med_model, spread = mcm.sample_walkers(10, samples, x=wave_i, xo1=L2wave, xo2=LHwave, xo3=L1wave, single=single, lfac12=lfac12, skew=skew)
294
+
295
+
296
+ import matplotlib.pyplot as plt
297
+ fig = plt.figure(figsize=(6*1.5,3*1.5))
298
+ ax1 = fig.add_subplot(1,1,1)
299
+ #ax1.set_xlim(lA1,lA2)
300
+ ax1.plot(wave_i,fluxt,label='Input spectrum')
301
+ ax1.plot(wave_i,model,label='Highest Likelihood Model')
302
+ plt.ylabel(r'$Flux\ [10^{-16} erg/s/cm^2/\AA]$',fontsize=16)
303
+ plt.xlabel(r'$Wavelength\ [\AA]$',fontsize=16)
304
+ ax1.fill_between(wave_i,med_model-spread*50,med_model+spread*50,color='grey',alpha=0.5,label=r'$1\sigma$ Posterior Spread')
305
+ ax1.legend(fontsize=14)
306
+ plt.tight_layout()
307
+ plt.savefig('spectra_mod_NAME.pdf'.replace('NAME',name_out2))
308
+ #plt.show()
309
+ if pgr_bar == False:
310
+ if single:
311
+ if skew:
312
+ print("A1=",A1_f,"A3=",A3_f,"dv1=",dv1_f,"fwhm=",fwhm1_f,"fwhm2=",fwhm2_f,"A7=",A7_f,"dv3=",dv3_f,"alph1=",alph1_f,"alphB=",alphB_f)
313
+ else:
314
+ print("A1=",A1_f,"A3=",A3_f,"dv1=",dv1_f,"fwhm=",fwhm1_f,"fwhm2=",fwhm2_f,"A7=",A7_f,"dv3=",dv3_f)
315
+ else:
316
+ if skew:
317
+ print("A1=",A1_f,"A3=",A3_f,"FAC=",fac_f,"dv1=",dv1_f,"dv2=",dv2_f,"fwhm=",fwhm1_f,"fwhm2=",fwhm2_f,"A7=",A7_f,"dv3=",dv3_f,"alph1=",alph1_f,"alphB=",alphB_f)
318
+ else:
319
+ print("A1=",A1_f,"A3=",A3_f,"FAC=",fac_f,"dv1=",dv1_f,"dv2=",dv2_f,"fwhm=",fwhm1_f,"fwhm2=",fwhm2_f,"A7=",A7_f,"dv3=",dv3_f)
320
+ if test:
321
+ sys.exit()
322
+ if pgr_bar:
323
+ pbar.update(1)
324
+
325
+ if single:
326
+ h1=fits.PrimaryHDU(model_all)
327
+ h2=fits.ImageHDU(model_Blue)
328
+ h4=fits.ImageHDU(model_Broad)
329
+ else:
330
+ h1=fits.PrimaryHDU(model_all)
331
+ h2=fits.ImageHDU(model_Blue)
332
+ h3=fits.ImageHDU(model_Red)
333
+ h4=fits.ImageHDU(model_Broad)
334
+ h_k=h1.header
335
+ keys=list(hdr.keys())
336
+ for i in range(0, len(keys)):
337
+ h_k[keys[i]]=hdr[keys[i]]
338
+ h_k.comments[keys[i]]=hdr.comments[keys[i]]
339
+ h_k['EXTNAME'] ='Model'
340
+ h_k.update()
341
+ if single:
342
+ h_t=h2.header
343
+ for i in range(0, len(keys)):
344
+ h_t[keys[i]]=hdr[keys[i]]
345
+ h_t.comments[keys[i]]=hdr.comments[keys[i]]
346
+ h_t['EXTNAME'] ='Narrow_Component'
347
+ h_t.update()
348
+ else:
349
+ h_t=h2.header
350
+ for i in range(0, len(keys)):
351
+ h_t[keys[i]]=hdr[keys[i]]
352
+ h_t.comments[keys[i]]=hdr.comments[keys[i]]
353
+ h_t['EXTNAME'] ='Blue_Component'
354
+ h_t.update()
355
+ h_r=h3.header
356
+ for i in range(0, len(keys)):
357
+ h_r[keys[i]]=hdr[keys[i]]
358
+ h_r.comments[keys[i]]=hdr.comments[keys[i]]
359
+ h_r['EXTNAME'] ='Red_Component'
360
+ h_r.update()
361
+ h_y=h4.header
362
+ for i in range(0, len(keys)):
363
+ h_y[keys[i]]=hdr[keys[i]]
364
+ h_y.comments[keys[i]]=hdr.comments[keys[i]]
365
+ h_y['EXTNAME'] ='Broad_Component'
366
+ h_y.update()
367
+ if single:
368
+ hlist=fits.HDUList([h1,h2,h4])
369
+ else:
370
+ hlist=fits.HDUList([h1,h2,h3,h4])
371
+ hlist.update_extend()
372
+ hlist.writeto(file_out+'.fits', overwrite=True)
373
+ tol.sycall('gzip -f '+file_out+'.fits')
374
+
375
+ h1=fits.PrimaryHDU(model_param)
376
+ h=h1.header
377
+ keys=list(hdr.keys())
378
+ for i in range(0, len(keys)):
379
+ if not "COMMENT" in keys[i] and not 'HISTORY' in keys[i]:
380
+ h[keys[i]]=hdr[keys[i]]
381
+ h.comments[keys[i]]=hdr.comments[keys[i]]
382
+ if single:
383
+ if hbfit:
384
+ h['Val_0'] ='OIII_5007_Amplitude'
385
+ h['Val_1'] ='OIII_4959Amplitude'
386
+ h['Val_2'] ='H_beta_Amplitude'
387
+ h['Val_3'] ='H_beta_Broad_Amplitude'
388
+ h['Val_4'] ='Narrow_vel'
389
+ h['Val_5'] ='Broad_vel'
390
+ h['Val_6'] ='FWHM_Narrow'
391
+ h['Val_7'] ='FWHM_Broad'
392
+ h['Val_8'] ='Noise_Median'
393
+ else:
394
+ h['Val_0'] ='NII_6585_Amplitude'
395
+ h['Val_1'] ='NII_6549_Amplitude'
396
+ h['Val_2'] ='H_alpha_Amplitude'
397
+ h['Val_3'] ='H_alpha_Broad_Amplitude'
398
+ h['Val_4'] ='Narrow_vel'
399
+ h['Val_5'] ='Broad_vel'
400
+ h['Val_6'] ='FWHM_Narrow'
401
+ h['Val_7'] ='FWHM_Broad'
402
+ h['Val_8'] ='Noise_Median'
403
+ if cont:
404
+ h['Val_9'] ='Continum'
405
+ ind=9
406
+ else:
407
+ ind=8
408
+ if skew:
409
+ h['Val_'+str(ind+1)]='Alpha_Narrow'
410
+ h['Val_'+str(ind+2)]='Alpha_Broad'
411
+ else:
412
+ if hbfit:
413
+ h['Val_0'] ='OIII_5007_Amplitude_blue'
414
+ h['Val_1'] ='OIII_4959_Amplitude_blue'
415
+ h['Val_2'] ='H_beta_Amplitude_blue'
416
+ h['Val_3'] ='H_beta_Broad_Amplitude'
417
+ h['Val_4'] ='Blue_Red_Factor'
418
+ h['Val_5'] ='NII_5007_Amplitude_red'
419
+ h['Val_6'] ='NII_4959_Amplitude_red'
420
+ h['Val_7'] ='H_beta_Amplitude_red'
421
+ h['Val_8'] ='Blue_vel'
422
+ h['Val_9'] ='Red_vel'
423
+ h['Val_10'] ='Broad_vel'
424
+ h['Val_11'] ='FWHM_Narrow'
425
+ h['Val_12'] ='FWHM_Broad'
426
+ h['Val_13'] ='Noise_Median'
427
+ else:
428
+ h['Val_0'] ='NII_6585_Amplitude_blue'
429
+ h['Val_1'] ='NII_6549_Amplitude_blue'
430
+ h['Val_2'] ='H_alpha_Amplitude_blue'
431
+ h['Val_3'] ='H_alpha_Broad_Amplitude'
432
+ h['Val_4'] ='Blue_Red_Factor'
433
+ h['Val_5'] ='NII_6585_Amplitude_red'
434
+ h['Val_6'] ='NII_6549_Amplitude_red'
435
+ h['Val_7'] ='H_alpha_Amplitude_red'
436
+ h['Val_8'] ='Blue_vel'
437
+ h['Val_9'] ='Red_vel'
438
+ h['Val_10'] ='Broad_vel'
439
+ h['Val_11'] ='FWHM_Narrow'
440
+ h['Val_12'] ='FWHM_Broad'
441
+ h['Val_13'] ='Noise_Median'
442
+ if cont:
443
+ h['Val_14'] ='Continum'
444
+ ind=14
445
+ else:
446
+ ind=13
447
+ if skew:
448
+ h['Val_'+str(ind+1)]='Alpha_Narrow'
449
+ h['Val_'+str(ind+2)]='Alpha_Broad'
450
+ try:
451
+ del h['CRVAL3']
452
+ del h['CRPIX3']
453
+ del h['CDELT3']
454
+ except:
455
+ print('No vals')
456
+
457
+ h.update()
458
+ hlist=fits.HDUList([h1])
459
+ hlist.update_extend()
460
+ hlist.writeto(file_out2+'.fits', overwrite=True)
461
+ tol.sycall('gzip -f '+file_out2+'.fits')
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env python
2
+ import numpy as np
3
+ import emcee
4
+ import MapLines.tools.models as mod
5
+
6
+ def mcmc(p0,nwalkers,niter,ndim,lnprob,data,verbose=False,multi=True,tim=False,ncpu=10):
7
+ if tim:
8
+ import time
9
+ if multi:
10
+ from multiprocessing import Pool
11
+ from multiprocessing import cpu_count
12
+ ncput=cpu_count()
13
+ if ncpu > ncput:
14
+ ncpu=ncput
15
+ if ncpu == 0:
16
+ ncpu=None
17
+ with Pool(ncpu) as pool:
18
+ #with Pool() as pool:
19
+ sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, args=data,pool=pool)
20
+ if tim:
21
+ start = time.time()
22
+ if verbose:
23
+ print("Running burn-in...")
24
+ p0, _, _ = sampler.run_mcmc(p0, 1000)
25
+ sampler.reset()
26
+ if verbose:
27
+ print("Running production...")
28
+ pos, prob, state = sampler.run_mcmc(p0, niter)
29
+ if tim:
30
+ end = time.time()
31
+ multi_time = end - start
32
+ print("Multiprocessing took {0:.1f} seconds".format(multi_time))
33
+ else:
34
+ sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, args=data)
35
+ if tim:
36
+ start = time.time()
37
+ if verbose:
38
+ print("Running burn-in...")
39
+ p0, _, _ = sampler.run_mcmc(p0, 1000)
40
+ sampler.reset()
41
+ if verbose:
42
+ print("Running production...")
43
+ pos, prob, state = sampler.run_mcmc(p0, niter)
44
+ if tim:
45
+ end = time.time()
46
+ serial_time = end - start
47
+ print("Serial took {0:.1f} seconds".format(serial_time))
48
+ return sampler, pos, prob, state
49
+
50
+
51
+ def sample_walkers(nsamples,flattened_chain,x=0,xo1=0,xo2=0,xo3=0,single=False, lfac12=2.93, skew=False):
52
+ models = []
53
+ draw = np.floor(np.random.uniform(0,len(flattened_chain),size=nsamples)).astype(int)
54
+ thetas = flattened_chain[draw]
55
+ for i in thetas:
56
+ modt = mod.line_model(i, x=x, xo1=xo1, xo2=xo2, xo3=xo3, lfac12=lfac12, single=single, skew=skew)
57
+ models.append(modt)
58
+ spread = np.std(models,axis=0)
59
+ med_model = np.median(models,axis=0)
60
+ return med_model,spread
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env python
2
+ import MapLines.tools.tools as tol
3
+ import numpy as np
4
+
5
+ def emission_line_model(x, xo=0, A=1.0, dv=[0.0], fwhm=[200.0], fac=[0.7], alph=[0.0], skew=False):
6
+ ct=299792.458
7
+ model_out=[]
8
+ for i in range(len(dv)):
9
+ sigma=fwhm[i]/ct*xo/(2.0*np.sqrt(2.0*np.log(2.0)))
10
+ xm=xo*(1.0+dv[i]/ct)
11
+ if i > 0:
12
+ A1=A/fac[i-1]
13
+ else:
14
+ A1=A
15
+ if skew:
16
+ alp=alph[i]
17
+ model=tol.gauss_K(x,sigma=sigma,xo=xm,A1=A1,alp=alp)
18
+ else:
19
+ model=tol.gauss_M(x,sigma=sigma,xo=xm,A1=A1)
20
+ model_out.extend([model])
21
+ if len(model_out) == 1:
22
+ return model_out[0]
23
+ else:
24
+ return model_out
25
+
26
+
27
+ def line_model(theta, x=0, xo1=0, xo2=0, xo3=0 ,ret_com=False, lfac12=2.93, single=False, skew=False):
28
+ '''Model for the line complex'''
29
+
30
+ if single:
31
+ if skew:
32
+ A1,A3,dv1,fwhm1,fwhm2,A7,dv3,alp1,alpb=theta
33
+ alph=[alp1]
34
+ alphb=[alpb]
35
+ else:
36
+ A1,A3,dv1,fwhm1,fwhm2,A7,dv3=theta
37
+ alph=[0]
38
+ alphb=[0]
39
+ dv=[dv1]
40
+ dvb=[dv3]
41
+ fwhm=[fwhm1]
42
+ fwhmb=[fwhm2]
43
+ fact=[]
44
+ else:
45
+ if skew:
46
+ A1,A3,fac,dv1,dv2,fwhm1,fwhm2,A7,dv3,alp1,alpb=theta
47
+ alph=[alp1,alp1]
48
+ alphb=[alpb]
49
+ else:
50
+ A1,A3,fac,dv1,dv2,fwhm1,fwhm2,A7,dv3=theta
51
+ alph=[0]
52
+ alphb=[0]
53
+ dv=[dv1,dv2]
54
+ dvb=[dv3]
55
+ fwhm=[fwhm1,fwhm1]
56
+ fwhmb=[fwhm2]
57
+ fact=[fac]
58
+
59
+
60
+ A5=A1/lfac12
61
+ ModA=emission_line_model(x, xo=xo1, A=A1, dv=dv ,fwhm=fwhm, fac=fact, alph=alph, skew=skew)
62
+ ModH=emission_line_model(x, xo=xo2, A=A3, dv=dv, fwhm=fwhm, fac=fact, alph=alph, skew=skew)
63
+ ModB=emission_line_model(x, xo=xo3, A=A5, dv=dv, fwhm=fwhm, fac=fact, alph=alph, skew=skew)
64
+ ModHB=emission_line_model(x, xo=xo2, A=A7, dv=dvb, fwhm=fwhmb, alph=alphb, skew=skew)
65
+
66
+ lin=0
67
+ if single:
68
+ lin=ModA+ModH+ModB
69
+ else:
70
+ for i in range(len(ModA)):
71
+ lin=ModA[i]+ModH[i]+ModB[i]+lin
72
+ lin=lin+ModHB
73
+ outvect=[]
74
+ outvect.extend([lin])
75
+ if single:
76
+ outvect.extend([ModA])
77
+ outvect.extend([ModH])
78
+ outvect.extend([ModB])
79
+ outvect.extend([ModHB])
80
+ else:
81
+ for i in range(len(ModA)):
82
+ outvect.extend([ModA[i]])
83
+ for i in range(len(ModH)):
84
+ outvect.extend([ModH[i]])
85
+ for i in range(len(ModA)):
86
+ outvect.extend([ModB[i]])
87
+ outvect.extend([ModHB])
88
+
89
+ if ret_com:
90
+ return outvect
91
+ else:
92
+ return lin
93
+
94
+ '''
95
+ def line_model_s(theta, x=0, xo1=0, xo2=0, xo3=0 ,ret_com=False, lfac12=2.93):
96
+ A1,A3,dv1,fwhm1,fwhm2,A7,dv3=theta
97
+ ct=299792.458
98
+ sigma1=fwhm1/ct*xo1/(2.0*np.sqrt(2.0*np.log(2.0)))
99
+ xo_b=xo1*(1.0+dv1/ct)
100
+ Gb=tol.gauss_M(x,sigma=sigma1,xo=xo_b,A1=A1)
101
+
102
+ sigma2=fwhm1/ct*xo2/(2.0*np.sqrt(2.0*np.log(2.0)))
103
+ xo_b=xo2*(1.0+dv1/ct)
104
+ hGb=tol.gauss_M(x,sigma=sigma2,xo=xo_b,A1=A3)
105
+
106
+ sigma3=fwhm1/ct*xo3/(2.0*np.sqrt(2.0*np.log(2.0)))
107
+ xo_b=xo3*(1.0+dv1/ct)
108
+ A5=A1/lfac12
109
+ nGb=tol.gauss_M(x,sigma=sigma3,xo=xo_b,A1=A5)
110
+
111
+ sigma4=fwhm2/ct*xo2/(2.0*np.sqrt(2.0*np.log(2.0)))
112
+ xo=xo2*(1.0+dv3/ct)
113
+ hGbr=tol.gauss_M(x,sigma=sigma4,xo=xo,A1=A7)
114
+
115
+ lin=Gb+hGb+nGb+hGbr
116
+ if ret_com:
117
+ return lin,Gb,hGb,nGb,hGbr
118
+ else:
119
+ return lin
120
+ '''
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env python
2
+ import MapLines.tools.models as mod
3
+ import numpy as np
4
+ '''This module contains the functions to calculate the likelihood and prior of the models'''
5
+
6
+
7
+ def lnlike_gauss_Lin(theta, spec, specE , x, xo1, xo2, xo3, lfac12, single, skew):
8
+ '''This function calculates the likelihood of a double model for the spectrum'''
9
+ model=mod.line_model(theta, x=x, xo1=xo1, xo2=xo2, xo3=xo3, lfac12=lfac12, single=single, skew=skew)
10
+ LnLike = -0.5*np.nansum(((spec-model)/specE)**2.0)
11
+ return LnLike
12
+
13
+
14
+ def lnprior_gauss_Lin(theta,At=0.05,dv1t=200,sim=False, single=False, skew=False):
15
+ '''This function calculates the prior of a line model spectra'''
16
+ dv1i=-dv1t
17
+ dv1s=0.0
18
+ dv2i=0.0
19
+ dv2s=50.0
20
+ if sim:
21
+ dv1i=-dv1t
22
+ dv1s=dv1t
23
+ dv2i=-dv1t
24
+ dv2s=dv1t
25
+ dA=At*0.3
26
+ if At-dA < 0:
27
+ Am1=0.0
28
+ else:
29
+ Am1=At-dA
30
+ Am2=At+dA
31
+ if single:
32
+ if skew:
33
+ A1,A3,dv1,fwhm1,fwhm2,A7,dv3,alp1,alpb=theta
34
+ if ((A1 >= 0) and (A1 <=1.8)) and ((A3 >= 0) and (A3 <=0.8)) and ((A7 >= Am1) and (A7 < Am2)) and ((fwhm1 >= 100.0) and (fwhm1 <= 900.0)) and ((fwhm2 >= 700.0) and (fwhm2 <= 10500.0)) and ((dv1 >= dv1i) and (dv1 <= dv1s)) and ((dv3 >= -1000) and (dv3 <= 1000)) and ((alp1 >= -10) and (alp1 <= 10)) and ((alpb >= -10) and (alpb <= 10)):
35
+ return 0.0
36
+ else:
37
+ return -np.inf
38
+ else:
39
+ A1,A3,dv1,fwhm1,fwhm2,A7,dv3=theta
40
+ if ((A1 >= 0) and (A1 <=1.8)) and ((A3 >= 0) and (A3 <=0.8)) and ((A7 >= Am1) and (A7 < Am2)) and ((fwhm1 >= 100.0) and (fwhm1 <= 800.0)) and ((fwhm2 >= 700.0) and (fwhm2 <= 10500.0)) and ((dv1 >= dv1i) and (dv1 <= dv1s)) and ((dv3 >= -1000) and (dv3 <= 1000)):
41
+ return 0.0
42
+ else:
43
+ return -np.inf
44
+ else:
45
+ if skew:
46
+ A1,A3,fac,dv1,dv2,fwhm1,fwhm2,A7,dv3,alp1,alpb=theta
47
+ if ((A1 >= 0) and (A1 <=1.8)) and ((A3 >= 0) and (A3 <=0.8)) and ((fac >= 1.0) and (fac <=30.0)) and ((A7 >= Am1) and (A7 < Am2)) and ((fwhm1 >= 100.0) and (fwhm1 <= 800.0)) and ((fwhm2 >= 700.0) and (fwhm2 <= 10500.0)) and ((dv1 >= dv1i) and (dv1 <= dv1s)) and ((dv2 >= dv2i) and (dv2 <= dv2s)) and ((dv3 >= -1000) and (dv3 <= 1000)) and ((alp1 >= -10) and (alp1 <= 10)) and ((alpb >= -10) and (alpb <= 10)):
48
+ return 0.0
49
+ else:
50
+ return -np.inf
51
+ else:
52
+ A1,A3,fac,dv1,dv2,fwhm1,fwhm2,A7,dv3=theta
53
+ if ((A1 >= 0) and (A1 <=1.8)) and ((A3 >= 0) and (A3 <=0.8)) and ((fac >= 1.0) and (fac <=30.0)) and ((A7 >= Am1) and (A7 < Am2)) and ((fwhm1 >= 100.0) and (fwhm1 <= 800.0)) and ((fwhm2 >= 700.0) and (fwhm2 <= 10500.0)) and ((dv1 >= dv1i) and (dv1 <= dv1s)) and ((dv2 >= dv2i) and (dv2 <= dv2s)) and ((dv3 >= -1000) and (dv3 <= 1000)):
54
+ return 0.0
55
+ else:
56
+ return -np.inf
57
+
58
+ def lnprob_gauss_Lin(theta, spec, specE, x, xo1, xo2, xo3, At, dv1t, sim, lfac12, single, skew):
59
+ '''This function calculates the posterior of the double model for the spectrum'''
60
+ lp = lnprior_gauss_Lin(theta,At=At, dv1t=dv1t, sim=sim, single=single, skew=skew)
61
+ if not np.isfinite(lp):
62
+ return -np.inf
63
+ else:
64
+ return lp + lnlike_gauss_Lin(theta, spec, specE, x, xo1, xo2, xo3, lfac12, single, skew)
65
+
66
+
67
+ #def lnlike_gauss_Lin_s(theta, spec, specE , x, xo1, xo2, xo3, lfac12, single):
68
+ # '''This function calculates the likelihood of a single model for the spectrum'''
69
+ # model=mod.line_model(theta, x=x, xo1=xo1, xo2=xo2, xo3=xo3, lfac12=lfac12, single=single)
70
+ # LnLike = -0.5*np.nansum(((spec-model)/specE)**2.0)
71
+ # return LnLike
72
+
73
+ #def lnprior_gauss_Lin_s(theta,At=0.05,dv1t=200,sim=False, single=False):
74
+ # '''This function calculates the prior of a single model for the spectrum'''
75
+ # dv1i=-dv1t
76
+ # dv1s=0.0
77
+ # if sim:
78
+ # dv1i=-dv1t
79
+ # dv1s=dv1t
80
+ # dA=At*0.3
81
+ # if At-dA < 0:
82
+ # Am1=0.0
83
+ # else:
84
+ # Am1=At-dA
85
+ # Am2=At+dA
86
+ # A1,A3,dv1,fwhm1,fwhm2,A7,dv3=theta
87
+ # if ((A1 >= 0) and (A1 <=1.8)) and ((A3 >= 0) and (A3 <=0.8)) and ((A7 >= Am1) and (A7 < Am2)) and ((fwhm1 >= 100.0) and (fwhm1 <= 800.0)) and ((fwhm2 >= 700.0) and (fwhm2 <= 10500.0)) and ((dv1 >= dv1i) and (dv1 <= dv1s)) and ((dv3 >= -1000) and (dv3 <= 1000)):
88
+ # return 0.0
89
+ # else:
90
+ # return -np.inf
91
+
92
+
93
+ #def lnprob_gauss_Lin_s(theta, spec, specE, x, xo1, xo2, xo3, At, dv1t, sim, lfac12, single):
94
+ # '''This function calculates the posterior of the single model for the spectrum'''
95
+ # lp = lnprior_gauss_Lin(theta,At=At, dv1t=dv1t, sim=sim, single=single)
96
+ # if not np.isfinite(lp):
97
+ # return -np.inf
98
+ # else:
99
+ # return lp + lnlike_gauss_Lin(theta, spec, specE, x, xo1, xo2, xo3, lfac12, single)
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env python
2
+ import numpy as np
3
+ from scipy.ndimage import gaussian_filter1d as filt1d
4
+ import os
5
+ import os.path as ptt
6
+ from scipy.special import erf as errf
7
+
8
+
9
+ def wfits_ext(name,hlist):
10
+ sycall("rm "+name+'.gz')
11
+ if ptt.exists(name) == False:
12
+ hlist.writeto(name)
13
+ else:
14
+ name1=name.replace("\ "," ")
15
+ name1=name1.replace(" ","\ ")
16
+ sycall("rm "+name1)
17
+ hlist.writeto(name)
18
+
19
+ def sycall(comand):
20
+ linp=comand
21
+ os.system(comand)
22
+
23
+ def conv(xt,ke=2.5):
24
+ nsf=len(xt)
25
+ krn=ke
26
+ xf=filt1d(xt,ke)
27
+ return xf
28
+
29
+ def gauss_K(x,sigma=1.0,xo=0.0,A1=1.0,alp=0):
30
+ dt=alp/np.sqrt(np.abs(1+alp**2))
31
+ xot=xo-sigma*dt*np.sqrt(2/np.pi)
32
+ omega=np.sqrt(sigma**2.0/(1-2*dt**2/np.pi))
33
+ #omega=sigma
34
+ t=(x-xot)/omega
35
+ Phi=(1+errf(alp*t/np.sqrt(2.0)))
36
+ Ghi=np.exp(-0.5*t**2.0)
37
+ y=A1*Ghi*Phi
38
+ return y
39
+
40
+ def gauss_M(x,sigma=1.0,xo=0.0,A1=1.0):
41
+ y=A1*np.exp(-0.5*(x-xo)**2.0/sigma**2.0)
42
+ return y
43
+
44
+ def step_vect(fluxi,sp=20,pst=True,sigma=10):
45
+ flux_sm=conv(fluxi,ke=sigma)
46
+ flux=fluxi-flux_sm
47
+ nz=len(flux)
48
+ flux_t=np.copy(flux)
49
+ for i in range(0, nz):
50
+ i0=int(i-sp/2.0)
51
+ i1=int(i+sp/2.0)
52
+ if i1 > nz:
53
+ i1=nz
54
+ if i0 > nz:
55
+ i0=int(nz-sp)
56
+ if i0 < 0:
57
+ i0=0
58
+ if i1 < 0:
59
+ i1=sp
60
+ if pst:
61
+ lts=np.nanpercentile(flux[i0:i1],78)
62
+ lt0=np.nanpercentile(flux[i0:i1],50)
63
+ lti=np.nanpercentile(flux[i0:i1],22)
64
+ val=(np.abs(lts-lt0)+np.abs(lti-lt0))/2.0
65
+ flux_t[i]=val#mean
66
+ else:
67
+ flux_t[i]=np.nanstd(flux[i0:i1])
68
+ return flux_t
MapLine-1.0.3/PKG-INFO ADDED
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.1
2
+ Name: MapLine
3
+ Version: 1.0.3
4
+ Summary: A Python implementation of the 3D emission line fitting code
5
+ Home-page: https://github.com/hjibarram/Map_line
6
+ Download-URL: https://github.com/hjibarram/Map_line/archive/refs/tags/v1.0.3.tar.gz
7
+ Author: hjibarram
8
+ Author-email: hjibarram@gmail.com
9
+ License: MIT
10
+ Keywords: galaxies
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: astropy
17
+ Requires-Dist: matplotlib
18
+ Requires-Dist: numpy
19
+ Requires-Dist: scipy
20
+ Requires-Dist: cloup
21
+
22
+ This is an empty readme file
@@ -0,0 +1 @@
1
+ This is an empty readme file
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import click
4
+ import cloup
5
+ from cloup.constraints import mutually_exclusive, RequireExactly, IsSet, If
6
+ import numpy as np
7
+ import warnings
8
+ warnings.filterwarnings("ignore")
9
+ from MapLines.tools.line_fit import line_fit
10
+ import MapLines.tools.tools as tol
11
+ import os.path as ptt
12
+
13
+ @click.group('run_mapline', short_help='CLI for the emission line mapper')
14
+ def cli():
15
+ pass
16
+
17
+
18
+ @cloup.command(short_help='Run the emission line mapper')
19
+ @click.option('-n', '--name', type=str, help='name of the IFS cube')
20
+ @click.option('-o', '--name_out', type=str, default='None', help='name of the output files')
21
+ @click.option('-m', '--mask', type=str, default='test', help='name of the mask map')
22
+ @click.option('-p', '--path', type=str, default='', help='path to the data cubes')
23
+ @click.option('-y', '--path_out', type=str, default='outputs/', help='path of the output files')
24
+ @click.option('-c', '--ncpus', type=int, default=10, help='number of CPUs')
25
+ @click.option('-d', '--double', is_flag=True, default=False,help='flag to run double peak mode')
26
+ @click.option('-k', '--kskew', is_flag=True, default=False,help='flag to run skew line profile mode')
27
+ @click.option('-t', '--test', is_flag=True, default=False,help='flag to run the full analysis')
28
+ @click.option('-e', '--error', is_flag=True, default=False,help='flag to run autocalculate the error vector')
29
+ @click.option('-z', '--zt', type=float, default=0, help='redshift of the object')
30
+ @click.option('-r', '--rvel', type=float, default=500.0, help='velocity shift range')
31
+ @click.option('-b', '--bcont', is_flag=True, default=False,help='flag to run deactivate autosubstract continum')
32
+ @click.option('-s', '--sprogressd', is_flag=True, default=False,help='deactivate the progress bar')
33
+ @click.option('-i', '--it', type=int, default=0, help='i index for test, default nx/2')
34
+ @click.option('-j', '--jt', type=int, default=0, help='j index for test, default ny/2')
35
+ @click.option('-h', '--hbet', is_flag=True, default=False,help='fit the hb region')
36
+
37
+ def run(name,mask,path,path_out,zt,rvel,ncpus,test,error,double,bcont,it,jt,sprogressd,hbet,name_out,kskew):
38
+
39
+
40
+ if name_out == 'None':
41
+ name_out=name
42
+
43
+ if test:
44
+ pgr_bar=False
45
+ plot_f=True
46
+ else:
47
+ plot_f=False
48
+ if sprogressd:
49
+ pgr_bar=False
50
+ else:
51
+ pgr_bar=True
52
+ if bcont:
53
+ cont=False
54
+ else:
55
+ cont=True
56
+ if double:
57
+ lab='_double'
58
+ single=False
59
+ else:
60
+ lab='_single'
61
+ single=True
62
+ if error:
63
+ error_c=False
64
+ else:
65
+ error_c=True
66
+ if hbet:
67
+ lA1=4700.0
68
+ lA2=5050.0
69
+ lbh='_hb'
70
+ hbfit=True
71
+ else:
72
+ lA1=6350.0
73
+ lA2=6850.0
74
+ lbh='_ha'
75
+ hbfit=False
76
+ if kskew:
77
+ skew=True
78
+ skl='_skew'
79
+ else:
80
+ skew=False
81
+ skl=''
82
+
83
+ dirt=path
84
+ dir_out=path_out
85
+ file1=dirt+'NAME.fits.gz'.replace('NAME',name)
86
+ file2=dirt+'NAME.fits.gz'.replace('NAME',name)
87
+ file3=dirt+'NAMEM.fits.gz'.replace('NAMEM',mask)
88
+ if ptt.exists(dir_out) == False:
89
+ tol.sycall('mkdir -p '+dir_out)
90
+ file_out=dir_out+'NAME_modelsV2'.replace('NAME',name_out)+lab+lbh+skl
91
+ file_out2=dir_out+'NAME_paramV2'.replace('NAME',name_out)+lab+lbh+skl
92
+ name_out2=name_out+lab+lbh+skl
93
+ line_fit(file1,file2,file3,file_out,file_out2,name_out2,z=zt,lA1=lA1,lA2=lA2,plot_f=plot_f,pgr_bar=pgr_bar,ncpu=ncpus,
94
+ single=single,skew=skew,flux_f=1.0,erft=0.75,dv1t=rvel,sim=True,cont=cont,hbfit=hbfit,test=test,error_c=error_c,i_t=it,j_t=jt)
95
+
96
+ cli.add_command(run)
97
+
98
+
99
+ if __name__ == "__main__":
100
+ cli()
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
MapLine-1.0.3/setup.py ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env python
2
+ import os
3
+ from setuptools import setup, find_packages
4
+
5
+ def version(fn):
6
+ v = '1.0.1'
7
+ with open(fn, 'r') as f:
8
+ for l in f.readlines():
9
+ if '__version__' in l:
10
+ v = l.split('=')[-1].strip().replace("'", '').split(' ')[-1][1:]
11
+ return v
12
+
13
+ #def readme():
14
+ # with open('README.md') as f:
15
+ # return f.read()
16
+
17
+ requirements = [
18
+ 'astropy',#>=3.2.1',
19
+ 'matplotlib',#>=3.1.1',
20
+ 'numpy',#>=1.17.2',
21
+ 'scipy',#>=1.3.0',
22
+ 'cloup',
23
+ ]
24
+
25
+ DATA_DIRNAME = 'data'
26
+ SCRIPTS_DIRNAME = 'bin'
27
+ VERSION_FILE = 'MapLines/common/constants.py'
28
+
29
+ all_packages = find_packages()
30
+ packages_data = {
31
+ package: [f'{DATA_DIRNAME}/*']+[f'{os.path.join(DATA_DIRNAME, sub)}/*' for root, subs, files in os.walk(os.path.join(package, DATA_DIRNAME)) for sub in subs]
32
+ for package in all_packages if os.path.isdir(os.path.join(package, DATA_DIRNAME))
33
+ }
34
+ scripts = ["bin/run_mapline"]
35
+ # os.path.join(SCRIPTS_DIRNAME, script_name)
36
+ # for script_name in os.listdir(SCRIPTS_DIRNAME) if script_name.endswith('.py')
37
+ #]
38
+ version = version(VERSION_FILE)
39
+
40
+ setup(
41
+ name='MapLine',
42
+ version=version,
43
+ description='A Python implementation of the 3D emission line fitting code',
44
+ #long_description=readme(),
45
+ classifiers=[
46
+ 'Development Status :: 5 - Production/Stable',
47
+ 'License :: OSI Approved :: MIT License',
48
+ 'Programming Language :: Python :: 3.8',
49
+ 'Topic :: Scientific/Engineering :: Astronomy',
50
+ ],
51
+ keywords='galaxies',
52
+ url='https://github.com/hjibarram/Map_line',
53
+ download_url=f'https://github.com/hjibarram/Map_line/archive/refs/tags/v{version}.tar.gz',
54
+ author='hjibarram',
55
+ author_email='hjibarram@gmail.com',
56
+ license='MIT',
57
+ packages=all_packages,
58
+ setup_requires=['wheel'],
59
+ install_requires=requirements,
60
+ include_package_data=True,
61
+ package_data=packages_data,
62
+ scripts=scripts,
63
+ zip_safe=False,
64
+ test_suite='nose.collector',
65
+ tests_require=['nose'],
66
+ long_description=open('README.md').read(),
67
+ long_description_content_type='text/markdown',
68
+ )