2323 get_object_attribute ,
2424 get_object_attribute_rgx ,
2525 get_object_attribute_advanced ,
26+ is_primitive ,
27+ get_obj_title ,
2628)
2729
2830from .datasets_io import get_path_in_external_with_path
@@ -382,18 +384,18 @@ def prod_n_tab(val: Union[float, int, str], tab: List[Union[float, int, str]]):
382384 """
383385 if val is None :
384386 return [None ] * len (tab )
385- logging .debug (f"Multiplying list by { val } : { tab } " )
387+ # logging.debug(f"Multiplying list by {val}: {tab}")
386388 # Convert to numpy array for vectorized operations, handling None values
387389 arr = np .array (tab , dtype = object )
388- logging .debug (f"arr: { arr } " )
390+ # logging.debug(f"arr: {arr}")
389391 # Create mask for non-None values
390392 mask = arr != None # noqa: E711
391393 # Create result array filled with None
392394 result = np .full (len (tab ), None , dtype = object )
393- logging .debug (f"result before multiplication: { result } " )
395+ # logging.debug(f"result before multiplication: {result}")
394396 # Multiply only non-None values
395397 result [mask ] = arr [mask ].astype (float ) * val
396- logging .debug (f"result after multiplication: { result } " )
398+ # logging.debug(f"result after multiplication: {result}")
397399 return result .tolist ()
398400
399401
@@ -453,10 +455,12 @@ def get_crs_obj(
453455 logging .error ("@get_crs_obj no Epc file given" )
454456 else :
455457 crs_list = search_attribute_matching_name (context_obj , r"\.*Crs" , search_in_sub_obj = True , deep_search = False )
456- if crs_list is not None and len (crs_list ) > 0 :
458+ if crs_list is not None and len (crs_list ) > 0 and crs_list [ 0 ] is not None :
457459 # logging.debug(crs_list[0])
460+ # logging.debug(f"CRS found for {get_obj_title(context_obj)} : {crs_list[0]}")
458461 crs = workspace .get_object (get_obj_uri (crs_list [0 ]))
459462 if crs is None :
463+ # logging.debug(f"CRS {crs_list[0]} not found (or not read correctly)")
460464 crs = workspace .get_object_by_uuid (get_obj_uuid (crs_list [0 ]))
461465 if crs is None :
462466 logging .error (f"CRS { crs_list [0 ]} not found (or not read correctly)" )
@@ -755,17 +759,19 @@ def _array_name_mapping(array_type_name: str) -> str:
755759 :param array_type_name:
756760 :return:
757761 """
758- array_type_name = array_type_name .replace ("3D" , "3d" ).replace ("2D" , "2d" )
759- if array_type_name .endswith ("ConstantArray" ):
762+ array_type_name = array_type_name .replace ("3D" , "3d" ).replace ("2D" , "2d" ).lower ()
763+ # logging.debug(f"=============> Mapping array type name '{array_type_name}' to reader function name...")
764+ if array_type_name .endswith ("constantarray" ):
760765 return "ConstantArray"
761- elif "External " in array_type_name or "Hdf5 " in array_type_name :
766+ elif "external " in array_type_name or "hdf5 " in array_type_name :
762767 return "ExternalArray"
763- elif array_type_name .endswith ("XmlArray" ):
768+ elif "xml" in array_type_name :
769+ # logging.debug("=============> XML array detected, be careful with the performance !")
764770 return "XmlArray"
765- elif "Jagged " in array_type_name :
771+ elif "jagged " in array_type_name :
766772 return "JaggedArray"
767- elif "Lattice " in array_type_name :
768- if "Integer " in array_type_name or "Double " in array_type_name or "FloatingPoint " in array_type_name :
773+ elif "lattice " in array_type_name :
774+ if "integer " in array_type_name or "double " in array_type_name or "floatingpoint " in array_type_name :
769775 return "int_double_lattice_array"
770776 return array_type_name
771777
@@ -879,7 +885,7 @@ def read_external_array(
879885 for ext_part in external_parts :
880886 start_indices , counts , external_uri = _extract_external_data_array_part_params (ext_part )
881887 pief_list = get_path_in_external_with_path (obj = ext_part )
882-
888+ # logging.debug(f"Pief : {pief_list}")
883889 for pief_path_in_obj , pief in pief_list :
884890 arr = workspace .read_array (
885891 proxy = crs or root_obj ,
@@ -890,6 +896,7 @@ def read_external_array(
890896 )
891897 if arr is not None :
892898 array = arr if array is None else np .concatenate ((array , arr ))
899+ # logging.debug(f"\t ExternalDataArrayPart read successfully. arr : {arr} : array : {array}")
893900 else :
894901 # RESQML v2.0.1: Extract count from parent object, no StartIndex or URI
895902 counts = None
@@ -933,6 +940,7 @@ def read_external_array(
933940 # Fallback for non-numpy arrays
934941 array = [array [idx ] for idx in sub_indices ]
935942
943+ # logging.debug(f"External array read successfully. => {array}")
936944 return array
937945
938946
@@ -964,8 +972,26 @@ def read_array(
964972 :param sub_indices: for SubRepresentation
965973 :return:
966974 """
967- if isinstance (energyml_array , list ):
975+ if isinstance (energyml_array , np .ndarray ):
976+ # if isinstance(energyml_array, list):
968977 return energyml_array
978+ elif isinstance (energyml_array , list ):
979+ # logging.debug("Warning: the array is a list, not a numpy array, be careful with the performance !")
980+ # logging.debug(energyml_array)
981+ if len (energyml_array ) > 0 and is_primitive (energyml_array [0 ]):
982+ return energyml_array
983+ else :
984+ return [
985+ read_array (
986+ energyml_array = elem ,
987+ root_obj = root_obj ,
988+ path_in_root = path_in_root ,
989+ workspace = workspace ,
990+ sub_indices = sub_indices ,
991+ )
992+ for elem in energyml_array
993+ if elem is not None
994+ ]
969995 array_type_name = _array_name_mapping (type (energyml_array ).__name__ )
970996
971997 reader_func = get_array_reader_function (array_type_name )
@@ -1030,8 +1056,10 @@ def read_xml_array(
10301056 :param sub_indices:
10311057 :return:
10321058 """
1059+
10331060 values = get_object_attribute_no_verif (energyml_array , "values" )
10341061 # count = get_object_attribute_no_verif(energyml_array, "count_per_value")
1062+ # logging.debug("values: ", values)
10351063
10361064 if sub_indices is not None and len (sub_indices ) > 0 :
10371065 if isinstance (values , np .ndarray ):
0 commit comments