def load(self):
        """Load the climate data as a map

        Returns:
            dict: {data: masked 3D numpy array containing climate data per month (first axis),
                   lat_idx: function converting a latitude to the (fractional) row index in the map,
                   lon_idx: function converting a longitude to the (fractional) column index in the map}
        """
        from scipy.io import netcdf_file
        from scipy import interpolate
        import numpy as np

        # load file
        f = netcdf_file(self.input_file)

        # extract data, make explicity copies of data
        out = dict()
        lats = f.variables['lat'][:].copy()
        lons = f.variables['lon'][:].copy()

        # lons start at 0, this is bad for working with data in Europe because the map border runs right through;
        # roll array by half its width to get Europe into the map center
        out['data'] = np.roll(f.variables[self.variable_name][:, :, :].copy(), shift=len(lons) // 2, axis=2)
        lons = np.roll(lons, shift=len(lons) // 2)

        # avoid wraparound problems around zero by setting lon range to -180...180, this is
        # also the format used in the GeoJSON NUTS2 polygons
        lons[lons > 180] -= 360

        # data contains some very negative value (~ -9e36) as 'invalid data' flag, convert this to a masked array
        out['data'] = np.ma.array(out['data'])
        out['data'][out['data'] < -1.e6] = np.ma.masked

        # -- start documentation include: climate-input-interp
        # build interpolators to convert lats/lons to row/column indices
        out['lat_idx'] = interpolate.interp1d(x=lats, y=np.arange(len(lats)))
        out['lon_idx'] = interpolate.interp1d(x=lons, y=np.arange(len(lons)))
        # -- end documentation include: climate-input-interp

        # clean up
        f.close()

        return out
def load ( self ) : from scipy . io import netcdf_file from scipy import interpolate import numpy as np f = netcdf_file ( self . input_file ) out = dict ( ) lats = f . variables [ 'lat' ] [ : ] . copy ( ) lons = f . variables [ 'lon' ] [ : ] . copy ( ) out [ 'data' ] = np . roll ( f . variables [ self . variable_name ] [ : , : , : ] . copy ( ) , shift = len ( lons ) // 2 , axis = 2 ) lons = np . roll ( lons , shift = len ( lons ) // 2 ) lons [ lons > 180 ] -= 360 out [ 'data' ] = np . ma . array ( out [ 'data' ] ) out [ 'data' ] [ out [ 'data' ] < - 1.e6 ] = np . ma . masked out [ 'lat_idx' ] = interpolate . interp1d ( x = lats , y = np . arange ( len ( lats ) ) ) out [ 'lon_idx' ] = interpolate . interp1d ( x = lons , y = np . arange ( len ( lons ) ) ) f . close ( ) return out
Load the climate data as a map

        Returns:
            dict: {data: masked 3D numpy array containing climate data per month (first axis),
                   lat_idx: function converting a latitude to the (fractional) row index in the map,
                   lon_idx: function converting a longitude to the (fractional) column index in the map}