Skip to content

isentropic_interpolation_as_dataset can create "None" Data Array #2369

@dopplershift

Description

@dopplershift

When calling isentropic_interpolation_as_dataset, if you pass in a DataArray that hasn't been part of a Dataset previously, like say the result of a calculation:

isen_level = np.array([320]) * units.kelvin
pressure = ds.Temperature_isobaric.metpy.vertical
mixing = mpcalc.mixing_ratio_from_relative_humidity(pressure, ds.Temperature_isobaric, ds.Relative_humidity_isobaric)
isen_ds = mpcalc.isentropic_interpolation_as_dataset(isen_level, ds.Temperature_isobaric,
                                                     ds['u-component_of_wind_isobaric'],
                                                     ds['v-component_of_wind_isobaric'],
                                                     mixing)

the resulting Dataset looks like:

<xarray.Dataset>
Dimensions:                       (lat: 101, lon: 161)
Coordinates:
    isentropic_level              int64 320
    time                          datetime64[ns] 2022-03-02T06:00:00
    metpy_crs                     object Projection: latitude_longitude
    reftime                       datetime64[ns] 2022-03-02
  * lat                           (lat) float32 60.0 59.5 59.0 ... 10.5 10.0
  * lon                           (lon) float32 230.0 230.5 ... 309.5 310.0
Data variables:
    pressure                      (lat, lon) float32 <Quantity([[245.1992  24...
    temperature                   (lat, lon) float64 <Quantity([[214.15431785...
    u-component_of_wind_isobaric  (lat, lon) float64 <Quantity([[ 5.90835487 ...
    v-component_of_wind_isobaric  (lat, lon) float64 <Quantity([[ 5.18840406 ...
    None                          (lat, lon) float64 <Quantity([[2.30282411e-...

the "workaround" is to assign to mixing a name, like mixing.name = 'mixing_ratio'. Things to consider:

  1. Error (maybe warning) when trying to add an unnamed DataArray to the result
  2. Support **kwargs on isentropic_interpolation_as_dataset so that there's a way to pass in the array with a name to use. Other than the few keyword-only parameters we have (which can't be used as variable names), this would work and be backwards-compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: GriddingPertains to calculating values on a regular gridArea: XarrayPertains to xarray integrationType: EnhancementEnhancement to existing functionality

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions