# A Data Processing Framework for Polar Performance Diagrams
## 3 The hrosailing Framework
### Computation of Isochrones
For example, we can use a file which contains artificial NMEA sentences, such as:



#### 4.3.2 Visualisation

If we use the following code on the polar diagram pd, the results obtained are shown in Figure 11.

import matplotlib.pyplot as plt ax1 = plt.subplot(121, projection=\"polar\") ax2 = plt.subplot(122, projection=\"polar\") for ax in [ax1, ax2]: #remove labels from axis ax.set_xticklabels([]) ax.set_yticklabels([]) pd.plot_polar( ws=10, color=\"blue\", marker=\"H\", ax=ax1 ) pd.plot_polar( ws=10, ls=\"-\", ms=2, ax=ax2 ) plt.show()

Figure 10: A visualisation of the interim results of the pipeline. Points with smaller weights are displayed with more shade (if weights are assigned). #### 4.3.3 Further Calculations with Polar Diagrams

The following code can be used to compute optimal manoeuvres with constant TWS of 15 knots aiming for a direction with TWA of 5 degrees:

from hrosailing.cruising import convex_direction

for dir in convex_direction(pd, ws=14, direction=5):

print(dir)

results in

Sail with an angle of 40.0 to the wind for 53.33 percent of the time

Sail with an angle of 325.0 to the wind for 46.67 percent of the time

If we had used PolarDiagramMultisails, additional information for which sail setting to use would also be given. In the following we initialise a WeatherModel from random gridded weather data. A random-weather model describing wind speeds and wind angles can be initialised, for example by:

import NumPy as np from hrosailing.cruising import WeatherModel from datetime import timedelta from datetime importdatetime as dt

n, m, k, l = 500, 50, 40, 2

data = 20 * (np.random.random((n, m, k, l)) - 0.5)

wm = WeatherModel( data=data, times=[dt.now() + i * timedelta(hours=1) for i in range(n)], lats=np.linspace(40, 50, m), lons=np.linspace(40, 50, k),

Figure 11: The result of the example code of Section 4.3.2.

attrs=[\"UGRID\", \"VGRID\"] )

Such a weather model can then be used to calculate the cost of a travel from \(A\) to \(B\), under the respective weather conditions using the Mercator projection. For example, if you want to travel from 42\({}^{\circ}\) latitude, 43\({}^{\circ}\) longitude to 42.5\({}^{\circ}\) latitude, 43\({}^{\circ}\) longitude starting right, now, you can use the following code (pd and wm are defined as before):

```
fromdatetimeimportdatetimeasdt fromhrosailing.cruisingimportcost_cruise cc=cost_cruise( pd=pd, start=(42, 43), end=(42.5, 43), start_time=dt.now(), wm=wm )
```

This results in roughly 3.48 h. The default cost function is the duration of the travel in hours. Different cost functions can also be defined by the optional parameters cost_fun_dens and cost_fun_abs. Another supported method of the hrosailing package can be used to compute isochrone points. For example, if you want to travel again from coordinates \((42^{\circ},43^{\circ})\) in an angle of 45\({}^{\circ}\) with respect to north for 20 min (1/3 h), you can calculate your expected position and the expected length of the way travelled by using the following code (pd and wm defined as before):

```
fromhrosailing.cruisingimportisochrone fromdatetimeimportdatetimeasdt ic=isochrone( pd=pd, start=(42,43), start_time=dt.now(), direction=45, wm=wm, total_time=1/3 )
```

This results in

```
((42.03, 44.44), 3.40)
```

where the first entry describes the coordinates of the destination and the second entry is the travelled distance in nautical miles. By iterating over several directions, you can generate a collection of isochrone points (see Figure 12). ## 5 Real-World Study Case

In this section we provide a small real-world study case using the hrosailing package, in particular our pipeline model, with real-world data. We have collected speed and wind data on a private sailing vessel of the \"Hiddensee\" type, during a journey in August 2021 from Rostock to Bornholm (Denmark) and back via Sweden.This type of vessel was construced in 1982 by different clubs and private initiatives during communist times in the former GDR.