-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewSteps.py
More file actions
733 lines (472 loc) · 21.6 KB
/
NewSteps.py
File metadata and controls
733 lines (472 loc) · 21.6 KB
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# =============================================================================
# Basics Modules
# =============================================================================
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib import colors
# =============================================================================
# Astropy
# =============================================================================
from astropy.wcs import WCS
from astropy.io import fits
# =============================================================================
# Originals Clean steps
# =============================================================================
"""
1. Reading the data and establishing properties of the Python object,
2. Creating a mask with the valid data (masking the edges of the CCD).
3. Cleaning the CCD defects NaN y Negativos
4. Fixing small wavelength shifts W
5. Applying throughput 2D T
6. Correcting for extinction X
7. Telluric correction (only for red data) U
NOT IMPLEMENTED YET: 8. Sky subtraction S
9. Correcting negative values N Sube algunas cuentas (negativos) del cielo
NOT IMPLEMENTED YET: 10. Emission lines identification E
11. Correcting small CCD / sky residuals R (Cosmic)
12. Saving the processed / cleaned RSS file.
List and description of the sample RSS in the red arm
modular_koala/input_data/sample_RSS/385R/27feb20025red.fits HD60753 C 3W WIDE
modular_koala/input_data/sample_RSS/385R/27feb20026red.fits HD60753 B 3S WIDE
modular_koala/input_data/sample_RSS/385R/27feb20027red.fits HD60753 A WIDE
modular_koala/input_data/sample_RSS/385R/27feb20028red.fits HILT600 A
modular_koala/input_data/sample_RSS/385R/27feb20029red.fits HILT600 B 3S
modular_koala/input_data/sample_RSS/385R/27feb20030red.fits HILT600 C 3W
modular_koala/input_data/sample_RSS/385R/27feb20031red.fits Tol30 A PA0
modular_koala/input_data/sample_RSS/385R/27feb20032red.fits He2-10 B 1.5S
modular_koala/input_data/sample_RSS/385R/27feb20033red.fits He2-10 C 1.5S 3E
modular_koala/input_data/sample_RSS/385R/27feb20034red.fits He2-10 D 18S 3E
modular_koala/input_data/sample_RSS/385R/27feb20035red.fits He2-10 E 1.5E
modular_koala/input_data/sample_RSS/385R/27feb20036red.fits He2-10 F 1.5E 1.5S
modular_koala/input_data/sample_RSS/385R/combined_skyflat_red.fits SKYFLAT
"""
# Save figures to PDF
pdf = PdfPages('test_output_data/figures.pdf')
# =============================================================================
# 1. Reading the data
# =============================================================================
# Main class for reading RSS files into RSS class
from modular_koala.rss import read_rss
# Ancilliary function to match the current structure of a PyKoala header
from modular_koala.ancillary import py_koala_header
# Ancilliary function to match the current structure of a PyKoala spaxels table
from modular_koala.ancillary import py_koala_spaxels_table
# COMMENT: The code repits any time we read a RSS file. But at the end of the day
# for reading KOALA RSS we are only telling the task a file path. In that way
# we keep RSS class simple and useful for any RSS data (only file_path and WCS
# are required arguments). At the same time is easy to write a function to read
# KOALA RSS, incluiding headers and spaxels table passing only file_path argument
# Standard star: HD60753 ------------------------------------------------------
file_path = 'modular_koala/input_data/sample_RSS/385R/27feb20025red.fits'
# Constructing PyKoala header from 2dfdr (header[0] and header[2])
header = fits.getheader(file_path,0) + fits.getheader(file_path,2)
koala_header = py_koala_header(header)
# WCS
koala_wcs = WCS(header)
# Constructing Pykoala Spaxels table from 2dfdr spaxels table (data[2])
spaxels_table = fits.getdata(file_path,2)
koala_spaxels_table = py_koala_spaxels_table(spaxels_table)
# List of bad spaxels from 2dfdr spaxels table
bad_spaxels_list = (spaxels_table['SPEC_ID'][spaxels_table['SELECTED']==0]-1).tolist()
# -1 to start in 0 rather than in 1
# Read RSS file into PyKoala structure
std_rss = read_rss(file_path,
wcs= koala_wcs,
bad_spaxels_list = bad_spaxels_list,
header=koala_header,
spaxels_table=koala_spaxels_table,
)
# combined_skyflat_red --------------------------------------------------------
file_path = 'modular_koala/input_data/sample_RSS/385R/combined_skyflat_red.fits'
# Constructing PyKoala header from 2dfdr (header[0] and header[2])
header = fits.getheader(file_path,0) + fits.getheader(file_path,2)
koala_header = py_koala_header(header)
# WCS
koala_wcs = WCS(header)
# Constructing Pykoala Spaxels table from 2dfdr spaxels table (data[2])
spaxels_table = fits.getdata(file_path,2)
koala_spaxels_table = py_koala_spaxels_table(spaxels_table)
# List of bad spaxels from 2dfdr spaxels table
bad_spaxels_list = (spaxels_table['SPEC_ID'][spaxels_table['SELECTED']==0]-1).tolist()
# -1 to start in 0 rather than in 1
# Read RSS file into PyKoala structure
skyflat_rss = read_rss(file_path,
wcs= koala_wcs,
bad_spaxels_list = bad_spaxels_list,
header=koala_header,
spaxels_table=koala_spaxels_table,
)
# Object: Tol30 ---------------------------------------------------------------
file_path = 'modular_koala/input_data/sample_RSS/385R/27feb20031red.fits'
# Constructing PyKoala header from 2dfdr (header[0] and header[2])
header = fits.getheader(file_path,0) + fits.getheader(file_path,2)
koala_header = py_koala_header(header)
# WCS
koala_wcs = WCS(header)
# Constructing Pykoala Spaxels table from 2dfdr spaxels table (data[2])
spaxels_table = fits.getdata(file_path,2)
koala_spaxels_table = py_koala_spaxels_table(spaxels_table)
# List of bad spaxels from 2dfdr spaxels table
bad_spaxels_list = (spaxels_table['SPEC_ID'][spaxels_table['SELECTED']==0]-1).tolist()
# -1 to start in 0 rather than in 1
# Read RSS file into PyKoala structure
tol30_rss = read_rss(file_path,
wcs= koala_wcs,
bad_spaxels_list = bad_spaxels_list,
header=koala_header,
spaxels_table=koala_spaxels_table,
)
# Object: He2_100 -------------------------------------------------------------
file_path = 'modular_koala/input_data/sample_RSS/385R/27feb20032red.fits'
# Constructing PyKoala header from 2dfdr (header[0] and header[2])
header = fits.getheader(file_path,0) + fits.getheader(file_path,2)
koala_header = py_koala_header(header)
# WCS
koala_wcs = WCS(header)
# Constructing Pykoala Spaxels table from 2dfdr spaxels table (data[2])
spaxels_table = fits.getdata(file_path,2)
koala_spaxels_table = py_koala_spaxels_table(spaxels_table)
# List of bad spaxels from 2dfdr spaxels table
bad_spaxels_list = (spaxels_table['SPEC_ID'][spaxels_table['SELECTED']==0]-1).tolist()
# -1 to start in 0 rather than in 1
# Read RSS file into PyKoala structure
he2_100_rss = read_rss(file_path,
wcs= koala_wcs,
bad_spaxels_list = bad_spaxels_list,
header=koala_header,
spaxels_table=koala_spaxels_table,
)
#------------------------------------------------------------------------------
# List of RSS corresponding to objects to iterate (as an example) further.
# More elegant to use dict here, buy we keep simple for geting the main idea.
sci_rss = [tol30_rss,he2_100_rss]
# =============================================================================
# Original rss
# =============================================================================
plt.close('all')
plt.figure(1,figsize=(14,8))
plt.suptitle('Original RSS',size=25)
ax1 = plt.subplot(2,2,1)
ax1.set_title('Combined sky flat')
skyflat_rss.show()
ax2 = plt.subplot(2,2,2,sharex=ax1,sharey=ax1)
ax2.set_title('Standard star (HD60753)')
std_rss.show()
ax3 = plt.subplot(2,2,3,sharex=ax1,sharey=ax1)
sci_rss[0].show()
ax3.set_title(sci_rss[0].header['OBJECT'])
ax4 = plt.subplot(2,2,4,sharex=ax1,sharey=ax1)
ax4.set_title(sci_rss[1].header['OBJECT'])
sci_rss[1].show()
plt.tight_layout()
pdf.savefig(1)
# =============================================================================
# 2. Creating a mask with the valid data (masking the edges of the CCD).
# =============================================================================
# Edges are automatically detected. Only NaNs pixels are corrected
from modular_koala.clean_residuals import fix_edges
# skyflat
skyflat_edges = fix_edges(skyflat_rss,verbose=True)
skyflat_edges.show()
# standard star
std_edges = fix_edges(std_rss,verbose=True)
std_edges.show()
# Iterating over all the science objects
sci_edge = []
for rss in sci_rss:
sci_edge.append( fix_edges(rss,verbose=True) )
# =============================================================================
# 3. Cleaning the CCD defects
# =============================================================================
# NaNs
from modular_koala.clean_residuals import clean_nans
# skyflat
skyflat_clean = clean_nans(skyflat_edges,verbose=True)
skyflat_clean.show()
# standard star
std_clean = clean_nans(std_edges,verbose=True)
std_clean.show()
# Iterating over all the science objects
sci_clean = []
for rss in sci_edge:
sci_clean.append( clean_nans(rss,verbose=True) )
# =============================================================================
# NaNs and edges corrected
# =============================================================================
plt.close('all')
plt.figure(1,figsize=(14,8))
plt.suptitle('NaNs and edges corrected',size=25)
ax1 = plt.subplot(2,2,1)
ax1.set_title('Combined sky flat')
skyflat_clean.show()
ax2 = plt.subplot(2,2,2,sharex=ax1,sharey=ax1)
ax2.set_title('Standard star (HD60753)')
std_clean.show()
ax3 = plt.subplot(2,2,3,sharex=ax1,sharey=ax1)
sci_clean[0].show()
ax3.set_title(sci_rss[0].header['OBJECT'])
ax4 = plt.subplot(2,2,4,sharex=ax1,sharey=ax1)
ax4.set_title(sci_rss[1].header['OBJECT'])
sci_clean[1].show()
plt.tight_layout()
pdf.savefig(1)
# =============================================================================
# 4. Fixing small wavelength shifts
# =============================================================================
# We compute and apply the wavelenght drift solution on the science RSS and then
# we apply one of this solution to the skyflat and the standadr star.
from modular_koala.fix_wavelengths import fix_wavelengths
# Loop over all the science objects
sci_drift = []
for rss in sci_clean:
sci_drift.append( fix_wavelengths(rss, grating='385R',verbose=True) )
# Compare the solution in the two science RSS
from modular_koala.fix_wavelengths import compare_fix_wavelengths
compare_fix_wavelengths(sci_drift[0],sci_drift[1])
# We apply the wavelength correction from Tol30 rss (i.e. first rss in sci_drift )
# to skyflat and std
sol = sci_drift[0].log['wavelenght fix']['sol']
# skyflat
skyflat_drift = fix_wavelengths(skyflat_clean, grating='385R',sol = sol)
# std
std_drift = fix_wavelengths(std_clean, grating='385R',sol = sol)
# =============================================================================
# 5. Applying throughput
# =============================================================================
# Constructing the 2D throughput from sky_flat
from modular_koala.throughput import get_from_sky_flat
throughput_2D = get_from_sky_flat(skyflat_drift)
# We apply the throughput to the std and the science rss
from modular_koala.throughput import apply_throughput
# From 2D array
std_throughput = apply_throughput(std_drift,throughput = throughput_2D,verbose=True)
# Loop over all the science objects
sci_throughput = []
for rss in sci_drift:
sci_throughput.append( apply_throughput(rss,throughput = throughput_2D,verbose=True) )
# =============================================================================
# 6. Correcting for extinction
# =============================================================================
from modular_koala.extinction import extinction
# This function compute the extinction from the KOALA headers
from modular_koala.ancillary import airmass_from_header
# std
airmass = airmass_from_header(std_throughput.header)
std_extinction = extinction(std_throughput,airmass=airmass,verbose=True,plot=True)
# Loop over all the science objects
sci_extinction = []
for rss in sci_throughput:
airmass = airmass_from_header(rss.header)
sci_extinction.append( extinction(rss,airmass = airmass,verbose=True,plot=True) )
# =============================================================================
# Throughput and extinction corrected
# =============================================================================
plt.close('all')
plt.figure(1,figsize=(14,8))
plt.suptitle('Throughput and extinction corrected',size=25)
ax1 = plt.subplot(2,2,1)
ax1.set_title('Combined sky flat')
ax1.text(0.5,0.5,'NO CORRECTED',ha='center',va='center',size = 20)
ax1.axis('off')
ax2 = plt.subplot(2,2,2)
ax2.set_title('Standard star (HD60753)')
std_extinction.show()
ax3 = plt.subplot(2,2,3)
sci_extinction[0].show()
ax3.set_title(sci_rss[0].header['OBJECT'])
ax4 = plt.subplot(2,2,4)
ax4.set_title(sci_rss[1].header['OBJECT'])
sci_extinction[1].show()
plt.tight_layout()
pdf.savefig(1)
# =============================================================================
# 7. Telluric correction (only for red data) U
# =============================================================================
from modular_koala.tellurics import Tellurics
# This class compute the telluric correction from a std star. Once computed we
# can apply this solution to RSS or save the correction to a file.
telluric_correction = Tellurics(std_extinction,
exclude_wlm= [[6245,6390],[6450,6750],[6840,7000],
[7140,7400],[7550,7720],[8050,8450]],
weight_fit_median = 1)
# This is the step for applying the computed telluric correction to the RSS
# rss_telluric = tellurric_correction.apply(XXX_extinction)
# Comparison between the two solutions.
# Computed
w = std_extinction.wavelength
corr = telluric_correction.telluric_correction
# From file
w_txt = np.genfromtxt('/Users/felipe/DataCentral/KOALA/sample_RSS/385R/telluric_correction_20180227_385R.dat')[:,0]
corr_txt = np.genfromtxt('/Users/felipe/DataCentral/KOALA/sample_RSS/385R/telluric_correction_20180227_385R.dat')[:,1]
plt.close('all')
plt.figure(1)
plt.plot(w,corr,label='Computed correction')
plt.plot(w_txt,corr_txt,label='From telluric_correction_20180227_385R.dat')
plt.legend()
# Some diferecnces between the existing and the computed solution.
# Are the parameters considered in telluric_correction correct?
# We apply the solution from file to the science RSS.
# We read an existing telluric solution
from modular_koala.tellurics import tellurics_from_file
telluric_file = '/Users/felipe/DataCentral/KOALA/sample_RSS/385R/telluric_correction_20180227_385R.dat'
# Loop over all the science objects
sci_tellurics = []
for rss in sci_extinction:
sci_tellurics.append( tellurics_from_file(rss, telluric_file=telluric_file) )
# =============================================================================
# Tellurics corrected
# =============================================================================
plt.close('all')
plt.figure(1,figsize=(14,8))
plt.suptitle('Tellurics correction',size=25)
ax1 = plt.subplot(2,2,1)
ax1.set_title('Combined sky flat')
ax1.text(0.5,0.5,'NO CORRECTED',ha='center',va='center',size = 20)
ax1.axis('off')
ax2 = plt.subplot(2,2,2)
ax2.set_title('Standard star (HD60753)')
ax2.text(0.5,0.5,'NO CORRECTED',ha='center',va='center',size = 20)
ax2.axis('off')
ax3 = plt.subplot(2,2,3)
sci_tellurics[0].show()
ax3.set_title(sci_rss[0].header['OBJECT'])
ax4 = plt.subplot(2,2,4)
ax4.set_title(sci_rss[1].header['OBJECT'])
sci_tellurics[1].show()
plt.tight_layout()
pdf.savefig(1)
# =============================================================================
# 9. Correcting negative values
# =============================================================================
from modular_koala.clean_residuals import extreme_negatives
# Loop over all the science objects
sci_extreme = []
for rss in sci_tellurics:
sci_extreme.append( extreme_negatives(rss,
fibre_list='all',
percentile_min=0.5,
plot=True,
verbose=True)
)
# =============================================================================
# 11. Correcting small CCD / sky residuals R (Cosmic)
# =============================================================================
# This is a new (test) implementation of the task using L.A.Cosmic
# Cosmics
# # 2D version
# from modular_koala.clean_residuals import kill_cosmics_2D
# for rss in sci_extreme:
# sci_cosmic.append( kill_cosmics_2D(rss, cleantype='idw',sigclip=15, objlim=7,verbose=True) )
from modular_koala.clean_residuals import kill_cosmics
Halpha = 6564.6 # Wavelengh of the brightest line
sci_cosmic = []
for rss in sci_extreme:
sci_cosmic.append( kill_cosmics(rss, Halpha) )
cosmic_mask = []
for rss in sci_cosmic:
cosmic_mask.append(rss.mask_layer(4))
# =============================================================================
# Cosmics ray corrected
# =============================================================================
plt.close('all')
plt.figure(1,figsize=(14,8))
plt.suptitle('Extreme negatives and cosmic rays correction',size=25)
ax1 = plt.subplot(2,2,1)
ax1.set_title('Combined sky flat')
ax1.text(0.5,0.5,'NO CORRECTED',ha='center',va='center',size = 20)
ax1.axis('off')
ax2 = plt.subplot(2,2,2)
ax2.set_title('Standard star (HD60753)')
ax2.text(0.5,0.5,'NO CORRECTED',ha='center',va='center',size = 20)
ax2.axis('off')
ax3 = plt.subplot(2,2,3)
sci_cosmic[0].show()
ax3.set_title(sci_rss[0].header['OBJECT'])
ax4 = plt.subplot(2,2,4)
ax4.set_title(sci_rss[1].header['OBJECT'])
sci_cosmic[1].show()
plt.tight_layout()
pdf.savefig(1)
# =============================================================================
# Mask
# =============================================================================
plt.close('all')
plt.figure(1,figsize=(14,8))
plt.suptitle('Masks',size=25)
ax1 = plt.subplot(2,2,1)
ax1.set_title('Combined sky flat')
skyflat_clean.show_mask()
ax2 = plt.subplot(2,2,2)
ax2.set_title('Standard star (HD60753)')
std_throughput.show_mask()
ax3 = plt.subplot(2,2,3)
ax3.set_title(sci_rss[0].header['OBJECT'])
sci_cosmic[0].show_mask()
ax4 = plt.subplot(2,2,4)
ax4.set_title(sci_rss[1].header['OBJECT'])
sci_cosmic[1].show_mask()
plt.tight_layout()
pdf.savefig(1)
# =============================================================================
# Just saving the colorbar
# =============================================================================
plt.close('all')
plt.figure(1,figsize=(14,8))
cmap = colors.ListedColormap(['darkgreen','blue','red','darkviolet','black','orange'])
figure = plt.imshow(sci_clean[0].mask,vmin=0,vmax=6, cmap=cmap, interpolation='none')
figure.remove()
plt.axis('off')
cb = plt.colorbar(figure,location="top",aspect=20)
ticks_position = np.arange(6)+0.5
ticks_name = ['From file','Blue edge','Red edge','NaN\'s','Cosmics','Extreme \n negatives']
cb.set_ticks(ticks_position)
cb.set_ticklabels(ticks_name)
pdf.savefig(1)
pdf.close()
# =============================================================================
# 12. Saving the processed / cleaned RSS file.
# =============================================================================
for rss in sci_cosmic:
# We save the fist with the name of the object + CLEAN
path = 'test_output_data'
name = rss.header['OBJECT'].replace(' ','_')+'_CLEAN.fits'
file_path = os.path.join(path,name)
rss.tofits(file_path)
"""
# # =============================================================================
# # Checking header
# # =============================================================================
header['DESCRIP'] = description
for item in rss.history_RSS:
if item == "- Created fits file (this file) :":
header['HISTORY'] = "- Created fits file :"
else:
header['HISTORY'] = item
header['FILE_IN'] = rss.filename
header['HISTORY'] = '-- RSS processing using PyKOALA '+ version
#header['HISTORY'] = 'Developed by Angel Lopez-Sanchez, Yago Ascasibar, Lluis Galbany et al.'
#header['HISTORY'] = version #'Version 0.10 - 12th February 2019'
now=datetime.datetime.now()
header['HISTORY'] = now.strftime("File created on %d %b %Y, %H:%M:%S using input file:")
header['DATE'] = now.strftime("%Y-%m-%dT%H:%M:%S") #'2002-09-16T18:52:44' # /Date of FITS file creation
#header['HISTORY'] = 'using input file:'
header['HISTORY'] = rss.filename
for item in rss.history:
header['HISTORY'] = item
header['HISTORY'] = "- Created fits file (this file) :"
header['HISTORY'] = " "+fits_file
header['FILE_OUT'] = fits_file
"""
#Checking the values of skylines in
# # TODO: Why add again this information
# py_koala_spaxels_table.header['CENRA'] = rss.RA_centre_deg / ( 180/np.pi ) # Must be in radians
# py_koala_spaxels_table.header['CENDEC'] = rss.DEC_centre_deg / ( 180/np.pi )
# fits_image_hdu = fits.PrimaryHDU(data)
# # TO BE DONE
# errors = [0] ### TO BE DONE
# error_hdu = fits.ImageHDU(errors)
# hdu_list = fits.HDUList([fits_image_hdu,error_hdu, header2_hdu])
# hdu_list.writeto(fits_file, overwrite=True)
# """