Skip to content

Accessing list of model constituents for any supported pyTMD model #449

Open

Description

@robbibt

Hey Tyler, I'm looking for a way to access a list of valid constituent names for a given tide model. I can do this easily for models I have access to locally, e.g.:

import pyTMD

pyTMD.io.model(directory=directory).elevation(m="FES2014").constituents

>>> ['2n2', 'eps2', 'j1', 'k1', 'k2', 'l2', 'lambda2', 'm2', 'm3', 'm4',
       'm6', 'm8', 'mf', 'mks2', 'mm', 'mn4', 'ms4', 'msf', 'msqm', 'mtm',
       'mu2', 'n2', 'n4', 'nu2', 'o1', 'p1', 'q1', 'r2', 's1', 's2', 's4',
       'sa', 'ssa', 't2']

However, this approach only works for models I have access to; otherwise I get a FileNotFoundError:

pyTMD.io.model(directory=directory).elevation(m="AOTIM-5").constituents

>>> FileNotFoundError: /var/share/tide_models/aotim5_tmd/grid_Arc5km

Is there an easy way to get a list of consitituent names for any pyTMD-supported tide model, without having access to their files? I've had a look in the model database, but I can't see a list of standardised constituent names defined in there.

(My end goal is to support running a tide aliasing analysis for all constituents in a given model, based on the overpass frequency of certain EO satellites).

Activity

  1. tsutterley commented on Aug 18, 2025

    @tsutterley
    Member

    great question! Right now for several model types the constituents are parsed or read from the files. I should be able to update the database to add the constituent parameter for any of the models.

  2. robbibt commented on Aug 19, 2025

    @robbibt
    ContributorAuthor

    OK, makes sense! Not a high priority thing - I think for now I can just base it on models the user has installed, as that's probably the most useful option anyway. 🙂

  3. robbibt commented on Sep 8, 2025

    @robbibt
    ContributorAuthor

    Hey @tsutterley, a possible related issue: I can do this to get a list of model constituents for most models:

    pytmd_model = pyTMD.io.model(directory=directory).elevation("FES2022_extrapolated")
    pytmd_model.constituents
    
    > ['2n2', ..., 't2']
    

    However, if I do the same thing for TPXO10, this just returns None:

    pytmd_model = pyTMD.io.model(directory=directory).elevation("TPXO10-atlas-v2-nc")
    pytmd_model.constituents
    

    (I'm on pyTMD==2.2.7)

  4. robbibt commented on Sep 8, 2025

    @robbibt
    ContributorAuthor

    Ah, I just saw this:

    Image

    So this likely isn't defined for non-FES models. Is there another way to get a list of model constituent names for a non-FES model like TPXO10, or would I need to read the model files first?

  5. tsutterley commented on Sep 8, 2025

    @tsutterley
    Member

    Hey @robbibt
    Yeah, for models where it's just parsing the filenames to get the constituents (like the TPXO atlas models) you should just need to run the model's parse_constituents function.

    pytmd_model.parse_constituents()
    print(pytmd_model.constituents)
    
  6. robbibt commented on Sep 8, 2025

    @robbibt
    ContributorAuthor

    Thanks @tsutterley! That's great to know. The only other issue I'm seeing now is that the list of returned constituents seems to be the full list supported by the model, and not any smaller subset of constituents the user has chosen to load - I'm not sure if that's because read_constants loads all available constituents (i.e. not just the requested subset), or because parse_constituents reads directly from the full list of file paths (i.e. not just the loaded constituents)

    constituents_subset = ["m2"]
    
    pytmd_model = pyTMD.io.model(directory=directory).elevation("TPXO10-atlas-v2-nc")
    pytmd_model.read_constants(constituents=constituents_subset)
    pytmd_model.parse_constituents()
    pytmd_model.constituents
    
    > ['2n2',  'k1',  'k2',  'm2',  'm4',  'mf',  'mm',  'mn4',  'ms4',  'n2',  'o1',  'p1',  'q1',  's1',  's2'] 
    
  7. tsutterley commented on Sep 8, 2025

    @tsutterley
    Member

    oh in that case I think it might be even easier. You should just need to run:

    pytmd_model.reduce_constituents(constituent_subset)
    pytmd_model.read_constants()
    pytmd_model.constituents
    

    OR! for all cases (including models where the constituents are not parsed from the filename)

    pytmd_model.read_constants(constituents=constituent_subset)
    pytmd_model._constituents.fields
    
  8. robbibt commented on Sep 8, 2025

    @robbibt
    ContributorAuthor

    The second option unfortunately doesn't seem to pick up the subset either:

    Image

    But the first option works perfectly!

    Image
  9. tsutterley commented on Sep 8, 2025

    @tsutterley
    Member

    Oh right I ran into that. Should be fixed in 2.2.8!
    But glad you have a solution!

  10. robbibt commented on Sep 8, 2025

    @robbibt
    ContributorAuthor

    Neat, yep, works great in 2.2.8:

    Image

    Thanks for the troubleshooting help!

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