Esempio n. 1
0
 def __init__(self, filepath):
     self.filepath = filepath
     self.damsP = DataAcquisitionManagementServicePlaceholder()
Esempio n. 2
0
 def __init__(self, filepath):
     self.filepath = filepath
     self.damsP = DataAcquisitionManagementServicePlaceholder()
Esempio n. 3
0
class Handler(BaseHandler):

    extensions = re.compile(r"^.*\.ionref$", re.IGNORECASE)
    damsP = None

    def __init__(self, filepath):
        self.filepath = filepath
        self.damsP = DataAcquisitionManagementServicePlaceholder()

    def parse_constraints(self, environ):
#        print ">> Start parse_constraints"
#        import pprint
#        pprint.pprint("")
#        pprint.pprint(environ)

        ds_name, ds_id, ds_url, buf_size = get_dataset_info(self)
#        print "DS Info:  name=%s ds_id=%s ds_url=%s buf_size=%s" % (ds_name, ds_id, ds_url, buf_size)

        # TODO: Call the "damsP" module to retrieve a BaseDatasetHandler based on the ds_id
        dsh = self.damsP.get_data_handlers(ds_id=ds_id)

        #DSH WAY
        dataset_type = DatasetType(name=ds_name, attributes={'NC_GLOBAL': dsh.get_attributes()})
        fields, queries = environ['pydap.ce']
        fields = fields or [[(name, ())] for name in dsh.ds.variables]

#        print "CE Fields: %s" % fields
#        print "CE Queries: %s" % queries

        pdr_obj = IonObject("PydapVarDataRequest", name="p_req")

        for fvar in fields:
            target = dataset_type
            while fvar:
                name, slice_ = fvar.pop(0)
                pdr_obj.name = name
                pdr_obj.slice = slice_
                if (name in dsh.ds.dimensions or not dsh.ds.variables[name].dimensions or target is not dataset_type):
#                    print "==> if"
                    nm, dat, tc, di, at = dsh.acquire_data(request=pdr_obj)
                    target[name] = BaseType(name=nm, data=dat, shape=dat.shape, type=tc, dimensions=di, attributes=at)
                elif fvar:
#                    print "==> elif"
                    attrs = dsh.get_attributes(name)
                    target.setdefault(name, StructureType(name=name, attributes=attrs))
                    target = target[name]
                else:
#                    print "==> else"
                    attrs = dsh.get_attributes(name)
                    grid = target[name] = GridType(name=name, attributes=attrs)
                    nm, dat, tc, di, at = dsh.acquire_data(request=pdr_obj)
                    grid[name] = BaseType(name=nm, data=dat, shape=dat.shape, type=tc, dimensions=di, attributes=at)
                    slice_ = list(slice_) + [slice(None)] * (len(grid.array.shape) - len(slice_))
                    for dim, dimslice in zip(dsh.ds.variables[name].dimensions, slice_):
                        pdr_obj.name=dim
                        pdr_obj.slice=dimslice
                        nm, dat, tc, di, at = dsh.acquire_data(request=pdr_obj)
                        grid[dim] = BaseType(name=nm, data=dat, shape=dat.shape, type=tc, dimensions=di, attributes=at)

        dataset_type._set_id()
        dataset_type.close = dsh.ds.close

#        print ">> End parse_constraints"
        return dataset_type
Esempio n. 4
0
class Handler(BaseHandler):

    extensions = re.compile(r"^.*\.ionref$", re.IGNORECASE)
    damsP = None

    def __init__(self, filepath):
        self.filepath = filepath
        self.damsP = DataAcquisitionManagementServicePlaceholder()

    def parse_constraints(self, environ):
        #        print ">> Start parse_constraints"
        #        import pprint
        #        pprint.pprint("")
        #        pprint.pprint(environ)

        ds_name, ds_id, ds_url, buf_size = get_dataset_info(self)
        #        print "DS Info:  name=%s ds_id=%s ds_url=%s buf_size=%s" % (ds_name, ds_id, ds_url, buf_size)

        # TODO: Call the "damsP" module to retrieve a BaseDatasetHandler based on the ds_id
        dsh = self.damsP.get_data_handlers(ds_id=ds_id)

        #DSH WAY
        dataset_type = DatasetType(
            name=ds_name, attributes={'NC_GLOBAL': dsh.get_attributes()})
        fields, queries = environ['pydap.ce']
        fields = fields or [[(name, ())] for name in dsh.ds.variables]

        #        print "CE Fields: %s" % fields
        #        print "CE Queries: %s" % queries

        pdr_obj = IonObject("PydapVarDataRequest", name="p_req")

        for fvar in fields:
            target = dataset_type
            while fvar:
                name, slice_ = fvar.pop(0)
                pdr_obj.name = name
                pdr_obj.slice = slice_
                if (name in dsh.ds.dimensions
                        or not dsh.ds.variables[name].dimensions
                        or target is not dataset_type):
                    #                    print "==> if"
                    nm, dat, tc, di, at = dsh.acquire_data(request=pdr_obj)
                    target[name] = BaseType(name=nm,
                                            data=dat,
                                            shape=dat.shape,
                                            type=tc,
                                            dimensions=di,
                                            attributes=at)
                elif fvar:
                    #                    print "==> elif"
                    attrs = dsh.get_attributes(name)
                    target.setdefault(
                        name, StructureType(name=name, attributes=attrs))
                    target = target[name]
                else:
                    #                    print "==> else"
                    attrs = dsh.get_attributes(name)
                    grid = target[name] = GridType(name=name, attributes=attrs)
                    nm, dat, tc, di, at = dsh.acquire_data(request=pdr_obj)
                    grid[name] = BaseType(name=nm,
                                          data=dat,
                                          shape=dat.shape,
                                          type=tc,
                                          dimensions=di,
                                          attributes=at)
                    slice_ = list(slice_) + [slice(None)] * (
                        len(grid.array.shape) - len(slice_))
                    for dim, dimslice in zip(dsh.ds.variables[name].dimensions,
                                             slice_):
                        pdr_obj.name = dim
                        pdr_obj.slice = dimslice
                        nm, dat, tc, di, at = dsh.acquire_data(request=pdr_obj)
                        grid[dim] = BaseType(name=nm,
                                             data=dat,
                                             shape=dat.shape,
                                             type=tc,
                                             dimensions=di,
                                             attributes=at)

        dataset_type._set_id()
        dataset_type.close = dsh.ds.close

        #        print ">> End parse_constraints"
        return dataset_type