Esempio n. 1
0
 def bbox(self, south_west, north_east, start='0001-01-01T00:00:00Z',
          end=None, groundwater_type="GWmMSL"):
     if not end:
         self.end = jsdt.now_iso()
     else:
         self.end = end
     self.start = start
     self.ts.queries = {"name": groundwater_type}
     self.locs.bbox(south_west, north_east)
     self.ts.bbox(south_west=south_west, north_east=north_east,
                  start=start, end=self.end)
Esempio n. 2
0
 def bbox(self,
          start='0001-01-01T00:00:00Z',
          end=None):
     if end:
         self.end = end
     else:
         self.end = jsdt.now_iso()
     self.start = start
     self.locs.bbox()
     self.ts.bbox(start=start,
                  end=self.end)
Esempio n. 3
0
 def uuid(self, uuid, start='0001-01-01T00:00:00Z', end=None):
     """
     Returns time series for a location by location-UUID.
     :param uuid: name of a location
     :param start: start timestamp in ISO 8601 format
     :param end: end timestamp in ISO 8601 format
     :return: a dictionary of with nested location, aquo quantities and
              events.
     """
     if not end:
         end = jsdt.now_iso()
     self.get(uuid=uuid, start=start, end=end)
Esempio n. 4
0
 def bbox(self,
          start='0001-01-01T00:00:00Z',
          end=None,
          groundwater_type="GWmMSL"):
     if end:
         self.end = end
     else:
         self.end = jsdt.now_iso()
     self.start = start
     self.ts.queries = {"name": groundwater_type}
     self.locs.bbox()
     self.ts.bbox(start=start,
                  end=self.end)
Esempio n. 5
0
 def uuid(self, ts_uuid, start='0001-01-01T00:00:00Z', end=None,
          organisation=None):
     """
     Returns time series for a timeseries by timeseries-UUID.
     :param ts_uuid: uuid of a timeseries
     :param start: start timestamp in ISO 8601 format
     :param end: end timestamp in ISO 8601 format
     :return: a dictionary of with nested location, aquo quantities and
              events.
     """
     if not end:
         end = jsdt.now_iso()
     old_base_url = self.base_url
     self.base_url += ts_uuid + "/"
     org_query = self.organisation_query(organisation)
     self.get(start=start, end=end, **org_query)
     self.base_url = old_base_url
Esempio n. 6
0
 def all_to_csv(self, start='0001-01-01T00:00:00Z', end=None,
            organisation=None):
     if not end:
         end = jsdt.now_iso()
     if isinstance(start, int):
         start -= 10000
     if isinstance(end, int):
         end += 10000
     org_query = self.organisation_query(organisation)
     self.get(
             start=start,
             end=end,
             **org_query
         )
     csv = (
         [r['name'], r['uuid'], jsdt.js_to_datestring(e['timestamp']), e['max']] for r
         in self.results for e in r['events']
     )
     loc = Locations(use_header=self.use_header)
     extra_queries_ts = copy.deepcopy(self.extra_queries).items()
     extra_queries = {
         key if not key.startswith("location__") else key[10:]: value
         for key, value in extra_queries_ts
     }
     org_query = self.organisation_query(organisation, '')
     extra_queries.update(**org_query)
     loc.get(**extra_queries)
     coords = loc.coord_uuid_name()
     headers = (
         [
             r['uuid'], r['name'], coords[r['location']['uuid']]['name'],
             coords[r['location']['uuid']]['coordinates'][0],
             coords[r['location']['uuid']]['coordinates'][1]
         ]
         for r in self.results
     )
     return headers, csv
Esempio n. 7
0
    def bbox(self, south_west, north_east, statistic=None,
                  start='0001-01-01T00:00:00Z', end=None):
        """
        Find all timeseries within a certain bounding box.
        Returns records within bounding box using Bounding Box format (min Lon,
        min Lat, max Lon, max Lat). Also returns features with overlapping
        geometry.
        :param south_west: lattitude and longtitude of the south-western point
        :param north_east: lattitude and longtitude of the north-eastern point
        :param start: start timestamp in ISO 8601 format
        :param end: end timestamp in ISO 8601 format
        :return: a dictionary of the api-response.
        """
        self.statistic = statistic
        if statistic == 'mean':
            statistic = ['count', 'sum']
        if not statistic:
            statistic = ['min', 'max', 'count', 'sum']
            self.statistic = None

        if not end:
            end = jsdt.now_iso()

        min_lat, min_lon = south_west
        max_lat, max_lon = north_east

        polygon_coordinates = [
            [min_lon, min_lat],
            [min_lon, max_lat],
            [max_lon, max_lat],
            [max_lon, min_lat],
            [min_lon, min_lat],
        ]
        points = ['%20'.join([str(x), str(y)]) for x, y in polygon_coordinates]
        geom_within = 'POLYGON%20((' + ',%20'.join(points) + '))'
        self.get(start=start, end=end, min_points=1, fields=statistic,
                 location__geom_within=geom_within)
Esempio n. 8
0
    def bbox(self, south_west, north_east, statistic=None,
             start='0001-01-01T00:00:00Z', end=None, organisation=None):
        """
        Find all timeseries within a certain bounding box.
        Returns records within bounding box using Bounding Box format (min Lon,
        min Lat, max Lon, max Lat). Also returns features with overlapping
        geometry.
        :param south_west: lattitude and longtitude of the south-western point
        :param north_east: lattitude and longtitude of the north-eastern point
        :param start_: start timestamp in ISO 8601 format
        :param end: end timestamp in ISO 8601 format
        :return: a dictionary of the api-response.
        """
        if not end:
            end = jsdt.now_iso()
        if isinstance(start, int):
            start -= 10000
        if isinstance(end, int):
            end += 10000

        min_lat, min_lon = south_west
        max_lat, max_lon = north_east

        polygon_coordinates = [
            [min_lon, min_lat],
            [min_lon, max_lat],
            [max_lon, max_lat],
            [max_lon, min_lat],
            [min_lon, min_lat],
        ]
        points = [' '.join([str(x), str(y)]) for x, y in polygon_coordinates]
        geom_within = {'a': 'POLYGON ((' + ', '.join(points) + '))'}
        geom_within = urllib.parse.urlencode(geom_within).split('=')[1]
        org_query = self.organisation_query(organisation)
        self.statistic = statistic
        if statistic == 'mean':
            statistic = ['count', 'sum']
        elif not statistic:
            statistic = ['min', 'max', 'count', 'sum']
            self.statistic = None
        elif statistic == 'range (max - min)':
            statistic = ['min', 'max']
        elif statistic == 'difference (last - first)':
            statistic = 'count'
        elif statistic == 'difference (mean last - first year)':
            year = dt.timedelta(days=366)
            first_end = jsdt.datetime_to_js(jsdt.js_to_datetime(start) + year)
            last_start = jsdt.datetime_to_js(jsdt.js_to_datetime(end) - year)
            self.get(
                start=start,
                end=first_end,
                min_points=1,
                fields=['count', 'sum'],
                location__geom_within=geom_within,
                **org_query
            )
            first_year = {}
            for r in self.results:
                try:
                    first_year[r['location']['uuid']] = {
                      'first_value_timestamp': r['first_value_timestamp'],
                      'mean': r['events'][0]['sum'] / r['events'][0]['count']
                    }
                except IndexError:
                    first_year[r['location']['uuid']] = {
                      'first_value_timestamp': np.nan,
                      'mean': np.nan
                    }
            self.results = []
            self.get(
                start=last_start,
                end=end,
                min_points=1,
                fields=['count', 'sum'],
                location__geom_within=geom_within,
                **org_query
            )
            for r in self.results:
                try:
                    r['events'][0]['difference (mean last - first year)'] = \
                        r['events'][0]['sum'] / r['events'][0]['count'] - \
                        first_year[r['location']['uuid']]['mean']
                    r['first_value_timestamp'] = \
                        first_year[
                            r['location']['uuid']]['first_value_timestamp']
                except IndexError:
                    r['events'] = [{
                        'difference (mean last - first year)': np.nan}]
                    r['first_value_timestamp'] = np.nan
                    r['last_value_timestamp'] = np.nan
            return

        self.get(
            start=start,
            end=end,
            min_points=1,
            fields=statistic,
            location__geom_within=geom_within,
            **org_query
        )