Closed Jiangchao3 closed 1 month ago
Hey @Jiangchao3,
I'm adding a notebook to plot cotidal charts in #345, which could be modified for the Bay of Bengal.
The code base has been refactored a few times for simplification. The parallel function now is pyTMD.io.ATLAS.extract_constants
Hope this helps.
Hi @tsutterley, thanks so much for the information, I will go to try pyTMD.io.ATLAS.extract_constants, and waiting for your notebook example release.
Dear @tsutterley ,
I can use pyTMD.io.ATLAS.extract_constants to extract M2 amp at a location
amp, ph, D, c = pyTMD.io.ATLAS.extract_constants(lon, lat, grid, files, TYPE="z", GZIP=False, METHOD="bilinear", EXTRAPOLATE=True, SCALE=1.0 / 1000)
i also have the fes2014 and fes2022 tide solution data,
I try to do the same thing, buf failed:
amp_fes, ph_fes, D_fes, c_fes = pyTMD.io.FES.extract_constants(lon, lat, fes2014)
it says:
Traceback (most recent call last):
Cell In[20], line 2 amp_fes, ph_fes, D_fes, c_fes = pyTMD.io.FES.extract_constants(lon, lat, fes2022)
File ~/miniconda3/envs/pytmd/lib/python3.12/site-packages/pyTMD/io/FES.py:242 in extract_constants dlon = lon[1] - lon[0]
UnboundLocalError: cannot access local variable 'lon' where it is not associated with a value
I also try to check the netcdf file,
pyTMD.io.FES.read_netcdf_file(fes2022)
it says
Traceback (most recent call last):
Cell In[21], line 1 pyTMD.io.FES.read_netcdf_file(fes2022)
File ~/miniconda3/envs/pytmd/lib/python3.12/site-packages/pyTMD/io/FES.py:721 in read_netcdf_file amp = fileID.variables[amp_key][:]
UnboundLocalError: cannot access local variable 'amp_key' where it is not associated with a value
Any suggestions to help solve the problem, I just want to compare the amp using the two products.
Thanks, Jiangchao
Hey @Jiangchao3,
Right. The FES reader requires a version
input as the variable names are different between models. I could probably improve that in the future to try a few different variable options, but for now it is hard coded to require a version. I also should probably improve the exception handling so that you would have more descriptive error messages. As I haven't done that yet, please change your command to be:
amp, phase = pyTMD.io.FES.extract_constants(lon, lat, fes2014, version='FES2014')
p.s. also note that the amplitude units are different between models! I have a scale
keyword argument to convert everything to meters. But without entering that option the data will be returned as is stored in the original files. Please check out the documentation and the new cotidal chart notebook for more info.
-ts
@tsutterley thanks so much for your help!
Let you know that I can successfully extract TPXO9, FES2014/2022 amp, phase information using pyTMD.
But when I try to use the notebook you create yesterday to plot the M2 map,
when I run
TMDwidgets.constituents.options = c TMDwidgets.constituents.value = c[0] display(TMDwidgets.constituents)
it says:
Traceback (most recent call last):
Cell In[47], line 1 TMDwidgets.constituents.options = c
AttributeError: 'widgets' object has no attribute 'constituents'
Looking forwart to your advice to let example run to the end.
Best, Jiangchao
Right. That widget I added in #345, so it isn't in a released version of pyTMD
. If you have the repository cloned, you can install the "bleeding edge" by running
python3 -m pip install -e .
from the pyTMD
base level directory (the directory containing setup.py
). Or you can install the software directly from the GitHub repository by running
python3 -m pip install git+https://github.com/tsutterley/pyTMD.git
-ts
@tsutterley, thanks for sharing this, even after installing pyTMD via git, i am still encountering some issues, I think i might just wait for the next version release. Feel soory for disturbing you so much!
Right. Do the full install to get ipywidgets
and other software for running the notebooks. The default installation is more minimal to address complaints (e.g. #94 and #156). I thought the conda
install+bleeding edge would cover all the bases.
python3 -m pip install .[all]
@tsutterley thanks for sharing! I didn't know ipywidgets is a package. But finally, I plot it using your jupyter notebook.
ps: the following two lines did not work, it says CRSError: Invalid projection: EPSG:3031: (Internal Proj Error: proj_create: no database context specified)
crs1 = pyproj.CRS.from_epsg(3031)
crs2 = pyproj.CRS.from_epsg(4326)
I thought there are some conflict between pyproj and other package, since some use pip some use conda to install. I change to use:
crs_3031 = ccrs.Stereographic(central_latitude=-90) # Polar Stereographic for Antarctic region
crs_4326 = ccrs.PlateCarree() # This is equivalent to EPSG:4326 (WGS84)
then it works.
also the BoB region, thank your so much @tsutterley, I can not make it without your help.
Great! Glad you got what you needed! I'm going to convert this issue to a Discussion to keep it open in case you need anything.
Dear @tsutterley ,
This is Jiangchao, a freshman just learn how to use pyTMD. I have gone through the document of pyTMD, but still get a bit confused abou how to use it. Could you please guide me a bit how to accmpolish my goal in using pyTMD?
Task1: I want to use the h_m2_tpxo9-atlas_30_v5.nc to get the M2 amplitude at a location (lon, lat) = (91.05,22.2188). I try to use the method provided here [https://github.com/tsutterley/pyTMD/issues/103], but it sames that the pyTMD.read_netcdf_model is no available.
Taks2: How to plot a M2 map using h_m2_tpxo9-atlas_30_v5.nc for a local region lon (80, 99), lat (10, 22), the Bay of Bangal.
Looking forward to your help and suggestion.
Best regards, Jiangchao