Skip to content
Advertisement

Running .EXE or Perl file on Google Colab

I want to process a set of HDR files with an Executable (e.g., falsecolor2.exe) file on google colab.

The source file is here: https://github.com/mostaphaRoudsari/honeybee/blob/master/resources/falsecolor2.exe?raw=true sample HDR files: http://www.anyhere.com/gward/hdrenc/pages/originals.html

The executable takes an HDR file with some arguments and generates a new HDR file. On my local machine and drive, the following code works OK:

import os
os.system(r'D:falsecolor2.exe -i D:test.hdr -s 250.0 -n 10 -mask 0.1 -l lux -m 179 -lp EN -z > D:test@fc.hdr')

I am not sure how to create a similar process in colab; after mounting the gdrive, the following code generates a 0 byte not-working HDR in my gdrive and returns error code 32256.

import os
os.system('/content/drive/My Drive/falsecolor2.exe -i /content/drive/My Drive/MOSELEY IMAGES/test.hdr -s 250.0 -n 10 -mask 0.1 -l lux -m 179 -lp EN -z > /content/drive/My Drive/test@fc.hdr')

I read some threads on shell and linux executables but could not replicate any of them successfully.

Advertisement

Answer

You can install Radiance in Google Colab like this:

# Download the Linux compiled version of radiance from Github (e.g. 5.3, latest official release at the moment):
!wget -O radiance.zip https://github.com/LBNL-ETA/Radiance/releases/download/012cb178/Radiance_012cb178_Linux.zip

# Unzip it
!unzip radiance.zip

# Extract the tar.gz to /usr/local/radiance
!tar -xvf radiance-5.3.012cb17835-Linux.tar.gz --strip-components=1 -C /

# Add /usr/local/radiance/bin to the PATH environment variable
path = %env PATH
%env PATH=/usr/local/radiance/bin:$path

# Set the RAYPATH environment variable to /usr/local/radiance/lib
%env RAYPATH=/usr/local/radiance/lib

I ran !lsb_release -a to find out the Linux distribution in Google Colab and it said that it was Ubuntu 18.04. Unfortunately, Radiance does not seem to be available for that version, but only for 16.04. That is why getting it from Github seems to be the next simplest solution. See radiance in Ubuntu Packages:

Exact hits

Package radiance

  • xenial (16.04LTS) (graphics): Lighting Simulation and Rendering System [universe] 4R1+20120125-1.1: amd64 arm64 armhf i386 powerpc ppc64el s390x

Then I tried to run your falsecolor command using one of the sample images you linked and found that the -lp and -z options are not available:

# Get a sample HDR file
!wget -O input.hdr http://www.anyhere.com/gward/hdrenc/pages/img/Apartment_float_o15C.hdr

# Try original command
!falsecolor -i input.hdr -s 250.0 -n 10 -mask 0.1 -l lux -m 179 -lp EN -z > output.hdr

# Output:
# bad option "-lp"

# Remove option -lp
!falsecolor -i input.hdr -s 250.0 -n 10 -mask 0.1 -l lux -m 179 -z > output.hdr

# Output:
# bad option "-z"

If you remove those options the command runs successfully:

# Remove option -z
!falsecolor -i input.hdr -s 250.0 -n 10 -mask 0.1 -l lux -m 179 > output.hdr

# List output file
!ls -lh output.hdr

# Output:
# -rw-r--r-- 1 root root 4.8M Mar 31 02:57 output.hdr

See a demo in this colab.

Advertisement