Exemple #1
0
 def inspect(self):
     '''Print inspection output using :class:`~ocgis.Inspect`. This is a 
     convenience method.'''
     
     ip = Inspect(self.uri,variable=self.variable,
                  interface_overload=self.interface)
     return(ip)
Exemple #2
0
def display_inspect(request):
    ## parse the query string
    query = parse_qs(request.META['QUERY_STRING'])
    uri = helpers._get_uri_(query, scalar=True)
    variable = QueryParm(query, 'variable', scalar=True)
    interface_overload = _get_interface_overload_(query)
    io = Inspect(uri.value,
                 variable=variable.value,
                 interface_overload=interface_overload)
    report = io.__repr__()
    response = HttpResponse(report, content_type="text/plain")
    return (response)
Exemple #3
0
 def test_low_res(self):
     ocgis.env.OVERWRITE = True
     nc_spatial = NcSpatial(5.0,(-90.0,90.0),(0.0,360.0))
     path = self.make_data(nc_spatial)
     
     dataset = {'uri':path,'variable':'foo'}
     output_format = 'shp'
     geom = self.nebraska
     ip = Inspect(dataset['uri'],dataset['variable'])
     
     for s_abstraction in ['point','polygon']:
         interface = {'s_abstraction':s_abstraction}
         ops = OcgOperations(dataset=dataset,
                             output_format=output_format,
                             geom=geom,
                             abstraction=s_abstraction)
         ret = OcgInterpreter(ops).execute()
Exemple #4
0
 def inspect_as_dct(self):
     '''
     Return a dictionary representation of the target's metadata. If the variable
     is `None`. An attempt will be made to find the target dataset's time bounds
     raising a warning if none is found or the time variable is lacking units
     and/or calendar attributes.
     
     >>> rd = ocgis.RequestDataset('rhs_day_CanCM4_decadal2010_r2i1p1_20110101-20201231.nc','rhs')
     >>> ret = rd.inspect_as_dct()
     >>> ret.keys()
     ['dataset', 'variables', 'dimensions', 'derived']
     >>> ret['derived']
     OrderedDict([('Start Date', '2011-01-01 12:00:00'), ('End Date', '2020-12-31 12:00:00'), ('Calendar', '365_day'), ('Units', 'days since 1850-1-1'), ('Resolution (Days)', '1'), ('Count', '8192'), ('Has Bounds', 'True'), ('Spatial Reference', 'WGS84'), ('Proj4 String', '+proj=longlat +datum=WGS84 +no_defs '), ('Extent', '(-1.40625, -90.0, 358.59375, 90.0)'), ('Interface Type', 'NcPolygonDimension'), ('Resolution', '2.80091351339')])        
     
     :rtype: :class:`collections.OrderedDict`
     '''
     ip = Inspect(request_dataset=self)
     ret = ip._as_dct_()
     return (ret)
Exemple #5
0
 def test_nc_conversion(self):
     ops = OcgOperations(dataset=self.get_dataset(), output_format='nc')
     ret = self.get_ret(ops)
     ip = Inspect(ret, 'foo')
Exemple #6
0
 def test_inspect(self):
     uri = self.get_dataset()['uri']
     for variable in [self.get_dataset()['variable'], None]:
         ip = Inspect(uri, variable=variable)
         ret = ip.__repr__()
         self.assertTrue(len(ret) > 100)
Exemple #7
0
    def write(self):
        ## call subclass write method
        ocgis_lh('starting subclass write method', self._log, logging.DEBUG)
        ret = self._write_()

        ## added OCGIS metadata output if requested.
        if self.add_meta:
            ocgis_lh('adding OCGIS metadata file', 'conv', logging.DEBUG)
            lines = MetaConverter(self.ops).write()
            out_path = os.path.join(
                self.outdir, self.prefix + '_' + MetaConverter._meta_filename)
            with open(out_path, 'w') as f:
                f.write(lines)

        ## add the dataset descriptor file if specified
        if self._add_did_file:
            ocgis_lh('writing dataset description (DID) file', 'conv',
                     logging.DEBUG)
            from ocgis.conv.csv_ import OcgDialect

            headers = [
                'DID', 'VARIABLE', 'ALIAS', 'URI', 'STANDARD_NAME', 'UNITS',
                'LONG_NAME'
            ]
            out_path = os.path.join(self.outdir, self.prefix + '_did.csv')
            with open(out_path, 'w') as f:
                writer = csv.writer(f, dialect=OcgDialect)
                writer.writerow(headers)
                for rd in self.ops.dataset:
                    row = [rd.did, rd.variable, rd.alias, rd.uri]
                    ref_variable = rd.ds.metadata['variables'][
                        rd.variable]['attrs']
                    row.append(ref_variable.get('standard_name', None))
                    row.append(ref_variable.get('units', None))
                    row.append(ref_variable.get('long_name', None))
                    writer.writerow(row)

        ## add user-geometry
        if self._add_ugeom and self.ops.geom is not None:
            ocgis_lh('writer user-geometry shapefile', 'conv', logging.DEBUG)
            if self._add_ugeom_nest:
                shp_dir = os.path.join(self.outdir, 'shp')
                try:
                    os.mkdir(shp_dir)
                ## catch if the directory exists
                except OSError:
                    if os.path.exists(shp_dir):
                        pass
                    else:
                        raise
            else:
                shp_dir = self.outdir
            shp_path = os.path.join(shp_dir, self.prefix + '_ugid.shp')
            self.ops.geom.write(shp_path)

        ## add source metadata if requested
        if self._add_source_meta:
            ocgis_lh('writing source metadata file', 'conv', logging.DEBUG)
            out_path = os.path.join(self.outdir,
                                    self.prefix + '_source_metadata.txt')
            to_write = []
            for rd in self.ops.dataset:
                ip = Inspect(request_dataset=rd)
                to_write += ip.get_report()
            with open(out_path, 'w') as f:
                f.writelines('\n'.join(to_write))

        ## return anything from the overloaded _write_ method. otherwise return
        ## the internal path.
        if ret is None:
            ret = self.path

        return (ret)
Exemple #8
0
    def inspect(self):
        '''Print inspection output using :class:`~ocgis.Inspect`. This is a 
        convenience method.'''

        ip = Inspect(request_dataset=self)
        return (ip)