WikiPrint - from Polar Technologies

Function:

A python function has been created in order to access the SPECS-EUPORIAS Data Portal in a user-friendly way, allowing the retrieval of dimensional slices of selected simulation members from the ECMWF's SYSTEM4 model. This function (?load_system4.py) automatically cares about the proper location of the right indices for data sub-setting across the different variable dimensions, given a few simple arguments for subset definition. In addition, instead of retrieving a NetCDF file that needs to be opened and read, the requested data is directly loaded into the current python working session, according to a particular structure described below, prior to data analysis and/or representation.

The request is simply formulated via the load_system4 function:

>>> load_system4(dataset, var, season, leadMonth, lonLim, latLim, year, members=[])

The arguments of the function are described below:

Short NameLong nameUnitsInstantaneousAggregated
tasmax Maximum temperature at 2 metres K No Yes
tasmin Minimum temperature at 2 metres K No Yes
tas Mean temperature at 2 metres K Yes Yes
pr Total precipitation accumulated mm No Yes
mslp Mean sea level pressure Pa Yes Yes

The output returned by the function consists of a list of user data objects (one for each member loaded) with the following methods that provide the necessary information for data representation and analysis:

Example:

An illustrative example of the load_system4 function is described in the next lines. We will retrieve System4 simulation data for the Iberian Peninsula, considering mean surface temperature for January and the first simulation member, for the 10-year period 1990-1999. It should be noted that the user must enter here his/her authorized username and password as character strings.

>>> var = "tas"
>>> season = [1]
>>> leadMonth = 1  
>>> lonlim = [-10,5]
>>> latlim= [35,45]
>>> year = [1990,1991,1992,1993,1994,1995,1996,1997,1998,1999]
>>> members = [0]
>>> username = "myUsername"
>>> password = "myPassword"
>>> dataset = "http://%s:%s@www.meteo.unican.es/tds5/dodsC/system4/System4_Seasonal_15Members.ncml" %(username,password)
>>> ud = loadSystem4(dataset,var,season, leadMonth,lonlim, latlim, year, members=[0])

Data is now loaded into the python session. One of the most common tasks consists on the representation of data, e.g. by mapping the spatial mean of the period under consideration. In addition, we will also add to the map the point locations of four Spanish cities. It can be done easily:

>>> cities_name=np.array(["Sevilla","Madrid","Santander","Zaragoza"])
>>> cities_latlon=np.array([[(37.41),(-5.9)],[(40.40),(-3.68)],[(43.43),(-3.82)],[(41.67),(-0.82)]])
>>> temporal_mean=ud.data.mean(axis=0)
>>> plot_map(temporal_mean,ud,season,var,cities_latlon,cities_name,method="pixels")

Another common task is the representation of time series for selected point locations/grid cells. In this example, we will display time series of the requested dataset at the four grid points coincident with the cities represented in the map. To this aim, we will create a function that search the data of the nearest grid points to the specified locations.

>>> def plot_serie_cities(cities_latlon,cities_name,ud):
...    pcolors = {
...      "0":"blue",
...      "1":"green",
...      "2":"red",
...      "3":"purple",
...      "4":"cyan",
...      "5":"yellow",
...      "6":"magenta",
...      "7":"pink",
...      "8":"orange",
...      "9":"brown",
...      "10":"grey",
...    }
...    fig=plt.figure()
...    ax = fig.add_subplot(111)
...    x=np.arange(len(ud.times))
...    xticks_mask = [d.month in season and d.day == 1 for d in ud.times]
...    xticks = x[np.array(xticks_mask)]
...    ax.set_xticks(xticks)
...    ticklabels=[t.strftime("%Y-%m") for t in ud.times[np.array(xticks_mask)]]
...    ax.set_xticklabels(ticklabels)
...    plt.xticks(rotation=25)
...    plt.ylabel("%s (%s)" %(var,ud.units))
...    lat = cities_latlon[:,0]
...    lon = cities_latlon[:,1]
...    for i in np.arange(len(cities_name)):
...       city_position=(((ud.LatLonCoords[0,:]-lon[i])**2)+((ud.LatLonCoords[1,:]-lat[i])**2)).argmin()
...       city = ud.data[:,city_position]
...       c=("%("+str(i)+")s") % pcolors
...       plt.plot(city,color=c, label=cities_name[i])
...    plt.legend(loc="lower left",prop={'size':'small'})
...    plt.savefig("map_serie_all_cities.png")

Once we hace the function defined, we use it to plot the graph.

>>> plot_serie_cities(cities_latlon,cities_name,ud)