@@ -509,12 +509,19 @@ def from_netCDF(
509509 raise ValueError (err )
510510 #bathymetry data is on cell centers, but needs to be averaged to the nodes in order
511511 #to properly define the terrain following coordinate.
512- k = (bathy_var [0 :- 1 ,:] + bathy_var [1 :,:]) / 2
513- psi_h = (k [:,0 :- 1 ] + k [:,1 :]) / 2
514- bathymetry = Bathymetry (
515- data = psi_h ,
516- grid = grid ,
517- name = "bathymetry" ,
512+ if 'node' in grid .infer_location (bathy_var ):
513+ bathymetry = Bathymetry (
514+ data = bathy_var ,
515+ grid = grid ,
516+ name = "bathymetry" ,
517+ )
518+ else :
519+ h = (bathy_var [0 :- 1 ,:] + bathy_var [1 :,:]) / 2
520+ psi_h = (h [:,0 :- 1 ] + h [:,1 :]) / 2
521+ bathymetry = Bathymetry (
522+ data = psi_h ,
523+ grid = grid ,
524+ name = "bathymetry" ,
518525 )
519526
520527 if zeta is None :
@@ -527,11 +534,14 @@ def from_netCDF(
527534 warnings .warn (warn )
528535 zeta = Zeta .constant (0 )
529536 else :
530- #zeta data is on cell centers, but needs to be averaged to the nodes in order
531- #to properly define the terrain following coordinate.
532- z = (zeta_var [0 :- 1 ,:] + zeta_var [1 :,:]) / 2
533- psi_z = (z [:,0 :- 1 ] + z [:,1 :]) / 2
534- zeta = Zeta (data = psi_z , grid = grid , time = time , name = "zeta" )
537+ if 'node' in grid .infer_location (bathy_var ):
538+ zeta = Zeta (data = zeta_var , grid = grid , time = time , name = "zeta" )
539+ else :
540+ #zeta data is on cell centers, but needs to be averaged to the nodes in order
541+ #to properly define the terrain following coordinate.
542+ z = (zeta_var [0 :- 1 ,:] + zeta_var [1 :,:]) / 2
543+ psi_z = (z [:,0 :- 1 ] + z [:,1 :]) / 2
544+ zeta = Zeta (data = psi_z , grid = grid , time = time , name = "zeta" )
535545
536546 if terms is None :
537547 terms = {}
0 commit comments