Skip to content

Commit 4d2d23a

Browse files
committed
update analysis function
1 parent 75fd966 commit 4d2d23a

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

examples/AnalysisThermoML.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,14 @@
522522
},
523523
{
524524
"cell_type": "code",
525-
"execution_count": 3,
525+
"execution_count": 5,
526526
"metadata": {},
527527
"outputs": [],
528528
"source": [
529-
"# Extract density data over the composition of choline chloride for different temperatures\n",
530-
"density_data = datareport.analysis_property_over_composition( component = \"choline chloride\",\n",
531-
" prop_name = \"Mass density\"\n",
532-
" )"
529+
"# Extract density data of the whole system\n",
530+
"density_data = datareport.analysis_property( prop_name = \"Mass density\",\n",
531+
" prop_identifier = \"\"\n",
532+
" )"
533533
]
534534
},
535535
{
@@ -541,7 +541,7 @@
541541
},
542542
{
543543
"cell_type": "code",
544-
"execution_count": 4,
544+
"execution_count": 8,
545545
"metadata": {},
546546
"outputs": [
547547
{
@@ -558,8 +558,8 @@
558558
"source": [
559559
"fig, ax = plt.subplots()\n",
560560
"\n",
561-
"for _,df in density_data.groupby(\"composition\"):\n",
562-
" ax.errorbar( df[\"Temperature, K\"], df[\"mean\"], df[\"95_confidence\"]/2, label=r'$x_\\mathrm{Ch^+,Cl^-} =$' + f'{df[\"composition\"].iloc[0]}' )\n",
561+
"for _,df in density_data.groupby(\"Mole fraction of choline chloride\"):\n",
562+
" ax.errorbar( df[\"Temperature, K\"], df[\"mean\"], df[\"95_confidence\"]/2, label=r'$x_\\mathrm{Ch^+,Cl^-} =$' + f'{df[\"Mole fraction of choline chloride\"].iloc[0]}' )\n",
563563
"ax.legend()\n",
564564
"ax.set_xlabel(\"Temperature / K\")\n",
565565
"ax.set_ylabel(\"Density / kg m$^{-3}$\")\n",

examples/AnalysisThermoML2.ipynb

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,14 @@
119119
},
120120
{
121121
"cell_type": "code",
122-
"execution_count": 3,
122+
"execution_count": 4,
123123
"metadata": {},
124-
"outputs": [
125-
{
126-
"name": "stdout",
127-
"output_type": "stream",
128-
"text": [
129-
"exists\n"
130-
]
131-
}
132-
],
124+
"outputs": [],
133125
"source": [
134-
"# Extract molality data of carbon dioxide over the composition of choline chloride\n",
135-
"molality_data = datareport.analysis_property_over_composition( component = \"choline chloride\",\n",
136-
" prop_name = \"Molality\",\n",
137-
" prop_identifier = \"carbon dioxide\"\n",
138-
" )"
126+
"# Extract molality data of carbon dioxide\n",
127+
"molality_data = datareport.analysis_property( prop_name = \"Molality\",\n",
128+
" prop_identifier = \"carbon dioxide\"\n",
129+
" )"
139130
]
140131
},
141132
{
@@ -147,7 +138,7 @@
147138
},
148139
{
149140
"cell_type": "code",
150-
"execution_count": 20,
141+
"execution_count": 6,
151142
"metadata": {},
152143
"outputs": [
153144
{
@@ -164,10 +155,10 @@
164155
"source": [
165156
"fig, ax = plt.subplots( figsize = (12,8) )\n",
166157
"\n",
167-
"for _,df in molality_data.groupby(\"composition\"):\n",
158+
"for _,df in molality_data.groupby(\"Solvent: Mole fraction of choline chloride\"):\n",
168159
"\n",
169160
" for _, dff in df.groupby(\"Temperature, K\"):\n",
170-
" ax.errorbar( dff[\"Pressure, kPa\"]*1000, dff[\"mean\"],dff[\"95_confidence\"]/2, label=r'$x_\\mathrm{Ch^+,Cl^-} =$' + f'{dff[\"composition\"].iloc[0]}; T = {dff['Temperature, K'].iloc[0]}' )\n",
161+
" ax.errorbar( dff[\"Pressure, kPa\"]*1000, dff[\"mean\"],dff[\"95_confidence\"]/2, label=r'$x_\\mathrm{Ch^+,Cl^-} =$' + f'{dff[\"Solvent: Mole fraction of choline chloride\"].iloc[0]}; T = {dff['Temperature, K'].iloc[0]}' )\n",
171162
"\n",
172163
"ax.legend()\n",
173164
"ax.set_xlabel(\"Pressure / Pa\")\n",

pyThermoML/core/datareport.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,25 +480,21 @@ def get_all_data(self, verbose: bool = True):
480480

481481
return final
482482

483-
def analysis_property_over_composition(
483+
def analysis_property(
484484
self,
485-
component: str | int,
486485
prop_name: str,
487486
prop_identifier: str = "",
488487
):
489488
"""
490-
Analyzes a specific property over the composition of a component in a DataReport.
489+
Analyzes a specific property in a DataReport.
491490
492491
Parameters:
493-
component (str|int): The (common) name of the component, or the reg num identifier of it.
494492
prop_name (str): The name of the property to analyze. This can also be a substring of the property.
495493
prop_identifier (RegNum, optional): Component identifier for the property. Defaults to "".
496494
497495
Returns:
498496
pd.DataFrame: A DataFrame containing the analyzed property values over the composition of the component.
499497
"""
500-
# Get reg_num identifier for component
501-
identifier = self.get_reg_num(component)
502498

503499
# Get reg_num for property identifier
504500
property_identifier = self.get_reg_num(prop_identifier)
@@ -518,17 +514,23 @@ def analysis_property_over_composition(
518514
# Check if property exists in pure of mixture data
519515
if pomd.property_exists(prop_name, property_identifier):
520516

521-
# Get composition
522-
composition = pomd.get_composition(identifier, id_dict)
523517

524518
# Get properties
525519
prop_df = pomd.get_property()
520+
521+
# Get variables
526522
variables = pomd.get_variables()
527523

528524
for variable in variables:
529525
prop_df[variable["type"]] = variable["values"]
530-
531-
prop_df["composition"] = [composition] * prop_df.shape[0]
526+
527+
# Get constraints
528+
constraints = pomd.get_constraints()
529+
530+
for const in constraints:
531+
txt = f'{const["type"]} of'
532+
txt += f' {id_dict[const["component_identifier"].n_org_num][0] if const["component_identifier"].n_org_num else "system"}'
533+
prop_df[txt] = [const["value"]] * prop_df.shape[0]
532534

533535
final.append(prop_df)
534536

0 commit comments

Comments
 (0)