Commit b28d3839 authored by Roberto Susino's avatar Roberto Susino
Browse files

Improve checks for compression consistency

parent e83bad78
Loading
Loading
Loading
Loading
+22 −19
Original line number Diff line number Diff line
pro check_compression, image, header
    bin_type = fxpar(header, 'BIN_TYPE', missing = -1)
    ; Check compression

    if bin_type lt 0 then return
    compr = fxpar(header, 'COMPR', missing = '')
    delta_q = fxpar(header, 'B0_DQ', missing = -1)

    nbin = fxpar(header, 'NBIN')
    bin_fact = 2^bin_type
    if compr.contains('enabled', /fold) then fxaddpar, header, 'COMPRESS', 'Lossless'
    if delta_q ge 0 then if delta_q gt 0 then fxaddpar, header, 'COMPRESS', 'Lossy'

    if nbin ne bin_fact^2 then begin
        naxis1 = fxpar(header, 'NAXIS1')
        naxis2 = fxpar(header, 'NAXIS2')
    ; Check binning

        naxis1 = naxis1/bin_fact
        naxis2 = naxis2/bin_fact
    bin_type = fxpar(header, 'BIN_TYPE')
    bin_size = 2 ^ bin_type

    if fxpar(header, 'NBIN') ne bin_size ^ 2 then begin
        naxis1 = fxpar(header, 'NAXIS1') / bin_size
        naxis2 = fxpar(header, 'NAXIS2') / bin_size
        image = rebin(image, naxis1, naxis2)
        image = long(image) * bin_fact^2
        image = long(image) * bin_size ^ 2

        fxaddpar, header, 'NAXIS1', naxis1
        fxaddpar, header, 'NAXIS2', naxis2
        fxaddpar, header, 'NBIN1', bin_fact
        fxaddpar, header, 'NBIN2', bin_fact
        fxaddpar, header, 'NBIN', bin_fact^2
        fxaddpar, header, 'NBIN1', bin_size
        fxaddpar, header, 'NBIN2', bin_size
        fxaddpar, header, 'NBIN', bin_size ^ 2
        fxaddpar, header, 'PXEND1', naxis1
        fxaddpar, header, 'PXEND2', naxis2
        fxaddpar, header, 'FIRSTROW', 0, before = 'CHECKSUM'
+2 −4
Original line number Diff line number Diff line
@@ -37,11 +37,9 @@ pro metis_l2_prep_uv

    data = mrdfits(input.file_name, 0, primary_header, /silent)

    foreach keyword, primary_header, k do primary_header[k] = keyword.replace('/  ', '/ ')
    ; fix compression header

    ; read the quality matrix

    quality_matrix = mrdfits(input.file_name, 'quality matrix', /silent)
    check_compression, data, primary_header

    ; convert the string header into an idl structure

+4 −0
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@ pro metis_l2_prep_vl_generic

    data = mrdfits(input.file_name, 0, primary_header, /silent)

    ; fix compression header

    check_compression, data, primary_header

    ; patch to fix the lack of the keyword SEQ_NUM

    pol_id = fxpar(primary_header, 'POL_ID', missing = 0)
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ pro metis_l2_prep_vl_polariz
        ; fix compression header

        check_compression, image, header
        check_compression, img, header

        ; fix the lack of the keyword seq_num