Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions idstools/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import imas
import yaml

from idstools.utils.utility_functions import add_query_to_uri

logger = logging.getLogger(f"module.{__name__}")


Expand Down Expand Up @@ -701,11 +703,16 @@ def create_connection(cls, imasargs, target_dd_version=None):
def get_connection(cls, imasargs):
connection = None
if imasargs.uri != "" and imasargs.uri is not None:
uri = add_query_to_uri(
imasargs.uri,
backend="uda",
query="cache_mode=none",
)
if "mode" in imasargs.__dict__:
connection = imas.DBEntry(imasargs.uri, imasargs.mode)
connection = imas.DBEntry(uri, imasargs.mode)
else:
try:
connection = imas.DBEntry(imasargs.uri, "r")
connection = imas.DBEntry(uri, "r")
except Exception as e:
print(e)
return connection
Expand Down
20 changes: 18 additions & 2 deletions idstools/scripts/bin/dblist
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,15 @@ def print_times(dbs, args, print_times=False, pulse_number=None, run_number=None
print(TAB * 4 + " Run: " + extended(str(run), RUN_STR_LEN))
available_ids_and_times = get_available_ids_and_times(connection)
for idsname, times in available_ids_and_times:
if len(times) == 1 and np.isnan(times[0]):
if times is None:
print(
TAB * 5
+ extended(idsname, IDSNAME_STR_LEN)
+ ": "
+ extended("N/A", SLICENUM_STR_LEN)
+ " slices ( time unavailable )"
)
elif len(times) == 1 and np.isnan(times[0]):
print(
TAB * 5
+ extended(idsname, IDSNAME_STR_LEN)
Expand Down Expand Up @@ -311,7 +319,15 @@ def print_times_with_folder(dbs, print_times=False, pulse_number=None, run_numbe
continue
available_ids_and_times = get_available_ids_and_times(connection)
for idsname, times in available_ids_and_times:
if times is not None:
if times is None:
print(
TAB * 15
+ extended(idsname, IDSNAME_STR_LEN)
+ ": "
+ extended("N/A", SLICENUM_STR_LEN)
+ " slices ( time unavailable )"
)
else:
if len(times) == 1 and np.isnan(times[0]):
print(
TAB * 15
Expand Down
4 changes: 2 additions & 2 deletions idstools/scripts/bin/idslist
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ if __name__ == "__main__":
type = time_array
elif time_array is None:
value = f"{not_applicable}"
type = "unknown"
table.add_row(ids_name, value, Pretty(type))
type = not_applicable
table.add_row(ids_name, value, type if isinstance(type, str) else Pretty(type))
if args.fullarray is True:
with np.printoptions(threshold=sys.maxsize, linewidth=1024, precision=4):
console.print(table)
Expand Down
5 changes: 4 additions & 1 deletion idstools/scripts/bin/idsprint
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,10 @@ if __name__ == "__main__":
table.add_column("SLICES", style="green")
table.add_column("TIME", style="green")
for ids_name, time_array in available_ids_and_times:
if len(time_array) == 1 and np.isnan(time_array[0]):
if time_array is None:
value = "N/A"
type = "unknown"
elif len(time_array) == 1 and np.isnan(time_array[0]):
value = f"{question_string}"
type = "heterogeneous IDS"
elif len(time_array) == 1 and time_array[0] == -np.inf:
Expand Down
8 changes: 7 additions & 1 deletion idstools/scripts/bin/idsquery
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ from idstools.utils.idshelper import (
get_ids_values,
)
from idstools.utils.idslogger import setup_logger
from idstools.utils.utility_functions import add_query_to_uri

logger = setup_logger("module", stdout_level=logging.INFO)

Expand Down Expand Up @@ -108,7 +109,12 @@ Example:
valpath = path[1 + len(idsname) :]
paths_info.append((path, idsname, valpath.replace("(", "[").replace(")", "]").replace("/", ".")))

ids_values = get_ids_values(args.uri, paths_info, dd_update=args.dd_update, verbose=args.verbose)
ids_values = get_ids_values(
add_query_to_uri(args.uri, backend="uda", query="cache_mode=none"),
paths_info,
dd_update=args.dd_update,
verbose=args.verbose,
)
if ids_values:
for _path, _value in ids_values.items():
if _value is None:
Expand Down
12 changes: 10 additions & 2 deletions idstools/scripts/bin/plotequicomp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ from idstools.utils.clihelper import (
rcparam_parser,
)
from idstools.utils.idslogger import setup_logger
from idstools.utils.utility_functions import add_query_to_uri
from idstools.view.common import PROVENANCE_TITLE_STYLE, PlotCanvas
from idstools.view.equilibrium import EquilibriumView
from idstools.view.wall import WallView

Expand Down Expand Up @@ -86,7 +88,10 @@ if __name__ == "__main__":
wall2 = None

if len(args.uri) >= 1:
connection1 = imas.DBEntry(args.uri[0], "r")
connection1 = imas.DBEntry(
add_query_to_uri(args.uri[0], backend="uda", query="cache_mode=none"),
"r",
)
if args.dd_update:
equilibrium1 = connection1.get("equilibrium", autoconvert=False)
equilibrium1 = imas.convert_ids(equilibrium1, connection1.factory.version)
Expand All @@ -110,7 +115,10 @@ if __name__ == "__main__":
logger.critical("----> Could not open first data entry. Aborted.")
exit(1)
if len(args.uri) == 2:
connection2 = imas.DBEntry(args.uri[1], "r")
connection2 = imas.DBEntry(
add_query_to_uri(args.uri[1], backend="uda", query="cache_mode=none"),
"r",
)
if args.dd_update:
equilibrium2 = connection2.get("equilibrium", autoconvert=False)
equilibrium2 = imas.convert_ids(equilibrium2, connection2.factory.version)
Expand Down
8 changes: 6 additions & 2 deletions idstools/utils/idshelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,12 @@ def get_available_ids_and_times(db_entry_object) -> list:
time_array = [-np.inf]
except Exception as e:
logger.debug(f"{e}")
time_array = []
logger.info(f"ERROR! IDS {_ids_name} : Reading time array fails due to following problem : {e}")
time_array = None
logger.warning(
"Unable to read the time array for IDS %s: %s",
_ids_name,
e,
)
if occurrence != 0:
result.append((f"{_ids_name}/{occurrence}", time_array))
else:
Expand Down
25 changes: 25 additions & 0 deletions idstools/utils/utility_functions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import logging
from urllib.parse import urlsplit, urlunsplit

logger = logging.getLogger(f"module.{__name__}")


def add_query_to_uri(uri: str, *, query: str, backend=None):
"""Add a query to the URI.

If a backend is given, add the query only when it matches the URI's
backend. Otherwise, return the original URI unchanged. When backend is
None, add the query to any URI.
"""
uri_parts = urlsplit(uri)
uri_backend = uri_parts.path.rsplit("/", 1)[-1]
if backend is not None and uri_backend != backend:
return uri

updated_query = f"{uri_parts.query};{query}"
return urlunsplit(
(
uri_parts.scheme,
uri_parts.netloc,
uri_parts.path,
updated_query,
uri_parts.fragment,
)
)


def get_slice_from_array(arr, slice_str):
if ":" not in slice_str:
index = int(slice_str)
Expand Down