code: def mergeDQarray(maskname,dqarr):
      
      maskarr = None
      if maskname is not None:
          if isinstance(maskname, str):
              # working with file on disk (default case)
              if os.path.exists(maskname):
                  mask = fileutil.openImage(maskname, memmap=False)
                  maskarr = mask[0].data.astype(np.bool)
                  mask.close()
          else:
              if isinstance(maskname, fits.HDUList):
                  # working with a virtual input file
                  maskarr = maskname[0].data.astype(np.bool)
              else:
                  maskarr = maskname.data.astype(np.bool)
  
          if maskarr is not None:
              # merge array with dqarr now
              np.bitwise_and(dqarr,maskarr,dqarr)
docs: Merge static or CR mask with mask created from DQ array on-the-fly here.