Exemple #1
0
def download_scenarios(mydate,
                       latBound=[43, 50],
                       lonBound=[-10 + 360, 360],
                       website='http://nomads.ncep.noaa.gov:9090/dods/',
                       scenario_ids=range(0, 21)):
    """
    To download the weathers scenarios for a MCTS.
    Scenarios are saved as '../data/' + mydate + '_' + s_id + '00z.obj' where s_id is the scenario id.
    id = 0 corresponds to the mean scenario. They are stored as :class:`weatherTLKT.Weather` objects.


    **Warning:** *you might need to launch it from a terminal and not your IDE*

    :param string mydate: 'yyyymmdd' date of the day starting the weather forecast in US format
    :param list(float,float) latBound: [latmin, latmax], latitude boundaries of the domain on which the forecast is desired
    :param list(float,float) lonBound: [lonmin, lonmax], longitude boundaries of the domain on which the forecast is desired
    :param string website: url of the server hosting the forecasts
    :param range scenario_ids: range covering the forecasts scenarios we want to download
    """
    pathToSaveObj = []
    for ii in scenario_ids:
        if ii < 10:
            s_id = '0' + str(ii)
        else:
            s_id = str(ii)
        if ii == 0:
            url = (website + 'gens/gens' + mydate + '/gec' + s_id + '_00z')
        else:
            url = (website + 'gens/gens' + mydate + '/gep' + s_id + '_00z')
        print("Downloading from : " + url)
        pathToSaveObj.append(('../data/' + mydate + '_' + s_id + '00z.obj'))
        Weather.download(url,
                         pathToSaveObj[ii],
                         latBound=latBound,
                         lonBound=lonBound,
                         timeSteps=[0, 64],
                         ens=True)
        print("Saved into : " + pathToSaveObj[-1])
    def doStep(self, 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. 
        
        :param float action: Boat's heading in degree.
        
        :return: Reference toward the updated simulator's state.
        :rtype: self.state
        """

        # we copy the current state into the previous one
        self.prevState = list(self.state)

        # we get the wind at current state
        uWind, vWind = self.getWind()
        windMag, windAng = Weather.returnPolarVel(uWind, vWind)

        # We get speed from wind on sail
        pOfSail = abs((windAng + 180) % 360 - action)
        boatSpeedDet = Boat.getDeterDyn(pOfSail, windMag, Boat.FIT_VELOCITY)
        boatSpeed = Boat.addUncertainty(boatSpeedDet)

        # We integrate it
        Dt = (self.times[self.state[0] + 1] -
              self.times[self.state[0]]) * DAY_TO_SEC
        DL = boatSpeed * Dt  # distance travelled

        # new position, correct if the boat follows an orthodrome
        newLat, newLon = self.getDestination(DL, action,
                                             [self.state[1], self.state[2]])

        self.state[0], self.state[1], self.state[
            2] = self.state[0] + 1, newLat, newLon

        return self.state
Exemple #3
0
def load_scenarios(mydate,
                   scenario_ids=range(0, 21),
                   latBound=[-90, 90],
                   lonBound=[0, 360],
                   timeSteps=[0, 64]):
    """
    Loads previously downloaded scenarios and returns the corresponding list of :class:`weatherTLKT.Weather` objects.

    :param string mydate: 'yyyymmdd' date of the day starting the weather forecast in US format
    :param scenario_ids: range covering the forecasts scenarios we want to download
    :param list(float,float) latBound: [latmin, latmax], latitude boundaries of the domain on which the forecast is desired.
                                        If smaller than domain of stored object, returns a cropped object.
                                        Returns stored object otherwise
    :param list(float,float) lonBound: [lonmin, lonmax], longitude boundaries of the domain on which the forecast is desired.
                                        If smaller than domain of stored object, returns a cropped object.
                                        Returns stored object otherwise
    :param list(int,int) timeSteps: [min_t_index, max_t_index], time span of the desired forecast.
                                        If smaller than domain of stored object, returns a cropped object.
                                        Returns stored object otherwise

    :return: List of of :class:`weatherTLKT.Weather`
    :rtype: list()
    """
    pathToSaveObj = []
    weather_scen = []
    for ii in scenario_ids:

        if ii < 10:
            s_id = '0' + str(ii)
        else:
            s_id = str(ii)

        pathToSaveObj.append(('../data/' + mydate + '_' + s_id + '00z.obj'))
        weather_scen.append(
            Weather.load(pathToSaveObj[ii], latBound, lonBound, timeSteps))
        print("Loaded : " + pathToSaveObj[-1])

    return weather_scen
Exemple #4
0
typ = 'ens'

for ss in range(1, 9):
    if typ == 'solo':
        mydate = '20171127'
        website = 'http://nomads.ncep.noaa.gov:9090/dods'
        model = 'gfs'
        resolution = '0p25'
        url = website + '/' + model + '_' + resolution + '/' + model + mydate + '/' + model + '_' + resolution + '_00z'
        pathToSaveObj = '../data/' + model + mydate + '_' + resolution

    else:
        mydate = '20171127'
        website = 'http://nomads.ncep.noaa.gov:9090/dods'
        model = 'gens'
        resolution = '0p25'
        num_scenario = '0' + str(ss)
        url = website + '/' + model + '/' + model + mydate + '/' + 'gep' + num_scenario + '_00z'
        pathToSaveObj = '../data/' + model + mydate + '_' + num_scenario

    latBound = [43, 50]
    lonBound = [-10 + 360, 360]

    Weather.download(url,
                     pathToSaveObj,
                     latBound=latBound,
                     lonBound=lonBound,
                     timeSteps=[0, 85],
                     ens=True)
import copy
import pickle
import sys
sys.path.append("../solver")

#from MyTree import Tree
from worker import Tree

# %% We load the forecast files

#ATTENTION il faudra prendre le fichier de vent moyen à terme!!!
mydate = '20180108'
modelcycle = '0100z'
pathToSaveObj = '../data/' + mydate + '_gep_' + modelcycle + '.obj'
Wavg = Weather.load(pathToSaveObj)
Wavg=Wavg.crop(latBound=[40, 50], lonBound=[360 - 15, 360])

#mydate = '20170519'
#modelcycle = '00'
#pathToSaveObj = '../data/' + mydate + '_' + modelcycle + '.obj'
#Wavg = Weather.load(pathToSaveObj)

# %% We shift the times so that all times are in the correct bounds for interpolations
Tini = Wavg.time[0]

Wavg.time = Wavg.time - Tini

# %% We set up the parameters of the simulation
# times=np.arange(0,min([Wavg.time[-1],Wspr.time[-1]]),1*HOURS_TO_DAY)
# Tf=len(times)
lonBound = [-10 + 360, 360]
url = []
pathToSaveObj = []
urlold = 'http://nomads.ncep.noaa.gov:9090/dods/gfs_0p25/gfs20171014/gfs_0p25_00z'
for i in range(2):
    url.append(website + 'gfs_' + resolution[i] + '/gfs' + mydate + '/gfs_' +
               resolution[i] + '_' + modelcycle + 'z')
    pathToSaveObj.append('../data/' + mydate + '_gfs_' + resolution[i] +
                         '.obj')

# launch in real python console
# Weather.download(url[0],pathToSaveObj[0],latBound=latBound,lonBound=lonBound,timeSteps=[0,81])
# Weather.download(url[1],pathToSaveObj[1],latBound=latBound,lonBound=lonBound,timeSteps=[0,81])

# %%
weather025 = Weather.load(pathToSaveObj[0])
weather1 = Weather.load(pathToSaveObj[1])

instant = 40
#weather025.plotMultipleQuiver(otherWeather = weather1)
time = weather025.time[instant]
weather1.Interpolators()
error = np.zeros((len(weather025.lat), len(weather025.lon)))
interp_u = np.zeros((len(weather025.lat), len(weather025.lon)))
interp_v = np.zeros((len(weather025.lat), len(weather025.lon)))

for i, lat in enumerate(weather025.lat):
    for j, lon in enumerate(weather025.lon):
        if lat >= min(weather1.lat) and lat <= max(
                weather1.lat) and lon >= min(weather1.lon) and lon <= max(
                    weather1.lon):