ec-jrc / pyPoseidon

Framework for Hydrodynamic simulations
https://pyposeidon.readthedocs.io/
European Union Public License 1.2
20 stars 8 forks source link

Configure update option #114

Closed brey closed 1 year ago

brey commented 2 years ago

This is a control on model building to exclude features such as update dem, meteo, etc. It's not fully integrated.

tomsail commented 9 months ago

I have a problem at this line when using the sizing from oceanmesh:

Traceback (most recent call last):
  File "/home/tomsail/work/python/pyPoseidon/Tutorial/mesh_model_test.py", line 40, in <module>
    b.create()
  File "/home/tomsail/work/python/pyPoseidon/pyposeidon/schism.py", line 455, in create
    self.mesh = pmesh.set(type="tri2d", **kwargs)
  File "/home/tomsail/work/python/pyPoseidon/pyposeidon/mesh.py", line 36, in set
    return tri2d(**kwargs)
  File "/home/tomsail/work/python/pyPoseidon/pyposeidon/mesh.py", line 226, in __init__
    g, bg = moceanmesh.get(self.boundary.contours, **kwargs)  # create mesh with OCEANMESH
  File "/home/tomsail/work/python/pyPoseidon/pyposeidon/moceanmesh.py", line 136, in get
    gr = make_oceanmesh(contours, **kwargs)
  File "/home/tomsail/work/python/pyPoseidon/pyposeidon/moceanmesh.py", line 411, in make_oceanmesh
    dem = om.DEM(dem_source, crs=crs, bbox=extent)
  File "/home/tomsail/work/python/pyPoseidon/Tutorial/.venv/lib/python3.10/site-packages/oceanmesh/geodata.py", line 777, in __init__
    if dem.exists():
  File "/home/tomsail/work/python/pyPoseidon/Tutorial/.venv/lib/python3.10/site-packages/xarray/core/common.py", line 278, in __getattr__
    raise AttributeError(
AttributeError: 'Dataset' object has no attribute 'exists'

This is cause by the update of this line :

kwargs.update({"dem_source": self.dem.Dataset})

is that line really needed ? since we already have the variable self.dem attributed?

pmav99 commented 9 months ago

The if dem.exists() line in oceamesh implies that dem is expected to be a pathlib.Path object on which they call the .exists() method.

Instead of a pathlib.Path object you pass an xarray.Dataset object. That's why the exception gets thrown.

If I remember well, self.dem is an instance of the Dem class which has an attribute named Dataset which is an instance of xarray Dataset. Check the other attributes and you may find a path to the DEM file. If there is such an attribute, pass that one to oceamesh. If the DEM has been downloaded from the internet then you may need to save it in a temporary file

tomsail commented 9 months ago

If I remember well, self.dem is an instance of the Dem class which has an attribute named Dataset which is an instance of xarray Dataset. Check the other attributes and you may find a path to the DEM file. If there is such an attribute, pass that one to oceamesh. If the DEM has been downloaded from the internet then you may need to save it in a temporary file

that's why I am asking if it is really necessary. If self.dem is an xarray, why should self.dem_source (originary a path) be replaced by self.dem? Having both as xarray is redundant

pmav99 commented 9 months ago

You will have to wait for @brey

BTW, shouldn't this be a different issue?