@@ -42,7 +42,11 @@ def get_all_time(data: (netCDF4.Dataset, xr.Dataset)) -> NDArray:
4242 seconds_run = np .ma .getdata (data .variables ["time" ][:], False )
4343
4444 elif isinstance (data , xr .Dataset ):
45- seconds_run = (data .time .values - data .time .values [0 ]).astype ('timedelta64[s]' ).astype (int )
45+ seconds_run = (
46+ (data .time .values - data .time .values [0 ])
47+ .astype ("timedelta64[s]" )
48+ .astype (int )
49+ )
4650
4751 return seconds_run
4852
@@ -273,7 +277,9 @@ def get_layer_data(
273277 bottom_depth = np .ma .getdata (
274278 data .variables ["mesh2d_waterdepth" ][time_index , :], False
275279 )
276- waterlevel = np .ma .getdata (data .variables ["mesh2d_s1" ][time_index , :], False )
280+ waterlevel = np .ma .getdata (
281+ data .variables ["mesh2d_s1" ][time_index , :], False
282+ )
277283 coords = str (data .variables ["waterdepth" ].coordinates ).split ()
278284
279285 elif str (data .variables [variable ].coordinates ) == "FlowElem_xcc FlowElem_ycc" :
@@ -287,7 +293,9 @@ def get_layer_data(
287293 "coords" : data .variables ["LayCoord_w" ][:],
288294 },
289295 }
290- bottom_depth = np .ma .getdata (data .variables ["waterdepth" ][time_index , :], False )
296+ bottom_depth = np .ma .getdata (
297+ data .variables ["waterdepth" ][time_index , :], False
298+ )
291299 waterlevel = np .ma .getdata (data .variables ["s1" ][time_index , :], False )
292300 coords = str (data .variables ["waterdepth" ].coordinates ).split ()
293301 else :
@@ -301,7 +309,9 @@ def get_layer_data(
301309 "coords" : data .variables ["LayCoord_w" ][:],
302310 },
303311 }
304- bottom_depth = np .ma .getdata (data .variables ["waterdepth" ][time_index , :], False )
312+ bottom_depth = np .ma .getdata (
313+ data .variables ["waterdepth" ][time_index , :], False
314+ )
305315 waterlevel = np .ma .getdata (data .variables ["s1" ][time_index , :], False )
306316 coords = str (data .variables ["waterdepth" ].coordinates ).split ()
307317
@@ -318,12 +328,16 @@ def get_layer_data(
318328 "name" : "mesh2d_nInterfaces" ,
319329 "coords" : data .variables ["mesh2d_interface_sigma" ][:],
320330 },
321- }
331+ }
322332 bottom_depth = data ["mesh2d_waterdepth" ].values [time_index , :]
323333 waterlevel = data ["mesh2d_s1" ].values [time_index , :]
324334 coords = list (data ["waterdepth" ].coords )
325- elif str (list (data [variable ].coords )) == "['FlowElem_xcc', 'FlowElem_ycc', 'time']" or \
326- str (list (data [variable ].coords )) == "['FlowLink_xu', 'FlowLink_yu', 'time']" :
335+ elif (
336+ str (list (data [variable ].coords ))
337+ == "['FlowElem_xcc', 'FlowElem_ycc', 'time']"
338+ or str (list (data [variable ].coords ))
339+ == "['FlowLink_xu', 'FlowLink_yu', 'time']"
340+ ):
327341 cords_to_layers = {
328342 "FlowElem_xcc FlowElem_ycc" : {
329343 "name" : "laydim" ,
@@ -332,8 +346,8 @@ def get_layer_data(
332346 "FlowLink_xu FlowLink_yu" : {
333347 "name" : "wdim" ,
334348 "coords" : data .variables ["LayCoord_w" ][:],
335- },
336- }
349+ },
350+ }
337351 bottom_depth = data ["waterdepth" ].values [time_index , :]
338352 waterlevel = data ["s1" ].values [time_index , :]
339353 coords = list (data ["waterdepth" ].coords )
@@ -351,19 +365,19 @@ def get_layer_data(
351365 bottom_depth = data ["waterdepth" ].values [time_index , :]
352366 waterlevel = data ["s1" ].values [time_index , :]
353367 coords = list (data ["waterdepth" ].coords )
354-
368+
355369 layer_dim = " " .join (map (str , list (data [variable ].coords )[0 :2 ]))
356370
357371 try :
358372 cord_sys = cords_to_layers [layer_dim ]["coords" ]
359373 except KeyError as exc :
360374 raise ValueError ("Coordinates not recognized." ) from exc
361-
375+
362376 if isinstance (data , netCDF4 .Dataset ):
363377 layer_percentages = np .ma .getdata (cord_sys , False ) # accumulative
364378 elif isinstance (data , xr .Dataset ):
365- layer_percentages = cord_sys .values # accumulative
366-
379+ layer_percentages = cord_sys .values # accumulative
380+
367381 if layer_dim == "FlowLink_xu FlowLink_yu" :
368382 # interpolate
369383 if isinstance (data , netCDF4 .Dataset ):
@@ -411,9 +425,13 @@ def get_layer_data(
411425 waterdepth = np .append (waterdepth , z )
412426
413427 if isinstance (data , netCDF4 .Dataset ):
414- time = np .ma .getdata (data .variables ["time" ][time_index ], False ) * np .ones (len (x ))
428+ time = np .ma .getdata (data .variables ["time" ][time_index ], False ) * np .ones (
429+ len (x )
430+ )
415431 elif isinstance (data , xr .Dataset ):
416- time = (data .time .values [time_index ] - data .time .values [0 ]).astype ('timedelta64[s]' ).astype (int ) * np .ones (len (x ))
432+ time = (data .time .values [time_index ] - data .time .values [0 ]).astype (
433+ "timedelta64[s]"
434+ ).astype (int ) * np .ones (len (x ))
417435
418436 index = np .arange (0 , len (time ))
419437 layer_data = xr .Dataset (
@@ -616,7 +634,9 @@ def variable_interpolation(
616634 )
617635
618636 if not isinstance (data , (netCDF4 .Dataset , xr .Dataset )):
619- raise TypeError (f"data must be netCDF4 or xarray Dataset object. Got { type (data )} " )
637+ raise TypeError (
638+ f"data must be netCDF4 or xarray Dataset object. Got { type (data )} "
639+ )
620640
621641 if not isinstance (to_pandas , bool ):
622642 raise TypeError (f"to_pandas must be of type bool. Got: { type (to_pandas )} " )
@@ -665,7 +685,10 @@ def variable_interpolation(
665685
666686
667687def get_all_data_points (
668- data : (netCDF4 .Dataset , xr .Dataset ), variable : str , time_index : int = - 1 , to_pandas : bool = True
688+ data : (netCDF4 .Dataset , xr .Dataset ),
689+ variable : str ,
690+ time_index : int = - 1 ,
691+ to_pandas : bool = True ,
669692) -> Union [pd .DataFrame , xr .Dataset ]:
670693 """
671694 Get data points for a passed variable for all layers at a specified time from
@@ -749,51 +772,55 @@ def get_all_data_points(
749772
750773 layer_dim = str (data .variables [variable ].coordinates )
751774 elif isinstance (data , xr .Dataset ):
752- if "mesh2d" in variable :
753- cords_to_layers = {
754- "mesh2d_face_x mesh2d_face_y" : {
755- "name" : "mesh2d_nLayers" ,
756- "coords" : data .variables ["mesh2d_layer_sigma" ][:],
757- },
758- "mesh2d_edge_x mesh2d_edge_y" : {
759- "name" : "mesh2d_nInterfaces" ,
760- "coords" : data .variables ["mesh2d_interface_sigma" ][:],
761- },
762- }
763- bottom_depth = data ["mesh2d_waterdepth" ].values [time_index , :]
764- waterlevel = data ["mesh2d_s1" ].values [time_index , :]
765- coords = list (data ["waterdepth" ].coords )
766- elif str (list (data [variable ].coords )) == "['FlowElem_xcc', 'FlowElem_ycc', 'time']" or \
767- str (list (data [variable ].coords )) == "['FlowLink_xu', 'FlowLink_yu', 'time']" :
768- cords_to_layers = {
769- "FlowElem_xcc FlowElem_ycc" : {
770- "name" : "laydim" ,
771- "coords" : data .variables ["LayCoord_cc" ][:],
772- },
773- "FlowLink_xu FlowLink_yu" : {
774- "name" : "wdim" ,
775- "coords" : data .variables ["LayCoord_w" ][:],
776- },
777- }
778- bottom_depth = data ["waterdepth" ].values [time_index , :]
779- waterlevel = data ["s1" ].values [time_index , :]
780- coords = list (data ["waterdepth" ].coords )
781- else :
782- cords_to_layers = {
783- "FlowElem_xcc FlowElem_ycc LayCoord_cc LayCoord_cc" : {
784- "name" : "laydim" ,
785- "coords" : data .variables ["LayCoord_cc" ][:],
786- },
787- "FlowLink_xu FlowLink_yu" : {
788- "name" : "wdim" ,
789- "coords" : data .variables ["LayCoord_w" ][:],
790- },
791- }
792- bottom_depth = data ["waterdepth" ].values [time_index , :]
793- waterlevel = data ["s1" ].values [time_index , :]
794- coords = list (data ["waterdepth" ].coords )
795-
796- layer_dim = " " .join (map (str , list (data [variable ].coords )[0 :2 ]))
775+ if "mesh2d" in variable :
776+ cords_to_layers = {
777+ "mesh2d_face_x mesh2d_face_y" : {
778+ "name" : "mesh2d_nLayers" ,
779+ "coords" : data .variables ["mesh2d_layer_sigma" ][:],
780+ },
781+ "mesh2d_edge_x mesh2d_edge_y" : {
782+ "name" : "mesh2d_nInterfaces" ,
783+ "coords" : data .variables ["mesh2d_interface_sigma" ][:],
784+ },
785+ }
786+ bottom_depth = data ["mesh2d_waterdepth" ].values [time_index , :]
787+ waterlevel = data ["mesh2d_s1" ].values [time_index , :]
788+ coords = list (data ["waterdepth" ].coords )
789+ elif (
790+ str (list (data [variable ].coords ))
791+ == "['FlowElem_xcc', 'FlowElem_ycc', 'time']"
792+ or str (list (data [variable ].coords ))
793+ == "['FlowLink_xu', 'FlowLink_yu', 'time']"
794+ ):
795+ cords_to_layers = {
796+ "FlowElem_xcc FlowElem_ycc" : {
797+ "name" : "laydim" ,
798+ "coords" : data .variables ["LayCoord_cc" ][:],
799+ },
800+ "FlowLink_xu FlowLink_yu" : {
801+ "name" : "wdim" ,
802+ "coords" : data .variables ["LayCoord_w" ][:],
803+ },
804+ }
805+ bottom_depth = data ["waterdepth" ].values [time_index , :]
806+ waterlevel = data ["s1" ].values [time_index , :]
807+ coords = list (data ["waterdepth" ].coords )
808+ else :
809+ cords_to_layers = {
810+ "FlowElem_xcc FlowElem_ycc LayCoord_cc LayCoord_cc" : {
811+ "name" : "laydim" ,
812+ "coords" : data .variables ["LayCoord_cc" ][:],
813+ },
814+ "FlowLink_xu FlowLink_yu" : {
815+ "name" : "wdim" ,
816+ "coords" : data .variables ["LayCoord_w" ][:],
817+ },
818+ }
819+ bottom_depth = data ["waterdepth" ].values [time_index , :]
820+ waterlevel = data ["s1" ].values [time_index , :]
821+ coords = list (data ["waterdepth" ].coords )
822+
823+ layer_dim = " " .join (map (str , list (data [variable ].coords )[0 :2 ]))
797824
798825 try :
799826 cord_sys = cords_to_layers [layer_dim ]["coords" ]
@@ -802,7 +829,7 @@ def get_all_data_points(
802829 if isinstance (data , netCDF4 .Dataset ):
803830 layer_percentages = np .ma .getdata (cord_sys , False ) # accumulative
804831 elif isinstance (data , xr .Dataset ):
805- layer_percentages = cord_sys .values # accumulative
832+ layer_percentages = cord_sys .values # accumulative
806833
807834 x_all = []
808835 y_all = []
0 commit comments