-
Notifications
You must be signed in to change notification settings - Fork 4
/
HST_stack_force_mean.query
208 lines (205 loc) · 19.4 KB
/
HST_stack_force_mean.query
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
/* Select only those sources with unique matches to HST data */
select c.class_star, c.mu_class, ot.objid, primaryDetection, nDetections, qualityFlag
into mydb.COSMOS_PS1_Xmatch_unique
from (select objid
from mydb.COSMOS_PS1_Xmatch
group by objid
having count(objid) = 1) s join mydb.COSMOS_PS1_Xmatch c on s.objid = c.objid
join objectthin ot on s.objid = ot.objid
order by objid
/* Get the whiteFlux Features */
select t.*,
(case when (soa.gPSFFlux > 0 AND soa.gApFlux > 0 AND soa.gKronFlux > 0)
then power(soa.gPSFFlux,3)/power(soa.gPSFFluxErr,2) else 0 end +
case when (soa.rPSFFlux > 0 AND soa.rApFlux > 0 AND soa.rKronFlux > 0)
then power(soa.rPSFFlux,3)/power(soa.rPSFFluxErr,2) else 0 end +
case when (soa.iPSFFlux > 0 AND soa.iApFlux > 0 AND soa.iKronFlux > 0)
then power(soa.iPSFFlux,3)/power(soa.iPSFFluxErr,2) else 0 end +
case when (soa.zPSFFlux > 0 AND soa.zApFlux > 0 AND soa.zKronFlux > 0)
then power(soa.zPSFFlux,3)/power(soa.zPSFFluxErr,2) else 0 end +
case when (soa.yPSFFlux > 0 AND soa.yApFlux > 0 AND soa.yKronFlux > 0)
then power(soa.yPSFFlux,3)/power(soa.yPSFFluxErr,2) else 0 end)/nullif(
case when (soa.gPSFFlux > 0 AND soa.gApFlux > 0 AND soa.gKronFlux > 0)
then power(soa.gPSFFlux,2)/power(soa.gPSFFluxErr,2) else 0 end +
case when (soa.rPSFFlux > 0 AND soa.rApFlux > 0 AND soa.rKronFlux > 0)
then power(soa.rPSFFlux,2)/power(soa.rPSFFluxErr,2) else 0 end +
case when (soa.iPSFFlux > 0 AND soa.iApFlux > 0 AND soa.iKronFlux > 0)
then power(soa.iPSFFlux,2)/power(soa.iPSFFluxErr,2) else 0 end +
case when (soa.zPSFFlux > 0 AND soa.zApFlux > 0 AND soa.zKronFlux > 0)
then power(soa.zPSFFlux,2)/power(soa.zPSFFluxErr,2) else 0 end +
case when (soa.yPSFFlux > 0 AND soa.yApFlux > 0 AND soa.yKronFlux > 0)
then power(soa.yPSFFlux,2)/power(soa.yPSFFluxErr,2) else 0 end, 0)
as wwPSFFlux,
(case when (soa.gPSFFlux > 0 AND soa.gApFlux > 0 AND soa.gKronFlux > 0)
then power(soa.gKronFlux,3)/power(soa.gKronFluxErr,2) else 0 end +
case when (soa.rPSFFlux > 0 AND soa.rApFlux > 0 AND soa.rKronFlux > 0)
then power(soa.rKronFlux,3)/power(soa.rKronFluxErr,2) else 0 end +
case when (soa.iPSFFlux > 0 AND soa.iApFlux > 0 AND soa.iKronFlux > 0)
then power(soa.iKronFlux,3)/power(soa.iKronFluxErr,2) else 0 end +
case when (soa.zPSFFlux > 0 AND soa.zApFlux > 0 AND soa.zKronFlux > 0)
then power(soa.zKronFlux,3)/power(soa.zKronFluxErr,2) else 0 end +
case when (soa.yPSFFlux > 0 AND soa.yApFlux > 0 AND soa.yKronFlux > 0)
then power(soa.yKronFlux,3)/power(soa.yKronFluxErr,2) else 0 end)/nullif(
case when (soa.gPSFFlux > 0 AND soa.gApFlux > 0 AND soa.gKronFlux > 0)
then power(soa.gKronFlux,2)/power(soa.gKronFluxErr,2) else 0 end +
case when (soa.rPSFFlux > 0 AND soa.rApFlux > 0 AND soa.rKronFlux > 0)
then power(soa.rKronFlux,2)/power(soa.rKronFluxErr,2) else 0 end +
case when (soa.iPSFFlux > 0 AND soa.iApFlux > 0 AND soa.iKronFlux > 0)
then power(soa.iKronFlux,2)/power(soa.iKronFluxErr,2) else 0 end +
case when (soa.zPSFFlux > 0 AND soa.zApFlux > 0 AND soa.zKronFlux > 0)
then power(soa.zKronFlux,2)/power(soa.zKronFluxErr,2) else 0 end +
case when (soa.yPSFFlux > 0 AND soa.yApFlux > 0 AND soa.yKronFlux > 0)
then power(soa.yKronFlux,2)/power(soa.yKronFluxErr,2) else 0 end, 0)
as wwKronFlux,
(case when (soa.gPSFFlux > 0 AND soa.gApFlux > 0 AND soa.gKronFlux > 0)
then power(soa.gApFlux,3)/power(soa.gPSFFluxErr,2) else 0 end +
case when (soa.rPSFFlux > 0 AND soa.rApFlux > 0 AND soa.rKronFlux > 0)
then power(soa.rApFlux,3)/power(soa.rPSFFluxErr,2) else 0 end +
case when (soa.iPSFFlux > 0 AND soa.iApFlux > 0 AND soa.iKronFlux > 0)
then power(soa.iApFlux,3)/power(soa.iPSFFluxErr,2) else 0 end +
case when (soa.zPSFFlux > 0 AND soa.zApFlux > 0 AND soa.zKronFlux > 0)
then power(soa.zApFlux,3)/power(soa.zPSFFluxErr,2) else 0 end +
case when (soa.yPSFFlux > 0 AND soa.yApFlux > 0 AND soa.yKronFlux > 0)
then power(soa.yApFlux,3)/power(soa.yPSFFluxErr,2) else 0 end)/nullif(
case when (soa.gPSFFlux > 0 AND soa.gApFlux > 0 AND soa.gKronFlux > 0)
then power(soa.gApFlux,2)/power(soa.gPSFFluxErr,2) else 0 end +
case when (soa.rPSFFlux > 0 AND soa.rApFlux > 0 AND soa.rKronFlux > 0)
then power(soa.rApFlux,2)/power(soa.rPSFFluxErr,2) else 0 end +
case when (soa.iPSFFlux > 0 AND soa.iApFlux > 0 AND soa.iKronFlux > 0)
then power(soa.iApFlux,2)/power(soa.iPSFFluxErr,2) else 0 end +
case when (soa.zPSFFlux > 0 AND soa.zApFlux > 0 AND soa.zKronFlux > 0)
then power(soa.zApFlux,2)/power(soa.zPSFFluxErr,2) else 0 end +
case when (soa.yPSFFlux > 0 AND soa.yApFlux > 0 AND soa.yKronFlux > 0)
then power(soa.yApFlux,2)/power(soa.yPSFFluxErr,2) else 0 end, 0)
as wwApFlux,
(case when (fmo.gFPSFFlux > 0 AND fmo.gFKronFlux > 0 AND fmo.gFPSFFluxErr > 0 AND fmo.gFKronFluxErr > 0 AND fmo.gFApFlux > 0 AND fmo.gFApFluxErr > 0)
then power(fmo.gFPSFFlux,3)/power(fmo.gFPSFFluxErr,2) else 0 end +
case when (fmo.rFPSFFlux > 0 AND fmo.rFKronFlux > 0 AND fmo.rFPSFFluxErr > 0 AND fmo.rFKronFluxErr > 0 AND fmo.rFApFlux > 0 AND fmo.rFApFluxErr > 0)
then power(fmo.rFPSFFlux,3)/power(fmo.rFPSFFluxErr,2) else 0 end +
case when (fmo.iFPSFFlux > 0 AND fmo.iFKronFlux > 0 AND fmo.iFPSFFluxErr > 0 AND fmo.iFKronFluxErr > 0 AND fmo.iFApFlux > 0 AND fmo.iFApFluxErr > 0)
then power(fmo.iFPSFFlux,3)/power(fmo.iFPSFFluxErr,2) else 0 end +
case when (fmo.zFPSFFlux > 0 AND fmo.zFKronFlux > 0 AND fmo.zFPSFFluxErr > 0 AND fmo.zFKronFluxErr > 0 AND fmo.zFApFlux > 0 AND fmo.zFApFluxErr > 0)
then power(fmo.zFPSFFlux,3)/power(fmo.zFPSFFluxErr,2) else 0 end +
case when (fmo.yFPSFFlux > 0 AND fmo.yFKronFlux > 0 AND fmo.yFPSFFluxErr > 0 AND fmo.yFKronFluxErr > 0 AND fmo.yFApFlux > 0 AND fmo.yFApFluxErr > 0)
then power(fmo.yFPSFFlux,3)/power(fmo.yFPSFFluxErr,2) else 0 end)/nullif(
case when (fmo.gFPSFFlux > 0 AND fmo.gFKronFlux > 0 AND fmo.gFPSFFluxErr > 0 AND fmo.gFKronFluxErr > 0 AND fmo.gFApFlux > 0 AND fmo.gFApFluxErr > 0)
then power(fmo.gFPSFFlux,2)/power(fmo.gFPSFFluxErr,2) else 0 end +
case when (fmo.rFPSFFlux > 0 AND fmo.rFKronFlux > 0 AND fmo.rFPSFFluxErr > 0 AND fmo.rFKronFluxErr > 0 AND fmo.rFApFlux > 0 AND fmo.rFApFluxErr > 0)
then power(fmo.rFPSFFlux,2)/power(fmo.rFPSFFluxErr,2) else 0 end +
case when (fmo.iFPSFFlux > 0 AND fmo.iFKronFlux > 0 AND fmo.iFPSFFluxErr > 0 AND fmo.iFKronFluxErr > 0 AND fmo.iFApFlux > 0 AND fmo.iFApFluxErr > 0)
then power(fmo.iFPSFFlux,2)/power(fmo.iFPSFFluxErr,2) else 0 end +
case when (fmo.zFPSFFlux > 0 AND fmo.zFKronFlux > 0 AND fmo.zFPSFFluxErr > 0 AND fmo.zFKronFluxErr > 0 AND fmo.zFApFlux > 0 AND fmo.zFApFluxErr > 0)
then power(fmo.zFPSFFlux,2)/power(fmo.zFPSFFluxErr,2) else 0 end +
case when (fmo.yFPSFFlux > 0 AND fmo.yFKronFlux > 0 AND fmo.yFPSFFluxErr > 0 AND fmo.yFKronFluxErr > 0 AND fmo.yFApFlux > 0 AND fmo.yFApFluxErr > 0)
then power(fmo.yFPSFFlux,2)/power(fmo.yFPSFFluxErr,2) else 0 end, 0)
as wwFPSFFlux,
(case when (fmo.gFPSFFlux > 0 AND fmo.gFKronFlux > 0 AND fmo.gFPSFFluxErr > 0 AND fmo.gFKronFluxErr > 0 AND fmo.gFApFlux > 0 AND fmo.gFApFluxErr > 0)
then power(fmo.gFKronFlux,3)/power(fmo.gFKronFluxErr,2) else 0 end +
case when (fmo.rFPSFFlux > 0 AND fmo.rFKronFlux > 0 AND fmo.rFPSFFluxErr > 0 AND fmo.rFKronFluxErr > 0 AND fmo.rFApFlux > 0 AND fmo.rFApFluxErr > 0)
then power(fmo.rFKronFlux,3)/power(fmo.rFKronFluxErr,2) else 0 end +
case when (fmo.iFPSFFlux > 0 AND fmo.iFKronFlux > 0 AND fmo.iFPSFFluxErr > 0 AND fmo.iFKronFluxErr > 0 AND fmo.iFApFlux > 0 AND fmo.iFApFluxErr > 0)
then power(fmo.iFKronFlux,3)/power(fmo.iFKronFluxErr,2) else 0 end +
case when (fmo.zFPSFFlux > 0 AND fmo.zFKronFlux > 0 AND fmo.zFPSFFluxErr > 0 AND fmo.zFKronFluxErr > 0 AND fmo.zFApFlux > 0 AND fmo.zFApFluxErr > 0)
then power(fmo.zFKronFlux,3)/power(fmo.zFKronFluxErr,2) else 0 end +
case when (fmo.yFPSFFlux > 0 AND fmo.yFKronFlux > 0 AND fmo.yFPSFFluxErr > 0 AND fmo.yFKronFluxErr > 0 AND fmo.yFApFlux > 0 AND fmo.yFApFluxErr > 0)
then power(fmo.yFKronFlux,3)/power(fmo.yFKronFluxErr,2) else 0 end)/nullif(
case when (fmo.gFPSFFlux > 0 AND fmo.gFKronFlux > 0 AND fmo.gFPSFFluxErr > 0 AND fmo.gFKronFluxErr > 0 AND fmo.gFApFlux > 0 AND fmo.gFApFluxErr > 0)
then power(fmo.gFKronFlux,2)/power(fmo.gFKronFluxErr,2) else 0 end +
case when (fmo.rFPSFFlux > 0 AND fmo.rFKronFlux > 0 AND fmo.rFPSFFluxErr > 0 AND fmo.rFKronFluxErr > 0 AND fmo.rFApFlux > 0 AND fmo.rFApFluxErr > 0)
then power(fmo.rFKronFlux,2)/power(fmo.rFKronFluxErr,2) else 0 end +
case when (fmo.iFPSFFlux > 0 AND fmo.iFKronFlux > 0 AND fmo.iFPSFFluxErr > 0 AND fmo.iFKronFluxErr > 0 AND fmo.iFApFlux > 0 AND fmo.iFApFluxErr > 0)
then power(fmo.iFKronFlux,2)/power(fmo.iFKronFluxErr,2) else 0 end +
case when (fmo.zFPSFFlux > 0 AND fmo.zFKronFlux > 0 AND fmo.zFPSFFluxErr > 0 AND fmo.zFKronFluxErr > 0 AND fmo.zFApFlux > 0 AND fmo.zFApFluxErr > 0)
then power(fmo.zFKronFlux,2)/power(fmo.zFKronFluxErr,2) else 0 end +
case when (fmo.yFPSFFlux > 0 AND fmo.yFKronFlux > 0 AND fmo.yFPSFFluxErr > 0 AND fmo.yFKronFluxErr > 0 AND fmo.yFApFlux > 0 AND fmo.yFApFluxErr > 0)
then power(fmo.yFKronFlux,2)/power(fmo.yFKronFluxErr,2) else 0 end, 0)
as wwFKronFlux,
(case when (fmo.gFPSFFlux > 0 AND fmo.gFKronFlux > 0 AND fmo.gFPSFFluxErr > 0 AND fmo.gFKronFluxErr > 0 AND fmo.gFApFlux > 0 AND fmo.gFApFluxErr > 0)
then power(fmo.gFApFlux,3)/power(fmo.gFPSFFluxErr,2) else 0 end +
case when (fmo.rFPSFFlux > 0 AND fmo.rFKronFlux > 0 AND fmo.rFPSFFluxErr > 0 AND fmo.rFKronFluxErr > 0 AND fmo.rFApFlux > 0 AND fmo.rFApFluxErr > 0)
then power(fmo.rFApFlux,3)/power(fmo.rFPSFFluxErr,2) else 0 end +
case when (fmo.iFPSFFlux > 0 AND fmo.iFKronFlux > 0 AND fmo.iFPSFFluxErr > 0 AND fmo.iFKronFluxErr > 0 AND fmo.iFApFlux > 0 AND fmo.iFApFluxErr > 0)
then power(fmo.iFApFlux,3)/power(fmo.iFPSFFluxErr,2) else 0 end +
case when (fmo.zFPSFFlux > 0 AND fmo.zFKronFlux > 0 AND fmo.zFPSFFluxErr > 0 AND fmo.zFKronFluxErr > 0 AND fmo.zFApFlux > 0 AND fmo.zFApFluxErr > 0)
then power(fmo.zFApFlux,3)/power(fmo.zFPSFFluxErr,2) else 0 end +
case when (fmo.yFPSFFlux > 0 AND fmo.yFKronFlux > 0 AND fmo.yFPSFFluxErr > 0 AND fmo.yFKronFluxErr > 0 AND fmo.yFApFlux > 0 AND fmo.yFApFluxErr > 0)
then power(fmo.yFApFlux,3)/power(fmo.yFPSFFluxErr,2) else 0 end)/nullif(
case when (fmo.gFPSFFlux > 0 AND fmo.gFKronFlux > 0 AND fmo.gFPSFFluxErr > 0 AND fmo.gFKronFluxErr > 0 AND fmo.gFApFlux > 0 AND fmo.gFApFluxErr > 0)
then power(fmo.gFApFlux,2)/power(fmo.gFPSFFluxErr,2) else 0 end +
case when (fmo.rFPSFFlux > 0 AND fmo.rFKronFlux > 0 AND fmo.rFPSFFluxErr > 0 AND fmo.rFKronFluxErr > 0 AND fmo.rFApFlux > 0 AND fmo.rFApFluxErr > 0)
then power(fmo.rFApFlux,2)/power(fmo.rFPSFFluxErr,2) else 0 end +
case when (fmo.iFPSFFlux > 0 AND fmo.iFKronFlux > 0 AND fmo.iFPSFFluxErr > 0 AND fmo.iFKronFluxErr > 0 AND fmo.iFApFlux > 0 AND fmo.iFApFluxErr > 0)
then power(fmo.iFApFlux,2)/power(fmo.iFPSFFluxErr,2) else 0 end +
case when (fmo.zFPSFFlux > 0 AND fmo.zFKronFlux > 0 AND fmo.zFPSFFluxErr > 0 AND fmo.zFKronFluxErr > 0 AND fmo.zFApFlux > 0 AND fmo.zFApFluxErr > 0)
then power(fmo.zFApFlux,2)/power(fmo.zFPSFFluxErr,2) else 0 end +
case when (fmo.yFPSFFlux > 0 AND fmo.yFKronFlux > 0 AND fmo.yFPSFFluxErr > 0 AND fmo.yFKronFluxErr > 0 AND fmo.yFApFlux > 0 AND fmo.yFApFluxErr > 0)
then power(fmo.yFApFlux,2)/power(fmo.yFPSFFluxErr,2) else 0 end, 0)
as wwFApFlux,
(case when (mo.gMeanPSFMag > 0 AND mo.gMeanKronMag > 0 AND mo.gMeanPSFMagErr > 0 AND mo.gMeanKronMagErr > 0 AND mo.gMeanApMag > 0 AND mo.gMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.gMeanPSFMag)*power(2.5/log(10)/mo.gMeanPSFMagErr,2) else 0 end +
case when (mo.rMeanPSFMag > 0 AND mo.rMeanKronMag > 0 AND mo.rMeanPSFMagErr > 0 AND mo.rMeanKronMagErr > 0 AND mo.rMeanApMag > 0 AND mo.rMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.rMeanPSFMag)*power(2.5/log(10)/mo.rMeanPSFMagErr,2) else 0 end +
case when (mo.iMeanPSFMag > 0 AND mo.iMeanKronMag > 0 AND mo.iMeanPSFMagErr > 0 AND mo.iMeanKronMagErr > 0 AND mo.iMeanApMag > 0 AND mo.iMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.iMeanPSFMag)*power(2.5/log(10)/mo.iMeanPSFMagErr,2) else 0 end +
case when (mo.zMeanPSFMag > 0 AND mo.zMeanKronMag > 0 AND mo.zMeanPSFMagErr > 0 AND mo.zMeanKronMagErr > 0 AND mo.zMeanApMag > 0 AND mo.zMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.zMeanPSFMag)*power(2.5/log(10)/mo.zMeanPSFMagErr,2) else 0 end +
case when (mo.yMeanPSFMag > 0 AND mo.yMeanKronMag > 0 AND mo.yMeanPSFMagErr > 0 AND mo.yMeanKronMagErr > 0 AND mo.yMeanApMag > 0 AND mo.yMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.yMeanPSFMag)*power(2.5/log(10)/mo.yMeanPSFMagErr,2) else 0 end)/nullif(
case when (mo.gMeanPSFMag > 0 AND mo.gMeanKronMag > 0 AND mo.gMeanPSFMagErr > 0 AND mo.gMeanKronMagErr > 0 AND mo.gMeanApMag > 0 AND mo.gMeanApMagErr > 0)
then power(2.5/log(10)/mo.gMeanPSFMagErr,2) else 0 end +
case when (mo.rMeanPSFMag > 0 AND mo.rMeanKronMag > 0 AND mo.rMeanPSFMagErr > 0 AND mo.rMeanKronMagErr > 0 AND mo.rMeanApMag > 0 AND mo.rMeanApMagErr > 0)
then power(2.5/log(10)/mo.rMeanPSFMagErr,2) else 0 end +
case when (mo.iMeanPSFMag > 0 AND mo.iMeanKronMag > 0 AND mo.iMeanPSFMagErr > 0 AND mo.iMeanKronMagErr > 0 AND mo.iMeanApMag > 0 AND mo.iMeanApMagErr > 0)
then power(2.5/log(10)/mo.iMeanPSFMagErr,2) else 0 end +
case when (mo.zMeanPSFMag > 0 AND mo.zMeanKronMag > 0 AND mo.zMeanPSFMagErr > 0 AND mo.zMeanKronMagErr > 0 AND mo.zMeanApMag > 0 AND mo.zMeanApMagErr > 0)
then power(2.5/log(10)/mo.zMeanPSFMagErr,2) else 0 end +
case when (mo.yMeanPSFMag > 0 AND mo.yMeanKronMag > 0 AND mo.yMeanPSFMagErr > 0 AND mo.yMeanKronMagErr > 0 AND mo.yMeanApMag > 0 AND mo.yMeanApMagErr > 0)
then power(2.5/log(10)/mo.yMeanPSFMagErr,2) else 0 end, 0)
as wwMeanPSFFlux,
(case when (mo.gMeanPSFMag > 0 AND mo.gMeanKronMag > 0 AND mo.gMeanPSFMagErr > 0 AND mo.gMeanKronMagErr > 0 AND mo.gMeanApMag > 0 AND mo.gMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.gMeanKronMag)*power(2.5/log(10)/mo.gMeanKronMagErr,2) else 0 end +
case when (mo.rMeanPSFMag > 0 AND mo.rMeanKronMag > 0 AND mo.rMeanPSFMagErr > 0 AND mo.rMeanKronMagErr > 0 AND mo.rMeanApMag > 0 AND mo.rMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.rMeanKronMag)*power(2.5/log(10)/mo.rMeanKronMagErr,2) else 0 end +
case when (mo.iMeanPSFMag > 0 AND mo.iMeanKronMag > 0 AND mo.iMeanPSFMagErr > 0 AND mo.iMeanKronMagErr > 0 AND mo.iMeanApMag > 0 AND mo.iMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.iMeanKronMag)*power(2.5/log(10)/mo.iMeanKronMagErr,2) else 0 end +
case when (mo.zMeanPSFMag > 0 AND mo.zMeanKronMag > 0 AND mo.zMeanPSFMagErr > 0 AND mo.zMeanKronMagErr > 0 AND mo.zMeanApMag > 0 AND mo.zMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.zMeanKronMag)*power(2.5/log(10)/mo.zMeanKronMagErr,2) else 0 end +
case when (mo.yMeanPSFMag > 0 AND mo.yMeanKronMag > 0 AND mo.yMeanPSFMagErr > 0 AND mo.yMeanKronMagErr > 0 AND mo.yMeanApMag > 0 AND mo.yMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.yMeanKronMag)*power(2.5/log(10)/mo.yMeanKronMagErr,2) else 0 end)/nullif(
case when (mo.gMeanPSFMag > 0 AND mo.gMeanKronMag > 0 AND mo.gMeanPSFMagErr > 0 AND mo.gMeanKronMagErr > 0 AND mo.gMeanApMag > 0 AND mo.gMeanApMagErr > 0)
then power(2.5/log(10)/mo.gMeanKronMagErr,2) else 0 end +
case when (mo.rMeanPSFMag > 0 AND mo.rMeanKronMag > 0 AND mo.rMeanPSFMagErr > 0 AND mo.rMeanKronMagErr > 0 AND mo.rMeanApMag > 0 AND mo.rMeanApMagErr > 0)
then power(2.5/log(10)/mo.rMeanKronMagErr,2) else 0 end +
case when (mo.iMeanPSFMag > 0 AND mo.iMeanKronMag > 0 AND mo.iMeanPSFMagErr > 0 AND mo.iMeanKronMagErr > 0 AND mo.iMeanApMag > 0 AND mo.iMeanApMagErr > 0)
then power(2.5/log(10)/mo.iMeanKronMagErr,2) else 0 end +
case when (mo.zMeanPSFMag > 0 AND mo.zMeanKronMag > 0 AND mo.zMeanPSFMagErr > 0 AND mo.zMeanKronMagErr > 0 AND mo.zMeanApMag > 0 AND mo.zMeanApMagErr > 0)
then power(2.5/log(10)/mo.zMeanKronMagErr,2) else 0 end +
case when (mo.yMeanPSFMag > 0 AND mo.yMeanKronMag > 0 AND mo.yMeanPSFMagErr > 0 AND mo.yMeanKronMagErr > 0 AND mo.yMeanApMag > 0 AND mo.yMeanApMagErr > 0)
then power(2.5/log(10)/mo.yMeanKronMagErr,2) else 0 end, 0)
as wwMeanKronFlux,
(case when (mo.gMeanPSFMag > 0 AND mo.gMeanKronMag > 0 AND mo.gMeanPSFMagErr > 0 AND mo.gMeanKronMagErr > 0 AND mo.gMeanApMag > 0 AND mo.gMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.gMeanApMag)*power(2.5/log(10)/mo.gMeanPSFMagErr,2) else 0 end +
case when (mo.rMeanPSFMag > 0 AND mo.rMeanKronMag > 0 AND mo.rMeanPSFMagErr > 0 AND mo.rMeanKronMagErr > 0 AND mo.rMeanApMag > 0 AND mo.rMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.rMeanApMag)*power(2.5/log(10)/mo.rMeanPSFMagErr,2) else 0 end +
case when (mo.iMeanPSFMag > 0 AND mo.iMeanKronMag > 0 AND mo.iMeanPSFMagErr > 0 AND mo.iMeanKronMagErr > 0 AND mo.iMeanApMag > 0 AND mo.iMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.iMeanApMag)*power(2.5/log(10)/mo.iMeanPSFMagErr,2) else 0 end +
case when (mo.zMeanPSFMag > 0 AND mo.zMeanKronMag > 0 AND mo.zMeanPSFMagErr > 0 AND mo.zMeanKronMagErr > 0 AND mo.zMeanApMag > 0 AND mo.zMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.zMeanApMag)*power(2.5/log(10)/mo.zMeanPSFMagErr,2) else 0 end +
case when (mo.yMeanPSFMag > 0 AND mo.yMeanKronMag > 0 AND mo.yMeanPSFMagErr > 0 AND mo.yMeanKronMagErr > 0 AND mo.yMeanApMag > 0 AND mo.yMeanApMagErr > 0)
then 3631*power(cast(10 as float),-0.4*mo.yMeanApMag)*power(2.5/log(10)/mo.yMeanPSFMagErr,2) else 0 end)/nullif(
case when (mo.gMeanPSFMag > 0 AND mo.gMeanKronMag > 0 AND mo.gMeanPSFMagErr > 0 AND mo.gMeanKronMagErr > 0 AND mo.gMeanApMag > 0 AND mo.gMeanApMagErr > 0)
then power(2.5/log(10)/mo.gMeanPSFMagErr,2) else 0 end +
case when (mo.rMeanPSFMag > 0 AND mo.rMeanKronMag > 0 AND mo.rMeanPSFMagErr > 0 AND mo.rMeanKronMagErr > 0 AND mo.rMeanApMag > 0 AND mo.rMeanApMagErr > 0)
then power(2.5/log(10)/mo.rMeanPSFMagErr,2) else 0 end +
case when (mo.iMeanPSFMag > 0 AND mo.iMeanKronMag > 0 AND mo.iMeanPSFMagErr > 0 AND mo.iMeanKronMagErr > 0 AND mo.iMeanApMag > 0 AND mo.iMeanApMagErr > 0)
then power(2.5/log(10)/mo.iMeanPSFMagErr,2) else 0 end +
case when (mo.zMeanPSFMag > 0 AND mo.zMeanKronMag > 0 AND mo.zMeanPSFMagErr > 0 AND mo.zMeanKronMagErr > 0 AND mo.zMeanApMag > 0 AND mo.zMeanApMagErr > 0)
then power(2.5/log(10)/mo.zMeanPSFMagErr,2) else 0 end +
case when (mo.yMeanPSFMag > 0 AND mo.yMeanKronMag > 0 AND mo.yMeanPSFMagErr > 0 AND mo.yMeanKronMagErr > 0 AND mo.yMeanApMag > 0 AND mo.yMeanApMagErr > 0)
then power(2.5/log(10)/mo.yMeanPSFMagErr,2) else 0 end, 0)
as wwMeanApFlux
into mydb.COSMOS_compare_white_phot
from ((mydb.COSMOS_PS1_Xmatch_unique t left join stackobjectattributes soa on t.objid = soa.objid)
left join forcedmeanobject fmo on t.objid = fmo.objid)
left join meanobject mo on t.objid = mo.objid
where soa.primaryDetection = 1