1+ from __future__ import annotations
2+
13import math
24import warnings
35from collections .abc import Iterable
46from ctypes import POINTER , Structure , c_float , c_int , pointer
57from glob import glob
68from pathlib import Path
7- from typing import TYPE_CHECKING , Any , Literal
9+ from typing import TYPE_CHECKING , Literal
810
911import dask .array as da
1012import numpy as np
5052
5153 from parcels .fieldset import FieldSet
5254
55+ T_SanitizedFilenames = list [str ] | dict [str , list [str ]]
56+
5357__all__ = ["Field" , "NestedField" , "VectorField" ]
5458
5559
@@ -464,7 +468,7 @@ def from_netcdf(
464468 time_periodic : TimePeriodic = False ,
465469 deferred_load : bool = True ,
466470 ** kwargs ,
467- ) -> " Field" :
471+ ) -> Field :
468472 """Create field from netCDF file.
469473
470474 Parameters
@@ -567,14 +571,14 @@ def from_netcdf(
567571 ), "The variable tuple must have length 2. Use FieldSet.from_netcdf() for multiple variables"
568572
569573 data_filenames = _get_dim_filenames (filenames , "data" )
570- lonlat_filename = _get_dim_filenames (filenames , "lon" )
574+ lonlat_filename_lst = _get_dim_filenames (filenames , "lon" )
571575 if isinstance (filenames , dict ):
572- assert len (lonlat_filename ) == 1
573- if lonlat_filename != _get_dim_filenames (filenames , "lat" ):
576+ assert len (lonlat_filename_lst ) == 1
577+ if lonlat_filename_lst != _get_dim_filenames (filenames , "lat" ):
574578 raise NotImplementedError (
575579 "longitude and latitude dimensions are currently processed together from one single file"
576580 )
577- lonlat_filename = lonlat_filename [0 ]
581+ lonlat_filename = lonlat_filename_lst [0 ]
578582 if "depth" in dimensions :
579583 depth_filename = _get_dim_filenames (filenames , "depth" )
580584 if isinstance (filenames , dict ) and len (depth_filename ) != 1 :
@@ -2549,7 +2553,7 @@ def __getitem__(self, key):
25492553 return val
25502554
25512555
2552- def _get_dim_filenames (filenames : str | Path | Any | dict [ str , str | Any ], dim : str ) -> Any :
2556+ def _get_dim_filenames (filenames : T_SanitizedFilenames , dim : str ) -> list [ str ] :
25532557 """Get's the relevant filenames for a given dimension."""
25542558 if isinstance (filenames , list ):
25552559 return filenames
@@ -2560,7 +2564,7 @@ def _get_dim_filenames(filenames: str | Path | Any | dict[str, str | Any], dim:
25602564 raise ValueError ("Filenames must be a string, pathlib.Path, or a dictionary" )
25612565
25622566
2563- def _sanitize_field_filenames (filenames , * , recursed = False ):
2567+ def _sanitize_field_filenames (filenames , * , recursed = False ) -> T_SanitizedFilenames :
25642568 """The Field initializer can take `filenames` to be of various formats including:
25652569
25662570 1. a string or Path object. String can be a glob expression.
0 commit comments