Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger crashes when trying to view Variables pane that contains xarray.DataArray #15816

Open
rbavery opened this issue Feb 16, 2024 · 4 comments
Labels

Comments

@rbavery
Copy link

rbavery commented Feb 16, 2024

Description

When I set a breakpoint in the code below, the breakpoint is reached but viewing the Variables pane crashes the kernel.

Here is my breakpoint and variables pane before the crash. The variable xarr lazily refers to the actual data, so memory use is very low at the breakpoint so this doesn't seem like a OOM error.

Selection_097

import geopandas as gpd
import pystac_client
import planetary_computer
import stackstac
import xarray as xr
import pyproj
from shapely.geometry import Point
import numpy as np
from collections import Counter
sample = solar_farms_in_arizona.sample(10).centroid

def xarr_from_aoi_point(point: Point, time_range: str = "2020-01-01/2021-01-01", max_cloud_cover: int = 15) -> xr.DataArray:
    collection_id = "sentinel-2-l2a"
    catalog = pystac_client.Client.open("https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace)
    
    def perform_search(tile: str = None):
        query_params = {"eo:cloud_cover": {"lt": max_cloud_cover}}
        if tile:
            query_params['s2:mgrs_tile'] = {'eq': tile}
        
        search = catalog.search(collections=[collection_id], 
                                intersects=point, 
                                datetime=time_range, 
                                query=query_params, 
                                max_items=4)
        return search.item_collection()
    
    items = perform_search()
    xarr = stackstac.stack(items, assets=["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B10", "B11", "B12"])
    
    if xarr.sizes["x"] != xarr.sizes["y"]:
        # The result is not square, find a tile code from the initial items
        tile_code = next((item.properties.get("s2:mgrs_tile") for item in items if "s2:mgrs_tile" in item.properties), None)
        
        if tile_code:
            # Re-run the search with the specific tile code
            items = perform_search(tile=tile_code)
            xarr = stackstac.stack(items, assets=["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B10", "B11", "B12"])

    # Attempt to determine a common EPSG code, fallback to a default if necessary
    epsg_codes = [item.properties.get('proj:epsg') for item in items if 'proj:epsg' in item.properties]
    if not len(set(epsg_codes)) == 1:
        print(epsg_codes)
        print([item.properties.get("s2:mgrs_tile") for item in items])
        epsg_counter = Counter(epsg_codes)
        most_common_epsg = epsg_counter.most_common(1)[0][0] if epsg_codes else None
        epsg_arg = {'epsg': most_common_epsg} if most_common_epsg else {}
        xarr = stackstac.stack(items, assets=["B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B8A", "B09", "B10", "B11", "B12"], **epsg_arg)
    return xarr

After opening the variables pane, my screen freezes, mouse movement stutters and my kernel crashes after about a minute. This does not happen when running the code without a debugger.

Reproduce

  1. Set breakpoint after an xarray.DataArray is created.
  2. Open variables pane.
  3. crash

Expected behavior

No crash

Context

  • Operating System and version: Ubuntu 22.04
  • Browser and version: Chrome121.0.6167.160
  • JupyterLab version: 4.0.10
Troubleshoot Output body is too long to submit issue if I include the output
Command Line Output the output is too long to copy. at a glance there are no warnings or errors.
Browser Output I can't access this during the crash
@rbavery rbavery added the bug label Feb 16, 2024
Copy link

welcome bot commented Feb 16, 2024

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Feb 16, 2024
@krassowski
Copy link
Member

Can you provide a smaller reproducer that could be run without installing additional packages?

How does the crash look like? Does the kernel die and UI remains responsive, or does the UI freeze?

@JasonWeill
Copy link
Contributor

@rbavery Can you please provide answers to @krassowski 's questions from earlier? Thanks!

@rbavery
Copy link
Author

rbavery commented Feb 27, 2024

Hey sorry I missed this!

How does the crash look like? Does the kernel die and UI remains responsive, or does the UI freeze?

The UI freezes, there is no kernel died error.

The reproducer requires xarray I'm pretty sure, The issue didn't come up when stepping through a simple program with no external libraries. the other libraries are required to request the xarray DataArray. This week I'm a bit slammed and it would take me too much effort to create an xarray from scratch and try to change it in a way that reproduces the issue. Maybe at a later date I can revisit making a smaller reproducer, but this snippet I provided can be run after

pip install geopandas numpy shapely pystac-client planetary-computer stackstac xarray pyproj in a venv. Understood if this is too much setup and this needs to be closed because of it.

@JasonWeill JasonWeill removed status:Needs Info status:Needs Triage Applied to new issues that need triage labels Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants