Skip to content

Query about interpolation in gridded_timeseries.py #140

Description

@sspagnol

Have a query about the interpolation done in grid_variable function in gridded_timeseries.py

Had a situation where in some timesteps the profile had nan data, which when interpolated seems to produce more nans that I expected. Consider the toy problem

print("np.interp test")
depth_bins = np.array([10, 20, 30, 40, 50])

depths = np.array([12, 27, 35, 46])
values = np.array([1, 2, np.nan, 5])

print(depth_bins)
interp_values = np.interp(depth_bins, depths, values, left=np.nan, right=np.nan)
print(interp_values)

# interpolate non-nan
nmask = np.logical_or(np.isnan(depths), np.isnan(values))
interp_values = np.interp(depth_bins, depths[~nmask], values[~nmask], left=np.nan, right=np.nan)
print(interp_values)

which produces

np.interp test
[10 20 30 40 50]
[       nan 1.53333333        nan        nan        nan]
[       nan 1.53333333 2.47368421 4.05263158        nan]

What is the reasoning to want depth_bins 30 and 40 to be set to nan?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    gridded_timeseriesIssues relating to the gridded time series productquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions