Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual Entry: Recalculate Area-derived Values on Land Cover Updates #3151

Merged
merged 3 commits into from Aug 27, 2019

Commits on Aug 26, 2019

  1. Add tests for MapShed calculations

    Using a sample area of interes and observed output, add
    a test that ensures the output matches. This is useful
    when making changes to the calculation to ensure that
    the numbers do not change significantly when the calcs
    are updated.
    
    The dictdiffer package is brought in which allows for
    deep comparison of dicts, with a configurable tolerance
    for numeric comparison. The tests are currently set to
    tolerate differences smaller than 1e-15.
    
    The test is implemented as a management command rather
    than a unit test because it needs access to the special
    MapShed tables to run the calculations, which are not
    available in the Unit Test database. To add the large
    tables as fixtures to the Unit Test database would be
    too big of a slowdown for the sake of this one test,
    and would considerably bloat the repo size. To ensure
    the test does not run with the others, it is tagged and
    excluded from the test script.
    rajadain committed Aug 26, 2019
    Copy the full SHA
    7c508c2 View commit details
    Browse the repository at this point in the history
  2. Recalculate Area derived values in back-end

    Previously, when the user would override Land Use values,
    we would only update the Area list in the MapShed dict.
    However, there are a number of other fields in the dict
    whose values are derived from the Area list, which were
    not updated.
    
    The derivation of those fields is now extracted into its
    own method, which is called in the initialization of the
    dict, as well as during ingestion of modifications from
    the user. If the set of modifications contains updates
    to the land use distribution, then the area derived
    fields are recalculated.
    
    Notably, the LS calculation is not included in this
    refactor. This is because while it does derive its value
    from Area, it is also dependent on the geoprocessing
    result of `lu_stream_pct`, which isn't saved anywhere.
    Because of that, we cannot adjust its value with new
    proportions when the user updates land use changes.
    Amending this would require a larger refactor, which is
    deferred to a later date.
    
    The test introduced in the previous commit serves to
    ensure that this refactoring does not alter the
    calculations.
    rajadain committed Aug 26, 2019
    Copy the full SHA
    7e2316b View commit details
    Browse the repository at this point in the history
  3. Recalculate Area derived values in front-end

    The changes made in the previous commit recalculate the
    derived values for running the MapShed model. The changes
    in this commit recalculate them for the data model in the
    front-end, which allows for other modifications to pick up
    on the land use changes.
    
    For example, if the user changes the area of Cropland in
    the Land Cover modal, the Area of Row Crops should change
    correspondingly for the respective Conservation Practices.
    This will now happen, as `n23` (the model field representing
    the Area of Row Crops), amongst others, is now updated.
    rajadain committed Aug 26, 2019
    Copy the full SHA
    baccd9f View commit details
    Browse the repository at this point in the history