samuelduchesne / pyumi

open and edit UMI projects with Python
4 stars 4 forks source link

Umi for Rhino does not preserve project.json structure, leading to incorrect behavior when reopening in pyumi #140

Open szvsw opened 2 years ago

szvsw commented 2 years ago

As alluded to in #139 , when you open a project in Umi for Rhino and then save it, project.json is mutated, however most of its structure is not preserved. Any previous user data from the original gdf is lost - the data that is preserved in the features table always has this schema:

features::[entry]::properties: {
    "FloorCount": 2,
    "GrossFloorArea": 307.16432571551132,
    "Height": 6.0,
    "Name": "23793",
    "Occupancy": 7,
    "TemplateName": "B_Res_0_Masonry",
    "UseType": "Residential and Lodging",
    "WwrE": 0.2,
    "WwrN": 0.2,
    "WwrS": 0.2,
    "WwrW": 0.2
}

Note that the WWR column names are different from what add_default_shoebox_settings expects, and additionally the "advanced" column settings are missing: CoreDepth, PerimeterOffset, Fdist, Envr, RoomWidth, FloorToFloorheight, FloorToFloorStrictTrue, EnergySimulatorName

    DEFAULT_SHOEBOX_SETTINGS = {
        "CoreDepth": 3,
        "Envr": 1,
        "Fdist": 1, 
        "FloorToFloorHeight": 3.0,
        "PerimeterOffset": 3.0,
        "RoomWidth": 3.0,
        "WindowToWallRatioE": 0.4,
        "WindowToWallRatioN": 0.4,
        "WindowToWallRatioRoof": 0,
        "WindowToWallRatioS": 0.4,
        "WindowToWallRatioW": 0.4,
        "TemplateName": np.NaN,
        "EnergySimulatorName": "UMI Shoeboxer (default)",
        "FloorToFloorStrict": True,
    }

So -

If you want to update the TemplateName column for instance using pyumi, you would call:

umi.gdf_3dm["TemplateName"] = some_new_series
umi.add_default_shoebox_settings() # Add the defaults or using existing columns if present
umi.update_umi_sqlite3()
umi.save("updated_umi_project.umi")

However, the original WWR settings and advanced building settings would all be overwritten, since add_default_shoebox_settings would not find the expected column names.

For the Wwrs, it would be easy enough to have add_default_shoebox_settings map the Wwwr<dir> columns to WindowToWallRatio<dir>, however I am not sure where the advanced settings are stored (probably need to make calls to the sqlite db?)

This is partially just a symptom of a larger issue of Umi for Rhino not preserving the original gdf structure in project.json, however the issue would still exist with a project natively created in Rhino.

szvsw commented 2 years ago

I also confirmed that user data (besides OriginalProjectedOrigin) is dropped from project-settings.json when saving an umi file in Umi for Rhino.

However custom user json files in sdl-common are not dropped - umi.sdl_common["my_data"] = {"template_map: template_map"} is sufficient to cache data with pyumi since umi.sdl_common's individual keys are dumped to json files in sdl-common.

We could use this approach to preserve and merge the geodataframe as well, however I think we should wait to see if the behavior described above is in spec or out of spec (i.e. project.json not preserving original data)

szvsw commented 2 years ago

As per Cody's message here, storing other data in project.json is considered out of spec for UMI, so I believe that means this issue needs to be resolved by changing the Open and Save methods to handle reading/writing data from a file in sdl-common other than project.json if we want the ability to preserve GIS information.