Skip to content

Commit

Permalink
fix(model): Add support for serializing more geoJSON attributes
Browse files Browse the repository at this point in the history
I am also fixing some issues with the default tolerances applied in the from_geojson pathway. And I am adding methods for serializing to/from JSON and pkl.
  • Loading branch information
chriswmackey committed Mar 9, 2021
1 parent 265ceb0 commit e02fb7d
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 102 deletions.
16 changes: 4 additions & 12 deletions dragonfly/cli/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ def convert_units(model_json, units, scale, output_file):
Choose from (Meters, Millimeters, Feet, Inches, Centimeters).
"""
try:
# serialize the Model to Python
with open(model_json) as json_file:
data = json.load(json_file)
parsed_model = Model.from_dict(data)

# convert the units of the model
# serialize the Model and convert the units
parsed_model = Model.from_file(model_json)
if scale:
parsed_model.convert_to_units(units)
else:
Expand Down Expand Up @@ -89,12 +85,8 @@ def solve_adjacency(model_json, surface, no_intersect, output_file):
model_json: Full path to a Model JSON file.
"""
try:
# serialize the Model to Python
with open(model_json) as json_file:
data = json.load(json_file)
parsed_model = Model.from_dict(data)

# check the Model tolerance
# serialize the Model and check tolerance
parsed_model = Model.from_file(model_json)
assert parsed_model.tolerance != 0, \
'Model must have a non-zero tolerance to use solve-adjacency.'
tol = parsed_model.tolerance
Expand Down
4 changes: 1 addition & 3 deletions dragonfly/cli/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def model_to_honeybee(model_json, obj_per_model, multiplier, no_plenum, no_cap,
preparedir(folder, remove_content=False)

# re-serialize the Dragonfly Model
with open(model_json) as json_file:
data = json.load(json_file)
model = Model.from_dict(data)
model = Model.from_file(model_json)
model.convert_to_units('Meters')

# convert Dragonfly Model to Honeybee
Expand Down
4 changes: 1 addition & 3 deletions dragonfly/cli/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def validate_model(model_json):
schema_model.Model.parse_file(model_json)
click.echo('Pydantic validation passed.')
# re-serialize the Model to make sure no errors are found in re-serialization
with open(model_json) as json_file:
data = json.load(json_file)
parsed_model = Model.from_dict(data)
parsed_model = Model.from_dfjson(model_json)
click.echo('Python re-serialization passed.')
# perform several other checks for key dragonfly model schema rules
parsed_model.check_duplicate_building_identifiers(raise_exception=True)
Expand Down

0 comments on commit e02fb7d

Please sign in to comment.