tsutterley / pyTMD

Python-based tidal prediction software
https://pytmd.readthedocs.io
MIT License
134 stars 40 forks source link

how to get the time series SET displacement at one specific location (lon,lat)? #365

Open GEOSCIENCELXG opened 8 hours ago

GEOSCIENCELXG commented 8 hours ago

I want to get time series SET displacement at one location (lat, long). Can anyone help fulfill the below SET part: #Compute solid earth tide deformation?

import pandas as pd import matplotlib.pyplot as plt from pyTMD import compute_tide_corrections

from compute_SET_displacements import compute_SET_displacements

Input data (only one station)

times = pd.date_range("2022-01-01", "2022-01-10", freq="1D") point1_df = pd.DataFrame({'lat': 66.123480, 'lon': 342.085300, 'time': times})

# Compute solid earth tide deformation solid_earth_tide = compute_SET_displacements()

Compute tide heights using the TPXO10 model

tpxo10_corrections = compute_tide_corrections( x=point1_df.lon, y=point1_df.lat, delta_time=point1_df.time.values, DIRECTORY="/data1/tidemodels", MODEL="TPXO10-atlas-v2-nc", EPSG=4326, TYPE="drift", TIME="datetime", METHOD="bilinear", )

Compute tide heights using the TPXO9 model

tpxo9_corrections = compute_tide_corrections( x=point1_df.lon, y=point1_df.lat, delta_time=point1_df.time.values, DIRECTORY="/data1/tidemodels", MODEL="TPXO9-atlas-v5-nc", EPSG=4326, TYPE="drift", TIME="datetime", METHOD="bilinear", )

Add tide height and solid earth tide deformation to DataFrame

point1_df['tpxo10_tide'] = tpxo10_corrections point1_df['tpxo9_tide'] = tpxo9_corrections point1_df['solid_earth_tide'] = solid_earth_tide # Add solid earth tide displacement data

Calculate the difference between the models

point1_df['tide_diff'] = point1_df['tpxo10_tide'] - point1_df['tpxo9_tide']

Create subplots

fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(10, 18))

Plot tide heights for TPXO10 and TPXO9 in the first subplot

ax1.plot(point1_df['time'], point1_df['tpxo10_tide'], label="TPXO10", color='b', linestyle='-') ax1.plot(point1_df['time'], point1_df['tpxo9_tide'], label="TPXO9", color='r', linestyle='--')

Add title and labels to the first subplot

ax1.set_title(f"Tide Heights Comparison for Point 1 (Lat: {point1_df['lat'].iloc[0]}, Lon: {point1_df['lon'].iloc[0]})") ax1.set_xlabel("Time") ax1.set_ylabel("Tide Height (m)") ax1.legend() ax1.grid(True) ax1.tick_params(axis='x', rotation=45)

Plot tide height difference in the second subplot

ax2.plot(point1_df['time'], point1_df['tide_diff'], label="Difference (TPXO10 - TPXO9)", color='g', linestyle=':')

Add title and labels to the second subplot

ax2.set_title("Tide Height Difference (TPXO10 - TPXO9)") ax2.set_xlabel("Time") ax2.set_ylabel("Tide Height Difference (m)") ax2.legend() ax2.grid(True) ax2.tick_params(axis='x', rotation=45)

Plot solid earth tide deformation in the third subplot

ax3.plot(point1_df['time'], point1_df['solid_earth_tide'], label="Solid Earth Tide Displacement", color='purple', linestyle='-.')

Add title and labels to the third subplot

ax3.set_title("Solid Earth Tide Deformation") ax3.set_xlabel("Time") ax3.set_ylabel("Solid Earth Tide Deformation (m)") ax3.legend() ax3.grid(True) ax3.tick_params(axis='x', rotation=45)

Adjust layout

plt.tight_layout()

Display the plot

plt.show()

tsutterley commented 3 hours ago

I think this should work.

point1_df['solid_earth_tide'] = pyTMD.compute.SET_displacements(
    point1_df.lon, point1_df.lat, point1_df.time, 
    EPSG=4326, TIME='datetime', TIDE_SYSTEM='tide_free'
)