raytools.io

functions for reading and writing

raytools.io.get_nproc(nproc=None)[source]
raytools.io.set_nproc(nproc)[source]
raytools.io.unset_nproc()[source]
raytools.io.np2bytes(ar, dtype='<f')[source]

format ar as bytestring

Parameters:
  • ar (np.array)

  • dtype (str) – argument to pass to np.dtype()

Return type:

bytes

raytools.io.np2bytefile(ar, outf, dtype='<f', mode='wb')[source]

save vectors to file

Parameters:
  • ar (np.array) – array to write

  • outf (str) – file to write to

  • dtype (str) – argument to pass to np.dtype()

raytools.io.bytes2np(buf, shape, dtype='<f')[source]

read ar from bytestring

Parameters:
  • buf (bytes, str)

  • shape (tuple) – array shape

  • dtype (str) – argument to pass to np.dtype()

Return type:

np.array

raytools.io.bytefile2np(f, shape, dtype='<f')[source]

read binary data from f

Parameters:
  • f (IOBase) – file object to read array from

  • shape (tuple) – array shape

  • dtype (str) – argument to pass to np.dtype()

Returns:

necessary for reconstruction

Return type:

ar.shape

raytools.io.array2hdr(ar, imgf, header=None, clean=False)[source]

write 2d np.array (x,y) to hdr image format

Parameters:
  • ar (np.array) – image array

  • imgf (str) – file path to right

  • header (list) – list of header lines to append to image header

Return type:

imgf

raytools.io.carray2hdr(ar, imgf, header=None, clean=False)[source]

write color channel np.array (3, x, y) to hdr image format

Parameters:
  • ar (np.array) – image array

  • imgf (str) – file path to right

  • header (list) – list of header lines to append to image header

Return type:

imgf

raytools.io.hdr2array(imgf, stdin=None, header=False)[source]

read np.array from hdr image

Parameters:
  • imgf (file path of image)

  • stdin – passed to Popen (imgf should be “”)

Returns:

ar

Return type:

np.array

raytools.io.hdr2carray(imgf, stdin=None, header=False)[source]

read np.array from color hdr image

Parameters:
  • imgf (file path of image)

  • stdin – passed to Popen (imgf should be “”)

Returns:

ar

Return type:

np.array

raytools.io.header_items(header, items)[source]
raytools.io.clean_header(header)[source]

remove redundant entries from radiance image header, updating view, purging pvalue and clasp_tmp file names

raytools.io.is_hdr(imgf)[source]
raytools.io.hdr_header(imgf, clean=False, items=None)[source]
raytools.io.rgb2rad(rgb, vlambda=(0.265, 0.67, 0.065))[source]
raytools.io.rgb2lum(rgb, vlambda=(0.265, 0.67, 0.065))[source]
raytools.io.rgbe2lum(rgbe)[source]

convert from Radiance hdr rgbe 4-byte data format to floating point luminance.

Parameters:

rgbe (np.array) – r,g,b,e unsigned integers according to: http://radsite.lbl.gov/radiance/refer/filefmts.pdf

Returns:

lum

Return type:

luminance in cd/m^2

raytools.io.load_txt(farray, **kwargs)[source]

consistent error handing of np.loadtxt

Parameters:
  • farray (any) – candidate to load

  • kwargs – passed to np.loadtxt

Return type:

np.array

Raises:
  • ValueError: – file exists, but is not loadable

  • FileNotFoundError: – farray is str, but file does not exist

  • TypeError: – farray is not str or bytes.

class raytools.io.CleanHeader(text, spacespertab=4, outtab='\t', headerwidth=150)[source]

Bases: object

takes lists of rgbe hdr format header lines (with tabbed hierarchy) and processes to group redundant information and avoid overly long lines (which throw errors with pfs tools). After initialization (or subsequent call to text setter, the ‘header’ parameter holds the cleaned header result as a list of header lines.

Parameters
text: Union(str, list)

the header to process

spacespertab: int, optional

convert leading spaces to tabs

outtab: str, optional

output tab

headerwidth: int, optional

property header

the output header

property text

text version of the input header