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

FES2022 does not produce tides at certain locations [see solution provided] #570

Open
mtzaria opened this issue Jan 25, 2025 · 2 comments
Open

Comments

@mtzaria
Copy link

mtzaria commented Jan 25, 2025

though no error exported my index of the dates_ts, tides_ts are zero. my centroid is: [-8.81612121 41.59466746]. the code run successfully for another location? may the location be problem?

@kvos kvos changed the title Issues with running compute tide FES2022 does not produce tides at certain locations [see solution provided] Jan 28, 2025
@kvos
Copy link
Owner

kvos commented Jan 28, 2025

yes it could be you're outside the range of the FES2022 grid. I suggest to load one netcdf file and then find the grid point closest to your centroid, something like this:

# load libraries
from netCDF4 import Dataset
import numpy as np
from coastsat import SDS_slope
filepath_FES = r'C:\Users\KilianVos\Documents\fes2022b'
# load lat-lon grid from one of the model files
data = Dataset(os.path.join(filepath_FES, 'ocean_tide', 'm2' + '_fes2022.nc'))
lats = np.array(data.variables['lat'])
lons = np.array(data.variables['lon'])
amplitude = np.array(data.variables['amplitude'])
no_data_value = data.variables['amplitude']._FillValue
mask = amplitude == no_data_value
grid_coords = np.stack([lons[np.where(~mask)[1]],lats[np.where(~mask)[0]]],axis=1)
# get polygon centroid, coordinates to get tides from
centroid = np.mean(polygon[0], axis=0)
# if longitude is negative add 180 (longitudes are from 0 to 360 in fes)
if centroid[0] < 0: centroid[0] += 180
# find closest point on global grid
idx_closest = np.argmin(np.linalg.norm(centroid-grid_coords, axis=1))
# get closest gridpoint point
centroid_gridded = grid_coords[idx_closest,:]

then querry the tide time-series at centroid_gridded!
tides = SDS_slope.compute_tide_dates(centroid_gridded, dates, ocean_tide, load_tide)

@Mascagni-ML
Copy link

There is a small error in this part of the code.
# if longitude is negative add 180 (longitudes are from 0 to 360 in fes) if centroid[0] < 0: centroid[0] += 180

The correct value to be added is 360 and not 180, to convert negative longitudes in the format [-180 to 180] to [0 to 360].
Correcting the value, for example:
longitudes -10 + 360 = 350.
longitudes -60 + 360 = 300.
and so on.

thus it should be:
# if longitude is negative add 360 (longitudes are from 0 to 360 in fes) if centroid[0] < 0: centroid[0] += 360

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

No branches or pull requests

3 participants