-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_FITSFile.py
More file actions
62 lines (52 loc) · 2.83 KB
/
Copy pathtest_FITSFile.py
File metadata and controls
62 lines (52 loc) · 2.83 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
import logging
from MetaFITS import FITSFile
from astropy.coordinates import SkyCoord
logging.basicConfig(filename='./tests/journal.log', encoding='utf-8', level=logging.WARNING,
format='%(asctime)s --- %(levelname)s --- %(message)s\n', datefmt='%H:%M:%S')
log = logging.getLogger(__name__)
log.setLevel(logging.root.level)
log.log(level=log.level, msg="NEW EXECUTION STARTS HERE\n**************************************************")
# Initializing 2 FITSFile instances from a given path
file = FITSFile(path='./tests/fitscollection/5GHz_n_f.fits')
file2 = FITSFile(path='./tests/fitscollection/5GHz_n_f.fits')
# Printing file
print(file)
# Testing wether two instances are equal
print(f"Before changing path property : {(file==file2)=}")
# Changing the path property of the 2nd instance of the same file.
# PLEASE NOTE IT DOES NOT CHANGE THE HEADER AND DATA PROPERTIES.
# In order to do so, you would have to write `file2 = FITSFile(newPath)`
file2.path = './tests/fitscollection/G9_POLIN.fits'
# Now the two instances are not equal anymore
print(f"After changing path property : {(file==file2)=}")
# Updating the header property of the instance
file.updateHeader({'OBJECT': 'NGC1415',
'NAXIS': 5,
'DATE':'12 january 1990',
'DATE-OBS': '1990-01-12T02:01:23'})
# Removing duplicates of keyword 'RA' if they exist
FITSFile.removeDuplicates(file, 'RA')
# Homogenizing the file dates
file.homogenizeDates()
# Homogenizing the file (dates, coordinates, coordinates system, deprecated keywords)
file.homogenize()
# Passing the modifications on the file header
file.updateFitsMetaData()
# Static methods to manipulate dates and MJD
print(f"Isoformatted date '1858-11-17T00:00:00.000' corresponds to"
" {FITSFile.iso2MJD('1858-11-17T00:00:00.000')} Modified Julian Days")
print(f"Isoformatted date {FITSFile.MJD2iso(FITSFile.iso2MJD('2012-12-21T12:30:07'))}"
f" corresponds to {FITSFile.iso2MJD('2012-12-21T12:30:07')} Modified Julian Days")
# Object name resolving, corners retrieving and STCS computing
print(f"{file!r}\n\t - Object Resolved : {file.resolve()!r} "
f"('OBJECT'={file.header.get('OBJECT')!r})\n\t"
f" - Image corners : {str(file.getCorners()).replace('\n', '\n\t\t\t ')}\n\t"
f" - STCS : {file.computeSTCS()!r}")
# Compute the PolygonSkyRegion of the file
polygon = file.computePolygon()
obj = SkyCoord(84.71504322970168, -69.13528638778595, unit='deg', frame='icrs')
file3 = FITSFile(path='./tests/fitscollection/G9_POLIN.fits')
# Returns some string if obj is contained in the image
iscontained = lambda f : 'contains' if f.containsObject(object=obj) else 'does not contain'
print(f"{file!r} {iscontained(file)} object {obj} whereas {file3!r} {iscontained(file3)} it.")
log.log(level=log.level, msg="\t\tEND\n**************************************************")