Changeset 312


Ignore:
Timestamp:
02/02/2011 11:07:16 AM (12 years ago)
Author:
marcus
Message:

More station handling (defect).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • SHX/trunk/src/SeismicHandler/modules/stations.py

    r297 r312  
    106106    def __getattr__(self, name): 
    107107        """ 
    108         Special handling for start and end date. 
    109         """ 
    110         if name.lower() not in ["start", "end"]: 
     108        Special handling for start and end date, combination of network and 
     109        station (netstation) and location, stream and component (lsc). 
     110        """ 
     111        if name.lower() not in ["start", "end", "netstation", "lsc"]: 
    111112            return self.__getattribute__(name) 
     113 
     114        if name.lower() == "netstation": 
     115            return ".".join([self.__dict__["network"], self.__dict__["station"]]) 
     116 
     117        if name.lower() == "lsc": 
     118            return ".".join([ 
     119                self.__dict__["location"], 
     120                self.__dict__["stream"], 
     121                self.__dict__["component"] 
     122            ]) 
    112123 
    113124        # build UTCDateTime from o[n|ff]date[ms] 
     
    206217        Init / refresh station information. 
    207218        """ 
     219        # read only information 
     220        data = [] 
     221        for db in Settings.config.inventory.readonly: 
     222            data += self.__readDB(db) 
     223 
    208224        # data base access r/w 
    209225        self.dbreadwrite = Settings.config.inventory.database[0] 
    210         data = self.__readDB() 
    211  
    212         # read only information 
    213         data_read = [] 
    214         for db in Settings.config.inventory.readonly: 
    215             data_read += self.__readDB(db) 
    216  
    217         # check for overlapping data from rw to readonly db 
    218         # first: identical datasets 
    219         double = set(data) & set(data_read) 
    220         for i in double: 
    221             if data[i] != data_read[i]: 
    222                 self.logger.critital("Concurrent data found for channel: %s " 
    223                                      "WARNING: It's very likely that you use " 
    224                                      "outdated channel information!", 
    225                                      i 
    226                                     ) 
    227             if data_read[i].fir and data_read[i].fir != data[i].fir: 
    228                 self.logger.warning("Concurrent FIR data for channel: %s ", 
    229                                      i 
    230                                     ) 
    231  
    232         print data, data_read 
     226        data += self.__readDB() 
     227         
     228        for i in data: 
     229            if not i.netstation in self.stations: 
     230                self.stations[i.netstation] = {} 
     231 
     232            try: 
     233                self.stations[i.netstation][i.lsc].append(i) 
     234            except KeyError: 
     235                self.stations[i.netstation][i.lsc] = [i] 
     236 
     237#        print self.stations 
    233238 
    234239    def __readDB(self, db=None): 
     
    250255 
    251256        return self.dbsessions[db].query(ChannelMeta).order_by("ondate").all() 
     257 
     258    def __getitem__(self, channeldate): 
     259        """ 
     260        Return channel meta data from channel code and time information. 
     261        """ 
     262        channel, dt = channeldate 
     263        print "xxx", channel 
     264        # check for overlapping data from rw to readonly db 
     265        # first: identical datasets 
     266#        double = set(data) & set(data_read) 
     267#        print double 
     268#        for i in double: 
     269#            if data[i] != data_read[i]: 
     270#                self.logger.critital("Concurrent data found for channel: %s " 
     271#                                     "WARNING: It's very likely that you use " 
     272#                                     "outdated channel information!", 
     273#                                     i 
     274#                                    ) 
     275#            if data_read[i].fir and data_read[i].fir != data[i].fir: 
     276#                self.logger.warning("Concurrent FIR data for channel: %s ", 
     277#                                     i 
     278#                                    ) 
     279 
    252280 
    253281    def add(self, station): 
     
    284312if __name__ == "__main__": 
    285313    stations = Stations() 
    286  
    287     GRA1 = ChannelMeta( 
    288         network="GR", 
    289         station="GRA1", 
    290         location="", 
    291         stream="BH", 
    292         component="Z", 
    293         latitude=49.691888, 
    294         longitude=11.221720, 
    295         elevation=499.5, 
    296         depth=0, 
    297         gain=0.6e9, 
    298         zeros="(0.0,0.0) (0.0,0.0)", 
    299         poles="(-0.037004,0.037016) (-0.037004,-0.037016)", 
    300         start=UTCDateTime("2006-05-10T16:00:00.000100"), 
    301     ) 
    302  
    303     GRA12 = ChannelMeta( 
    304         network="GR", 
    305         station="GRA1", 
    306         location="", 
    307         stream="BH", 
    308         component="Z", 
    309         latitude=49.691888, 
    310         longitude=11.221720, 
    311         elevation=499.5, 
    312         depth=0, 
    313         gain=0.6e9, 
    314         zeros="(0.0,0.0) (0.0,0.0)", 
    315         poles="(-0.037004,0.037016) (-0.037004,-0.037016)", 
    316         start=UTCDateTime("2006-05-10T16:00:00.000"), 
    317     ) 
    318  
    319 #    print GRA1 == GRA12, GRA1, GRA12 
    320  
    321 #    stations.add(GRA1) 
    322  
    323     print GRA1.ondate, GRA1.start, GRA1.fir 
    324      
     314    print stations[("GR.GRA1..BHZ", UTCDateTime())] 
Note: See TracChangeset for help on using the changeset viewer.