Ignore:
Timestamp:
Feb 19, 2009, 10:45:22 AM (15 years ago)
Author:
rwilson
Message:

Made events file be generated into it's own directory, as per new requirements.

Location:
misc/tools/event_selection
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • misc/tools/event_selection/EventSelection.py

    r6333 r6362  
    5353# program name and version
    5454APP_NAME = 'EventSelection'
    55 APP_VERSION = '0.7'
     55APP_VERSION = '0.8'
    5656
    5757# name of the configuration filename
     
    170170
    171171class Config(object):
    172     """
    173     An object that behaves like a dictionary but is persistent:
     172    """An object that behaves like a dictionary but is persistent
    174173
    175174        cfg = Config('filename')
     
    183182
    184183    def __init__(self, configfile=None):
    185         """
    186         __init__(self, String filename=None) -> Config
    187         """
     184        """__init__(self, String filename=None) -> Config"""
    188185
    189186        self.delconf = False
     
    207204
    208205    def __setitem__(self, key, value):
    209         """
    210         Override to allow: cfg[<key>] = <value>
    211         """
     206        """Override to allow: cfg[<key>] = <value>"""
     207       
    212208        self.cfgdict[key] = value
    213209        self.changed = True
    214210
    215211    def __getitem__(self, key):
    216         """
    217         Override to allow: <var> = cfg[<key>]
    218         """
     212        """Override to allow: <var> = cfg[<key>]"""
     213       
    219214        return self.cfgdict.get(key, None)
    220215
    221216    def __str__(self):
    222         """
    223         __str__(self) -> String
    224         """
     217        """__str__(self) -> String"""
     218       
    225219        return "<config object at %s>" % hex(id(self))
    226220
    227221    def getfilename(self):
    228         """
    229         getfilename(self) -> String filename
    230         """
     222        """getfilename(self) -> String filename"""
     223       
    231224        return self.configfile
    232225
    233226    def setdeleted(self):
    234         """
    235         setdeleted(self)
    236         """
     227        """setdeleted(self)"""
     228       
    237229        self.delconf = True
    238230
    239231    def save(self):
    240         """
    241         save(self)
    242         """
     232        """save(self) -> save data to a file"""
     233       
    243234        try:
    244235            f = open(self.configfile, "w")
     
    252243
    253244    def close(self):
    254         """
    255         close(self)
    256         """
     245        """close(self) - close the save file"""
    257246        if self.changed:
    258247            self.save()
     
    262251
    263252    def __del__(self):
    264         """
    265         __del__(self)
    266         """
     253        """__del__(self) - ensure save file is closed"""
     254       
    267255        self.close()
    268256
     
    805793        ######
    806794        def MultimuxClick(self, event):
     795            # check we have an output base directory
     796            output_base_dir = self.txtOutputDir.GetValue()
     797            if len(output_base_dir) == 0:
     798                self.error('You must select an output base directory first')
     799                return
     800
    807801            # check we have a quake ID
    808802            quake_ID = self.txtQuakeID.GetValue()
     
    813807                quake_ID = int(quake_ID)
    814808            except:
    815                 self.error("You must enter a Quake ID")
     809                self.error("You must enter a Quake ID integer")
    816810                return
    817811
     
    839833            self.panel.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
    840834
    841             fault_event_filename = ('%s/event_%6.6d.list' %
    842                                     (ResultSubdir, quake_ID))
     835            fault_event_dir = os.path.join(output_base_dir, '%6.6d' % quake_ID)
     836            os.makedirs(fault_event_dir)
     837            fault_event_filename = os.path.join(fault_event_dir, 'event.list')
     838
    843839            wx.Yield()          # allow GUI refresh
    844840
     
    892888                last_weight = weight
    893889                filenames.append(filename)
    894             # write data to the file
    895             urs_filename = '%s/%s' % (ResultSubdir, URSDataFilename % quake_ID)
    896             try:
    897                 out_fd = open(urs_filename, "w")
    898             except IOError, msg:
    899                 self.error("Error opening output file %s': %s" %
    900                            (urs_filename, msg))
    901                 return
    902             if last_weight and filenames:
    903                 out_fd.write('# Data for region %s,\n'
    904                              '#          hazard %d,\n'
    905                              '#          min height %.2f,\n'
    906                              '#          max height %.2f,\n'
    907                              '#          quake ID %d\n' %
    908                              (Region, GaugeNumber, MinimumHeight,
    909                               MaximumHeight, quake_ID))
    910                 out_fd.write('# Generated on %s.\n' % time.asctime(time.localtime()))
    911                 out_fd.write('\n')
    912                 out_fd.write('import os.path\n')
    913                 out_fd.write('\n')
    914                 out_fd.write('def getInfo(base_directory):\n')
    915                 out_fd.write('    """\n')
    916                 out_fd.write('    Return the weight factor and list of URS data filenames\n')
    917                 out_fd.write('\n')
    918                 out_fd.write('        (weight_factor, [filenames]) <- get_urs_data(base_directory)\n')
    919                 out_fd.write('\n')
    920                 out_fd.write('    where base_directory is the path to the mux files.\n')
    921                 out_fd.write('    """\n')
    922                 out_fd.write('\n')
    923                 out_fd.write('    weight_factor = %f\n' % last_weight)
    924                 out_fd.write('    mux_filenames = [')
    925                 if filenames:
    926                     for fn in filenames[:-1]:
    927                         out_fd.write('"%%s" %% os.path.join(base_directory, "%s"),\n                     ' % fn)
    928                     out_fd.write('"%%s" %% os.path.join(base_directory, "%s")\n                    ' % filenames[-1])
    929                 out_fd.write(']\n')
    930                 out_fd.write('\n')
    931                 out_fd.write('    return (weight_factor, mux_filenames)\n')
    932             out_fd.close()
     890               
     891## No longer generate the python data file
     892##            # write data to the file
     893##            urs_filename = '%s/%s' % (ResultSubdir, URSDataFilename % quake_ID)
     894##            try:
     895##                out_fd = open(urs_filename, "w")
     896##            except IOError, msg:
     897##                self.error("Error opening output file %s': %s" %
     898##                           (urs_filename, msg))
     899##                return
     900##            if last_weight and filenames:
     901##                out_fd.write('# Data for region %s,\n'
     902##                             '#          hazard %d,\n'
     903##                             '#          min height %.2f,\n'
     904##                             '#          max height %.2f,\n'
     905##                             '#          quake ID %d\n' %
     906##                             (Region, GaugeNumber, MinimumHeight,
     907##                              MaximumHeight, quake_ID))
     908##                out_fd.write('# Generated on %s.\n' % time.asctime(time.localtime()))
     909##                out_fd.write('\n')
     910##                out_fd.write('import os.path\n')
     911##                out_fd.write('\n')
     912##                out_fd.write('def getInfo(base_directory):\n')
     913##                out_fd.write('    """\n')
     914##                out_fd.write('    Return the weight factor and list of URS data filenames\n')
     915##                out_fd.write('\n')
     916##                out_fd.write('        (weight_factor, [filenames]) <- get_urs_data(base_directory)\n')
     917##                out_fd.write('\n')
     918##                out_fd.write('    where base_directory is the path to the mux files.\n')
     919##                out_fd.write('    """\n')
     920##                out_fd.write('\n')
     921##                out_fd.write('    weight_factor = %f\n' % last_weight)
     922##                out_fd.write('    mux_filenames = [')
     923##                if filenames:
     924##                    for fn in filenames[:-1]:
     925##                        out_fd.write('"%%s" %% os.path.join(base_directory, "%s"),\n                     ' % fn)
     926##                    out_fd.write('"%%s" %% os.path.join(base_directory, "%s")\n                    ' % filenames[-1])
     927##                out_fd.write(']\n')
     928##                out_fd.write('\n')
     929##                out_fd.write('    return (weight_factor, mux_filenames)\n')
     930##            out_fd.close()
    933931           
    934932        ######
  • misc/tools/event_selection/installer/EventSelection.nsi

    r6331 r6362  
    11!define PRODUCT_NAME "EventSelection"
    2 !define PRODUCT_VERSION "0.7"
     2!define PRODUCT_VERSION "0.8"
    33!define ICON_FILE "tsunami.ico"
    44
Note: See TracChangeset for help on using the changeset viewer.