-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcompress.py
More file actions
24 lines (20 loc) · 719 Bytes
/
compress.py
File metadata and controls
24 lines (20 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def compress(file, dims):
"""
Will compress a given ``file`` with a factor of ``factor``.
Will only work for files that sunpy.map.Map can read.
Parameters
----------
file : `str`
File to compress.
dims : `float`
Final dimensions of the compressed image in pixels.
"""
import astropy.units as u
from astropy.io import fits
from sunpy.map import Map
amap = Map(file)
new_dimensions = [dims, dims] * u.pixel
resampled_map = amap.resample(new_dimensions)
# Write the resampled map to a new file.
# You will want to move the file to the correct location later on.
resampled_map.save(f"{file}.resample.fits", hdu_type=fits.CompImageHDU)