swirlspy.rad package

Submodules

swirlspy.rad.ascii module

swirlspy.rad.ascii.read_ascii(file, valid_time, path='')

Reads ASCII file. The data should already be in Cartesian coodinates in Regular LatLon Projection. Returns a labelled xarray.DataArray.

Parameters:
  • file (str) – Name of ASCII file to read.
  • valid_time (str) – Time in [yyyymmddHHMM] of the first timestep radar file.
Returns:

xr_dataarray – A xarray.DataArray populated with radar reflectivity and metadata.

Return type:

xarray.DataArray

swirlspy.rad.cinrad module

swirlspy.rad.cinrad.read_cinrad(file, xllcenter, yllcenter, nrows, ncols, valid_time, time_step_size, proj, radar_radius, band_name)

Reads cinrad radar data (either in c-band or s-band) and returns reflectivity data in xarray.DataArray.

@author: qzhang

Parameters:
  • file (str) – Name of cinrad file to read. Reflectivity data contained by this file should be in spherical coordinates.
  • xllcenter (float) – longitude of radar site.
  • yllcenter (float) – latitude of radar site.
  • nrows (int) – Number of rows of the output interpolated cartesian grid.
  • ncols (int) – Number of columns of the output interpolated cartesian grid.
  • valid_time (str) – [YYYYMMDDhhmm] of the first-timestep radar file.
  • time_step_size (int) – Seperation time between 2 input radar files in minutes.
  • proj (str) – PROJ.4 parameters, proj4-string.
  • radar_radius (int) – Radar radius in km.
  • band_name (str) – Band name, either “c-band” or “s-band”
Returns:

xr_dataarray – A 2D xarray.DataArray. Reflectivity data is in “.values” attribute.

Return type:

xarray.DataArray

swirlspy.rad.hdf5 module

swirlspy.rad.hdf5.read_hdf5(file, minutize=True, path='')

Reads hdf5 file. Reflectivity data should already be in Cartesian Coordinates in Azimuthal Equidistant Projection. Units are in metres for distance x and y from the radar site. Returns a labelled xarray.DataArray.

Parameters:
  • file (str) – Name of the hdf5 file to read. Reflectivity data of this file should already be in Cartesian Coordinates.
  • minutize (bool) – If True, pandas.Timestamps are rounded down to the nearest minute. Defaults to True.
  • path(optional) (str) – Directory to save output as a .nc file.
Returns:

reflectivity – A xarray.DataArray populated with radar reflectivity and metadata. Coodinate vertices of grid can be accessed through DataArray attributes.

Return type:

xarray.DataArray

swirlspy.rad.iris module

swirlspy.rad.iris.read_iris(file, area_def=None, coord_label=['x', 'y'], radar_radius=250000, res=500, minutize=True, path='')

Reads Vaisala Sigmet IRIS RAW data file. Regrid radar reflectivity data from Spherical coordinates to Cartesian coordinates, in a projection specified with pyresample’s AreaDefinition. Returns a labelled xarray.DataArray.

Parameters:
  • file (str) – Name of IRIS RAW file to read.
  • area_def (pyresample.geometry.AreaDefinition) – Pyresample AreaDefinition of the target grid. Defaults to None.
  • coord_label (list of strings.) – [x_axis_label, y_axis_label]. Defaults to [‘x’, ‘y’].
  • radar_radius (float) – Radar radius in units of targeted projection. Default to 250000. Units in meters.
  • res(optional) (int) – Only define if area_def is not defined. Resolution of the default grid.
  • minutize(optional) (bool) – If True, pandas.Timestamps are rounded down to the nearest minute. Defaults to True.
  • path (str, optional) – If provided, save the result as a NetCDF file to the path specified.
Returns:

reflectivity – A xarray.DataArray populated with radar reflectivity and metadata.

Return type:

xarray.DataArray

swirlspy.rad.netcdf_ph module

swirlspy.rad.netcdf_ph.read_netcdf_ph(file, minutize=True)

Reads Philippine netCDF file and returns reflectivity data in xarray.DataArray. Reflectivity data should be in Cartesian Coordinates in Azimuthal Equidistant Projection. Units are in metres for distances x and y away from the radar site. Returns a labelled xarray.DataArray.

Parameters:
  • file (str) – Name of Philippine netCDF file to read. Reflectivity should already be in Cartesian Coordinates. in Azimuthal Equidistant Projection.
  • minutize (bool) – If True, pandas.Timestamps are rounded down to the nearest minute. Defaults to True.
Returns:

reflectivity – A labelled xarray.DataArray populated with radar reflectivity and metadata.

Return type:

xarray.DataArray

swirlspy.rad.netcdf_vn_dh module

swirlspy.rad.netcdf_vn_dh.read_netcdf_vn_dh(file, minutize=True)

Reads Vietnamese netCDF file (file name begins with “DH”). Data is already in LatLon Cartesian Coordinates. Returns an xarray.DataArray.

Parameters:
  • file (str) – Name of netCDF file to read.
  • minutize (bool) – If True, pandas.Timestamps are rounded down to the nearest minute. Defaults to True.
Returns:

reflectivity – A labelled xarray populated with radar reflectivity and metadata.

Return type:

xarray.DataArray

swirlspy.rad.netcdf_vn_don module

swirlspy.rad.netcdf_vn_don.read_netcdf_vn_don(file, area_def=None, coord_label=['x', 'y'], radar_radius=250000, res=500, minutize=True)

Reads Vietnamese netCDF file (file name begins with “DON”). Regrid reflectivity data from Polar coordinates to Cartesian coordinates in projection specified by AreaDefinition. Returns a labelled xarray.DataArray.

Parameters:
  • file (str) – Name of netCDF file to read
  • area_def (pyresample.geometry.AreaDefinition) – Pyresample AreaDefinition of the target grid. Defaults to None.
  • coord_label (list of strings.) – [x_axis_label, y_axis_label]. Defaults to [‘x’, ‘y’].
  • radar_radius (float) – Radar radius in units of targeted projection. Defaults to 250000
  • res(optional) (int) – Only define if area_def is not defined. Resolution of the default grid. Defaults to 500.
  • minutize (bool) – If True, pandas.Timestamps are rounded down to the nearest minute. Defaults to True.
Returns:

reflectivity – A xarray.DataArray populated with radar reflectivity and metadata.

Return type:

xarray.DataArray

swirlspy.rad.sph2cart_interpolation module

swirlspy.rad.sph2cart_interpolation.sph2cart_interpolation(radius, azimuth, elevation, xllcenter, yllcenter, nrows, ncols, data)
Convert data from spherical coordinates to cartesian coordinates

by interpolation.

Masked values and negative values in the grid of cartesian coordinates are replaced by 0.

Parameters:
  • radius (numpy.ndarray) – Contains the radial distances in meters.
  • azimuth (numpy.ndarray) – Contains the azimuthal angles in degree.
  • elevation (numpy.ndarray) – Contains the elevation angles in degree.
  • xllcenter (float) – Radar site longitude.
  • yllcenter (float) – Radar site latitude.
  • nrows (int) – Number of rows of the output interpolated cartesian grid.
  • ncols (int) – Number of columns of the output interpolated cartesian grid.
  • data (numpy.ndarray) – array of float, the data that should be interpolated on the cartesian grid.
Returns:

Cartesian Grid – an array of float with a dimension of (nrows,ncols), the data that should be interpolated on the cartesian grid.

Return type:

numpy.2darray

swirlspy.rad.time_update module

swirlspy.rad.time_update.time_update(initial, time_step_size)

Shift time by a certain amount.

Parameters:
  • initial (str) – Base time, in YYYYMMDDhhmm.
  • time_step_size (str) – Amount of time to shift, in minutes.
Returns:

end – Updated time, in YYYYMMDDhhmm.

Return type:

str

swirlspy.rad.uf_ph module

swirlspy.rad.uf_ph.read_uf_ph(file, area_def=None, coord_label=['x', 'y'], radar_radius=250000, res=500, minutize=True, path='')

Reads Philippine UF file. Regrid reflectivity data from Polar coordinates to Cartesian coordinates in projection specified by AreaDefinition. Returns a labelled xarray.DataArray.

Parameters:
  • file (str) – Name of Philippine UF file to read.
  • area_def (pyresample.geometry.AreaDefinition) – Pyresample AreaDefinition of the target grid. Defaults to None.
  • coord_label (list of strings.) – [x_axis_label, y_axis_label]. Defaults to [‘x’, ‘y’].
  • radar_radius (float) – Radar radius in units of targeted projection. Default is 250000. Units in meters.
  • res(optional) (int) – Only define if area_def is not defined. Resolution of the default grid.
  • minutize (bool) – If True, pandas.Timestamps are rounded down to the nearest minute. Defaults to True.
  • path(optional) (str) – Directory to save output as a .nc file.
Returns:

reflectivity – A xarray.DataArray populated with radar reflectivity and metadata.

Return type:

xarray.DataArray

swirlspy.rad.utils module

swirlspy.rad.utils.default_area_def(sitecoords, res=500, radius=250000)

Generate the default pyresample AreaDefinition. Azimuthal Equidistant Projection centered at sitecoords.

Parameters:
  • sitecoords (tuple of floats) – (Longitude, Latitude, Altitude) of radar site.
  • res (int) – Resolution of default grid. Defaults to 500.
  • radius (float) – The radius of the radar. Defaults to 250000. Units in meters.
Returns:

area_def – AreaDefinition of default grid.

Return type:

pyresample.geometry.AreaDefinition

swirlspy.rad.utils.gen_rad_xarray(x_grid, y_grid, grid_final, t, x_name, y_name, proj_site, long_name='reflectivity', units='dBZ')

Convenience function for generating xarrays from radar data. Returns a labelled xarray.DataArray.

Parameters:
  • x_grid (numpy.array) – Contains the x-axis coordinate values of target projection.
  • y_grid (numpy.array) – Contains the y-axis coordinate values of the target projection
  • grid_final (numpy.2darray) – An array of dimension (y, x) that contains the interpolated reflectivity values in the target projection.
  • t (pandas.Timestamp) – Time of radar data.
  • x_name (str) – Name of the x coordinate axis.
  • y_name (str) – Name of the y coordinate axis
  • proj_site (tuple of floats) – Radar site in target projection coordinates. (Longitude, Latitude)
  • long_name (str) – Short description of data. Defaults to ‘Reflectivity’
  • units (str) – Data units Defaults to ‘dBZ’
Returns:

reflectivity – A xarray.DataArray populated with radar reflectivity and metadata.

Return type:

xarray.DataArray

swirlspy.rad.utils.sph2cart(r, a, h, z, t, site, area_def, radar_radius)

Takes in radar variables and data in target grid and metadata that can be used to generate xarray.DataArray.

Parameters:
  • r (numpy.array) – Contains the radial distances in metres.
  • a (numpy.array) – Contains the azimuthal angles in degrees.
  • h (numpy.array) – Contains the elevation angles in degrees.
  • z (numpy.narray) – Array of float, the data that should be interpolated on the cartesian grid.
  • site (tuple of floats) – Radar site longitude, latitude and altitude. (longitude, latitude, altitude)
  • area_def (pyresample.geometry.AreaDefinition) – pyresample.AreaDefinition of user-defined grid.
  • radar_radius (float) – Effective radius of the radar in units of targeted projection.
Returns:

  • x_grid (numpy.array) – Contains the x-axis coordinate values of target projection.
  • y_grid (numpy.array) – Contains the y-axis coordinate values of the target projection.
  • proj_site (tuple of floats) – Radar site in the coordinates of the target projection.
  • grid_final (numpy.2darray) – An array of dimension (y, x) that contains the interpolated reflectivity values in the target projection.

swirlspy.rad.xr2d module

swirlspy.rad.xr2d.xr2d(np_array, end_time, duration)

Transform numpy array to xarray.DataArray.

Parameters
np_array: np.2darray
Must be 2-dimensional, dimension will be hardcoded as ‘x’ and ‘y’.
end_time: str
End time when your data stops accumulating [YYYYMMDDhhmm].
duration: str
Accumulation period of your data, in minutes.
Return

xr2d: xarray.DataArray (2-dimensional, in ‘x’ ‘y’) .. attribute:: dims

tuple Tuple of dimension names associated with this array. Hardcoded as ‘x’ and ‘y’.
swirlspy.rad.xr2d.values

np.ndarray The array’s data as a numpy.ndarray.

swirlspy.rad.xr2d.coords

dict_like Dictionary-like container of coordinate arrays of ‘x’ and ‘y’.

swirlspy.rad.xr2d.attrs

OrderedDict Dictionary storing arbitrary metadata with this array, including ‘end_time’ and ‘duration’.

swirlspy.rad.xrnd module

swirlspy.rad.xrnd.xrnd(*arg)

Concatenate multiple ‘xr2d’ into a single xarray, along a new axis called ‘end_time’. Use this function to make an xarray for qpf.

Parameters

Any number of ‘xr2d’ (xarray.DataArray).

Return
ndxr: xarray.DataArray
Number of ‘xr2d’ concatenated along ‘end_time’ axis depends on number of input.