Skip to content

Feature suggestion: control dtype for tide prediction #618

Open

Description

@robbibt

Currently, modelled tides are returned with a float64 dtype:

import pandas as pd
import pyTMD
import timescale

# Define coordinates and time period
x_coords = [150, 155]
y_coords = [-35, -40]
time = pd.date_range("2020-01", "2020-03", periods=2)

# Model tides
ts = timescale.time.Timescale().from_datetime(time)
m = pyTMD.io.model("/gdata1/data/tide_models/").from_database("EOT20")
ds = m.open_dataset(group="z", constituents=["m2"])
X, Y = ds.tmd.coords_as(x_coords, y_coords, type="trajectory", crs=4326)
local = ds.tmd.interp(x=X, y=Y, extrapolate=True)
tide = local.tmd.predict(ts.tide, deltat=ts.tt_ut1, corrections=m.corrections)
tide += local.tmd.infer(ts.tide, deltat=ts.tt_ut1, corrections=m.corrections)
tide.dtype

>>> dtype('float64')

This can use a lot of memory when running a large tidal analysis. Given the precision of the models, it's likely that float64 is overkill - in many cases, float32 would be sufficient and less memory hungry. I can convert my tide output to float32 after the fact easily enough (e.g. tide.astype("float32")) but this doesn't entirely avoid peak memory issues that occur before the conversion.

It would be fantastic if we could specify an output dtype during tide prediction to control the dtype used by the output xarray.DataArray. For example, something like:

tide = local.tmd.predict(ts.tide, deltat=ts.tt_ut1, corrections=m.corrections, dtype="float32")
tide += local.tmd.infer(ts.tide, deltat=ts.tt_ut1, corrections=m.corrections, dtype="float32")
tide.dtype

>>> dtype('float32')

Activity

  1. changed the title [-]Feature suggestion: control dtype for modelled tides[/-] [+]Feature suggestion: control dtype for tide prediction[/+] on Aug 21, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions