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

Issue with Iterating Over Model Files in pyTMD.io.ATLAS.extract_constants() #258

Closed
mirkorupani opened this issue Nov 17, 2023 · 2 comments · Fixed by #259
Closed

Issue with Iterating Over Model Files in pyTMD.io.ATLAS.extract_constants() #258

mirkorupani opened this issue Nov 17, 2023 · 2 comments · Fixed by #259

Comments

@mirkorupani
Copy link

Description:
I have encountered an issue in the extract_constants function in pyTMD.io.ATLAS, specifically when using the 'TPXO9-atlas-v2' model for currents. In previous versions, the function iterated over a list of model files directly, while in the latest version, it iterates over the keys ("u" and "v") of a dictionary containing the model files. This change causes the function to incorrectly loop over the dictionary keys instead of the actual files.

Affected Code:
The relevant code snippets in the latest version looks like this:
# number of constituents nc = len(model_files)

for i, model_file in enumerate(model_files):

Proposed Fix:
I have found that these corrections fix this issue, at least in my specific case.
The loop should iterate over the list of model files corresponding to the specified type. The modified snippets should be:
# number of constituents nc = len(model_files[kwargs['type']])

for i, model_file in enumerate(model_files[kwargs['type']]):

These changes ensure that the function correctly calculates the number of constituents and iterates over the actual files associated with the specified type.

Steps to Reproduce:

  1. Use a 'TPXO9-atlas-v2' currents model.
    model = pyTMD.io.model(tpxodirectory).current('TPXO9-atlas-v2')
  2. Call the extract_constants function, specifying 'u' or 'v' as the type.
    (amplitude, phase, D, constituents) = extract_constants(ilon, ilat, model.grid_file, model.model_file, type="u")

Expected Result:
The function should iterate over the list of model files for the specified type.

Actual Result:
The function currently iterates over the dictionary keys, causing a FileNotFoundError.

Additional Information:

  • pyTMD version: 2.0.8
  • Model: 'TPXO9-atlas-v2' currents
  • Type: 'u' or 'v'

Thank you for your attention to this matter.

Best regards,
Mirko.

@tsutterley
Copy link
Owner

Hi @mirkorupani,
I am reverting some changes I made in April for the TPXO9-atlas currents in #259. I think this fixes the issue in the case where the model files are netCDF4. I only have the OTIS-formatted versions of the atlas current files, so I'm not 100%. model.model_file being a dictionary is purposeful. I think the changes you'd have to make are to put the extraction function in a for loop.

for t in model.type:
    amplitude, phase, D, constituents = pyTMD.io.ATLAS.extract_constants(
        ilon, ilat, model.grid_file, model.model_file[t], type=t,
        scale=model.scale)

Let me know if this fixes the issue.

tsutterley added a commit that referenced this issue Nov 17, 2023
test: fix u and v for TPXO9-atlas netCDF

fix: escape sequences in docstrings to raw
tsutterley added a commit that referenced this issue Nov 18, 2023
…259)

* test: fix u and v for TPXO9-atlas netCDF
* fix: escape sequences in docstrings to raw
* fix: updated ssl context to fix deprecation error
* docs: update docstrings for ssl context
@tsutterley
Copy link
Owner

Changes are now merged into main. Feel free to reopen this issue if need be :)

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

Successfully merging a pull request may close this issue.

2 participants