-
Notifications
You must be signed in to change notification settings - Fork 132
support hdf5 serialization/unserialization of all the world data #153
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
Changes from all commits
ede042b
8892241
d58ef5b
8ea4166
e4bb632
2d887f6
5e5e59c
9a67eda
7f9c177
7803ee5
3f7f629
867fcf7
1b80850
1c45746
b911d00
fcba3a8
ec83aa7
6d4206f
e0b8a8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| $URL = http://www.hdfgroup.org/ftp/HDF5/current/bin/windows/hdf5-1.8.15-patch1-win32-vs2013-shared.zip | ||
|
|
||
| function main () { | ||
| $basedir = $pwd.Path + "\" | ||
| $filename = "hdf5.zip" | ||
| $filepath = $basedir + $filename | ||
| Write-Host "Downloading" $filename "from" $URL | ||
| $retry_attempts = 3 | ||
| for($i=0; $i -lt $retry_attempts; $i++){ | ||
| try { | ||
| $webclient.DownloadFile($URL, $filepath) | ||
| break | ||
| } | ||
| Catch [Exception]{ | ||
| Start-Sleep 1 | ||
| } | ||
| } | ||
| $outpath = $basedir + "\hdf5_unzipped" | ||
| [System.IO.Compression.ZipFile]::ExtractToDirectory($filepath, $outpath) | ||
| $msipath = $outpath + "\HDF5-1.8.15-win64.msi" | ||
| Invoke-Command -ScriptBlock { & cmd /c "msiexec.exe /i $msipath" /qn ADVANCED_OPTIONS=1 CHANNEL=100} | ||
| } | ||
|
|
||
| main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # For export support, you'll need HDF5 | ||
| -r requirements.txt | ||
| h5py==2.5.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,10 @@ | |
| from worldengine.plates import Step, world_gen | ||
| from worldengine.world import World | ||
| from worldengine.common import _equal | ||
| import tempfile | ||
| import os | ||
| from worldengine.hdf5_serialization import save_world_to_hdf5, load_world_to_hdf5 | ||
|
|
||
|
|
||
| class TestSerialization(unittest.TestCase): | ||
|
|
||
|
|
@@ -32,6 +36,41 @@ def test_protobuf_serialize_unserialize(self): | |
| self.assertEqual(sorted(dir(w)), sorted(dir(unserialized))) | ||
| self.assertEqual(w, unserialized) | ||
|
|
||
| def test_hdf5_serialize_unserialize(self): | ||
| filename = None | ||
| try: | ||
| w = world_gen("Dummy", 32, 16, 1, step=Step.get_by_name("full")) | ||
| f = tempfile.NamedTemporaryFile(delete=False) | ||
| f.close() | ||
| filename = f.name | ||
| serialized = save_world_to_hdf5(w, filename) | ||
| unserialized = load_world_to_hdf5(filename) | ||
| self.assertTrue(_equal(w.elevation['data'], unserialized.elevation['data'])) | ||
| self.assertEqual(w.elevation['thresholds'], unserialized.elevation['thresholds']) | ||
| self.assertTrue(_equal(w.ocean, unserialized.ocean)) | ||
| self.assertTrue(_equal(w.biome, unserialized.biome)) | ||
| self.assertTrue(_equal(w.humidity['quantiles'], unserialized.humidity['quantiles'])) | ||
| self.assertTrue(_equal(w.humidity['data'], unserialized.humidity['data'])) | ||
| self.assertTrue(_equal(w.humidity, unserialized.humidity)) | ||
| self.assertTrue(_equal(w.irrigation, unserialized.irrigation)) | ||
| self.assertTrue(_equal(w.permeability, unserialized.permeability)) | ||
| self.assertTrue(_equal(w.watermap, unserialized.watermap)) | ||
| self.assertTrue(_equal(w.precipitation['thresholds'], unserialized.precipitation['thresholds'])) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The _equal() method works recursively, so these manual "extractions" shouldn't be necessary (the other formats don't do it, either).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but when something is wrong I can find out immediately what it is. That is why I prefer to have also the single fields comparisons. For example this line: would make these lines redundant: However these lines tell me if I had a problem serializing/unserializing the humidity data or the humidity quantiles
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that might be a valid reason. Although this certainly makes maintenance more difficult and the gain isn't too big. |
||
| self.assertTrue(_equal(w.precipitation['data'], unserialized.precipitation['data'])) | ||
| self.assertTrue(_equal(w.precipitation, unserialized.precipitation)) | ||
| self.assertTrue(_equal(w.temperature, unserialized.temperature)) | ||
| self.assertTrue(_equal(w.sea_depth, unserialized.sea_depth)) | ||
| self.assertEquals(w.seed, unserialized.seed) | ||
| self.assertEquals(w.n_plates, unserialized.n_plates) | ||
| self.assertTrue(_equal(w.ocean_level, unserialized.ocean_level)) | ||
| self.assertTrue(_equal(w.lake_map, unserialized.lake_map)) | ||
| self.assertTrue(_equal(w.river_map, unserialized.river_map)) | ||
| self.assertEquals(w.step, unserialized.step) | ||
| self.assertEqual(sorted(dir(w)), sorted(dir(unserialized))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comparison part should be moved to its own function. I think this piece of code exists three times now. And should another save-format ever be supported, things would get even messier. EDIT: Yes, three times.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think this code has to be moved into its own function to then replace the tests for all formats. |
||
| #self.assertEqual(w, unserialized) | ||
| finally: | ||
| if filename: | ||
| os.remove(filename) | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
tox.inithere is a different numpy-version used that looks like it is newer than the highest version here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is true. Here the version has been chosen to make AppVeyor happy. Version 1.10.1 has no wheels packages available. However version 1.10.1 was working on Travis. Let me check if other version works on Travis too.