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

Bug Report: Zoo Tide Correction Not Working #227

Closed
2320sharon opened this issue Jan 30, 2024 · 2 comments
Closed

Bug Report: Zoo Tide Correction Not Working #227

2320sharon opened this issue Jan 30, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@2320sharon
Copy link
Collaborator

Zoo is not correcting tides correctly. It either returns incorrect tide values or can't return any tides as indicated by this error.

Screenshot

image (14)

Snippet from Log FIle

2024-01-29 11:16:35,190 - file_utilities.py at line 178 in find_file_by_regex() - INFO : config_gdf.geojson matched regex
2024-01-29 11:16:35,396 - exception_handler.py at line 161 in handle_exception() - ERROR : Traceback (most recent call last):
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\coastseg_map.py", line 495, in compute_tidal_corrections
    tide_correction.correct_all_tides(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 95, in correct_all_tides
    correct_tides(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 203, in correct_tides
    predicted_tides_df = predict_tides(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 929, in predict_tides
    all_tides_df = handle_tide_predictions(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 898, in handle_tide_predictions
    all_tides_df = model_tides_by_region_id(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 873, in model_tides_by_region_id
    tides_for_region_df = predict_tides_for_df(subset_gdf, timeseries_df, config)
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 495, in predict_tides_for_df
    all_tides_df = pd.concat(all_tides.tolist())
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\pandas\core\reshape\concat.py", line 372, in concat
    op = _Concatenator(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\pandas\core\reshape\concat.py", line 429, in __init__
    raise ValueError("No objects to concatenate")
ValueError: No objects to concatenate

2024-01-29 11:16:35,396 - exception_handler.py at line 176 in handle_exception() - ERROR : No objects to concatenate</br>Additional Information</br>Traceback (most recent call last):
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\coastseg_map.py", line 495, in compute_tidal_corrections
    tide_correction.correct_all_tides(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 95, in correct_all_tides
    correct_tides(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 203, in correct_tides
    predicted_tides_df = predict_tides(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 929, in predict_tides
    all_tides_df = handle_tide_predictions(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 898, in handle_tide_predictions
    all_tides_df = model_tides_by_region_id(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 873, in model_tides_by_region_id
    tides_for_region_df = predict_tides_for_df(subset_gdf, timeseries_df, config)
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\coastseg\tide_correction.py", line 495, in predict_tides_for_df
    all_tides_df = pd.concat(all_tides.tolist())
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\pandas\core\reshape\concat.py", line 372, in concat
    op = _Concatenator(
  File "C:\Users\Redme\miniconda3\envs\coastseg\lib\site-packages\pandas\core\reshape\concat.py", line 429, in __init__
    raise ValueError("No objects to concatenate")
ValueError: No objects to concatenate


@2320sharon 2320sharon added the bug Something isn't working label Jan 30, 2024
@2320sharon 2320sharon self-assigned this Jan 30, 2024
@2320sharon
Copy link
Collaborator Author

I spent a long time today researching how our tide model works. Basically all the inputs to tide correction need to be in CRS 4326. The tide model region geojson file's CRS should NEVER be changed to any other CRS other than 4326. This is because of how it was created in geojson.io and how some polygons in the tide regions file cross the 180th meridian causing their longitude values to extend beyond the accepted range of -180 - 180 degrees. If you don't convert the tide model geojson file to any other crs than 4326 it seems to work just fine.

Now the issue in the Zoo workflow came from the fact the config_gdf.geojson were not always being saved in CRS epsg 4326 which was causing issues when the transects were being read in to be used for tide correction. The tide correction workflow assumed the transects were in crs 4326 in the get_seaward_points_gdf function

def get_seaward_points_gdf(transects_gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
    """
    Creates a GeoDataFrame containing the seaward points from a given GeoDataFrame containing transects.

    Parameters:
    - transects_gdf: A GeoDataFrame containing transect data.

    Returns:
    - gpd.GeoDataFrame: A GeoDataFrame containing the seaward points for all of the transects
    Contains columns transect_id,x,y
    """
    data = []
   # should have converted the transects_gdf to crs 4326 or set the crs if it had none

    for index, row in transects_gdf.iterrows():
        points = list(row["geometry"].coords)
        seaward_point = points[1] if len(points) > 1 else (None, None)

        # Append data for each transect to the data list
        data.append(
            {"transect_id": row["id"], "x": seaward_point[0], "y": seaward_point[1]}
        )

    # Convert the data list to a pandas DataFrame
    df = pd.DataFrame(data)

    # Create a GeoDataFrame with geometry as Point objects from x and y columns
    gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.x, df.y))
    gdf = gdf.set_crs("epsg:4326")

    return gdf

@2320sharon
Copy link
Collaborator Author

Closed in version 1.1.30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant