Fix/incorrect handling of error/warning when idslist is applied to a uda uri#38
Conversation
| logger = logging.getLogger(f"module.{__name__}") | ||
|
|
||
|
|
||
| def add_default_uda_cache_mode(uri): |
There was a problem hiding this comment.
I'm surprised to find this function in database module and not in the utils
|
|
||
| if len(args.uri) >= 1: | ||
| connection1 = imas.DBEntry(args.uri[0], "r") | ||
| connection1 = imas.DBEntry(add_default_uda_cache_mode(args.uri[0]), "r") |
There was a problem hiding this comment.
In the case of this script, we don't lazy read the equilibrium, either it will be beneficial and we should do it (then it's fine to use cache_mode=none), or we need everything and cache_mode=none is going to kill perfs...
| if not isinstance(uri, str): | ||
| return uri | ||
|
|
||
| uri_part, fragment_separator, fragment = uri.partition("#") |
There was a problem hiding this comment.
I'm surprised that we don't use or have a nicer API to interact with URIs in Python
|
|
||
| def add_default_uda_cache_mode(uri): | ||
| """Add ``cache_mode=none`` to UDA URIs unless it is already specified.""" | ||
| if not isinstance(uri, str): |
There was a problem hiding this comment.
A URI is always a string no?
| if any(parameter.partition("=")[0] == "cache_mode" for parameter in parameters): | ||
| return uri | ||
|
|
||
| parameter_separator = ";" if query_separator else "?" |
There was a problem hiding this comment.
The else case can't be true here (the uri would miss the query)
| logger = logging.getLogger(f"module.{__name__}") | ||
|
|
||
|
|
||
| def add_default_uda_cache_mode(uri): |
There was a problem hiding this comment.
I think you are overcomplicating stuff here, we just want to append cache_mode=none in case the URI is a UDA one (it does not harm if the same query is already present, so you don't need the if line 28)
Ideally, you could make a more general function that would append a given query pair to a URI of a given backend type:
add_query_to_uri(backend="uda", query="cache_mode=none")
--> this would then allow to append a different option for a different use case, e.g. equicomp which needs the entire IDS could use "fetch=1"
Or if we had a better API to interact with the URI (and extract the backend), then you won't even need to pass the backend and could do:
add_query_to_uri("cache_mode=none") if from_uri(uri, "backend")==uda else uri
Automatically adds cache_mode=none to UDA URIs.
$ idslist --uri "imas://uda.iter.org:56565/uda?path=/work/imas/shared/imasdb/ITER/3/134173/106;backend=hdf5" 13:07:55 INFO Parsing data dictionary version 4.1.1 @dd_zip.py:89 13:07:56 INFO Parsing data dictionary version 3.38.1 @dd_zip.py:89 List of IDSes ┏━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ IDS ┃ SLICES ┃ TIME ┃ ┡━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ core_profiles │ 871 │ array([ 3.99, 3.99, 3.99, ..., 792. , 792. , 792. ]) │ │ core_sources │ 871 │ array([ 3.99, 3.99, 3.99, ..., 792. , 792. , 792. ]) │ │ core_transport │ 871 │ array([ 3.99, 3.99, 3.99, ..., 792. , 792. , 792. ]) │ │ equilibrium │ 871 │ array([ 1.2 , 1.4 , 1.6 , ..., 797.92, 798.42, 798.92]) │ │ summary │ 871 │ array([ 3.99, 3.99, 3.99, ..., 792. , 792. , 792. ]) │ └────────────────┴────────┴──────────────────────────────────────────────────────────────┘