Skip to content

Commit

Permalink
first_overwork
Browse files Browse the repository at this point in the history
  • Loading branch information
samirdarouich committed Oct 27, 2023
1 parent 8cc89ed commit 07c15ac
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 399 deletions.
Binary file added .DS_Store
Binary file not shown.
107 changes: 31 additions & 76 deletions 1.1_Main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from pathlib import Path\n",
"from sdRDM import DataModel"
]
Expand All @@ -42,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -51,91 +52,28 @@
"# lib = DataModel.from_markdown('specifications/datamodel_b07_tc.md')"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Instantiate ```Dataset``` class of the data model. It is the root class of the data model containing all the other classes. The yet empty dataset is printed to showcase its structure in json format."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note that there is a fundamental difference between a dataset and a data model! Whereas the data model holds the hierarchically structured python classes created by sdRDM, the dataset comprises only the python classes that are instantiated yet, where multiple instances of the same class can be allowed.**"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"id\": \"dataset0\",\n",
" \"__source__\": {\n",
" \"root\": \"Dataset\",\n",
" \"repo\": \"https://github.com/FAIRChemistry/datamodel_b07_tc.git\",\n",
" \"commit\": \"8d0ead376455dd3dd946d6ba534438a14ffcb7ae\",\n",
" \"url\": \"https://github.com/FAIRChemistry/datamodel_b07_tc/tree/8d0ead376455dd3dd946d6ba534438a14ffcb7ae\"\n",
" }\n",
"}\n"
]
}
],
"source": [
"dataset = lib.Dataset()\n",
"print(dataset.json())"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Instantiate further classes of the data model and filling them with content, for example the title of the project, the authors and a project description into the data model. A class can either be instantiated ```empty``` , where the content is added ```afterwards```,"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"gen_inf = lib.GeneralInformation()\n",
"title = 'Electrocatalytic CO2-reduction on carbon'\n",
"gen_inf.title = title\n",
"description = 'The aim of this project is to blablabla'\n",
"gen_inf.description = description"
"dataset.general_information.add_to_authors"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"or ```directly``` when the object is ```created```."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"author_1 = lib.Author(name= 'Richard Schömig', affiliation = 'University of Stuttgart')\n",
"author_2 = lib.Author(name= 'Maximilian Schmidt', affiliation = 'University of Stuttgart')\n",
"gen_inf.authors = [author_1, author_2]"
"Instantiate ```Dataset``` class of the data model. It is the root class of the data model containing all the other classes. The yet empty dataset is printed to showcase its structure in json format."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ```general_information``` is subsequently added to the dataset."
"**Note that there is a fundamental difference between a dataset and a data model! Whereas the data model holds the hierarchically structured python classes created by sdRDM, the dataset comprises only the python classes that are instantiated yet, where multiple instances of the same class can be allowed.**"
]
},
{
Expand All @@ -144,14 +82,27 @@
"metadata": {},
"outputs": [],
"source": [
"dataset.general_information = gen_inf"
"## Initialize the dataset ##\n",
"\n",
"dataset = lib.Dataset()\n",
"\n",
"# Define name of the project, description as well as authors #\n",
"dataset.general_information.title = 'Electrocatalytic CO2-reduction on carbon'\n",
"dataset.general_information.description = 'The aim of this project is to blablabla'\n",
"\n",
"# List with authors and their affiliation #\n",
"authors = [ 'Richard Schömig', 'Maximilian Schmidt' ] \n",
"affiliations = [ 'University of Stuttgart', 'University of Stuttgart' ]\n",
"\n",
"for aut,aff in zip(authors,affiliations):\n",
" dataset.general_information.add_to_authors( name=aut, affiliation=aff )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The framework of the dataset is with some metadata about the project is now set up and will be stored in a json file in the ```datasets/``` directory."
"General metadata about the project is now added in the dataset and will be stored in a json file in the ```datasets/``` directory."
]
},
{
Expand All @@ -160,12 +111,16 @@
"metadata": {},
"outputs": [],
"source": [
"current_directory = Path.cwd()\n",
"path_to_datasets = current_directory / 'datasets'\n",
"# Define name of dataset #\n",
"dataset_name = 'b07.json'\n",
"\n",
"# Define output folder #\n",
"path_to_datasets = Path.cwd() / 'datasets'\n",
"path_to_dataset_file = path_to_datasets / dataset_name\n",
"with open(path_to_dataset_file, \"w\") as f:\n",
" f.write(dataset.json())"
"\n",
"# Write file #\n",
"if not os.path.exists(path_to_datasets): os.makedirs(path_to_datasets)\n",
"with open(path_to_dataset_file, \"w\") as f: f.write(dataset.json())"
]
}
],
Expand All @@ -185,7 +140,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
"version": "3.11.5"
},
"orig_nbformat": 4
},
Expand Down
Loading

0 comments on commit 07c15ac

Please sign in to comment.