Repository navigation
Conversation
…the dataset Comparing an xarray.Dataset to None with '==' is element-wise and yields a truthy Dataset, so the cache guard was true on every call and the weather file was reopened and fully loaded on every routing step. Add a regression test that counts xr.open_dataset calls across repeated get_weather_data() calls.
|
Dear user, |
|
Hi @kdemmich, thanks for the pointer and for taking a look. I read through the CLA guidelines, and as far as I can tell the agreement has to be printed, signed and sent by post to 52°North in Germany. I'm a student in India and that's unfortunately not really feasible for me, so I won't be able to complete the CLA in its current form. If an electronically signed scan sent by email would be acceptable, let me know and I'll send one right away. Otherwise, feel free to close this PR. Thanks again! |
9e927a0 to
02fee5c
Compare
|
Dear @amanbn8, |
Related Issue / Discussion:
Fixes Issue #213
Changes:
WeatherRoutingTool/ship/ship.py:Boat.get_weather_data()now checksself.weather_data is Noneinstead of== None.tests/test_ship.py: new testtest_get_weather_data_opens_file_only_oncethat wrapsxr.open_datasetwith a counter, callsget_weather_data()twice on aConstantFuelBoat, and checks that the file is opened once and the same Dataset object is returned both times.Further Details:
Summary:
get_weather_data()is documented as opening the weather NetCDF once and caching it. The guard compared anxarray.DatasettoNonewith==, which xarray evaluates element-wise and returns a Dataset that is truthy. So after the first call the condition stayed true and the file was reopened and fully loaded on every call, from every routing step, for both the isobased and genetic algorithms.Before:
xr.open_datasetis called once perget_weather_data()call, and each call returns a new Dataset.After: the file is opened once per
Boatinstance and the cached Dataset is returned on later calls, which is what the docstring already describes.The new test fails on
main(two calls toopen_dataset, two different objects) and passes with the fix. flake8 runs clean on both files with the repo's settings.Dependencies:
None.
PR Checklist:
In the context of this PR, I: