def test_gis_location_service(self):
     glr=GisLocationService()
     nea_nid=[598, 574]
     # we test that for the same point, different projections, we get same heights and approx. different positions
     utm32_loc=glr.get_locations(nea_nid, 32632)
     utm33_loc=glr.get_locations(nea_nid, 32633)
     self.assertIsNotNone(utm32_loc)
     self.assertIsNotNone(utm33_loc)
     for p in nea_nid:
         self.assertAlmostEqual(utm32_loc[p][2],utm33_loc[p][2])
         self.assertGreater(fabs(utm32_loc[p][1]-utm33_loc[p][1]),10*1000,"expect y same")
         self.assertGreater(fabs(utm32_loc[p][0]-utm33_loc[p][0]),30*1000,"expect x diff same")
 def test_gis_location_service(self):
     glr=GisLocationService()
     nea_nid=[402, 460]
     # we test that for the same point, different projections, we get same heights and approx. different positions
     utm32_loc=glr.get_locations(nea_nid, 32632)
     utm33_loc=glr.get_locations(nea_nid, 32633)
     self.assertIsNotNone(utm32_loc)
     self.assertIsNotNone(utm33_loc)
     for p in nea_nid:
         self.assertAlmostEqual(utm32_loc[p][2],utm33_loc[p][2])
         self.assertLess(fabs(utm32_loc[p][1]-utm33_loc[p][1]),10*1000,"expect y same")
         self.assertGreater(fabs(utm32_loc[p][0]-utm33_loc[p][0]),30*1000,"expect x diff same")
Beispiel #3
0
    def plot_region_model(self, catchment_type, identifier, x0, y0, dx, dy, nx, ny,
                          catch_indicies, station_ids, epsg_id):
        grid_spec = GridSpecification(epsg_id, x0, y0, dx, dy, nx, ny)
        cf = CellDataFetcher(catchment_type, identifier, grid_spec, id_list=catch_indicies)
        print("Start fetching data")
        cf.fetch()
        print("Done, now preparing plot")
        # Plot the extracted data
        fig, ax = plt.subplots(1)
        color_map = {"forest": 'g', "lake": 'b', "glacier": 'r', "cell": "0.75", "reservoir": "purple"}

        extent = grid_spec.geometry[0], grid_spec.geometry[2], grid_spec.geometry[1], grid_spec.geometry[3]
        ax.imshow(cf.elevation_raster, origin='upper', extent=extent, cmap=cm.gray)

        for catchment_cells in iter(cf.cell_data.values()):
            self.add_plot_polygons(ax, [cell["cell"] for cell in catchment_cells], color=color_map["cell"])
        for catchment_land_type in iter(cf.catchment_land_types.values()):
            for k, v in iter(catchment_land_type.items()):
                self.add_plot_polygons(ax, v, color=color_map[k])

        geometry = grid_spec.geometry
        if station_ids is not None:
            glr = GisLocationService()
            stations = glr.get_locations(station_ids, epsg_id)
            if stations:
                points = stations.values()
                ax.scatter([pt[0] for pt in points], [pt[1] for pt in points], alpha=0.5)
                station_min_x = min([v[0] for v in points]) - 1000
                station_max_x = max([v[0] for v in points]) + 1000
                station_min_y = min([v[1] for v in points]) - 1000
                station_max_y = max([v[1] for v in points]) + 1000
                geometry[0] = min(station_min_x, geometry[0])
                geometry[1] = min(station_min_y, geometry[1])
                geometry[2] = max(station_max_x, geometry[2])
                geometry[3] = max(station_max_y, geometry[3])
                base_dir = path.join(shyftdata_dir, "repository", "arome_data_repository")
                EPSG = grid_spec.epsg()
                bbox = grid_spec.bounding_box(EPSG)
                arome4 = AromeDataRepository(EPSG, base_dir, filename="arome_metcoop_default2_5km_*.nc",
                                             bounding_box=bbox, allow_subset=True)
                # data_names = ("temperature", "wind_speed", "precipitation", "relative_humidity","radiation")
                # utc_period = api.UtcPeriod(
                #    api.Calendar().time(api.YMDhms(2015, 10, 1, 0, 0, 0)),
                #    api.Calendar().time(api.YMDhms(2015, 10, 2, 0, 0, 0))
                # )
                # arome_ts=arome4.get_timeseries(["temperature"],utc_period)
                # arome_points=[gts.mid_point() for gts in arome_ts['temperature']]
                # ax.scatter( [pt.x for pt in arome_points ],[pt.y for pt in arome_points],c=[pt.z for pt in arome_points],alpha=0.5,cmap='gray',s=100)#, facecolors=('r'))

        ax.set_xlim(geometry[0], geometry[2])
        ax.set_ylim(geometry[1], geometry[3])
        plt.show()
 def plot_region_model(self, catchment_type, identifier ,x0, y0, dx, dy, nx, ny,
                       catch_indicies, station_ids,epsg_id):
     grid_spec = GridSpecification(epsg_id, x0, y0, dx, dy, nx, ny)
     cf = CellDataFetcher(catchment_type, identifier, grid_spec, id_list=catch_indicies)
     print( "Start fetching data")
     cf.fetch()
     print ("Done, now preparing plot")
     # Plot the extracted data
     fig, ax = plt.subplots(1)
     color_map = {"forest": 'g', "lake": 'b', "glacier": 'r', "cell": "0.75", "reservoir": "purple"}
 
     extent = grid_spec.geometry[0], grid_spec.geometry[2], grid_spec.geometry[1], grid_spec.geometry[3]
     ax.imshow(cf.elevation_raster, origin='upper', extent=extent, cmap=cm.gray)
 
     for catchment_cells in iter(cf.cell_data.values()):
         self.add_plot_polygons(ax, [cell["cell"] for cell in catchment_cells], color=color_map["cell"])
     for catchment_land_type in iter(cf.catchment_land_types.values()):
         for k,v in iter(catchment_land_type.items()):
             self.add_plot_polygons(ax, v, color=color_map[k])
 
     geometry = grid_spec.geometry
     if station_ids is not None:
         glr = GisLocationService()
         stations = glr.get_locations(station_ids, epsg_id)
         if stations:
             points = stations.values()
             ax.scatter([pt[0] for pt in points], [pt[1] for pt in points], alpha=0.5)
             station_min_x = min([v[0] for v in points]) - 1000
             station_max_x = max([v[0] for v in points]) + 1000
             station_min_y = min([v[1] for v in points]) - 1000
             station_max_y = max([v[1] for v in points]) + 1000
             geometry[0] = min(station_min_x, geometry[0])
             geometry[1] = min(station_min_y, geometry[1])
             geometry[2] = max(station_max_x, geometry[2])
             geometry[3] = max(station_max_y, geometry[3])
             base_dir = path.join(shyftdata_dir, "repository", "arome_data_repository")
             EPSG = grid_spec.epsg_id
             bbox = grid_spec.bounding_box(EPSG)
             arome4 = AromeDataRepository(EPSG, base_dir, filename="arome_metcoop_default2_5km_*.nc",
                                          bounding_box=bbox, allow_subset=True)
             #data_names = ("temperature", "wind_speed", "precipitation", "relative_humidity","radiation")
             utc_period = api.UtcPeriod(
                 api.Calendar().time(api.YMDhms(2015,10,1,0,0,0)),
                 api.Calendar().time(api.YMDhms(2015,10,2,0,0,0)) 
             )
             #arome_ts=arome4.get_timeseries(["temperature"],utc_period)
             #arome_points=[gts.mid_point() for gts in arome_ts['temperature']]
             #ax.scatter( [pt.x for pt in arome_points ],[pt.y for pt in arome_points],c=[pt.z for pt in arome_points],alpha=0.5,cmap='gray',s=100)#, facecolors=('r'))
     
     ax.set_xlim(geometry[0], geometry[2])
     ax.set_ylim(geometry[1], geometry[3])
     plt.show()