MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / repair_set

Function repair_set

pyxrf/model/load_data_from_db.py:1936–1962  ·  view source on GitHub ↗

Replaces corrupt rows (incorrect number of points) with closest 'good' row. This allows to load and use data from corrupt scans. The function will have no effect on 'good' scans. If there are no rows with correct number of points (unlikely case), then the array r

(dset_list, n_row_pts, msg)

Source from the content-addressed store, hash-verified

1934 logger.error(f"Error occurred while reading data: {ex}. Trying to retrieve available data ...")
1935
1936 def repair_set(dset_list, n_row_pts, msg):
1937 """
1938 Replaces corrupt rows (incorrect number of points) with closest 'good' row. This allows to load
1939 and use data from corrupt scans. The function will have no effect on 'good' scans.
1940 If there are no rows with correct number of points (unlikely case), then the array remains unchanged.
1941 """
1942 missed_rows = []
1943 n_last_good_row = -1
1944 for n in range(len(dset_list)):
1945 d = dset_list[n]
1946 n_pts = d.shape[0]
1947 if n_pts != n_row_pts:
1948 print(
1949 f"WARNING: ({msg}) Row #{n + 1} has {n_pts} data points. {n_row_pts} points are expected."
1950 )
1951 if n_last_good_row == -1:
1952 missed_rows.append(n)
1953 else:
1954 dset_list[n] = np.array(dset_list[n_last_good_row])
1955 print(f"({msg}) Data in row #{n + 1} is replaced by data from row #{n_last_good_row}")
1956 else:
1957 n_last_good_row = n
1958 if missed_rows:
1959 for nr in missed_rows:
1960 dset_list[nr] = np.array(dset_list[n_last_good_row])
1961 print(f"({msg}) Data in row #{nr + 1} is replaced by data from row #{n_last_good_row}")
1962 missed_rows = []
1963
1964 sclr_name = list(sclr_dict.keys())
1965

Callers 1

map_data2D_srx_newFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected