pycaps.interp package¶
Submodules¶
pycaps.interp.interp module¶
-
class
Interpolator
(wrap, buffer, agl)[source]¶ Bases:
object
Base class for the Interpolator objects. Needs to be re-implemented in a subclass.
Parameters: - wrap (bool) – What to do with points that are out of the domain. wrap == True means to assign the nearest point in the domain, wrap == False means to assign NaN to those points.
- buffer (bool) – Wether to add a one grid point buffer around the data when it’s loaded (usually used when you need a derivative across the plane of the data).
- agl (bool) – Wether or not the heights are above ground level (agl == True) or above mean sea level (agl == False).
-
is_agl
()[source]¶ Return whether or not the heights in this interpolator refer to AGL (True) or MSL (False)
-
class
NullInterpolator
[source]¶ Bases:
pycaps.interp.interp.Interpolator
A null interpolator (that is: don’t do any interpolation). This is useful for functions that expect an interpolator, but the user doesn’t want to do any interpolation.
-
__call__
(data)[source]¶ Do the interpolation.
Parameters: data – The grid to interpolate. Note: this method assumes that you’ve already subsetted the grid according to the bounds returned by getBounds(). It also assumes that data is three-dimensional, even if one or more of those dimensions has length 1. Returns: Interpolated data as a Numpy array.
-
-
class
PointInterpolator
(points, axes=None, coords='hght', wrap=False, buffer=False, agl=False)[source]¶ Bases:
pycaps.interp.interp.Interpolator
Interpolate to points.
Parameters: - points (dict) – A dictionary containing all the points to interpolate to. The dictionary must contain ‘x’, ‘y’, and ‘z’ keys pointing to numpy arrays or single floats containing the respective coordinates.
- axes (dict) – A dictionary that must contain ‘x’, ‘y’, and ‘z’ keys corresponding to the x, y, and z axes. x and y must be one-dimensional, z must be three-dimensional. Optional.
- coords (str) – String specifying which coordinate system to do the interpolation in. Valid values are ‘hght’ for height coordinates (default) or ‘pres’ for pressure coordinates. In the case of pressure coordinates, axes[‘z’] is interpreted as pressure instead of height.
- wrap (bool) – What to do with points that are out of the domain. wrap == True means to assign the nearest point in the domain, wrap == False means to assign NaN to those points.
- buffer (bool) – Wether to add a one grid point buffer around the data when it’s loaded (usually used when you need a derivative across the plane of the data).
- agl (bool) – Wether or not the heights are above ground level (agl == True) or above mean sea level (agl == False).
-
__call__
(data)[source]¶ Do the interpolation.
Parameters: data – The grid to interpolate. Note: this method assumes that you’ve already subsetted the grid according to the bounds returned by getBounds(). It also assumes that data is three-dimensional, even if one or more of those dimensions has length 1. Returns: Interpolated as a Numpy array.
-
class
SigmaInterpolator
(sigma, axes=None, buffer=False)[source]¶ Bases:
pycaps.interp.interp.Interpolator
“Interpolate” to sigma levels in the model (that is: just pull out the relevant level, perhaps with a buffer).
Parameters: - sigma (int) – The model level to use.
- axes (dict) – A dictionary that must contain ‘x’, ‘y’, and ‘z’ keys corresponding to the x, y, and z axes. x and y must be one-dimensional, z must be three-dimensional. Optional.
- buffer (bool) – Wether to add a one grid point buffer around the data when it’s loaded (usually used when you need a derivative across the plane of the data).
-
__call__
(data)[source]¶ Do the interpolation.
Parameters: data – The grid to interpolate. Note: this method assumes that you’ve already subsetted the grid according to the bounds returned by getBounds(). It also assumes that data is three-dimensional, even if one or more of those dimensions has length 1. Returns: Interpolated data as a Numpy array.
-
class
SoundingInterpolator
(point, axes=None, k_min=None, k_max=None, buffer=False)[source]¶ Bases:
pycaps.interp.interp.Interpolator
Interpolate to single columns.
Parameters: - point (dict) – A dictionary containing the point to interpolate to. The dictionary must contain ‘x’ and ‘y’ keys pointing the respective coordinates in meters of the point.
- axes (dict) – A dictionary that must contain ‘x’, ‘y’, and ‘z’ keys corresponding to the x, y, and z axes. x and y must be one-dimensional, z must be three-dimensional. Optional.
- k_min (int) – Minimum sigma level to use in the cross section. Defaults to None (the bottom of the domain).
- k_max (int) – Maximum sigma level to use in the cross section. Defaults to None (the top of the domain).
- buffer (bool) – Wether to add a one grid point buffer around the data when it’s loaded (usually used when you need a derivative across the plane of the data).
-
__call__
(data)[source]¶ Do the interpolation.
Parameters: data – The grid to interpolate. Note: this method assumes that you’ve already subsetted the grid according to the bounds returned by getBounds(). It also assumes that data is three-dimensional, even if one or more of those dimensions has length 1. Returns: Interpolated data as a Numpy array.
-
class
XSectInterpolator
(start_point, end_point, axes=None, k_min=None, k_max=None, buffer=False)[source]¶ Bases:
pycaps.interp.interp.Interpolator
Interpolate to arbitrary vertical cross sections.
Parameters: - start_point (dict) – Dictionary containing the start point for the cross section. The dictionary should contain ‘x’ and ‘y’ keys pointing to the respective coordinates of the start point in meters.
- end_point (dict) – As in start_point, but for the end of the cross section. Because the cross section is given the same grid spacing as the input grid, the cross section may not end exactly on end_point. In that case, end_point will be between the last two columns on the cross section.
- axes (dict) – A dictionary that must contain ‘x’, ‘y’, and ‘z’ keys corresponding to the x, y, and z axes. x and y must be one-dimensional, z must be three-dimensional. Optional.
- k_min (int) – Minimum sigma level to use in the cross section. Defaults to None (the bottom of the domain).
- k_max (int) – Maximum sigma level to use in the cross section. Defaults to None (the top of the domain).
- buffer (bool) – Wether to add a one grid point buffer around the data when it’s loaded (usually used when you need a derivative across the plane of the data).
-
__call__
(data)[source]¶ Do the interpolation.
Parameters: data – The grid to interpolate. Note: this method assumes that you’ve already subsetted the grid according to the bounds returned by getBounds(). It also assumes that data is three-dimensional, even if one or more of those dimensions has length 1. Returns: Interpolated data as a Numpy array.
-
class
ZInterpolator
(z_coord, axes=None, coords='hght', wrap=False, buffer=False, agl=False)[source]¶ Bases:
pycaps.interp.interp.Interpolator
Interpolate to specific heights (e.g. 500 m AGL, 6 km MSL) or pressures (e.g. 500 hPa).
Parameters: - z_coord (float) – The height or pressure at which to do the interpolation. Units must match the units of axes[‘z’].
- axes (dict) – A dictionary that must contain ‘x’, ‘y’, and ‘z’ keys corresponding to the x, y, and z axes. x and y must be one-dimensional, z must be three-dimensional. Optional.
- coords (str) – String specifying which coordinate system to do the interpolation in. Valid values are ‘hght’ for height coordinates (default) or ‘pres’ for pressure coordinates. In the case of pressure coordinates, axes[‘z’] is interpreted as pressure instead of height.
- wrap (bool) – What to do with points that are out of the domain. wrap == True means to assign the nearest point in the domain, wrap == False means to assign NaN to those points.
- buffer (bool) – Wether to add a one grid point buffer around the data when it’s loaded (usually used when you need a derivative across the plane of the data).
- agl (bool) – Wether or not the heights are above ground level (agl == True) or above mean sea level (agl == False).
-
__call__
(data)[source]¶ Do the interpolation.
Parameters: data – The grid to interpolate. Note: this method assumes that you’ve already subsetted the grid according to the bounds returned by getBounds(). It also assumes that data is three-dimensional, even if one or more of those dimensions has length 1. Returns: Interpolated data as a Numpy array.
-
interp_column
(data, axes, column, k_min=None, k_max=None)[source]¶ Interpolate 3-dimensional data to a column
Parameters: - data (np.array) – A 3-dimensional array (NZ x NY x NX) of data to interpolate
- axes (dict) – A dictionary containing the coordinate axes of the array. It must have ‘x’, ‘y’, and ‘z’ keys, whose values must be the x, y, and z coordinates, respectively, of each point in the grid. The x and y coordinate arrays must be 1-dimensional, and the z coordinate array must be 3-dimensional. Units are assumed to be meters.
- column (dict) – A dictionary containing the column to interpolate to. It must have ‘x’ and ‘y’ keys, whose values must be the x and y coordinates, respectively, of the column to interpolate to. Units are assumed to be meters.
- k_min (int) – Lowest sigma level to include in the column
- k_max (int) – Highest sigma level to include in the column
Returns: A 1-dimensional array of interpolated data
-
interp_height
(data, z_coord, height)[source]¶ Interpolate 3-dimensional data to a given height
Parameters: - data (np.array) – A 3-dimensional array (NZ x NY x NX) of data to interpolate
- z_coord (np.array) – A 3-dimensional array containing the height of each point in the data grid. Units are assumed to be meters.
- height (float) – The height to interpolate to. Units are assumed to be meters.
Returns: A 2-dimensional array of interpolated data.
-
interp_points
(data, axes, points)[source]¶ Interpolate 3-dimensional data to one or more points in space
Parameters: - data (np.array) – A 3-dimensional array (NZ x NY x NX) of data to interpolate
- axes (dict) – A dictionary containing the coordinate axes of the array. It must have ‘x’, ‘y’, and ‘z’ keys, whose values must be the x, y, and z coordinates, respectively, of each point in the grid. The x and y coordinate arrays must be 1-dimensional, and the z coordinate array must be 3-dimensional. Units are assumed to be meters.
- points (dict) – A dictionary containing the points to interpolate to. It must have ‘x’, ‘y’, and ‘z’ keys, whose values must be the x, y, and z coordinates, respectively, of the points to interpolate to. The coordinates can be either single floats or 1-dimensional arrays. Units are assumed to be meters.
Returns: If the coordinates were specified as 1-dimensional arrays, returns a 1-dimensional array of the interpolated data. The order of this array is the same as the order of the points. Otherwise, returns a single float of interpolated data.
-
interp_xsect
(data, axes, start_point, end_point, k_min=None, k_max=None)[source]¶ Interpolate 3-dimensional data to a vertical cross section in an arbitrary direction. The interpolation creates a cross section grid that has the same horizontal grid interval as the source data. The user is not expected to provide an endpoint that occurs exactly at a grid interval. Rather, the cross section extends no more than 1 grid interval beyond the end point to provide an integer number of grid intervals in the interpolated data.
Parameters: - data (np.array) – A 3-dimensional array (NZ x NY x NX) of data to interpolate
- axes (dict) – A dictionary containing the coordinate axes of the array. It must have ‘x’, ‘y’, and ‘z’ keys, whose values must be the x, y, and z coordinates, respectively, of each point in the grid. The x and y coordinate arrays must be 1-dimensional, and the z coordinate array must be 3-dimensional. Units are assumed to be meters.
- start_point (dict) – A dictionary containing the coordinates of start column for the cross section. It must have ‘x’ and ‘y’ keys, whose values must be the x and y coordinates, respectively, of start column. Units are assumed to be meters.
- end_point (dict) – As in the start_point argument, but for the ending point. The cross section will not necessarily stop exactly at this column, but this column will be contained in the last grid interval.
- k_min (int) – Lowest sigma level to include in the cross section
- k_max (int) – Highest sigma level to include in the cross section
Returns: A tuple containing the 2-dimensional grid of interpolated data, as well as the x and y coordinates of the cross section in meters.
pycaps.interp.setup_subdomain module¶
-
setup_subdomain
(xmin, xmax, ymin, ymax, dx, dy, trulat1, trulat2, var2d, fullmap)[source]¶ Takes data from a larger domain and maps it onto a smaller subdomain.
Parameters: - xmin – i-coordinate of the west boundary of the subdomain
- ymin – j-coordinate of the south boundary of the subdomain
- xmax – i-coordinate of the east boundary of the subdomain
- ymax – j-coordinate of the north boundary of the subdomain
- dx – the horizontal grid spacing in the east-west direction, in meters
- dy – the horizontal grid spacing in the north-south direction, in meters
- trulat1 – the first trulat value of the Lambert conformal map projection (often 30.0)
- trulat2 – the second trulat value of the Lambert conformal map projection (often 60.0)
- var2d – the variable you need to map to a subdomain (as a 2D x-y slice)
- fullmap – the Basemap object associated with the larger domain (within which you are putting the subdomain)
Returns: a Basemap object for the new subdomain x: a 2D array containing the x-coordinate, suitable for plotting with matplotlib y: a 2D array containing the y-coordinate, suitable for plotting with matplotlib var2d: the 2D variable specified in the input, mapped to the subdomain
Return type: map