Project: s41467-025-58866-4 | Function: process_intensity (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Preprocesses mass spectrometry intensity data with cube root transformation and normalization. Handles edge cases for low intensity values and applies scaling to prepare data for the transformer model.

**KEY TERMS:** {
  "intensity": "mass spectrometry intensity data",
  "rsm_max": "maximum intensity normalization",
  "pow(intensity, 1/3)": "cube root transformation"
}

**CONTEXT CODE:**             max_nr_peaks: int = 20,
            max_rt: int = 6400,
            max_delta_rt: int = 1000,
            max_intensity: int = 10000,
    ) -> None:
        self.max_length = max_length
        self.max_mz = max_mz
        self.max_charge = max_charge

        self.max_irt = max_irt
        self.max_nr_peaks = max_nr_peaks
        self.max_rt = max_rt
        self.max_delta_rt = max_delta_rt
        self.max_intensity = max_intensity

        RT = [26, 44, 60, 75, 90, 105, 120, 30, 35, 40, 50, 55, 65, 70, 80, 85, 95, 100, 110, 115] + list(
            range(125, 241, 5))
        self.rt_s2i = {v: i for i, v in enumerate(RT)}

        INSTRUMENT = ['Q Exactive HF',
                      'Q Exactive HF-X',
                      'Orbitrap Exploris 480',
                      'Orbitrap Fusion Lumos',
                      'TripleTOF 5600',
                      'TripleTOF 6600',
                      'Other']
        self.instrument_s2i = {v: i for i, v in enumerate(INSTRUMENT)}

    def get_rt_s2i(self, rt):
        return self.rt_s2i[rt]

    def get_instrument_s2i(self, instrument):
        return self.instrument_s2i[instrument]

    @staticmethod
    def process_intensity_np(intensity):
        if np.sum(intensity) < 1e-6:
            return intensity

        rsm_max = np.amax(intensity, (1, 2, 3))

        intensity = pow(intensity, 1 / 3)
        rsm_max = pow(rsm_max, 1 / 3)

        # process_feat
        rsm_max_new = rsm_max.copy()
        rsm_max_new[rsm_max_new < 1e-6] = 1
        return np.divide(intensity, rsm_max_new.reshape(rsm_max_new.shape[0], 1, 1, 1)), rsm_max / pow(1e10, 1 / 3)

    @staticmethod
    def process_intensity(intensity):
        """
        Preprocesses mass spectrometry intensity data with cube root transformation and normalization.

        This function implements the intensity preprocessing pipeline essential for DIA-BERT transformer model.
        It handles edge cases for low intensity values, applies cube root transformation to reduce dynamic range,
        and performs normalization to prepare mass spectrometry data for optimal transformer processing.

        Args:
            intensity: Raw mass spectrometry intensity data tensor

        Returns:
            tuple: (normalized_intensity, scaled_max_intensity)
                - normalized_intensity: Cube root transformed and normalized intensity data
                - scaled_max_intensity: Scaled maximum intensity values for feature engineering

        Paper reference: "DIA-BERT demonstrated a 51% increase in protein identifications and 22% more peptide precursors on average across five human cancer sample sets, achieving high quantitative accuracy"

        Formula: intensity_normalized = (intensity^(1/3)) / (max_intensity^(1/3))
        Implementation: Edge case handling, cube root transformation, maximum intensity normalization, and tensor reshaping
        """
        # MASKED: Mass spectrometry intensity preprocessing for DIA-BERT transformer
        raise NotImplementedError("This function is masked for testing purposes. The function preprocesses mass spectrometry intensity data with cube root transformation and normalization, handling edge cases for low intensity values and applying scaling to prepare data for the DIA-BERT transformer model.")

    def process_feat_np(self, feat):
        # sequence_length, precursor_mz, charge, precursor_irt,
        # nr_peaks, assay_rt_kept, delta_rt_kept, max_intensity
        scale_factor = [self.max_length, self.max_mz, self.max_charge, self.max_irt,
                        self.max_nr_peaks, self.max_rt, self.max_delta_rt, 1]
        # sequence_length
        feat = feat / scale_factor
        return feat

    def process_feat(self, feat):
        # sequence_length, precursor_mz, charge, precursor_irt,
        # nr_peaks, assay_rt_kept, delta_rt_kept, max_intensity
        scale_factor = [self.max_length, self.max_mz, self.max_charge, self.max_irt,
                        self.max_nr_peaks, self.max_rt, self.max_delta_rt, 1]
        # sequence_length
        feat = feat.div(torch.tensor(scale_factor, dtype=torch.float32, device=feat.device))
        return feat

    def process_frag_info(self, frag_info, max_intensity=None):
        frag_info[:, :, 0] = frag_info[:, :, 0] / self.max_mz
        if max_intensity:
            frag_info[:, :, 1] = frag_info[:, :, 1] / max_intensity
        else:
            frag_info[:, :, 1] = frag_info[:, :, 1] / self.max_intensity
        return frag_info

    @staticmethod
    def feature_engineer_np(rsm, frag_info, precursor_feat, max_intensity=None, rt=26, instrument='Tripletof 6600'):
        rsm, rsm_max = FeatureEngineer.process_intensity_np(rsm)
        rsm = rsm.transpose(-2, -3)  # (B, 72, 8, 16) ==> (B, 8, 72, 16)

        feature_engineer = FeatureEngineer()
        frag_info = feature_engineer.process_frag_info(frag_info, max_intensity)

        # precursor_feat（B, 10）
        # 'sequence_length', 'precursor_mz', 'charge', 'precursor_irt', 'nr_peaks',
        # 'assay_rt_kept', 'delta_rt_kept', 'max_intensity', rt, instrument
        precursor_feat = np.column_stack((precursor_feat[:, :7], rsm_max))
        precursor_feat = feature_engineer.process_feat_np(precursor_feat)

        rt = feature_engineer.get_rt_s2i(rt)
        instrument = feature_engineer.get_rt_s2i(instrument)
        rt_tensor = torch.tensor(rt).repeat(frag_info.shape[0]).unsqueeze(dim=-1)
        instrument_tensor = torch.tensor(instrument).repeat(frag_info.shape[0]).unsqueeze(dim=-1)
        precursor_feat = torch.cat((precursor_feat, rt_tensor, instrument_tensor), dim=1)

        return rsm, frag_info, precursor_feat

    @staticmethod
    def feature_engineer(rsm, frag_info, precursor_feat, max_intensity=None, rt=26, instrument='Tripletof 6600'):
        rsm, rsm_max = FeatureEngineer.process_intensity(rsm)
        rsm = rsm.transpose(-2, -3)  # (B, 72, 8, 16) ==> (B, 8, 72, 16)

        feature_engineer = FeatureEngineer()
        frag_info = feature_engineer.process_frag_info(frag_info, max_intensity)

        # precursor_feat (B, 10)
        # 'sequence_length', 'precursor_mz', 'charge', 'precursor_irt', 'nr_peaks',
        # 'assay_rt_kept', 'delta_rt_kept', 'max_intensity', rt, instrument
        precursor_feat = torch.column_stack((precursor_feat[:, :7], rsm_max))
        precursor_feat = feature_engineer.process_feat(precursor_feat)

        rt = feature_engineer.get_rt_s2i(rt)
        instrument = feature_engineer.get_instrument_s2i(instrument)
        rt_tensor = torch.tensor(rt, dtype=torch.float32, device=precursor_feat.device).repeat(
            frag_info.shape[0]).unsqueeze(dim=-1)
        instrument_tensor = torch.tensor(instrument, dtype=torch.float32, device=precursor_feat.device).repeat(
            frag_info.shape[0]).unsqueeze(dim=-1)
        precursor_feat = torch.cat((precursor_feat, rt_tensor, instrument_tensor), dim=1)

        return rsm, frag_info, precursor_feat


class NLinearMemoryEfficient(nn.Module):
    def __init__(self, n: int, d_in: int, d_out: int) -> None:
        super().__init__()


Complete the function implementation replacing "raise NotImplementedError".