Skip to main content

Tools to manipulate the IDSPy Dictionaries

Project description

This module contains a serie of function to help mange and manipulate IDSPy dataclasses

  • fill_missing_values

  • ids_to_hdf5

  • hdf5_to_ids

  • get_ids_value_from_string

  • set_ids_value_from_string

  • list_ids_members

  • copy_ids

Please note that this work is still under progress/heavy development and as experimental status. This means that functions arguments/signatures as long as HDF5 structure might be totally redesigned in the next updates.

## Quick example

 1  import pprint
 2  import dataclasses
 3 
 4  import idspy_toolkit
 5  from idspy_dictionaries import ids_gyrokinetics_local as gkids
 6 
 7  pp = pprint.PrettyPrinter(indent=2)
 8 
 9  ids_test = gkids.GyrokineticsLocal()
10  # you can directly print the class to see what it looks like  :
11  pp.pprint(ids_test)
12 
13  # if you want to see all the available classes in the current module :
14  ids_dict = idspy_toolkit.list_ids_members(gkids)
15  pp.pprint(ids_dict)
16 
17  #to fill an IDS with default values following IMAS standard
18  idspy_toolkit.fill_missing_values(ids_test)
19 
20  # you can use the . to access ids members :
21  pp.pprint(ids_test.ids_properties)
22 
23  # and to set a value :
24  ids_test.ids_properties.comment="a comment"
25 
26  # if in a script you want to reach a "deeper" value, you can use the function *get_ids_value_from_string*
27  idspy_toolkit.get_ids_value_from_string(ids_test, "ids_properties/comment")
28  # and for list element, put the element index after an #
29  idspy_toolkit.get_ids_value_from_string(ids_test, "tag#0/name")
30 
31  # same kind of function exist to set a value :
32  idspy_toolkit.set_ids_value_from_string(ids_test, "tag#0/name", "a new tag name")
33 
34  # to print the ids as a dictionary ( better with a vertical screen ;)):
35  ids_dict = dataclasses.asdict(ids_test)
36  pp.pprint(ids_dict)
37 
38  # HDF5 Operations Example
39  # Save IDS to HDF5 file (will raise IOError if file exists)
40  idspy_toolkit.ids_to_hdf5(ids_test, "my_ids.h5")
41 
42  # Save with overwrite option and array size constraints
43  idspy_toolkit.ids_to_hdf5(ids_test, "my_ids.h5",
44                           overwrite=True,          # Overwrite existing file
45                           max_array_dim=2,         # Maximum array dimensions
46                           max_array_size=100,      # Maximum size in MB
47                           max_array_elements=1000) # Maximum number of elements
48 
49  # Load IDS from HDF5 file with constraints
50  loaded_ids = idspy_toolkit.hdf5_to_ids("my_ids.h5",
51                                        ids_gyrokinetics.Gyrokinetics,
52                                        fill=True,           # Fill missing values with defaults
53                                        todict=True,         # Convert XML strings to dictionaries
54                                        max_array_dim=2,     # Maximum array dimensions to load
55                                        max_array_size=100,  # Maximum array size in MB
56                                        max_array_elements=1000) # Maximum number of elements

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

idspy_toolkit-1.0.1.tar.gz (38.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

idspy_toolkit-1.0.1-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file idspy_toolkit-1.0.1.tar.gz.

File metadata

  • Download URL: idspy_toolkit-1.0.1.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for idspy_toolkit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1e65ee60319deba588c8b3d439d58b04a994e43f1c0a9f874e1f9d61fb97566d
MD5 0b3d1ce795acdc830298179518866315
BLAKE2b-256 16c5bbb5cda691ea3d94a96d50fbfecc0c4f3bd194123a70a5b7f4fdfa0b68b3

See more details on using hashes here.

File details

Details for the file idspy_toolkit-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: idspy_toolkit-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.10

File hashes

Hashes for idspy_toolkit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2bafe1ad5797640139dbb42b18bc8acd34600765c0a8baf18bc2d93a8a5578cf
MD5 fb3a040244c406d3de92d8f6c5ffef97
BLAKE2b-256 2a829adba58271ae43aed16ca3d4437620a2cb551bbce2f8f53e1182857b9e9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page