def total_mortality( self, species=None, time=None, sex=None, group=None, mortality_name=None, as_population=True, ): """ Collect either the total population or the mortality parameter value for the given query :param str species: Species name :param time: time slice - may be an iterable or int :param str sex: Sex ('male' or 'female') - may be an iterable :param str group: Group name - may be an iterable :param bool as_population: Use to determine whether the query output is the population that succumbs to the mortality, or the mortality rate :return: ndarray of the mortality population or parameter """ species, time, sex, group = self.collect_iterables( species, time, sex, group) if as_population: _type = "flux" else: _type = "params" mortality = [] for t in time: for sp in species: for s in sex: for gp in group: base_key = "{}/{}/{}/{}/{}/mortality".format( sp, s, gp, t, _type) if mortality_name is None: try: names = self.domain.file[base_key].keys() except KeyError: continue else: names = [mortality_name] for name in names: try: mortality.append(self.arrays["{}/{}".format( base_key, name)]) except KeyError: continue if len(mortality) == 0: self.to_compute.append( pd.da_zeros(self.domain.shape, self.domain.chunks)) else: self.to_compute.append(pd.dsum(mortality))
def total_carrying_capacity(self, species=None, time=None, sex=None, group=None): """ Collect the total carrying capacity in the domain for the given query. .. Attention:: Carrying capacity may be calculated for an entire species in the solver (see :ref:`solvers`). As such, query results that are filtered by sex or age group will include carrying capacity for the entire species. :param str species: Species name :param time: time slice - may be an iterable or int :param str sex: Sex ('male' or 'female') - may be an iterable :param str group: Group name - may be an iterable :return: ndarray of total carrying capacity """ # TODO: Raise exception if specified group or sex does not exist, as it will still return results with typos def retrieve(species, time, sex, group): species, time, sex, group = self.collect_iterables( species, time, sex, group) for t in time: for sp in species: for s in sex: for gp in group: cc = "{}/{}/{}/{}/params/carrying capacity/Carrying Capacity".format( sp, s, gp, t) try: carrying_capacity.append(self.arrays[cc]) except KeyError: pass carrying_capacity = [] retrieve(species, time, sex, group) # If the total species carrying capacity was used for density during the simulation, # there will not be any carrying capacity associated with sexes/groups. if len(carrying_capacity) == 0 and (sex is not None or group is not None): # Try to collect the species-wide dataset sex, group = None, None carrying_capacity = [] retrieve(species, time, sex, group) if len(carrying_capacity) == 0: self.to_compute.append( pd.da_zeros(self.domain.shape, self.domain.chunks)) else: self.to_compute.append(pd.dsum(carrying_capacity))
def fecundity(self, species=None, time=None, sex=None, group=None, coeff=False): """ Collect the total fecundity using the given query :param str species: Species name :param time: time slice - may be an iterable or int :param str sex: Sex ('male' or 'female') - may be an iterable :param str group: Group name - may be an iterable :param bool coeff: If True, the average fecundity reduction rate based on density is returned :return: ndarray of total offspring """ species, time, sex, group = self.collect_iterables( species, time, sex, group) # Determine whether the fecundity value, or the density-based coefficient should be return if coeff: _type = "Density-Based Fecundity Reduction Rate" else: _type = "Fecundity" _fecundity = [] for t in time: for sp in species: for s in sex: for gp in group: fec = "{}/{}/{}/{}/params/fecundity/{}".format( sp, s, gp, t, _type) try: _fecundity.append(self.arrays[fec]) except KeyError: pass if len(_fecundity) == 0: self.to_compute.append( pd.da_zeros(self.domain.shape, self.domain.chunks)) else: if coeff: self.to_compute.append(pd.dmean(_fecundity)) else: self.to_compute.append(pd.dsum(_fecundity))
def total_population(self, species=None, time=None, sex=None, group=None, age=None): """ Collect the sum of populations from a domain, filtering by sub-populations :param str species: Species name - may be an iterable :param time: time slice: int or iterable :param sex: Sex (one of 'male' or 'female') - may be an iterable :param group: group name - may be an iterable :param age: discrete Age - may be an iterable :return: ndarray with the total population """ species, time, sex, group, ages = self.collect_iterables( species, time, sex, group, age) populations = [] for t in time: for sp in species: for s in sex: for gp in group: # If ages are None, they must be collected for the group if len(ages) == 0: try: _ages = self.domain.age_from_group( sp, s, gp) # Returns a list except pd.PopdynError: # This group is not associated with the current species or sex in the iteration continue else: _ages = ages for age in _ages: population = self.domain.get_population( sp, t, s, gp, age) if population is not None: populations.append(self.arrays[population]) if len(populations) == 0: self.to_compute.append( pd.da_zeros(self.domain.shape, self.domain.chunks)) else: self.to_compute.append(pd.dsum(populations))
def total_offspring(self, species=None, time=None, sex=None, group=None, offspring_sex=None): """ Collect the total offspring using the given query :param str species: Species name :param time: time slice - may be an iterable or int :param str sex: Sex ('male' or 'female') - may be an iterable :param str group: Group name - may be an iterable :return: ndarray of total offspring """ species, time, sex, group = self.collect_iterables( species, time, sex, group) if offspring_sex is None: offspring_sex = ["Male Offspring", "Female Offspring"] else: offspring_sex = [offspring_sex] offspring = [] for t in time: for sp in species: for s in sex: for gp in group: for _type in offspring_sex: off = "{}/{}/{}/{}/flux/offspring/{}".format( sp, s, gp, t, _type) try: offspring.append(self.arrays[off]) except KeyError: pass if len(offspring) == 0: self.to_compute.append( pd.da_zeros(self.domain.shape, self.domain.chunks)) else: self.to_compute.append(pd.dsum(offspring))