-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
167 lines (113 loc) · 4.48 KB
/
main.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 16 17:41:02 2022
@author: nati
"""
# =============================================================================
# Importar paquetes
# =============================================================================
from astropy.io import fits
import numpy.ma as ma
import time
from aux.graf import graffit,param_plot,muplot
from bkg import bkg
from bkg.mask import masking
from phot import ellip1, inellip
from residue import model
from aux import isosave
import parameters as pmt
#%%
def main():
### open image
nfile_ref=pmt.fname['ref']['path']+'/'+pmt.fname['ref']['name']
with fits.open( nfile_ref, mode='readonly' ) as ref_hdu :
ref_data = ref_hdu[0].data
ref_hed = ref_hdu[0].header
grafs=[]
## set timer
st = time.time()
if pmt.bkg['bkg']==None: ### if there is no sky level,
cielo=bkg(ref_data) ### makes an estimation
else:
cielo=pmt.bkg['bkg'] ### or uses input
## masking
if pmt.mask['calc'] : ### makes a mask for other sources
aux_isolist,a,b= ellip1(ref_data,
pmt.ellipse_incial_0,
pmt.fit_ell_par_0)
grafs.append(a)
grafs.append(b)
## uses residue of 1st approx to detect sources
aux_model,aux_residual,a=model(ref_data,aux_isolist,cielo,save=False)
grafs.append(a)
## generates mask using the residual
ref_m,a=masking(ref_data,
aux_residual,
cielo,
nthr=pmt.mask['nthr'],
fwhm=pmt.mask['fwhm'],
sharp=pmt.mask['sharp'],
roundlim=pmt.mask['roundlim'],
threshold=pmt.mask['threshold'],
outf='mask.fits'
)
grafs.append(a)
else: ## given a .fits image that has a mask
with fits.open(pmt.mask['path']+'/'+pmt.mask['file'], mode='readonly') as mask_hdu :
mask_data = mask_hdu[0].data
# apply mask
ref_m = ma.masked_where(mask_data>0, ref_data, copy=True)
a = graffit(ref_m,cbar=True,title='Máscara dada por input')
grafs.append(a)
### do photometry
isolist,a,b = ellip1(ref_m,
pmt.ellipse_incial,
pmt.fit_ell_par)
grafs.append(a)
grafs.append(b)
# # # # # #
### shows reside of model
model_image,residual,a=model(ref_data,
isolist,
cielo,
pmt.guardar['residue'],
pmt.fname['out']['residue']['name'],
pmt.fname['out']['residue']['path'],
ref_hed)
grafs.append(a)
grafs2=[None,None]
if pmt.plots['param_plot']:
grafs2[0]= param_plot(isolist,
req=pmt.plots['req'],
n=pmt.plots['n_par'],
E=pmt.plots['E'],
arcmin=pmt.plots['arcmin'])
if pmt.plots['mu_plot'] :
grafs2[1]=muplot(isolist,
E = pmt.plots['E'],
texp = pmt.plots['texp'],
B = cielo,
mu0 = pmt.plots['mu0'],
n = pmt.plots['n_mu'],
arcmin = pmt.plots['arcmin'])
if pmt.guardar['save_iso']: ## save isophote list as file
isosave(isolist,
path=pmt.fname['out']['table']['path'],
namef=pmt.fname['out']['table']['name'])
et = time.time()
elapsed_time = et - st
print('Execution time:', time.strftime("%H:%M:%S", time.gmtime(elapsed_time)))
return(grafs,grafs2,cielo)
#%%
if __name__== "__main__":
main()
#%%
# =============================================================================
# hay algo malito aun,sospecho que la determinacion del bkg !
## si no, probar de nuevo jugando a dejar todo libre, o ++ step adentro?
# =============================================================================
# =============================================================================
# puede ser tamb que no logre enmascarar bien esa galaxia, entonces hayq ue
# probar con el segmentations de photutils !!
# =============================================================================