def get_nlat_nlon(n_nodes, lonlat_ratio):
    """Calculate the width (longitudes) and height (latitude) of an equiangular grid provided in 1D.
    
    Parameters
    ----------
    lonlat_ratio : int
        lonlat_ratio = H // W = n_longitude rings / n_latitude rings
        Aspect ratio to reshape the input 1D data to a 2D image.
        A ratio of 2 means the equiangular grid has the same resolution
        in latitude and longitude.
    """
    # ratio = n_lon/n_lat (width/height)
    n_lat = int((n_nodes / lonlat_ratio) ** 0.5)
    n_lon = int((n_nodes * lonlat_ratio) ** 0.5)
    if n_lat * n_lon != n_nodes: # Try to correct n_lat or n_lon if ratio is wrong
        if n_nodes % n_lat == 0:
            n_lon = n_nodes // n_lat
        if n_nodes % n_lon == 0:
            n_lat = n_nodes // n_lon
    assert n_lat * n_lon == n_nodes, f'Unable to unpack nodes: {n_nodes}, lonlat_ratio: {lonlat_ratio}'
    return n_lat, n_lon