Package model¶
This package contains the two classes useful to construct the model.
weatherTLKT¶
Autors: | Paul Barde & Fabien Brulport |
---|
Module encapsulating all the classes required to manipulate weather forecasts.
-
class
weatherTLKT.
Weather
(lat=None, lon=None, time=None, u=None, v=None)¶ Bases:
object
This class is supposed to be used on GrAD’s server files. No warranty however.
Variables: - lat (numpy.array) – latitude in degree, comprised in [-90 : 90]
- lon (numpy.array) – longitude in degree, comprised in [0 : 360]
- time (numpy.array) – in days. Time is given in days (GrADS gives 81 times steps of 3hours so it is 10.125 days with time steps of 0.125 days)
- u – velocity toward east in m/s. Must be of shape (ntime, nlat, nlon)
- v – velocity toward north.
-
Interpolators
()¶ Add the u and v Interpolator objects to the weather object (two new attributes : self.uInterpolator and self.vInterpolator).
u = self.uInterpolator([t,lat,lon]) #with u in m/s, t in days, lat and lon in degrees.
-
animateQuiver
(proj='mill', res='i', instant=0, Dline=5, density=1)¶ Pretty much the same than
plotQuiver()
but animating the quiver over the different time steps starting at instant.
-
crop
(latBound=[-90, 90], lonBound=[0, 360], timeSteps=[0, 64])¶ Returns a cropped Weather object’s data to the selected range of lon, lat and time steps. If no lat or lon boundaries are defined it takes the whole span present in the object. If no number of time step is defined it takes the whole span present if the object (but not more than 81 the value for GrAD files)
Parameters: - latBound (list of int) – [minlat, maxlat], the largest span is [-90,90]
- lonBound (list of int) – [minlon, maxlon], the largest span is [0,360]
- nbTimes (int) – number of frames to load
Returns: the cropped object.
Return type:
-
classmethod
download
(url, path, ens=False, latBound=[-90, 90], lonBound=[0, 360], timeSteps=[0, 64])¶ Downloads Weather object from url server and writes it into path file.
Parameters: - url (str) – url to server (designed for GrAD server).
- path (str) – path toward where the downloaded object is to be saved.
- ens (bool) – True is the downloaded data corresponds to a GEFS forecast, False for GFS.
- latBound (list of int.) – [minlat, maxlat], lat span one wants to consider, the largest span is [-90,90].
- lonBound (list of int.) – [minlon, maxlon], lon span one wants to consider, the largest span is [0,360].
- timeSteps (list of int.) – time steps of the forecasts one wants to load.
Returns: the object corresponding to the downloaded weather.
Return type:
-
getPolarVel
()¶ Computes wind magnitude and direction and adds it to the object’s attribute as self.wMag (magnitude) and self.wAng (direction toward which the wind is blowing).
-
classmethod
load
(path, latBound=[-90, 90], lonBound=[0, 360], timeSteps=[0, 64])¶ Takes a file path where a Weather object is saved and loads it into the script. If no lat or lon boundaries are defined, it takes the whole span present in the saved object. If no number of time step is defined it takes the whole span present if the saved object (but not more than 81 the value for GrAD files).
Parameters: - path (str) – path to file of saved Weather object.
- latBound (list of int.) – [minlat, maxlat], lat span one wants to consider, the largest span is [-90,90].
- lonBound (list of int.) – [minlon, maxlon], lon span one wants to consider, the largest span is [0,360].
- timeSteps (list of int.) – time steps of the forecasts one wants to load.
Returns: loaded object.
Return type:
-
plotColorQuiver
(proj='mill', res='i', instant=0, Dline=5, density=1)¶ Pretty much the same than
plotQuiver()
but on a contour plot of wind magnitude.
-
plotMultipleQuiver
(otherWeather, proj='mill', res='i', instant=0, Dline=5, density=1)¶ Pretty much the same than
plotQuiver()
but to superimpose two quivers.Parameters: otherWeather (Weather) – Second forecasts to be plotted with the one calling the method.
-
plotQuiver
(proj='mill', res='i', instant=0, Dline=5, density=1)¶ Plots a quiver of the
Weather
object’s wind for a given instant. Basemap projection using the lat/lon limits of the data itself.Parameters: Returns: Plot framework.
Return type:
-
static
returnPolarVel
(u, v)¶ Computes wind magnitude and direction from the velocities u and v.
Parameters: - u (float) – velocity toward east.
- v (float) – velocity toward north.
Returns: magnitude, direction
Return type: float, float
simulatorTLKT¶
Autors: | Paul Barde & Fabien Brulport |
---|
Module encapsulating all the classes required to run a simulation.
-
simulatorTLKT.
ACTIONS
= (0, 45, 90, 135, 180, 225, 270, 315)¶ Actions that are authorized i.e. headings the boat can follow. Must be sorted.
-
class
simulatorTLKT.
Boat
¶ Bases:
object
Class defining the boat’s dynamics.
-
FIT_VELOCITY
= ((-0.0310198207067136, -0.0600881995286002, 0.0286695485969272, -0.00684406929296715, 0.000379636836557256, -6.77704610076153e-06), (0.0106968590293653, 0.00665508747173206, -4.03686836415123e-05, 2.38962919033178e-05, -6.16724919464073e-07, 0), (-0.00037026055411375, -7.68003222256045e-05, -2.44425618051996e-06, -2.16961875441841e-08, 0, 0), (4.94175336099537e-06, 5.68757177397705e-07, 1.17646387245609e-08, 0, 0, 0), (-2.91900968067076e-08, -1.67287818401469e-09, 0, 0, 0, 0), (6.34463723894578e-11, 0, 0, 0, 0, 0))¶ Coefficients of the polar fitted with a 5th order two dimensionnal polynomial.
-
POLAR_MAX_POFSAIL
= 160¶ Maximal point of sail where the boat can sail without tacking.
-
POLAR_MAX_WIND_MAG
= 19.1¶ Maximal wind magnitude acceptable by the polar fit. If experienced magnitude is greater the wind magnitude is set to POLAR_MAX_WIND_MAG.
-
POLAR_MIN_POFSAIL
= 35¶ Minimal point of sail where the boat can sail without tacking.
-
UNCERTAINTY_COEFF
= 0.2¶ Characterizes the uncertainty on the boat’s dynamics, proportion coefficient between the mean velocity and its variance.
-
static
addUncertainty
(boatSpeed)¶ Returns the noisy boat velocity.
Parameters: boatSpeed (float) – deterministic boat velocity in m/s. Returns: Stochastic boat speed in m/s. Return type: float
-
static
getDeterDyn
(pOfSail, windMag, fitCoeffs)¶ Returns the deterministic boat velocity for a given wind magnitude and point of sail.
Parameters: - pOfSail (float) – point of sail of the boat (in degree).
- windMag (float) – magnitude of the winf in m/s.
- fitCoeffs (tuple) – coefficients of the fitted velocity polar cf:
FIT_VELOCITY
.
Returns: deterministic boat’s speed in m/s (in direction of heading).
Return type: float
-
-
simulatorTLKT.
DAY_TO_SEC
= 86400¶ Constant to convert days in seconds.
-
simulatorTLKT.
DESTINATION_ANGLE
= 8.726646259971648e-05¶ Angular margin that characterizes the destination point.
-
simulatorTLKT.
EARTH_RADIUS
= 6371000.0¶ Earth radius in meters.
-
simulatorTLKT.
HOURS_TO_DAY
= 0.041666666666666664¶ Constant to convert hours to days
-
class
simulatorTLKT.
Simulator
(times, lats, lons, WeatherAvg, stateInit)¶ Bases:
object
Class embedding the boat and weather interactions with also the tools required to do projection on earth surface. For now, only used by the MCTS tree search.
Variables: - times (numpy.array) – Vector of the instants used for the simulation in days.
- lons (numpy.array) – Longitudes in degree in [0 , 360].
- lats (numpy.array) – Latitudes in degree in [-90 : 90].
- state (list) – Current state [time index, lat, lon] of the boat in (int,degree,degree).
- prevState (list) – Previous state [time index, lat, lon] of the boat in (int,degree,degree).
- uWindAvg (Interpolator) – Interpolator for the wind velocity blowing toward West. Generated at initialisation with
WeatherTLKT.Weather.Interpolators()
. - vWindAvg (Interpolator) – Interpolator for the wind velocity blowing toward North. Generated at initialisation with
WeatherTLKT.Weather.Interpolators()
.
-
animateTraj
(states)¶ Animates the trajectory corresponding to the list of states.
Parameters: states (list) – List of boat states along its trajectory. Returns: Animation function. Return type: FuncAnimation
-
doStep
(action)¶ Does one iteration of the simulation (one time step) following a provided action. Updates and returns the new boat state. Supposes constant wind during a time step. Also constant boat speed. Assumes that the boat moves following orthodomes trajectories. This is correct if the distances covered during the time step is relatively small (and we are not close to the poles): the orthodrome’s headings do not vary much.
Parameters: action (float) – Boat’s heading in degree. Returns: Reference toward the updated simulator’s state. Return type: self.state
-
static
fromGeoToCartesian
(coordinates)¶ Transforms geographic coordinates to cartesian coordinates. The cartesian frame has its origin at the center of the earth. Its orientation and so on is not explicitely given since the function is only used to create a plane.
Parameters: coordinates ([float : lat, float : lon]) – Coordinates in geographical frame. Returns: x,y,z coordinates. Return type: [float, float, float]
-
getDestination
(distance, bearing, departure)¶ Returns the destination point following a orthodrome trajectory for a given bearing and distance. Link to documentation.
Parameters: - distance (float) – Distance in meters to the destination.
- bearing (float) – Initial bearing of the orthodrome trajectory starting at departure and ending at destination. In degrees.
- departure (list(float : lat, float : lon)) – Departure point of the trajectory.
Returns: Destination reached following the othodrome trajectory.
Return type: [float : lat, float : lon]
-
getDistAndBearing
(position, destination)¶ Returns the distance and the initial bearing to follow to go to a destination following a great circle trajectory (orthodrome). Link to documentation
Parameters: - position (list(float : lat, float : lon)) – Current position of the boat.
- destination (list(float : lat, float : lon)) – Point toward which the distance and initial bearing are computed.
Returns: Shortest distance between the two points in meters, and initial bearing of the orthodrome trajectory in degrees.
Return type: float: distance, float: bearing
-
getWind
()¶ Returns the wind at the current simulator state.
Returns: Wind toward the East in m/s and wind toward the North in m/s. Return type: float : uAvg, float : vAvg
-
play_scenario
(idsc=0, interactive=True)¶
-
plotTraj
(states, basemap, quiv=False, scatter=False, color='black', label='')¶ Draw the states on the map either as a trajectory and/or scatter of points. Can also plot mean wind for each state and return it.
Parameters: - states (array or list) – List of all the state (state is an array)
- basemap – Basemap object on which the trajectory will be drawn
- quiv (boolean) – If True, shows the wind at each time step and returns it.
- scatter (boolean) – If True, plots the positions of the boat at each time step as scatter only
- color (str) – Color of the trajectory points
Returns: u,v if quiver is true
Return type: float,float
-
prepareBaseMap
(proj='mill', res='i', Dline=5, dl=1.5, dh=1, centerOfMap=None)¶ Prepares the figure to plot a trajectory. Based on mpl_toolkits.basemap.Basemap.
Parameters: Returns: The initialized basemap.
Return type:
-
reset
(stateInit)¶ Reset the simulated boat to a specific state.
Parameters: stateInit (list) – State to which the simulator is reinitialized.