From ace7cc294d8a6618ba658c3a653c42e489c6e3d3 Mon Sep 17 00:00:00 2001 From: Enrico Ferreguti Date: Sun, 21 Nov 2021 12:17:59 +0100 Subject: [PATCH] code cleanup --- wind_forecast_routing_algorithm.py | 13 ++----------- wind_forecast_routing_launch.py | 7 ------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/wind_forecast_routing_algorithm.py b/wind_forecast_routing_algorithm.py index 8a47be6..4af3dc0 100644 --- a/wind_forecast_routing_algorithm.py +++ b/wind_forecast_routing_algorithm.py @@ -141,13 +141,13 @@ def __init__(self, gribLayer, wind_idx, destinationCrs=None): def getWindAt(self, t, lat, lon): """ Returns (twd, tws) for the given point (lat, lon) at time t """ if t >= self.start_time and t<=self.end_time: - delta = t - self.start_time #self.grib.dataProvider().temporalCapabilities().referenceTime().toPyDateTime() + delta = t - self.start_time interval = QgsInterval(delta.total_seconds()) lon_lat = QgsPointXY(lon, lat) interval = self.grib.datasetIndexAtRelativeTime (interval, self.wind_idx) wind_value = self.grib.datasetValue(interval, lon_lat) twd = math.radians( heading( wind_value.x(), wind_value.y() ) ) - tws = wind_value.scalar()#*1.943844 + tws = wind_value.scalar() return (twd,tws) else: print ("OUT_OF_RANGE", t, self.start_time, self.end_time) @@ -231,7 +231,6 @@ def processAlgorithm(self, parameters, context, feedback): """ grib_layerfile = self.parameterAsFile(parameters, self.GRIB, context) grib_layer = self.parameterAsLayer(parameters, self.GRIB, context) - print ("GRIB DETAILS:", grib_layerfile, grib_layer, grib_layer.id()) wind_ds = self.parameterAsInt(parameters, self.WIND_DATASET_INDEX, context) polar_filename = self.polar_names[self.parameterAsEnum(parameters, self.POLAR, context)] polar = Polar(os.path.join(self.polars_dir,self.polars[polar_filename])) @@ -239,8 +238,6 @@ def processAlgorithm(self, parameters, context, feedback): start_point = self.parameterAsPoint(parameters, self.START_POINT, context, crs=grib_layer.crs()) end_point = self.parameterAsPoint(parameters, self.END_POINT, context, crs=grib_layer.crs()) - print ("parameters", parameters) - track = ((start_point.y(), start_point.x()), (end_point.y(), end_point.x())) geo_context = QgsRectangle(start_point.x(),start_point.y(), end_point.x(),end_point.y()) track_dist = QgsPointXY(start_point.x(),start_point.y()).sqrDist(end_point.x(), end_point.y()) @@ -248,11 +245,6 @@ def processAlgorithm(self, parameters, context, feedback): checkValidity = in_sea_checker(geo_context) grib_reader = grib_sampler(grib_layer,wind_ds) - #test - #print ("TESTGRIB",grib_reader.getWindAt(datetime.strptime("02/02/21 18:00", "%d/%m/%y %H:%M"),39.31064,5.06086)) - - print ("track", track) - route_process = Routing(LinearBestIsoRouter, polar, track, grib_reader, start.toPyDateTime(), lineValidity = checkValidity.path_in_sea_xy,) step = 1 execution = "ok" @@ -289,7 +281,6 @@ def processAlgorithm(self, parameters, context, feedback): if execution == "ok": tr.append((*track[-1], dateutil.parser.parse(tr[-1][2])+timedelta(hours=1), 0, 0, 0, 0)) - print (tr) route_polyline = [] diff --git a/wind_forecast_routing_launch.py b/wind_forecast_routing_launch.py index b40a43c..dac2d48 100644 --- a/wind_forecast_routing_launch.py +++ b/wind_forecast_routing_launch.py @@ -172,7 +172,6 @@ def initAlgorithm(self, config): Here we define the inputs and output of the algorithm, along with some other properties. """ - print ("CONFIG LAUNCH", config) if "nooutput" in config: self.allow_output = False else: @@ -191,7 +190,6 @@ def initAlgorithm(self, config): for wm in wind_models: wind_models_labels.append(wm["context"]) - print (wind_models_labels) # We add the input vector features source. It can have any kind of # geometry. self.addParameter(QgsProcessingParameterEnum(self.MODEL, 'Wind Model', options=wind_models_labels, defaultValue=0, allowMultiple=False)) @@ -275,7 +273,6 @@ def processAlgorithm(self, parameters, context, feedback): model = self.parameterAsEnum(parameters, self.MODEL, context) - print (model) wind_model_def = None if model == 0: for wm in wind_models: @@ -306,7 +303,6 @@ def processAlgorithm(self, parameters, context, feedback): rawReplyObject = manager.blockingGet(request) j = QJsonDocument.fromJson(rawReplyObject.content()) replyObject = j.toVariant() - print("replyObject", replyObject) if replyObject["status"]: download_params = { @@ -314,7 +310,6 @@ def processAlgorithm(self, parameters, context, feedback): 'OUTPUT': grib_output } - print ("download_params:",download_params) output_download = processing.run('native:filedownloader', download_params, context=context, feedback=feedback, is_child_algorithm=True) else: print ("ERROR", replyObject) @@ -341,9 +336,7 @@ def processAlgorithm(self, parameters, context, feedback): "extent": QgsMeshLayer(output_download['OUTPUT'],"grib","mdal").extent(), "Inverted_clip": output_context } - print ("context_land_params", context_land_params) context_land_results = processing.run('sailtools:inverted_clip', context_land_params, context=context, feedback=feedback, is_child_algorithm=True) - print ("context_land_results", context_land_results) self.output_routing[self.OUTPUT_CONTEXT] = context_land_results['OUTPUT'] self.output_routing["elab_name"] = "wind routing %s %s %s %.2f,%.1f,%.1f,%.1f" % (