def get_stations_by_latlon(self, latitudes, longitudes, **kwargs): """ retrieves Station objects from Nerrs determined by the series of latitudes and longitudes - latitudes: comma-deliminated string of latitude values - longitudes: comma-deliminated string of longitude values optionals: - min_date - max_date - observed_property returns a StationCollection object from the parser """ if latitudes is None or longitudes is None: return None lats = str(latitudes).split(',') lons = str(longitudes).split(',') # make sure the lists are equal in size while len(lats) > len(lons): noop = lats.pop() while len(lons) > len(lats): noop = lons.pop() metadata = self.__get_metadata() desired_stations = list() for station in metadata: for index, value in enumerate(lats): if station.location.latitude == float(value) and station.location.longitude == float(lons[index]) and station not in desired_stations: desired_stations.append(station) args = dict(min_date=kwargs.get('min_date'),max_date=kwargs.get('max_date'),observed_property=kwargs.get('observed_property')) reply = Reply(None) return reply.parse_station_collection(self.get_station, args, desired_stations)
def get_station(self, station_code, **kwargs): """ retrieves a Station object from Nerrs, found by the given station code - station_code: the uid of the station optionals: - metadata - min_date - max_date - observed_property """ if station_code is None: return None metadata = kwargs.get('metadata') if metadata is None: metadata = self.__get_metadata(station_code=station_code, site_id=kwargs.get('site_id')) metadata = metadata[0] # need to explore the limitations requested by the user in order to define what we are retrieving from nerrs min_date = kwargs.get('min_date') if min_date is None: min_date = metadata.activity.get_start(date=True) max_date = kwargs.get('max_date') if max_date is None: max_date = metadata.activity.get_end(date=True) data = list() param = kwargs.get('observed_property') if param is None: param = metadata.parameters else: param = param.split(',') for p in param: d = self.__get_station_data(station_code=station_code, min_date=min_date, max_date=max_date, param=p) if d is not None: data.append(d) reply = Reply(None) return reply.parse_station(metadata, data)
def get_stations_by_bbox(self, south, west, north, east, **kwargs): """ retrieves Station objects from Nerrs determined by the boundaries given - south: the southern-most latitude (in degrees North) - west: western-most longitude (in degrees West) - north: northern-most latitude (in degrees North) - east: eastern-most longitude (in degrees West) optionals: - min_date - max_date - observed_property returns a StationCollection object from the parser """ metadata = self.__get_metadata() desired_stations = list() for station in metadata: if station.location.longitude >= east and station.location.longitude <= west: if station.location.latitude <= north and station.location.longitude >= south: desired_stations.append(station) args = dict(min_date=kwargs.get('min_date'),max_date=kwargs.get('max_date'),observed_property=kwargs.get('observed_property')) reply = Reply(None) return reply.parse_station_collection(self.get_station, args, desired_stations)