Loading environment.yml +1 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,4 @@ dependencies: - pandas - sqlalchemy - pyyaml - networkx plio/examples/loggers/logging.json +19 −19 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ "info_file_handler": { "formatter": "simple", "backupCount": 10, "level": "INFO", "level": "DEBUG", "encoding": "utf8", "class": "logging.handlers.RotatingFileHandler", "maxBytes": 10485760, Loading plio/io/io_controlnetwork.py +21 −17 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ class IsisStore(object): self._path = path if not mode: mode = 'a' # pragma: no cover mode = 'wb' # pragma: no cover self._mode = mode self._handle = None Loading @@ -170,13 +170,13 @@ class IsisStore(object): self._handle.seek(offset) self._handle.write(data) def create_points(self, obj, pointid_prefix, pointid_suffix): def create_points(self, graphs, pointid_prefix, pointid_suffix): """ Step through a control network (C) and return protocol buffer point objects Parameters ---------- obj : list graphs : list of iterable objects (dataframes) with the appropriate attributes: point_id, point_type, serial, measure_type, x, y required. The entries in the list must support grouping by the point_id attribute. Loading @@ -197,20 +197,21 @@ class IsisStore(object): # TODO: Rewrite using apply syntax for performance point_sizes = [] point_messages = [] for df in obj: for i, g in df.groupby('point_id'): for graph in graphs: for i, control_point_id in enumerate(graph.point_nodes): control_point = graph.node[control_point_id] point_spec = cnf.ControlPointFileEntryV0002() point_spec.id = _set_pid(self.pointid) point_spec.id = _set_pid(control_point['pointid']) for attr, attrtype in self.point_attrs: if attr in g.columns: if attr in control_point.keys(): # As per protobuf docs for assigning to a repeated field. if attr == 'aprioriCovar': arr = g.iloc[0]['aprioriCovar'] arr = control_point['aprioriCovar'] point_spec.aprioriCovar.extend(arr.ravel().tolist()) else: setattr(point_spec, attr, attrtype(g.iloc[0][attr])) point_spec.type = int(g.point_type.iat[0]) # The third argument casts the value to the correct type setattr(point_spec, attr, attrtype(control_point[attr])) point_spec.type = int(control_point.get('point_type', 2)) # The reference index should always be the image with the lowest index point_spec.referenceIndex = 0 Loading @@ -218,14 +219,19 @@ class IsisStore(object): # A single extend call is cheaper than many add calls to pack points measure_iterable = [] for node_id, m in g.iterrows(): for j, control_measure_id in graph.edges(control_point_id): control_measure = graph.node[control_measure_id] if control_measure['node_type'] != 'correspondence': continue measure_spec = point_spec.Measure() # For all of the attributes, set if they are an dict accessible attr of the obj. for attr, attrtype in self.measure_attrs: if attr in g.columns: setattr(measure_spec, attr, attrtype(m[attr])) measure_spec.type = int(m.measure_type) if attr in control_measure.keys(): setattr(measure_spec, attr, attrtype(control_measure[attr])) measure_spec.type = int(control_measure['measure_type']) measure_spec.line = float(control_measure['y']) measure_spec.sample = float(control_measure['x']) measure_iterable.append(measure_spec) self.nmeasures += 1 point_spec.measures.extend(measure_iterable) Loading Loading @@ -364,5 +370,3 @@ class IsisStore(object): if self._handle is not None: self._handle.close() self._handle = None plio/io/io_gdal.py +9 −5 Original line number Diff line number Diff line Loading @@ -198,6 +198,12 @@ class GeoDataset(object): self._gcs = self._srs.CloneGeogCS() return self._srs @property def nbands(self): if not getattr(self, '_nbands', None): self._nbands = self.dataset.RasterCount return self._nbands @property def geospatial_coordinate_system(self): if not getattr(self, '_gcs', None): Loading Loading @@ -321,10 +327,8 @@ class GeoDataset(object): @property def coordinate_transformation(self): if not getattr(self, '_ct', None): print('Getting CT') self._ct = osr.CoordinateTransformation(self.spatial_reference, self.geospatial_coordinate_system) print('CT', self._ct) return self._ct @property Loading @@ -332,7 +336,6 @@ class GeoDataset(object): if not getattr(self, '_ict', None): self._ict = osr.CoordinateTransformation(self.geospatial_coordinate_system, self.spatial_reference) print(self._ict) return self._ict @property Loading Loading @@ -558,6 +561,7 @@ def match_rasters(match_to, match_from, destination, GRA_Cubic, GRA_CubicSpline, GRA_Lanczos, GRA_Average, GRA_Mode} """ import gdalconst # import here so Sphinx can build the docos, mocking is not working # TODO: If a destination is not provided create an in-memory GeoDataSet object match_to_srs = match_to.dataset.GetProjection() Loading @@ -567,8 +571,8 @@ def match_rasters(match_to, match_from, destination, match_from__srs = match_from.dataset.GetProjection() match_from__gt = match_from.geotransform dst = gdal.GetDriverByName('GTiff').Create(destination, width, height, match_from.RasterCount, gdalconst.GDT_Float32) dst = gdal.GetDriverByName('GTiff').Create(destination, width, height, 1, gdalconst.GDT_Float64) dst.SetGeoTransform(match_to_gt) dst.SetProjection(match_to_srs) Loading plio/io/io_krc.py +6 −3 Original line number Diff line number Diff line Loading @@ -364,9 +364,9 @@ class ReadBin52(object): self.nseasons) caseidx = np.repeat(np.arange(self.ncases), self.nseasons) seasonidx = np.repeat(np.arange(self.nseasons), self.ncases) flt_seasitems = seasitems.reshape(len(self.vlabels), flt_seasitems = seasitems.reshape(len(columns), self.ncases * self.nseasons) self.seasons = pd.DataFrame(flt_seasitems, self.seasons = pd.DataFrame(flt_seasitems.T, index=[caseidx,seasonidx], columns=columns) self.seasons.index.names = ['Case', 'Season'] Loading Loading @@ -432,6 +432,9 @@ class ReadBin52(object): #Extract the hourly temperature data hourly2dataframe() # Extract the seasons season2dataframe() # Extract by layer data from the data cube layeritems = self.bin52data[: , self.ndx: , : , 5: 7, : ] latitems2dataframe() Loading Loading
environment.yml +1 −0 Original line number Diff line number Diff line Loading @@ -10,3 +10,4 @@ dependencies: - pandas - sqlalchemy - pyyaml - networkx
plio/examples/loggers/logging.json +19 −19 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ "info_file_handler": { "formatter": "simple", "backupCount": 10, "level": "INFO", "level": "DEBUG", "encoding": "utf8", "class": "logging.handlers.RotatingFileHandler", "maxBytes": 10485760, Loading
plio/io/io_controlnetwork.py +21 −17 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ class IsisStore(object): self._path = path if not mode: mode = 'a' # pragma: no cover mode = 'wb' # pragma: no cover self._mode = mode self._handle = None Loading @@ -170,13 +170,13 @@ class IsisStore(object): self._handle.seek(offset) self._handle.write(data) def create_points(self, obj, pointid_prefix, pointid_suffix): def create_points(self, graphs, pointid_prefix, pointid_suffix): """ Step through a control network (C) and return protocol buffer point objects Parameters ---------- obj : list graphs : list of iterable objects (dataframes) with the appropriate attributes: point_id, point_type, serial, measure_type, x, y required. The entries in the list must support grouping by the point_id attribute. Loading @@ -197,20 +197,21 @@ class IsisStore(object): # TODO: Rewrite using apply syntax for performance point_sizes = [] point_messages = [] for df in obj: for i, g in df.groupby('point_id'): for graph in graphs: for i, control_point_id in enumerate(graph.point_nodes): control_point = graph.node[control_point_id] point_spec = cnf.ControlPointFileEntryV0002() point_spec.id = _set_pid(self.pointid) point_spec.id = _set_pid(control_point['pointid']) for attr, attrtype in self.point_attrs: if attr in g.columns: if attr in control_point.keys(): # As per protobuf docs for assigning to a repeated field. if attr == 'aprioriCovar': arr = g.iloc[0]['aprioriCovar'] arr = control_point['aprioriCovar'] point_spec.aprioriCovar.extend(arr.ravel().tolist()) else: setattr(point_spec, attr, attrtype(g.iloc[0][attr])) point_spec.type = int(g.point_type.iat[0]) # The third argument casts the value to the correct type setattr(point_spec, attr, attrtype(control_point[attr])) point_spec.type = int(control_point.get('point_type', 2)) # The reference index should always be the image with the lowest index point_spec.referenceIndex = 0 Loading @@ -218,14 +219,19 @@ class IsisStore(object): # A single extend call is cheaper than many add calls to pack points measure_iterable = [] for node_id, m in g.iterrows(): for j, control_measure_id in graph.edges(control_point_id): control_measure = graph.node[control_measure_id] if control_measure['node_type'] != 'correspondence': continue measure_spec = point_spec.Measure() # For all of the attributes, set if they are an dict accessible attr of the obj. for attr, attrtype in self.measure_attrs: if attr in g.columns: setattr(measure_spec, attr, attrtype(m[attr])) measure_spec.type = int(m.measure_type) if attr in control_measure.keys(): setattr(measure_spec, attr, attrtype(control_measure[attr])) measure_spec.type = int(control_measure['measure_type']) measure_spec.line = float(control_measure['y']) measure_spec.sample = float(control_measure['x']) measure_iterable.append(measure_spec) self.nmeasures += 1 point_spec.measures.extend(measure_iterable) Loading Loading @@ -364,5 +370,3 @@ class IsisStore(object): if self._handle is not None: self._handle.close() self._handle = None
plio/io/io_gdal.py +9 −5 Original line number Diff line number Diff line Loading @@ -198,6 +198,12 @@ class GeoDataset(object): self._gcs = self._srs.CloneGeogCS() return self._srs @property def nbands(self): if not getattr(self, '_nbands', None): self._nbands = self.dataset.RasterCount return self._nbands @property def geospatial_coordinate_system(self): if not getattr(self, '_gcs', None): Loading Loading @@ -321,10 +327,8 @@ class GeoDataset(object): @property def coordinate_transformation(self): if not getattr(self, '_ct', None): print('Getting CT') self._ct = osr.CoordinateTransformation(self.spatial_reference, self.geospatial_coordinate_system) print('CT', self._ct) return self._ct @property Loading @@ -332,7 +336,6 @@ class GeoDataset(object): if not getattr(self, '_ict', None): self._ict = osr.CoordinateTransformation(self.geospatial_coordinate_system, self.spatial_reference) print(self._ict) return self._ict @property Loading Loading @@ -558,6 +561,7 @@ def match_rasters(match_to, match_from, destination, GRA_Cubic, GRA_CubicSpline, GRA_Lanczos, GRA_Average, GRA_Mode} """ import gdalconst # import here so Sphinx can build the docos, mocking is not working # TODO: If a destination is not provided create an in-memory GeoDataSet object match_to_srs = match_to.dataset.GetProjection() Loading @@ -567,8 +571,8 @@ def match_rasters(match_to, match_from, destination, match_from__srs = match_from.dataset.GetProjection() match_from__gt = match_from.geotransform dst = gdal.GetDriverByName('GTiff').Create(destination, width, height, match_from.RasterCount, gdalconst.GDT_Float32) dst = gdal.GetDriverByName('GTiff').Create(destination, width, height, 1, gdalconst.GDT_Float64) dst.SetGeoTransform(match_to_gt) dst.SetProjection(match_to_srs) Loading
plio/io/io_krc.py +6 −3 Original line number Diff line number Diff line Loading @@ -364,9 +364,9 @@ class ReadBin52(object): self.nseasons) caseidx = np.repeat(np.arange(self.ncases), self.nseasons) seasonidx = np.repeat(np.arange(self.nseasons), self.ncases) flt_seasitems = seasitems.reshape(len(self.vlabels), flt_seasitems = seasitems.reshape(len(columns), self.ncases * self.nseasons) self.seasons = pd.DataFrame(flt_seasitems, self.seasons = pd.DataFrame(flt_seasitems.T, index=[caseidx,seasonidx], columns=columns) self.seasons.index.names = ['Case', 'Season'] Loading Loading @@ -432,6 +432,9 @@ class ReadBin52(object): #Extract the hourly temperature data hourly2dataframe() # Extract the seasons season2dataframe() # Extract by layer data from the data cube layeritems = self.bin52data[: , self.ndx: , : , 5: 7, : ] latitems2dataframe() Loading