Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving function for exporting in fits #63

Open
EmilieMauduit opened this issue Oct 9, 2023 · 2 comments
Open

Improving function for exporting in fits #63

EmilieMauduit opened this issue Oct 9, 2023 · 2 comments
Labels
Improve This works, but make it faster / easier / broader...

Comments

@EmilieMauduit
Copy link
Collaborator

Proposition to modify the SourceInLobes.export() function, so that the .fits files take less space.

def export(self, filename: str , in_bytes : bool = False):
""" Exports the time-frequency contamination array in FITS. The mask being either in floats or in bytes.
:param filename:
FITS file name.
:type filename:
str
:param in_bytes:
Set to True ton convert the mask array to bytes. Default is False.
:type in_bytes:
bool

    """
    t_size, f_size = self.time.size, self.frequency.size

    if in_bytes :
        mask.value = np.array(np.floor(mask.value*255)).astype(int)
        dtype = [('contamination', 'B', (t_size,))]
    else :
        dtype = [('contamination', 'i8' if mask.value.dtype==np.int32 else 'f8', (t_size,))]
    
    primary_hdu = fits.PrimaryHDU()

    time_jd= self.time.jd
    time_data = fits.BinTableHDU.from_columns([fits.Column(name='time_jd', format='f8', array=time_jd)])
    freq_mhz= self.frequency.to(u.MHz).value
    freq_data = fits.BinTableHDU.from_columns([fits.Column(name='freq_mhz', format='f8', array=freq_mhz)])

    data = np.zeros(f_size, dtype=dtype)
    data['contamination'] = self.value
    cont_data = fits.BinTableHDU(data)

    hdu_list = fits.HDUList([primary_hdu,time_data,freq_data,cont_data])
    hdu_list.writeto(filename, overwrite=True)
@EmilieMauduit EmilieMauduit added the Improve This works, but make it faster / easier / broader... label Oct 9, 2023
@AlanLoh
Copy link
Owner

AlanLoh commented Oct 9, 2023

No longer time_lst HDU?

@EmilieMauduit
Copy link
Collaborator Author

Oups, we should keep it yes !

AlanLoh added a commit that referenced this issue Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improve This works, but make it faster / easier / broader...
Projects
None yet
Development

No branches or pull requests

2 participants