Grabs a lux reading either with autoranging (gain=0) or with a specified gain (1, 16)

def read_value(self):
        """Grabs a lux reading either with autoranging (gain=0) or with a specified gain (1, 16)"""
        if self.gain == 1 or self.gain == 16:
            self.set_gain(self.gain)
            ambient = self.read_full()
            ir_reading = self.read_ir()
        elif self.gain == 0:
            self.set_gain(16)
            ambient = self.read_full()
            if ambient < 65535:
                ir_reading = self.read_ir()
            if ambient >= 65535 or ir_reading >= 65535:
                self.set_gain(1)
                ambient = self.read_full()
                ir_reading = self.read_ir()

        if self.gain == 1:
            ambient *= 16
            ir_reading *= 16

        if ambient == 0:
            ratio = 0
        else:
            ratio = (ir_reading / float(ambient))

        if (ratio >= 0) & (ratio <= 0.52):
            lux = (0.0315 * ambient) - (0.0593 * ambient * (ratio**1.4))
        elif ratio <= 0.65:
            lux = (0.0229 * ambient) - (0.0291 * ir_reading)
        elif ratio <= 0.80:
            lux = (0.0157 * ambient) - (0.018 * ir_reading)
        elif ratio <= 1.3:
            lux = (0.00338 * ambient) - (0.0026 * ir_reading)
        elif ratio > 1.3:
            lux = 0

        return lux