Add cohort data exporter from PlantsModel#912
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #912 +/- ##
===========================================
+ Coverage 93.89% 94.00% +0.10%
===========================================
Files 77 78 +1
Lines 5912 6067 +155
===========================================
+ Hits 5551 5703 +152
- Misses 361 364 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dalonsoa
left a comment
There was a problem hiding this comment.
Conceptually, I think this approach makes sense, leaving up to the model to export some of the data relevant for it. My only concern is if the data it exports might be ever be updated by a model run after plats within the same timestep. I wonder if it would be better to have an export step that is run for every model after all the updates are done.
After all the updates are done within a time step. That's an interesting idea that I think might be useful. In this specific case, we're intending to exporting the internal cohort structure and tree allometry, which is only under the control of the plants model, and indeed isn't exposed to the other models through But... I think we could revisit this same structure and make it part of the BaseModel to create model exporter methods for dumping internal model state. I'm just not keen to do that now 😄 |
…porter-from-plantsmodel
dalonsoa
left a comment
There was a problem hiding this comment.
I have a couple of comments, but it is broadly looking good.
| time=self.model_timing.start_time | ||
| + time_index * self.model_timing.update_interval, |
There was a problem hiding this comment.
It might come handy to add a simple method in the base model that returns the current time:
def current_time(self, time_index: int) -> int: # was this in epoch?
return self.model_timing.start_time + time_index * self.model_timing.update_intervalThere was a problem hiding this comment.
We need to revisit the timing in more detail but this is a good idea.
Co-authored-by: Diego Alonso Álvarez <6095790+dalonsoa@users.noreply.github.com>
for more information, see https://pre-commit.ci
…://github.com/ImperialCollegeLondon/virtual_rainforest into 911-add-cohort-data-exporter-from-plantsmodel
|
@sallymatson I've finished updating from @dalonsoa's review now. Diego - your suggestions have simplified the code and testing quite a bit. Nothing hugely changed but just more polished, I think. |
|
Hi @davidorme, I just had a look at this, the exporter looks very neat and will be super useful for looking at the outputs! |
Description
This PR introduces the
models.plants.exportermodule that provides a theCommunityDataExportertool for plant community data. This data could be worked into thedataobject and exported by the standard mechanism, but the data is not used by any other model and consists of sets of highly ragged arrays of community data per cell that is much more suited to a data frame style export than the DataArray format.There are three kinds of data:
Each of those different classes has a bunch of attributes that are stored within the
communities,canopiesandstem_allocationattributes within the Plants Model.So, this PR:
Adds the new exporter class
CommunityDataExplorerwith:__init__method that the settings above directlyfrom_configfactory method that creates an instance from the settings loaded in a Config object.dumpmethod that can be called to compile and output the three data types to CSV file. It switches from write to append mode after first use to avoid duplicating column headers.Updates
PlantsModelto require aCommunityDataExplorerobject at__init__and then to call thedump()method at the end of model setup and in each update.Adds a bunch of tests in
tests.models.plants.test_explorer.pyFixes #911 (issue)
Type of change
Key checklist
pre-commitchecks:$ pre-commit run -a$ poetry run pytestFurther checks