def test_coeff(self, months, seasons, month_to_season_coefficients): register = NDimensionalRegister() register.register(IntervalSet('months', months)) register.register(IntervalSet('seasons', seasons)) actual = register.get_coefficients('months', 'seasons') expected = month_to_season_coefficients assert np.allclose(actual, expected, rtol=1e-05, atol=1e-08)
def generate_coefficients(self, from_spec, to_spec) -> np.ndarray: """Generate conversion coefficients for interval dimensions Assumes that the Coordinates elements contain an 'interval' key whose value corresponds to :class:`Interval` data, that is a `{'name': interval_id, 'interval': list of interval extents}`. For example, intervals covering each hour of a period :: { 'name': 'first_hour', 'interval': [('PT0H', 'PT1H')] } { 'name': ''second_hour', 'interval': [('PT1H', 'PT2H')] } ... Or intervals corresponding to repeating hours for each day of a period :: { 'name': midnight', 'interval': [ ('PT0H', 'PT1H'), ('PT24H', 'PT25H'), ('PT48H', 'PT49H'), ... ] }, { 'name': ''one_am', 'interval': [ ('PT1H', 'PT2H'), ('PT25H', 'PT26H'), ('PT49H', 'PT50H'), ... ] } ... """ # find dimensions to convert from_dim, to_dim = self.get_convert_dims(from_spec, to_spec) # get dimension coordinates from_coords = from_spec.dim_coords(from_dim) to_coords = to_spec.dim_coords(to_dim) # create IntervalSets from Coordinates from_set = IntervalSet(from_dim, from_coords.elements) to_set = IntervalSet(to_dim, to_coords.elements) # register IntervalSets register = NDimensionalRegister() register.register(from_set) register.register(to_set) # use NDimensionalRegister to get coefficients coefficients = register.get_coefficients(from_dim, to_dim) return coefficients
def generate_coefficients(self, from_spec, to_spec): """Generate conversion coefficients for spatial dimensions Assumes that the Coordinates elements contain a 'feature' key whose value corresponds to a GDAL vector feature represented as a dict, for example as returned by a `fiona` reader. """ # find dimensions to convert from_dim, to_dim = self.get_convert_dims(from_spec, to_spec) # get dimension coordinates from_coords = from_spec.dim_coords(from_dim) to_coords = to_spec.dim_coords(to_dim) # create RegionSets from Coordinates from_set = RegionSet(from_dim, from_coords.elements) to_set = RegionSet(to_dim, to_coords.elements) # register RegionSets register = NDimensionalRegister() register.register(from_set) register.register(to_set) # use NDimensionalRegister to get coefficients coefficients = register.get_coefficients(from_dim, to_dim) return coefficients