Skip to content

Instantly share code, notes, and snippets.

@rywall
Created December 3, 2012 06:30
Show Gist options
  • Save rywall/4193156 to your computer and use it in GitHub Desktop.
Save rywall/4193156 to your computer and use it in GitHub Desktop.
# Calculate the intake fraction where iF = SUM(popDensN * DispN)
# where popDensN is the population density in an N meter buffer minus the previous buffer
def intake_fraction
fraction = 0
inner_pop = 0
inner_area = 0
DISPERSION_FACTORS.each do |buffer, value|
pop_in_buffer = send("pop#{buffer}m").to_i
area_in_buffer = send("area#{buffer}m").to_i
fraction += value * (pop_in_buffer - inner_pop) / (area_in_buffer - inner_area)
# Save the population and area from this buffer to subtract from the next
inner_pop = pop_in_buffer
inner_area = area_in_buffer
end
return fraction
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment