def time_step(self): """ Return time step of all time series. If time step is not the same for all time series, raises exception. """ time_step = None for filename in self.files: with open(filename) as f: t = Timeseries() t.read_meta(f) item_time_step = (t.time_step.length_minutes, t.time_step.length_months) if time_step and (item_time_step != time_step): raise WrongValueError( 'Not all time series have the same step') time_step = item_time_step return time_step
def create_ogr_layer_from_timeseries(filenames, epsg, data_source): # Prepare the co-ordinate transformation from WGS84 to epsg source_sr = osr.SpatialReference() source_sr.ImportFromEPSG(4326) target_sr = osr.SpatialReference() target_sr.ImportFromEPSG(epsg) transform = osr.CoordinateTransformation(source_sr, target_sr) layer = data_source.CreateLayer('stations', target_sr) layer.CreateField(ogr.FieldDefn('filename', ogr.OFTString)) for filename in filenames: with open(filename) as f: ts = Timeseries() ts.read_meta(f) point = ogr.Geometry(ogr.wkbPoint) point.AddPoint(ts.location['abscissa'], ts.location['ordinate']) point.Transform(transform) f = ogr.Feature(layer.GetLayerDefn()) f.SetGeometry(point) f.SetField('filename', filename) layer.CreateFeature(f) return layer