Open abbaad opened 5 years ago
It has already been implemented in all Honeybee objects. After creating an analysis recipe try .to_json() method which will give you the JSON data. Write the JSON object to a file and follow the sample code in honeybee-server-daylight to submit it for simulation.
There are some objects which don't currently get serialized properly (e.g., RadianceNumberType
) and some which can't be serialized without some architectural changes (e.g., StaticScene
s which refer to .rad
files that aren't machine-relocatable)
There are some objects which don't currently get serialized properly (e.g., RadianceNumberType)
I'm not sure why would you need to serialize RadianceNumberType. Just use it's value (number) and it will be fine.
some which can't be serialized without some architectural changes (e.g., StaticScenes which refer to .rad files that aren't machine-relocatable)
This is True. All was an overestimation. Also XML files are not currently supported. If you want to go ahead and add support for missing objects that would be a great but I suggest to hold on for now as the overall workflow is currently under being redesigned and some of these objects will not look the same including the StaticScene class.
I'm not sure why would you need to serialize RadianceNumberType. Just use it's value (number) and it will be fine.
RadianceNumberType
is currently the type of some member variables for objects which are supposedly serialized by to_json()
, but since it's not natively serializable, you can't get a JSON string out of it using python's json
module.
If I remember correctly we only use those types for Radiance parameters and we change radiance parameters to string in JSON objects. Do you have an example where this type creates an issue?
Do you have an example where this type creates an issue?
Maybe I'm using the interface wrong. But here's an example of what I mean:
import json
...
_analysisRecipe.hb_objects = _HBObjects
_analysisRecipe.scene = radScene_
serialized = _analysisRecipe.to_json()
print type(serialized['surfaces'][0]['surface_material']['specularity'])
# Error in following line, because json.dumps cant't handle RadianceNumberType
string_to_POST = json.dumps(serialized)
Which gives the following output:
Found 1 opaque surfaces.
Found 0 fenestration surfaces.
Found 0 window-groups.
<class 'honeybee.radiance.datatype.RadianceNumberType'>
Runtime error (TypeErrorException): 0.0 is not JSON serializable
This is a bug in how to_json is written for the materials. Interesting that I have never faced this issue. 😕
Semi-related question: is it infeasible to import
3rd party libraries because of the way Grasshopper usually works? Specifically, I'm asking about jsonpickle.
Do you mean for honeybee core library or in general?
For Honeybee we have to keep it compatible with IronPython but if you want to run it from command line or write your own script and run it outside Grasshopper/IronPython there will be no limitations.
Sorry, I had meant for honeybee core. I wasn't sure if external dependencies are permitted by your code guidelines.
HoneybeeCore is also used in Grasshopper and therefore must be able to run in IronPython and not install dependencies via pip
. An example of an existing dependency (sort of) is in the ladybug repo where the Euclid package has been copied into the repository.
Is anyone currently working on the JSON serialization-deserialization to get honeybee working better with honeybee-server-daylight?
If not, I'd like to try working on this enhancement (at least in a hackish way to test honeybee-server-daylight for my own needs first).