public
anonymous / settings_w.py
Created

  • Download Gist
settings_w.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#! /usr/bin/env python
"""
Implementation of the settings class
"""
 
from enthought.traits.api import HasTraits, Button, CFloat, CInt, Trait, Enum
from enthought.traits.ui.api import Item, View, Group, Handler
from enthought.traits.ui.message import message
from enthought.traits.api import HasTraits, Str, File
from enthought.traits.ui.menu import Action, OKButton, CancelButton
import cPickle as pickle
 
 
ViewHelp = """
This is the help for the settings dialog box used to enter the files to be processed.
"""
 
class SaveRestore_Handler ( Handler ):
def save( self, info ):
print 'save settings called...'
 
 
pickle.dump( info.object, open( "./settings.p", "wb" ) )
 
print 'saved settings'
def restore( self, info):
print 'restore settings called...'
pickled_settings = pickle.load( open( "./settings.p", "rb" ) )
info.object.hyr2_file_name = pickled_settings.hyr2_file_name
info.object.hyr2_frame_num = pickled_settings.hyr2_frame_num
info.object.modeled_nedt_file_name = pickled_settings.modeled_nedt_file_name
print 'restored settings'
# Close the file
#fin.close()
class Settings_W ( HasTraits ):
""" Defines the settings class.
"""
 
hyr2_file_name = File(desc="the HYR2 file containing all the relevant data for analysis")
modeled_nedt_file_name = File(desc="Modeled NEdT values (from Hal)")
cbb_temp = CFloat(0.0, desc="Temperature of the cold BB in C")
wbb_temp = CFloat(0.0, desc="Temperature of the warm BB in C")
hyr2_frame_num = CInt(1, desc="Frame Number")
settings_group = Group(
Item('hyr2_file_name', style = 'simple', label = 'HYR2 file'),
Item('_'),
Item('modeled_nedt_file_name', style = 'simple', label = 'Modeled NEdT'),
Item('_'),
Item('hyr2_frame_num', style = 'simple', label = 'Frame Number to use from the HYR2 File, starts with 1'),
Item('_'),
label = 'Set the input files to process',
help = ViewHelp
)
 
# The view includes one group per data type. These will be displayed
# on separate tabbed panels:
view = View(
settings_group,
title = 'Settings Editor',
width = 500,
buttons = [OKButton, CancelButton, Action(name='Save settings', action='save'),
Action(name='Restore settings', action='restore'), 'Help' ],
kind = 'modal',
handler = SaveRestore_Handler()
)
# Create the demo:
test_popup = Settings_W()
 
# Run the demo (if invoked from the command line):
if __name__ == '__main__':
test_popup.configure_traits()
tsa.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
"""
Thermal Spectrometer Analyzer
"""
 
from enthought.traits.api import HasTraits, Button
from enthought.traits.ui.api import Item, View, Group
from enthought.traits.ui.message import message
from enthought.traits.api import HasTraits, Str, File
 
from data import *
from settings_w import *
from calibrate_w import *
from calibrate import *
from calc_ne_w import *
from show_dwr_w import *
from calc_emis_w import *
from calc_emis import *
from calc_uniformity_w import *
from xyplot_slider2 import *
from xy2plots import *
from xyplot_2sliders_ref import *
 
from numpy import linspace
#-------------------------------------------------------------------------------
# Main Menu Class
#-------------------------------------------------------------------------------
 
# The objects that need to persist
data = Data()
settings_w=Settings_W()
calibrate_w = Calibrate_W()
calibrate = Calibrate()
calc_ne_w = Calc_NE_W()
calc_u_w = Calc_Uniformity_W()
show_dwr_w = Show_Dwr_W()
calc_emis_w = Calc_Emis_W()
calc_emis = Calc_Emis()
 
class MainMenu ( HasTraits ):
""" This class specifies the details of the Main Menu.
"""
 
# The buttonns in the button bar
settings=Button('Settings')
raw_data=Button('Raw data')
calibrate = Button('Calibrate')
calc_neq = Button('Noise Equivalence')
calc_uniformity = Button('Uniformity')
calc_emis = Button('Emissivity')
analyze_emissivity = Button('Analyze Emissivity')
def _settings_fired():
# Display the settings widget
settings_w.configure_traits(kind="livemodal")
# Read in the data specified in the settings widget
data.readfiles(settings_w)
# Copy over the BB values to the data class
#data.setBB(settings_w.cbb_temp, settings_w.wbb_temp)
def _raw_data_fired():
# If have sample and dwr data see which one to display
if data.dataflag ==True and data.dwrflag == True:
show_dwr_w.configure_traits(kind="livemodal")
if show_dwr_w.show_dwr=='Sample':
# Display the raw sample data
demo = XYPlot_Slider2('Raw Sample Data Plot (C)',data.wve, data.sam, data.cbb[:,100], data.wbb[:,100], 'Wavelength (um)', 'DN', 0, 0, True, True)
demo.configure_traits(kind="livemodal")
else:
# Display the raw downwelling data
demo = XYPlot_Slider2('Raw Downwelling Data Plot (D)',data.wve, data.dwr, data.cbb[:,100], data.wbb[:,100], 'Wavelength (um)', 'DN', 0, 0, True, True)
demo.configure_traits(kind="livemodal")
# If just have sample data and no dwr display it
if data.dataflag == True and data.dwrflag == False:
# Display the raw sample data
#print data.wve.shape
#print data.sam.shape
#print data.cbb.shape
#print data.wbb.shape
#all the data for a specific wavelength
#print data.wve[:,100]
#accross the wave 7-12
#print data.wve[100,:]
# Display the raw downwelling data
demo = XYPlot_Slider2('Raw Data',data.wve, data.sam, data.cbb[:,100], data.wbb[:,100], 'Wavelength (um)', 'DN', 0, 0, True, True)
demo.configure_traits(kind="live")
# If just have dwr data and sample data display it
if data.dataflag == False and data.dwrflag == True:
# Display the raw downwelling data
demo = XYPlot_Slider2('Raw Data (B)',data.wve, data.dwr, data.cbb[:,100], data.wbb[:,100], 'Wavelength (um)', 'DN', 0, 0, True, True)
demo.configure_traits(kind="livemodal")
# If have no data ask the user to enter some under settings
if data.dataflag == False and data.dwrflag==False:
print 'You need to load some data via the settings button!'
def _calibrate_fired():
# Check data are available, if no then return
if data.dataflag ==False:
message('You must first read in the data via the Settings \n button')
return
# Call widget to tweak the BB values and change the display format
calibrate_w.setBB(data.cbb_temp, data.wbb_temp)
calibrate_w.configure_traits(kind="livemodal")
data.setBB(calibrate_w.cbb_temp, calibrate_w.wbb_temp)
# Calibrate the data
calibrate.calibrate(data)
# Successfully read the data so display a dialog with the calibrate settings
if calibrate_w.display_units=='Radiance':
ytitle='Radiance'
ydata=data.samrad
ref1=data.r1rad[:,100]
ref2=data.r2rad[:,100]
else:
ytitle='Temperature (Celsius)'
ydata=data.samtem
ref1=data.r1tem[:,100] - 273.15
ref2=data.r2tem[:,100] - 273.15
# Use the settings from the calibrate_w dialog to produce the plot
demo = XYPlot_Slider2('Calibrated Data Plot',data.wve, ydata, ref1, ref2, "Wavelength (um)", ytitle, 0, 0, True, True)
demo.configure_traits(kind="live")
def _calc_neq_fired():
# Check Cbb, Wbb, Sam and Wve are available, if no then return
if data.dataflag ==False:
message('You must first read in the data via the Settings \n button')
return
# Check if the modeled NEdT is available
if data.modnedtflag ==False:
message('You must also read in the modeled NEdT for this function \n')
return
# Check is the data has been calibrated, if not then warn user
if data.calflag ==False:
message('You must calibrate the data first \n')
return
# Set the values for the calc_ne widget
calc_ne_w.setBB(data.cbb_temp, data.wbb_temp)
# calc_ne_w.setScale(0.0, 1.0, True, True)
calc_ne_w.setArrayLimits(0, data.chipsize_rows-1, 0, data.chipsize_cols-1)
# Display the calc_ne widget, save the cbb and wbb temps
calc_ne_w.configure_traits(kind="livemodal")
data.setBB(calc_ne_w.cbb_temp, calc_ne_w.wbb_temp)
# Calculate the NEdT for the selected region
#print calc_ne_w.ne_minrow, calc_ne_w.ne_maxrow, calc_ne_w.ne_mincol, calc_ne_w.ne_maxcol
calibrate.calc_means(data, calc_ne_w.display_units, calc_ne_w.ne_minrow, calc_ne_w.ne_maxrow, calc_ne_w.ne_mincol, calc_ne_w.ne_maxcol)
# Set the titles
if calc_ne_w.display_units == 'Radiance':
ytitle1=ytitle2='Radiance'
else:
ytitle1=ytitle2='Std. Dev. Temp. (Celsius)'
# Use the values from the calc_ne dialog for the plot parameters
mincol=calc_ne_w.ne_mincol
maxcol=calc_ne_w.ne_maxcol
minrow=calc_ne_w.ne_minrow
maxrow=calc_ne_w.ne_maxrow
x0=np.linspace(mincol, maxcol, maxcol-mincol+1)
title1='Spatial NE Plot'
xtitle1='Column#'
ylegend1='Spatial Std ('+str('%3.2f' % np.mean(data.spatial_std))+')'
title2='Spectral NE Plot'
xtitle2='Wavelength (um)'
ylegend2='Spectral Std ('+str('%3.2f' % np.mean(data.spectral_std))+')'
ylegend3='Modeled NEdT'
ymin=calc_ne_w.ymin # same value used for both plots
ymax=calc_ne_w.ymax # same value used for both plots
yminautoscale=calc_ne_w.auto_scale_ymin # same value used for both plots
ymaxautoscale=calc_ne_w.auto_scale_ymax # same value used for both plots
x1=data.wve[minrow:maxrow+1,:].mean(axis=1)
 
# Plot the data
demo = XY2Plots(x0, data.spatial_std, title1, xtitle1, ytitle1, ymin, ymax, yminautoscale, ymaxautoscale, ylegend1,
x1, data.spectral_std, title2, xtitle2,
ytitle2, ymin, ymax, yminautoscale, ymaxautoscale, ylegend2, ylegend3, data.modnedtwve,data.modnedtdat)
demo.configure_traits(kind="live")
def _calc_uniformity_fired():
# Check data are available, if no then return
if data.dataflag ==False:
message('You must first read in the data via the Settings \n button')
return
# Check is the data has been calibrated, if not then warn user
if data.calflag ==False:
message('You must calibrate the data first \n')
return
# Set the values for the calc_ne widget
calc_u_w.setBB(data.cbb_temp, data.wbb_temp)
 
# Set the array limits
calc_u_w.setArrayLimits(0, data.chipsize_rows-1, 0, data.chipsize_cols-1)
# Display the calc_ne widget
calc_u_w.configure_traits(kind="livemodal")
data.setBB(calc_u_w.cbb_temp, calc_u_w.wbb_temp)
# Calc the noise equivalents
calibrate.calc_means(data, calc_u_w.display_units, calc_ne_w.ne_minrow, calc_ne_w.ne_maxrow+1, calc_ne_w.ne_mincol, calc_ne_w.ne_maxcol+1)
# Set the titles
if calc_ne_w.display_units == 'Radiance':
ytitle1=ytitle2='Radiance'
else:
ytitle1=ytitle2='Temperature (Celsius)'
 
# Use the values from the calc_u dialog for the plot parameters
mincol=calc_u_w.ne_mincol
maxcol=calc_u_w.ne_maxcol
minrow=calc_u_w.ne_minrow
maxrow=calc_u_w.ne_maxrow
x0=np.linspace(mincol, maxcol, maxcol-mincol+1)
title1='Spatial Uniformity Plot'
xtitle1='Column#'
ylegend1='Spatial Mean '+str('%3.2f' % np.mean(data.spatial_mean)) + ' (+/- '+str('%3.3f' % np.std(data.spatial_mean)) +')'
title2='Spectral Uniformity Plot'
xtitle2='Wavelength (um)'
ylegend2='Spectral Mean '+str('%3.2f' % np.mean(data.spectral_mean)) + ' (+/- '+str('%3.3f' % np.std(data.spectral_mean)) +')'
ylegend3='ignore' #tell XY2Plots to ignore this line
ymin=calc_u_w.ymin # same value used for both plots
ymax=calc_u_w.ymax # same value used for both plots
yminautoscale=calc_u_w.auto_scale_ymin # same value used for both plots
ymaxautoscale=calc_u_w.auto_scale_ymax # same value used for both plots
x1=x1=data.wve[minrow:maxrow+1,:].mean(axis=1)
 
print "Spectral Mean",data.spectral_mean
# Plot the data
demo = XY2Plots(x0, data.spatial_mean, title1, xtitle1, ytitle1, ymin, ymax, yminautoscale, ymaxautoscale, ylegend1,
x1, data.spectral_mean, title2, xtitle2,
ytitle2, ymin, ymax, yminautoscale, ymaxautoscale, ylegend2, ylegend3, data.modnedtwve,data.modnedtdat)
demo.configure_traits(kind="live")
def _calc_emis_fired():
# Check is the data has been calibrated, if not ask user to calibrate
if data.calflag ==False:
message('You must calibrate your data first via the calibrate button')
return
# Check dwr panel data is available
if data.dwrflag ==False:
message('You must include downwelling panel data (enter file via settings \n and then calibrate')
return
# Update the panel temp for the emissivity panel from settings
calc_emis_w.panel_temp = settings_w.panel_temp
# Get the emissivity calculate parameters
calc_emis_w.configure_traits(kind="livemodal")
# Update the panel temp for the settings
settings_w.panel_temp = calc_emis_w.panel_temp
# Calculate the emissivity
calc_emis.calc_emis(data, calc_emis_w, settings_w)
# Use the settings from the calibrate_w dialog to produce the plot
ytitle='Emissivity'
ref1=np.linspace(0.4,0.4,64)
ref2=np.linspace(1.0,1.0,64)
# Add a reference emissivity if requested
if calc_emis_w.ref_refl == False:
reference = None
else:
reference=data.refemis[:,65]
# Show the results
if calc_emis_w.emis_method == 'Normalized':
demo = XYPlot_2Sliders_Ref('Normalized Emissivity Plot',data.wve, data.norme, reference, "Wavelength (um)", ytitle, 'Ottawa Sand',
calc_emis_w.ymin, calc_emis_w.ymax, calc_emis_w.auto_scale_ymin, calc_emis_w.auto_scale_ymax)
demo.configure_traits(kind="livemodal")
else:
demo = XYPlot_2Sliders_Ref('Online/Offline Emissivity Plot',data.wve, data.onoffemis, reference, "Wavelength (um)", ytitle, 'Ottawa Sand',
calc_emis_w.ymin, calc_emis_w.ymax, calc_emis_w.auto_scale_ymin, calc_emis_w.auto_scale_ymax)
demo.configure_traits(kind="livemodal")
def _analyze_emissivity_fired():
print 'anaylze emissivity fired'
# ButtonEditor display
event_group = Group( Item('settings', style='simple', show_label = False),
Item('_'),
Item('raw_data', style='simple', show_label = False),
Item('_'),
Item('calibrate', style='simple', show_label = False),
Item('_'),
Item('calc_neq', style='simple', show_label = False),
Item('_'),
Item('calc_uniformity', style='simple', show_label = False),
Item('_'),
Item('calc_emis', style='simple', show_label = False),
Item('_'),
Item('analyze_emissivity', style='simple', show_label = False),
Item('_'),
)
 
# Demo view
view1 = View( event_group,
title = 'Main Menu',
buttons = ['OK'],
width = 250 )
 
# Create the demo:
popup = MainMenu()
 
# Run the demo (if invoked from the command line):
if __name__ == '__main__':
popup.configure_traits()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.