Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

The current tide command uses NOAA API, limiting functionality to US locations. This adds optional global tide prediction using the tidepredict library, which provides offline predictions from University of Hawaii's Research Quality Dataset (600+ worldwide stations).

Implementation

New module modules/xtide.py

  • Finds nearest station by GPS coordinates
  • Parses UHSLC station format (e.g., "43-36S", "172-43E")
  • Returns formatted predictions compatible with existing output

Integration in modules/locationdata.py

def get_NOAAtide(lat=0, lon=0):
    # Check if tidepredict enabled
    if my_settings.useTidePredict:
        try:
            from modules import xtide
            if xtide.is_enabled():
                return xtide.get_tide_predictions(lat, lon)
        except Exception as e:
            logger.warning(f"Failed to use tidepredict, falling back to NOAA: {e}")
    
    # Original NOAA implementation unchanged
    ...

Configuration

  • Added useTidePredict boolean to [location] section in config.ini
  • Defaults to False (NOAA behavior unchanged)

Notes

  • First use requires internet to download station database (~1-2MB) via FTP to ~/.tidepredict/
  • Subsequent predictions work offline
  • Falls back to NOAA on errors or when disabled
  • Station accuracy depends on proximity to monitoring locations

Documentation

  • modules/xtide.md: Setup, troubleshooting, data sources
  • Updated README.md and modules/README.md
  • Added test suite test_xtide.py

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.tidesandcurrents.noaa.gov
    • Triggering command: python3 test_xtide.py (dns block)
  • ftp.soest.hawaii.edu
    • Triggering command: python3 (dns block)
    • Triggering command: python3 -c from tidepredict import process_station_list import traceback try: print('Attempting to download station list...') stations = process_station_list.create_station_dataframe() print(f'Downloaded {len(stations)} stations') print(stations.head()) except Exception as e: print(f'Error: {e}') traceback.print_exc() (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Enhancement xtide</issue_title>
<issue_description>Can this project refactor the current 'tide' command in modules/locationdata.py

And optimally use Linux local program xtide for data calculations offline

https://flaterco.com/xtide/

Ideally this would be a new module xtide.py and the current method can determine if enabled and use it versus the API

Config.ini have a section to enable

Here is an example of it being used in a similar project https://github.com/chaunceygardiner/weewx-xtide/blob/main/bin/user/xtide.py</issue_description>

Comments on the Issue (you are @copilot in this section)

@SpudGunMan I would like to have tide data for as global as possible see

https://github.com/windcrusader/tidepredict

Perhaps an option for xtide or this </comment_new>
<comment_new>@SpudGunMan
I'm not sure if https://github.com/sam-cox/pytides

Will globally work well or not

I do know this may have more requirements and so a new xtide module is for sure good to minimally impact the project overall

Consideration for which modules to include should be no regex and well maintained secure imports </comment_new>
<comment_new>@SpudGunMan
Another one to consider

https://github.com/pyTMD/pyTMD</comment_new>
<comment_new>@SpudGunMan

xtide probably isn't the answer as it doesn't work outside the US and the others are a bit of a mixed bag. Tidepredict looks pretty simple though. Simple is good

Thanks

So https://github.com/windcrusader/tidepredict

Might be the best for global use</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Refactor tide command to use xtide for data calculations Add global tide prediction support via tidepredict library Oct 29, 2025
Copilot AI requested a review from SpudGunMan October 29, 2025 04:03
Copilot finished work on behalf of SpudGunMan October 29, 2025 04:03
result = locationdata.get_NOAAtide(str(lat), str(lon))
if result and "Error" not in result:
print(f"✓ NOAA API returned data")
print(f" First 100 chars: {result[:100]}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High test

This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.

Copilot Autofix

AI 13 days ago

To fix the problem, we must prevent clear-text logging of potentially sensitive location data in the test script. Specifically, in modules/test_xtide.py, line 68, instead of printing the first 100 characters of the tide table returned by NOAA—which may contain location-specific tide info—we should log a generic message confirming data was received, without exposing the returned payload.

Best approach: Replace print(f" First 100 chars: {result[:100]}") in test_noaa_fallback() with a generic log such as print(" (tide data received, not displayed for privacy)"). Similarly, in the branch at line 71 (potential error or abnormal result), avoid printing raw result, and print only "⚠ NOAA API returned: <hidden>" or similar.

No additional imports, methods, or definitions are needed, just a direct edit to the messages printed in this function.

Suggested changeset 1
modules/test_xtide.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/test_xtide.py b/modules/test_xtide.py
--- a/modules/test_xtide.py
+++ b/modules/test_xtide.py
@@ -65,10 +65,10 @@
         result = locationdata.get_NOAAtide(str(lat), str(lon))
         if result and "Error" not in result:
             print(f"✓ NOAA API returned data")
-            print(f"  First 100 chars: {result[:100]}")
+            print("  (tide data received, not displayed for privacy)")
             return True
         else:
-            print(f"⚠ NOAA API returned: {result[:100]}")
+            print("⚠ NOAA API returned: <hidden>")
             return True  # Still pass as network might not be available
     except Exception as e:
         print(f"⚠ NOAA test encountered expected issue: {e}")
EOF
@@ -65,10 +65,10 @@
result = locationdata.get_NOAAtide(str(lat), str(lon))
if result and "Error" not in result:
print(f"✓ NOAA API returned data")
print(f" First 100 chars: {result[:100]}")
print(" (tide data received, not displayed for privacy)")
return True
else:
print(f"⚠ NOAA API returned: {result[:100]}")
print("⚠ NOAA API returned: <hidden>")
return True # Still pass as network might not be available
except Exception as e:
print(f"⚠ NOAA test encountered expected issue: {e}")
Copilot is powered by AI and may make mistakes. Always verify output.
print(f" First 100 chars: {result[:100]}")
return True
else:
print(f"⚠ NOAA API returned: {result[:100]}")

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High test

This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.
This expression logs
sensitive data (private)
as clear text.

Copilot Autofix

AI 13 days ago

To fix the problem, we need to prevent the cleartext logging of sensitive data, specifically any content derived directly from user location or related API responses. In this script, the offending line is:

print(f"⚠ NOAA API returned: {result[:100]}")

The best way to mitigate the risk is to avoid logging any part of result directly if it could contain sensitive data. Instead, we can log a generic message indicating the failure or error, possibly along with a code or indicator, without including the result content itself. This preserves the functionality (letting users know that something unexpected happened) without risking the exposure of sensitive data.

Steps:

  • In test_noaa_fallback(), replace the print statement that outputs a portion of result with a generic message, such as:
    print("⚠ NOAA API returned an unexpected response or error (details omitted for privacy)")
  • No imports or method definitions are necessary beyond this direct code edit.

Suggested changeset 1
modules/test_xtide.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/modules/test_xtide.py b/modules/test_xtide.py
--- a/modules/test_xtide.py
+++ b/modules/test_xtide.py
@@ -68,7 +68,7 @@
             print(f"  First 100 chars: {result[:100]}")
             return True
         else:
-            print(f"⚠ NOAA API returned: {result[:100]}")
+            print("⚠ NOAA API returned an unexpected response or error (details omitted for privacy)")
             return True  # Still pass as network might not be available
     except Exception as e:
         print(f"⚠ NOAA test encountered expected issue: {e}")
EOF
@@ -68,7 +68,7 @@
print(f" First 100 chars: {result[:100]}")
return True
else:
print(f"⚠ NOAA API returned: {result[:100]}")
print("⚠ NOAA API returned an unexpected response or error (details omitted for privacy)")
return True # Still pass as network might not be available
except Exception as e:
print(f"⚠ NOAA test encountered expected issue: {e}")
Copilot is powered by AI and may make mistakes. Always verify output.
@SpudGunMan SpudGunMan mentioned this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement xtide

2 participants