Comments (8)
I've noticed another issue with model definition files which is somehow connected to this issue (therefore I'm just adding this point here).
For OTIS/ATLAS/GOT-type models, the respective extract_constants
function returns a list of constituents names. This is not the case for FES-type models. Therefore, you define model.constituents
manually in model.py for FES-type models. However, if the model is defined by definition file, model.constituents
is None
and pyTMD.predict.drift
fails.
I think one possibility would be to define the constituents list in the definition file as well (but this would conflict with the Glob patterns). I suggest another way of handling this:
For the other type of models, you return the constituents directly from extract_constants
. Maybe this could be adapted for FES-type models as well. As the constituent name is not saved in the file (e.g. as a nc-attribute), it needs to be extracted from the filename. These are:
- for FES:
'2n2.nc','eps2.nc','j1.nc',...
- for EOT:
'2N2_ocean_eot20.nc','J1_ocean_eot20.nc','K1_ocean_eot20.nc','K2_ocean_eot20.nc',...
- for HAMTIDE:
'2n.hamtide11a.nc','k1.hamtide11a.nc','k2.hamtide11a.nc','m2.hamtide11a.nc','n2.hamtide11a.nc',...
For FES and EOT, this does the job for me:
if(model.version=="FES2014"):
model.constituents = [pathlib.PurePath(file_now).stem for file_now in model.model_file]
elif(model.version=="EOT20"):
model.constituents = [pathlib.PurePath(file_now).stem.replace("_ocean_eot20","").lower() for file_now in model.model_file]
for i,cons in enumerate(model.constituents):
if(cons=="la2"): model.constituents[i] = "lambda2"
Maybe this could be integrated in extract_constants
in FES.py
? For the sake of robustness, you could allow to still define the constituents manually but if they are None
, those extracted from the filenames will be used.
BTW thanks for the hint with pathlib
! Especially stem
is very nice, as it avoids the need for sebsequent calls of os.path.basename
and os.path.splitext
;)
from pytmd.
Alright. I think I have this all working now in main. The constituents parsing bit did require some remapping functionality for the lambda2 case as you said (there's also a 2n2 case for HAMTIDE models).
To use globs with definition files:
- Define a base path in
io.model
to search for the files - Set the glob string as
model_file
in your model definition file. This can include subdirectories if wanting to use a set base directory for all tide models.
For FES2014 elevations, this would look like
model_file fes2014/ocean_tide/*.nc.gz
For FES2014 currents, this would look like
model_file fes2014/eastward_velocity/*.nc.gz;fes2014/northward_velocity/*.nc.gz
The python call for reading the definition file would look like
model = pyTMD.io.model(DIRECTORY).from_file(DEFINITION_FILE)
where DIRECTORY
is not None
. Having DIRECTORY
be None
uses fully defined paths in the definition file (as it was previously for all definition file cases).
Happy to work on this more, but I figured I could get this initial capability out for you to tinker with! Let me know what you think! :)
from pytmd.
Amazing how fast you implemented that! It works almost like a charm but I have two remaining suggestions:
- If the globbing fails, either in case of typos or if the user uses
DIRECTORY
+ full path in theDEFINITION_FILE
(as I did at first :) ) no files are found and you get this error message:
File "pyTMD/io/model.py", line 1358, in from_file
temp.model_directory = temp.model_file[0].parent
IndexError: list index out of range
Maybe you could check this case and send an error message that makes it easier to understand whats going on. I suggest:
globstr = temp.directory.joinpath(temp.model_file) # need to save this as temp.model_file gets overwritten
temp.model_file = list(temp.directory.glob(temp.model_file))
if(len(temp.model_file)<1): print("No model files found for "+str(globstr)); exit()
- For consistency, prepending the
DIRECTORY
to the files specified in theDEFINITION_FILE
should be done for thegrid_file
(e.g. for TPXO) as well.
from pytmd.
Perfect! Thanks!
from pytmd.
Thanks @DerLude, this is a good idea I just need to think about how I want to implement it.
The print test bug is fixed in the dev
branch. Hopefully I finish what I'm working on and can get that bug squashed. 🤦
from pytmd.
ok. the fix is in #186.
still need to think about how to implement the glob strings
from pytmd.
ok. I'm working on implementing the ability to use glob patterns in the latest dev
branch. Going to refactor a bit of the code base to use pathlib
to define, expand and operate on paths. This'll be for the next release 2.0.4
.
from pytmd.
I like those changes! They're in #190
from pytmd.
Related Issues (20)
- `scipy` v1.10.0 fails for `RegularGridInterpolator`
- compute_tidal_elevations.py --type=grid fails with shape mismatch HOT 1
- Suggestion: show tidal models in help HOT 2
- pyTMD without Jupyter HOT 2
- Getting-Started.rst old link to Arc2kmTM HOT 1
- Netcdf time needs to be double HOT 1
- Definition File for HAMTIDE constituents HOT 3
- pyTMD.io.model not working for current with FES2014 HOT 3
- How to get a datum and a datum value? HOT 2
- setting directory and model HOT 17
- FES2012 support? HOT 4
- FileNotFoundError HOT 1
- Interpolation `METHOD="spline"` fails for TPXO8 HOT 8
- Issue with Iterating Over Model Files in pyTMD.io.ATLAS.extract_constants() HOT 2
- NameError: name 'ipyleaflet' is not defined HOT 1
- module 'pyTMD' has no attribute 'compute' HOT 2
- pyTMD.compute.tide_currents needing both u_* and v_* rather than only u_* HOT 16
- From barotropic velocity to surface velocity
- X-TRACK tidal constants and pyTMD? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytmd.