def select_in(table, x, y, w):
    """Given a detection table and square ROI, return detections within it.

    Parameters
    ----------
    table : pandas DataFrame
        A dSTORM detection table, drift corrected. (Usually in file ending in
        ``_LDCTracked.txt``.)
    x, y : float
        x and y coordinates of the top left corner of a square ROI. In µm.
    w : float
        Width (and height) in µm of the ROI.

    Returns
    -------
    roi : pandas DataFrame
        The subset of detections in `table` that fell within the square ROI

    Notes
    -----
    This function hardcodes many details that may not generalise across dSTORM
    microscopes or even experiments, such as the field of view width and the
    scale of coordinates in the table (nm). Do some sanity checks (see below)
    to make sure that the coordinate translations are working for you.
    """
    # convert input coordinates (in µm) to table coordinates (nm)
    x *= 1000
    y *= 1000
    w *= 1000
    # Compute subset selection in x
    x_in = (x < table['X_COORD']) & (table['X_COORD'] < x + w)
    # Compute subset selection in y. For some reason, y coordinates are
    # inverted in the table compared to the image in Fiji.
    y_in = (y < 20480 - table['Y_COORD']) & (20480 - table['Y_COORD'] < y + w)
    # Return the subsetted table
    return table.loc[x_in & y_in][['Y_COORD', 'X_COORD']]