Keck-DataReductionPipelines / KCWI_DRP

KCWI python DRP
BSD 3-Clause "New" or "Revised" License
9 stars 13 forks source link

Massive memory usage because of a bug #47

Open lucarizzi opened 3 years ago

lucarizzi commented 3 years ago

To reproduce, use the files in 2020 may 16, and specifically the configuration that relies on frame 29 as the arc.

Because of a hidden bug that I am trying to track down, the geometry transformation uses in excess of 20Gb of RAM per slice, ending in a hard crash of the computer.

On close inspection, it turns out that the wavelength range adopted is completely wrong: Typical values are: 2021-04-12 21:32:45:KCWI:INFO:SolveGeom.py: WAVE RANGE: 4280.00 - 5394.00 2021-04-12 21:32:45:KCWI:INFO:SolveGeom.py: WAVE GOOD: 4406.81 - 4280.27 2021-04-12 21:32:45:KCWI:INFO:SolveGeom.py: WAVE ALL: 4127.81 - 5394.40 2021-04-12 21:32:45:KCWI:INFO:SolveGeom.py: WAVE MID: 4552.32 2021-04-12 21:32:45:KCWI:INFO:SolveGeom.py: Output slices will be 69 x 2228 px

But for this file, the result is: 2021-04-12 21:34:35:KCWI:INFO:SolveGeom.py: WAVE RANGE: 3626.00 - 10026914.00 2021-04-12 21:34:35:KCWI:INFO:SolveGeom.py: WAVE GOOD: 5405.40 - 3626.14 2021-04-12 21:34:35:KCWI:INFO:SolveGeom.py: WAVE ALL: -237392.61 - 10026914.49 2021-04-12 21:34:35:KCWI:INFO:SolveGeom.py: WAVE MID: 2449638.35 2021-04-12 21:34:35:KCWI:INFO:SolveGeom.py: Output slices will be 69 x 20046576

Clearly the issue is that the output slices are 2,000,000 x 69.

I tracked it down to a problem in SolveGeom.py, in the area that calculates the output wavelengths.

I run the code modified as follows to get more info:

# Calculate output wavelengths
        dwout = self.action.args.dwout
        ndels = int((trimw0 - self.config.instrument.WAVEFID) / dwout)
        print("Diagnostic: ", self.config.instrument.WAVEFID)
        print("Diagnostic: ", float(ndels))
        print("Diagnostic: ", dwout)
        self.action.args.wave0out = \
            self.config.instrument.WAVEFID + float(ndels) * dwout
        ndels = int((trimw1 - self.config.instrument.WAVEFID) / dwout)
        print("Diagnostic: ", trimw1)
        print("Diagnostic: ", float(ndels))
        print("Diagnostic: ", dwout)
        self.action.args.wave1out = \
            self.config.instrument.WAVEFID + float(ndels) * dwout
        self.logger.info("WAVE RANGE: %.2f - %.2f" %
                         (self.action.args.wave0out, self.action.args.wave1out))

The result for a normal run is:

Diagnostic: 3000.0 Diagnostic: 2560.0 Diagnostic: 0.5 Diagnostic: 5394.396990863172 Diagnostic: 4788.0 Diagnostic: 0.5

But for this specific troubled files, the result is:

Diagnostic: 3000.0 Diagnostic: 1252.0 Diagnostic: 0.5 Diagnostic: 10026914.488111256 Diagnostic: 20047828.0 Diagnostic: 0.5

So trimw1 and ndels are calculated incorrectly.

As time allows I will dig deeper.