Exemplo n.º 1
0
    def __init__(self, networkCode):
        self.__fmt__ = None
        self.takeSugestions = None

        self.filename = None

        self.networkCode = networkCode
        self.stationList = None

        self.nat = None
        self.sat = None
        self.sma = None
        self.inst = None
        self.defaultEpoch = parseDate("1980/001")

        self.start = 0
        self.code = 0
        self.description = 0
        self.datalogger = 0
        self.sensor = 0
        self.channel = 0
        self.gaind = 0
        self.longitude = 0
        self.latitude = 0
        self.elevation = 0
        self.end = 0
        self.depth = 0
        self.orientation = 0

        ## default dates
        self.startDate = parseDate("1980/001")
        self.endDate = parseDate(None)
Exemplo n.º 2
0
    def __convertLine__(self, line, fdo, atFront):
        lnfmt = self.__fmtline__()

        # Split line
        items = line.split()

        try:
            code = items.pop(0)
        except Exception as e:
            raise Exception("Missing Code on %s" % line)

        if code not in self.stationList:
            raise Exception("Unknow station code $s" % code)

        try:
            hummanStr(items.pop(0))
        except Exception as e:
            raise Exception("Missing Gain on %s" % line)

        try:
            datalogger = items.pop(0)
        except Exception as e:
            raise Exception("Missing Datalogger on %s" % line)

        try:
            sensor = items.pop(0)
        except Exception as e:
            raise Exception("Missing Sensor on %s" % line)

        try:
            gaind = items.pop(0)
            if float(gaind) != 1.0:
                if not self.inst:
                    raise Exception(
                        "Instrument database needed to convert gain")
                try:
                    dte = self.inst.dls[str(datalogger).split("%")[0]]
                except Exception as e:
                    print(e, file=sys.stderr)
                    raise Exception("Datalogger %s not found" %
                                    str(datalogger).split("%")[0])
                datalogger += "%%%s" % (float(dte.gain) * float(gaind))
                print(
                    " Converting gain multiplier to real gain using instrument DB on %s"
                    % code,
                    file=sys.stderr)
        except Exception as e:
            raise Exception("Missing Gain on %s (%s)" % (line, str(e)))

        try:
            channel = items.pop(0)
        except Exception as e:
            raise Exception("Missing Channel on %s" % line)

        try:
            latitude = items.pop(0)
        except Exception as e:
            raise Exception("Missing Latitude on %s" % line)

        try:
            longitude = items.pop(0)
        except Exception as e:
            raise Exception("Missing Longitude on %s" % line)
        try:
            elevation = items.pop(0)
        except Exception as e:
            raise Exception("Missing Elevation on %s" % line)

        try:
            depth = items.pop(0)
        except Exception as e:
            raise Exception("Missing Depth on %s" % line)

        #Orientation
        try:
            float(depth)
            orientation = "ZNE"
        except:
            orientation = "Z"
            (depth, a1, a2) = depth.split("/")

            a1n = float(a1)
            if a1n == 0.0:
                orientation += "1"
            else:
                orientation += "1(0.0,%s)" % a1

            a2n = float(a2)
            if a2n == 90.0:
                orientation += "2"
            else:
                orientation += "2(0.0,%s)" % a2

        # Start
        try:
            start = items.pop(0)
        except Exception:
            raise Exception("Missing Start on %s" % line)

        try:
            start = parseDate(start)
        except Exception as e:
            raise Exception("Invalide Start date: %s (%s) on %s" %
                            (start, e, line))

        #End
        try:
            end = items.pop(0)
        except:
            end = ""

        try:
            end = parseDate(end)
        except Exception as e:
            raise Exception("Invalide End date: %s (%s) on %s" %
                            (end, e, line))

        [place, country] = self.sat.parseStationLine(line.split())
        description = "%s/%s" % (place, country)

        ## Prepare necessary output
        if not atFront:
            self.sma.dump(fdo, code)
            self.sat.dump(fdo, code)

        for (start, end) in self.sma.getMappings(code, start, end):
            fdo.write(lnfmt %
                      (code, quote(description), datalogger, sensor, channel,
                       orientation, latitude, longitude, elevation, depth,
                       formatDate(start), formatDate(end)) + "\n")

        return code
Exemplo n.º 3
0
    def __analyseLine__(self, items):
        inputLine = " ".join(items)
        if len(items) < 4:
            raise Exception("Invalid items count on line %s" % inputLine)

        if len(items) <= 5:
            netCode = items[2]
            if netCode != self.networkCode:
                raise Exception(
                    "Tab file (%s) doesn't match class (%s) -- %s" %
                    (netCode, self.networkCode, inputLine))
            return [None, None, None]
        else:
            if len(items) < 6:
                raise Exception("Invalid Station line %s" % inputLine)

            stationCode = items.pop(0)
            code = len(stationCode)
            self.code = max(self.code, code)

            description = len(quote(hummanStr(items.pop(0))))
            self.description = max(self.description, description)

            datalogger = len(items.pop(0))
            self.datalogger = max(self.datalogger, datalogger)

            sensor = len(items.pop(0))
            self.sensor = max(self.sensor, sensor)

            # Gain
            gaind = items.pop(0)
            if float(gaind) != 1.0:
                self.datalogger = max(self.datalogger, datalogger + len(gaind))

            channel = len(items.pop(0))
            self.channel = max(self.channel, channel)

            latitude = len(items.pop(0))
            self.latitude = max(self.latitude, latitude)

            longitude = len(items.pop(0))
            self.longitude = max(self.longitude, longitude)

            elevation = len(items.pop(0))
            self.elevation = max(self.elevation, elevation)

            #Orientation
            depth = items.pop(0)
            try:
                float(depth)
                orientation = "ZNE"
            except:
                orientation = "Z"
                (depth, a1, a2) = depth.split("/")

                a1n = float(a1)
                a2n = float(a2)

                orientation += "1"
                if a1n != 0.0: orientation += "(0.0,%s)" % a1

                orientation += "2"
                if a2n != 90.0: orientation += "(0.0,%s)" % a1

            orientation = len(orientation)
            self.orientation = max(self.orientation, orientation)

            depth = len(depth)
            self.depth = max(self.depth, depth)

            # Start
            try:
                start = parseDate(items.pop(0))
                self.start = max(self.start, len(formatDate(start)))
            except:
                raise Exception("Invalid Station line start date %s" %
                                inputLine)

            # End
            try:
                end = parseDate(items.pop(0))
            except:
                end = parseDate("")
                pass
            self.end = max(self.end, len(formatDate(end)))

            return [stationCode, start, end]