Example #1
0
 def test_wrapper2(self):
     sub = multipolygon_operation(
         'http://cida.usgs.gov/qa/thredds/dodsC/maurer/monthly',
         'sresa1b_miroc3-2-medres_2_Prcp',
         ocg_opts={
             'colbnds_name': u'bounds_longitude',
             'calendar': u'proleptic_gregorian',
             'time_name': u'time',
             'time_units': u'days since 1950-01-01 00:00:00',
             'rowbnds_name': u'bounds_latitude'
         },
         polygons=[{
             'gid':
             None,
             'geom':
             wkt.loads(
                 'POLYGON ((-104.0000000000000000 39.0000000000000000, -95.0000000000000000 39.0000000000000000, -95.0000000000000000 44.0000000000000000, -104.0000000000000000 39.0000000000000000))'
             )
         }],
         time_range=[
             datetime.datetime(2000, 1, 1, 0, 0),
             datetime.datetime(2001, 12, 31, 0, 0)
         ],
         level_range=None,
         clip=True,
         union=True,
         in_parallel=True,
         max_proc=8,
         max_proc_per_poly=2,
         allow_empty=True)
Example #2
0
 def sub_ocg_dataset(self):
     sub = multipolygon_operation(
         self.nc_path,
         self.nc_var_name,
         ocg_opts=self.nc_opts,
         polygons=[
             {
                 'gid': 99,
                 'geom': self.nebraska()
             },
             {
                 'gid': 100,
                 'geom': self.iowa()
             },
             #                                               {'gid':200,'geom':self.vermont()}
         ],
         time_range=[
             datetime.datetime(2011, 1, 1),
             datetime.datetime(2013, 12, 31)
         ],
         level_range=None,
         clip=True,
         union=True,
         in_parallel=True,
         max_proc=8,
         max_proc_per_poly=2)
     return (sub)
    def _read_(self, request):
        #        import ipdb;ipdb.set_trace()
        logger.debug("starting SpatialHandler._read_()...")
        dataset = self.ocg.simulation_output.netcdf_variable.netcdf_dataset

        ## arguments for the dataset object
        kwds = dict(
            rowbnds_name=dataset.rowbnds_name,
            colbnds_name=dataset.colbnds_name,
            time_name=dataset.time_name,
            time_units=dataset.time_units,
            calendar=dataset.calendar,
        )
        #                    level_name=self.ocg.dataset.level_name,) TODO: add level variable name

        ## construct arguments to clip operation
        if self.ocg.operation == 'clip':
            clip = True
        else:
            clip = False

        ## choose extraction mode and pull data appropriately.
        if settings.MAXPROCESSES == 1:
            in_parallel = False
        else:
            in_parallel = True

        ## TODO: for netcdf outputs, we will need to initialize the dataset again.
        ## not ideal and should be fixed in the future.
        request.ocg.ocg_opts = kwds
        request.ocg.dataset_uri = dataset.uri

        try:
            sub = multipolygon_operation(
                dataset.uri,
                self.ocg.simulation_output.netcdf_variable.code,
                ocg_opts=kwds,
                polygons=self.ocg.aoi,
                time_range=self.ocg.temporal,
                level_range=None,
                clip=clip,
                union=self.ocg.aggregate,
                in_parallel=in_parallel,
                max_proc=settings.MAXPROCESSES,
                max_proc_per_poly=settings.MAXPROCESSES_PER_POLY,
                allow_empty=False)
        except EmptyDataNotAllowed:
            raise (AoiError)
        except RuntimeError:
            raise (UncaughtRuntimeError)
        except:
            raise

        logger.debug("...ending SpatialHandler._read_()")
        return (sub)
Example #4
0
    def _read_(self,request):
#        import ipdb;ipdb.set_trace()
        logger.debug("starting SpatialHandler._read_()...")
        dataset = self.ocg.simulation_output.netcdf_variable.netcdf_dataset
        
        ## arguments for the dataset object
        kwds = dict(rowbnds_name=dataset.rowbnds_name,
                    colbnds_name=dataset.colbnds_name,
                    time_name=dataset.time_name,
                    time_units=dataset.time_units,
                    calendar=dataset.calendar,)
#                    level_name=self.ocg.dataset.level_name,) TODO: add level variable name

        ## construct arguments to clip operation
        if self.ocg.operation == 'clip':
            clip = True
        else:
            clip = False
        
        ## choose extraction mode and pull data appropriately.
        if settings.MAXPROCESSES == 1:
            in_parallel = False
        else:
            in_parallel = True
        
        ## TODO: for netcdf outputs, we will need to initialize the dataset again.
        ## not ideal and should be fixed in the future.
        request.ocg.ocg_opts = kwds
        request.ocg.dataset_uri = dataset.uri
        
        try:
            sub = multipolygon_operation(dataset.uri,
                                         self.ocg.simulation_output.netcdf_variable.code,
                                         ocg_opts=kwds,
                                         polygons=self.ocg.aoi,
                                         time_range=self.ocg.temporal,
                                         level_range=None, 
                                         clip=clip,
                                         union=self.ocg.aggregate,
                                         in_parallel=in_parallel, 
                                         max_proc=settings.MAXPROCESSES,
                                         max_proc_per_poly=settings.MAXPROCESSES_PER_POLY,
                                         allow_empty=False)
        except EmptyDataNotAllowed:
            raise(AoiError)
        except RuntimeError:
            raise(UncaughtRuntimeError)
        except:
            raise

        logger.debug("...ending SpatialHandler._read_()")
        return(sub)
Example #5
0
 def test_wrapper2(self):
     sub = multipolygon_operation('http://cida.usgs.gov/qa/thredds/dodsC/maurer/monthly',
                                  'sresa1b_miroc3-2-medres_2_Prcp',
         ocg_opts = {'colbnds_name': u'bounds_longitude', 'calendar': u'proleptic_gregorian', 'time_name': u'time', 'time_units': u'days since 1950-01-01 00:00:00', 'rowbnds_name': u'bounds_latitude'},
         polygons = [{'gid': None, 'geom': wkt.loads('POLYGON ((-104.0000000000000000 39.0000000000000000, -95.0000000000000000 39.0000000000000000, -95.0000000000000000 44.0000000000000000, -104.0000000000000000 39.0000000000000000))')}],
         time_range = [datetime.datetime(2000, 1, 1, 0, 0), datetime.datetime(2001, 12, 31, 0, 0)],
         level_range = None,
         clip = True,
         union = True,
         in_parallel = True,
         max_proc = 8,
         max_proc_per_poly = 2,
         allow_empty = True)
Example #6
0
    def sub_ocg_dataset(self):
        sub = multipolygon_operation(self.nc_path,
                                     self.nc_var_name,
                                     ocg_opts=self.nc_opts,
                                     polygons=[
                                               {'gid':99,'geom':self.nebraska()},
                                               {'gid':100,'geom':self.iowa()},
#                                               {'gid':200,'geom':self.vermont()}
                                               ],
                                     time_range=[datetime.datetime(2011,1,1),
                                                 datetime.datetime(2013,12,31)],
                                     level_range=None,
                                     clip=True,
                                     union=True,
                                     in_parallel=True,
                                     max_proc=8,
                                     max_proc_per_poly=2)
        return(sub)
Example #7
0
def f(polygons):
    times = 1
    for ii in range(0,times):
        print(ii+1)
        sub = multipolygon_operation('http://cida.usgs.gov/qa/thredds/dodsC/maurer/monthly',
                                     'sresa1b_miroc3-2-medres_2_Prcp',
                                     ocg_opts=dict(rowbnds_name='bounds_latitude',
                                                   colbnds_name='bounds_longitude',
                                                   calendar='proleptic_gregorian',
                                                   time_units='days since 1950-01-01 00:00:0.0'),
                                     polygons=polygons,
                                     time_range=[datetime.datetime(2011,11,1),datetime.datetime(2031,11,30)],
                                     level_range=None,
                                     clip=True,
                                     union=True,
                                     in_parallel=False,
                                     max_proc=8,
                                     max_proc_per_poly=1)
        assert(sub.value.shape[2] > 0)
        lshp = LinkedShpConverter(sub,'foo')
        out = lshp.convert(None)
        print(out)