Opened 17 years ago

Closed 15 years ago

#1 closed task (fixed)

Automatic CASI RGB TIF production

Reported by: mggr Owned by: mggr
Priority: whenever Milestone:
Component: PML utilities Keywords:
Cc: Other processors:

Description

Currently, the batch files output a fixed set of bands (2, 3, 5). This won't work for the dynamic bands in CASI. We need a small utility to pick out the 3 bands closest to RGB from an HDF file.

Change History (2)

comment:1 Changed 16 years ago by mggr

  • Owner set to mggr
  • Status changed from new to assigned

Some initial work done on this - needs cleaning up:

#!/usr/bin/env python

import subprocess
import copy

# file output is probably:
#  1000.0
if not subprocess.call(["azexhdf", "-vf", "CAradsc.txt", "-vn", "CAradsc", "-h", "c166011b.hdf"]):
   raise Exception("azexhdf command failed")

# file output is probably:
# 10.51081 9.57682 5.82034 6.78231 3.94991 4.90609 4.91650 4.91998 4.93188 3.97656 3.02035 3.98657 4.96749 4.99069 5.03539
if not subprocess.call(["azexhdf", "-vf", "CAwavh.txt", "-vn", "CAwavh", "-h", "c166011b.hdf"]):
   raise Exception("azexhdf command failed")

# file output is probably:
# 448.46 488.94 551.17 606.95 649.63 669.60 700.09 709.63 740.24 748.86 761.34 779.60 819.14 863.75 940.04
if not subprocess.call(["azexhdf", "-vf", "CAwavc.txt", "-vn", "CAwavc", "-h", "c166011b.hdf"]):
   raise Exception("azexhdf command failed")

# red absorbing cones; those that absorb best at the relatively long wavelengths peaking at 565 nm
# green absorbing cones with a peak absorption at 535 nm
# blue absorbing cones with a peak absorption at 440 nm.

f = open("CAwavc.txt")
wavelengths_line = f.readlines()[0].strip()
f.close()
print "wavelength = {", wavelengths_line.replace(" ", ", "), " }"
print "wavelength units = nm"
wavelengths = map(float, wavelengths_line.split(" "))

 # not sure wavh ("half bandwidth") is the same as fwhm ("full width at half maximum")
#f = open("CAwavh.txt")
#wavebandwidths_line = f.readlines()[0].strip()
#f.close()
#print "fwhm = {", wavebandwidths_line.replace(" ", ", "), "}"

f = open("CAradsc.txt")
scaling_line = f.readlines()[0].strip()
f.close()
print "reflectance scale factor = ", scaling_line

# red absorbing cones; those that absorb best at the relatively long wavelengths peaking at 565 nm
# green absorbing cones with a peak absorption at 535 nm
# blue absorbing cones with a peak absorption at 440 nm.
red_band = 565
green_band = 535
blue_band = 440
best_red   = 9999999999
best_green = 9999999999
best_blue  = 9999999999
wavelen_copy = copy.copy(wavelengths)
 # pick out best red band and remove from list
for band in wavelengths:
   if abs(band - red_band)   < abs(best_red - red_band):     best_red = band
wavelengths.remove(best_red)
 # pick out best remaining green band and remove from list
for band in wavelengths:
   if abs(band - green_band) < abs(best_green - green_band): best_green = band
wavelengths.remove(best_green)
 # pick out best remaining blue band
for band in wavelengths:
   if abs(band - blue_band)  < abs(best_blue - blue_band):   best_blue = band

 # sort in reverse order to ensure the best RGB bands are in frequency order (loops above may get order wrong)
rgb = [best_red, best_green, best_blue]
rgb.sort(reverse=True)

print "default bands = { %d, %d, %d }" % (wavelen_copy.index(rgb[0])+1, wavelen_copy.index(rgb[1])+1, wavelen_copy.index(rgb[2])+1)

comment:2 Changed 15 years ago by mggr

  • Resolution set to fixed
  • Status changed from assigned to closed

Done for Eagle - don't need it for CASI any more.

Note: See TracTickets for help on using tickets.