src/tropycal/rain/dataset.py
def interpolate_to_grid(self,storm,grid_res=0.1,method='linear',return_xarray=False):
        
        r"""
        Interpolates storm rainfall data to a horizontal grid.
        
        Interpolation is performed using Scipy's `scipy.interpolate.griddata()` interpolation function.
        
        Parameters
        ----------
        storm : tropycal.tracks.Storm
            Instance of a Storm object.
        grid_res : int or float
            Horizontal resolution of the desired grid in degrees. Default is 0.1 degrees.
        method : str
            Method for interpolation to pass to scipy's interpolation function. Default is "linear".
        return_xarray : bool
            If True, output is returned as an xarray DataArray with coordinates included. Default is false.
            
        Returns
        -------
        dict or xarray.DataArray
            If return_xarray is True, an xarray DataArray is returned. Otherwise, a dict including the grid lat, lon and grid values is returned.
        """
        
        #Check if xarray is installed
        try:
            import xarray as xr
        except ImportError as e:
            return_xarray = False
            msg = "xarray is not installed in your python environment. Defaulting to return_xarray=False."
            warnings.warn(msg)
        
        #Check if Storm object contains rainfall data
        try:
            storm.rain
        except:
            storm.rain = self.get_storm_rainfall(storm)
        
        #Create grid to interpolate observations to
        grid_lon = np.arange(-140,-60+grid_res,grid_res)
        grid_lat = np.arange(20,50+grid_res,grid_res)
        
        #Retrieve data for interpolation
        rainfall = storm.rain['Total'].values
        lat = storm.rain['Lat'].values
        lon = storm.rain['Lon'].values

        #Perform the interpolation
        grid = griddata((lat, lon), rainfall, (grid_lat[None,:], grid_lon[:,None]), method=method)
        grid = np.transpose(grid)

        #Return data
        if return_xarray:
            return xr.DataArray(grid,coords=[grid_lat,grid_lon],dims=['lat','lon'])
        else:
            return {'grid':grid,'lat':grid_lat,'lon':grid_lon}
r"""
        Interpolates storm rainfall data to a horizontal grid.
        
        Interpolation is performed using Scipy's `scipy.interpolate.griddata()` interpolation function.
        
        Parameters
        ----------
        storm : tropycal.tracks.Storm
            Instance of a Storm object.
        grid_res : int or float
            Horizontal resolution of the desired grid in degrees. Default is 0.1 degrees.
        method : str
            Method for interpolation to pass to scipy's interpolation function. Default is "linear".
        return_xarray : bool
            If True, output is returned as an xarray DataArray with coordinates included. Default is false.
            
        Returns
        -------
        dict or xarray.DataArray
            If return_xarray is True, an xarray DataArray is returned. Otherwise, a dict including the grid lat, lon and grid values is returned.
        
r"""
Interpolates storm rainfall data to a horizontal grid.

Interpolation is performed using Scipy's `scipy.interpolate.griddata()` interpolation function.

Parameters

storm : tropycal.tracks.Storm
Instance of a Storm object.
grid_res : int or float
Horizontal resolution of the desired grid in degrees.

Returns

dict or xarray.DataArray
If return_xarray is True, an xarray DataArray is returned. Otherwise, a dict including the grid lat, lon and grid values is returned.
r " " " Interpolates storm rainfall data to a horizontal grid . Interpolation is performed using Scipy ' s ` scipy . interpolate . griddata () ` interpolation function . Parameters storm : tropycal . tracks . Storm Instance of a Storm object . grid_res : int or float Horizontal resolution of the desired grid in degrees . Returns dict or xarray . DataArray If return_xarray is True an xarray DataArray is returned . Otherwise a dict including the grid lat lon and grid values is returned .
def interpolate_to_grid(self,storm,grid_res=0.1,method='linear',return_xarray=False):
        try:
            import xarray as xr
        except ImportError as e:
            return_xarray = False
            msg = "xarray is not installed in your python environment. Defaulting to return_xarray=False."
            warnings.warn(msg)
        try:
            storm.rain
        except:
            storm.rain = self.get_storm_rainfall(storm)
        grid_lon = np.arange(-140,-60+grid_res,grid_res)
        grid_lat = np.arange(20,50+grid_res,grid_res)
        rainfall = storm.rain['Total'].values
        lat = storm.rain['Lat'].values
        lon = storm.rain['Lon'].values
        grid = griddata((lat, lon), rainfall, (grid_lat[None,:], grid_lon[:,None]), method=method)
        grid = np.transpose(grid)
        if return_xarray:
            return xr.DataArray(grid,coords=[grid_lat,grid_lon],dims=['lat','lon'])
        else:
            return {'grid':grid,'lat':grid_lat,'lon':grid_lon}
def interpolate_to_grid ( self , storm , grid_res = 0.1 , method = 'linear' , return_xarray = False ) : try : import xarray as xr except ImportError as e : return_xarray = False msg = "xarray is not installed in your python environment. Defaulting to return_xarray=False." warnings . warn ( msg ) try : storm . rain except : storm . rain = self . get_storm_rainfall ( storm ) grid_lon = np . arange ( - 140 , - 60 + grid_res , grid_res ) grid_lat = np . arange ( 20 , 50 + grid_res , grid_res ) rainfall = storm . rain [ 'Total' ] . values lat = storm . rain [ 'Lat' ] . values lon = storm . rain [ 'Lon' ] . values grid = griddata ( ( lat , lon ) , rainfall , ( grid_lat [ None , : ] , grid_lon [ : , None ] ) , method = method ) grid = np . transpose ( grid ) if return_xarray : return xr . DataArray ( grid , coords = [ grid_lat , grid_lon ] , dims = [ 'lat' , 'lon' ] ) else : return { 'grid' : grid , 'lat' : grid_lat , 'lon' : grid_lon }
r"""
Interpolates storm rainfall data to a horizontal grid.
r " " " Interpolates storm rainfall data to a horizontal grid .
r"""
        Interpolates storm rainfall data to a horizontal grid.
        
        Interpolation is performed using Scipy's `scipy.interpolate.griddata()` interpolation function.
        
        Parameters
        ----------
        storm : tropycal.tracks.Storm
            Instance of a Storm object.
        grid_res : int or float
            Horizontal resolution of the desired grid in degrees. Default is 0.1 degrees.
        method : str
            Method for interpolation to pass to scipy's interpolation function. Default is "linear".
        return_xarray : bool
            If True, output is returned as an xarray DataArray with coordinates included. Default is false.
            
        Returns
        -------
        dict or xarray.DataArray
            If return_xarray is True, an xarray DataArray is returned. Otherwise, a dict including the grid lat, lon and grid values is returned.
        """ #Check if xarray is installed #Check if Storm object contains rainfall data #Create grid to interpolate observations to #Retrieve data for interpolation #Perform the interpolation #Return data
self
storm
grid_res
method
return_xarray