Skip to content

Errors in final cells of Xenium H&E Alignment tutorial: NameError for tpointsI and AttributeError for `.to_csv() #47

Description

@albert239825

Title: Errors in final cells: NameError for tpointsI and AttributeError for .to_csv()

Description
In the last two cells of the tutorial, there are two errors:

  1. NameError: name 'tpointsI' is not defined
    • The code uses tpointsI.numpy() in np.hstack((df, tpointsI.numpy())), but tpointsI is never defined. It looks like the intended variable might be tpointsJ instead, or another point transformation variable.
  2. AttributeError: 'numpy.ndarray' object has no attribute 'to_csv'
    • After using np.hstack, the result is a NumPy array, which doesn’t have a .to_csv() method. Converting to a pandas DataFrame before calling .to_csv() would fix this.

These issues occur in docs/notebooks/xenium-heimage-alignment.ipynb.

Proposed Fixes

  1. Replace tpointsI with the correct variable (likely tpointsJ).
  2. Instead of using np.hstack, add the aligned coordinates directly to the original DataFrame and then export it. For example:
    # Create a copy of the original DataFrame
    df_results = df.copy()
    
    # Add aligned coordinates to the DataFrame
    df_results['aligned_y'] = tpointsJ[:, 0].detach().numpy()
    df_results['aligned_x'] = tpointsJ[:, 1].detach().numpy()
    
    # Save the new DataFrame as a compressed CSV
    df_results.to_csv(
        '../xenium_data/Xenium_Breast_Cancer_Rep1_STalign_to_HE.csv.gz',
        compression='gzip',
        index=False
    )

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions