chanzuckerberg / cryoet-data-portal-backend

CryoET Data Portal API server & ingestion scripts
MIT License
1 stars 2 forks source link

Fix setting extended header when importing MRC #169

Closed uermel closed 1 month ago

uermel commented 1 month ago

Relates to

166

Description

The property MrcObject.extended_header may return None, or values of type np.recarray or np.ndarray. In contrast to python lists, np.ndarray is not truthy, so comparison with any np.ndarray will raise exceptions. In order to circumvent, we ensure that the result of MRCReader.get_mrc_extended_header() is a np.array and then convert to a python list that enables truthy/falsy comparison.

Covers the following cases:

  1. do set extended header on filled np.ndarray > np.array(val: np.ndarray).tolist() -> list
  2. do set extended header on filled np.recarray > np.array(val: np.recarray).tolist() -> list
  3. skip setting extended header on empty np.ndarray > np.array(np.empty(0)).tolist() == []
  4. skip setting extended header on None > np.array(None).tolist() == None