def lon_to_180(ds):
    """This is a function for converting longitude from (0, 360) to (-180, 180)
    ref: https://gis.stackexchange.com/questions/201789/verifying-formula-that-will-convert-longitude-0-360-to-180-to-180/201793

    Parameters
    ----------
    ds : xarray.Dataset
        a dataset with the longitude ranging from 0 to 360

    Returns
    -------
    xarray.Dataset
        a dataset with the longitude ranging from -180 to 180
    """
    ds=ds.assign_coords(lon=(((ds.lon + 180) % 360) - 180))
    ds=ds.reindex(lon=sorted(ds.lon))  
    return ds