Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Importing and Exporting Systems

  1. All Infrasys systems can be serialized and deserialized using the to_json and from_json methods.

  2. The DistributionSystem class can also be exported to GeoDataFrame and GeoJSON formats using the to_gdf and to_geojson methods.

We start by loading a sample distribution system.

from gdm.distribution import DistributionSystem
from gdmloader.constants import GCS_CASE_SOURCE
from gdmloader.source import SystemLoader

gdm_loader = SystemLoader()
gdm_loader.add_source(GCS_CASE_SOURCE)

distribution_system: DistributionSystem = gdm_loader.load_dataset(
    source_name=GCS_CASE_SOURCE.name,
    system_type=DistributionSystem,
    dataset_name="p5r",
)
distribution_system.name = "P5R"
/opt/homebrew/Caskroom/miniconda/base/envs/gdm2/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py:502: UserWarning: Ellipsis is not a Python type (it may be an instance of an object), Pydantic will allow any object with no validation since we cannot even enforce that the input is an instance of the given type. To get rid of this error wrap the type with `pydantic.SkipValidation`.
  warn(

The DistributionSystem can be serialized to disk using the to_json method. If the model already exists, set the overwrite parameter to True. Serialization ensures no loss of information. The JSON file can be deserialized using the from_json method.

distribution_system.to_json("test.json", overwrite=True)
system = DistributionSystem.from_json("test.json")

The DistributionSystem can also be exported in GeoDataFrame and GeoJSON formats.

system.to_gdf(“test.csv”) system.to_geojson(“test.geojson”)

system.to_gdf("test.csv")
system.to_geojson("test.geojson")