def __getSatNodeForLatLonAndTime__()

in analysis/webservice/algorithms/doms/MatchupQuery.py [0:0]


    def __getSatNodeForLatLonAndTime__(self, chunksByDay, source, lat, lon, searchTime):

        timeDiff = 86400 * 365 * 1000
        foundNodes = []

        for ts in chunksByDay:
            chunks = chunksByDay[ts]
            # print chunks
            # ts = calendar.timegm(chunks.start.utctimetuple()) * 1000
            if abs((ts * 1000) - searchTime) < timeDiff:
                value = self.__getValueForLatLon(chunks, lat, lon, arrayName="data")
                value = self.__checkNumber(value)

                # _Really_ don't like doing it this way...

                sst = None
                sss = None
                windSpeed = None
                windDirection = None
                windU = None
                windV = None

                if "GHRSST" in source:
                    sst = value

                if "ASCATB" in source:
                    windU = value

                if len(chunks) > 0 and "wind_dir" in chunks[0].meta_data:
                    windDirection = self.__checkNumber(self.__getValueForLatLon(chunks, lat, lon, arrayName="wind_dir"))
                if len(chunks) > 0 and "wind_v" in chunks[0].meta_data:
                    windV = self.__checkNumber(self.__getValueForLatLon(chunks, lat, lon, arrayName="wind_v"))
                if len(chunks) > 0 and "wind_speed" in chunks[0].meta_data:
                    windSpeed = self.__checkNumber(self.__getValueForLatLon(chunks, lat, lon, arrayName="wind_speed"))

                foundNode = {
                    "sea_water_temperature": sst,
                    "sea_water_salinity": sss,
                    "wind_speed": windSpeed,
                    "wind_direction": windDirection,
                    "wind_uv": {
                        "u": windU,
                        "v": windV
                    },
                    "time": ts,
                    "x": lon,
                    "y": lat,
                    "depth": 0,
                    "sea_water_temperature_depth": 0,
                    "source": source,
                    "id": "%s:%s:%s" % (ts, lat, lon)
                }

                isValidNode = True
                if "ASCATB" in source and windSpeed is None:
                    isValidNode = None

                if isValidNode:
                    foundNodes.append(foundNode)
                timeDiff = abs(ts - searchTime)

        return foundNodes