Skip to content

anonymous /settings_w.py
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#! /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()
"""
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.