Skip to content

Commit

Permalink
overwork ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
samirdarouich committed Mar 6, 2024
1 parent 2fe2705 commit 085bbc8
Show file tree
Hide file tree
Showing 9 changed files with 10,165 additions and 155 deletions.
Binary file modified .DS_Store
Binary file not shown.
15 changes: 12 additions & 3 deletions FAIRFlowChemistry/tools/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def read_pid(self,_):

def visualize_pid(self,_):
# Function that visualizes the PID as graph
self.read_pid(None)
# If plant is just initialized read in PID first
if not self.plant.components:
self.read_pid(None)
self.plant.visualize()

def save_dataset(self,_):
Expand Down Expand Up @@ -186,6 +188,15 @@ def dataset_input_handler(self,_):
with open(self.dataset_dropdown.value) as f:
self.dataset = Dataset.from_json(f)
self.experiments.value = [ exp.id for exp in self.dataset.experiments ]
self.plant = self.dataset.experiments[0].plant_setup if self.dataset.experiments else PlantSetup()

# Update component list
self.component_list = [ pl.component_id for pl in self.plant.components ]

if self.component_list:
with self.pid_output:
self.pid_output.clear_output(wait=False)
print("PID taken from first experiment of dataset!\n")
except:
raise KeyError("\nChoosen dataset cannot be interpreted!\n")

Expand Down Expand Up @@ -290,8 +301,6 @@ def choose_data(self, root: Path, dataset_directory: str) -> None:

# Initialize several objects
self.dataset_input_handler(None)
self.plant = PlantSetup()
self.component_list = [ ]
self.measurement_objects = [ ]
self.measurements.value = [ "Measurement 1" ]

Expand Down
13 changes: 6 additions & 7 deletions FAIRFlowChemistry/tools/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _calculate_real_volumetric_flow(self):
correction_factor_CO2 = self.experiment.get("species_data", "species", "Carbon dioxide")[0][0].correction_factor

volumetric_fraction_H = self.volumetric_fractions_df.loc["Hydrogen"].values[0]
volumetric_fraction_CO = self.volumetric_fractions_df.loc["Carbon Monooxide"].values[0]
volumetric_fraction_CO = self.volumetric_fractions_df.loc["Carbon monoxide"].values[0]

k1 = volumetric_fraction_H / correction_factor_H
k2 = ( 1 - volumetric_fraction_H + volumetric_fraction_CO ) / correction_factor_CO2
Expand Down Expand Up @@ -110,7 +110,7 @@ def _calculate_theoretical_material_flow(self):
and a factor describing the electron transfer for each species
"""
faraday_constant = const.physical_constants["Faraday constant"][0]
factors = { esd.species: esd.faraday_coefficient for esd in self.experiment.species_data }
factors = { esd.species: esd.electron_transfer for esd in self.experiment.species_data }
self.theoretical_material_flow_df = pd.DataFrame( index=[species for species in factors.keys()], columns = ["Theoretical_material_flow [mol/s]"] )

# Current_density i provided in mA/cm^2; Electrode surface A is given as cm^2 --> current I = i*A_surface * 1A / 1000mA [A]
Expand Down Expand Up @@ -176,10 +176,9 @@ def calculate_faraday_efficiencies(self, gc_measurement: Measurement):
faraday_efficiency_df = self.material_flow_df.divide( self.theoretical_material_flow_df["Theoretical_material_flow [mol/s]"], axis="index", ).rename(columns=rename) * 100
faraday_efficiency_df.dropna(inplace=True)

# Write into logger (but just in the first handler (which is the file handler))
logger.info("\n%s\n%s\n%s\n%s\n\n",
self.volumetric_fractions_df.to_string(),
(self.material_flow_df*60*1000).rename( columns={"Material_flow [mol/s]":"Material_flow [mmol/min]"}).to_string(),
(self.theoretical_material_flow_df*60*1000).rename( columns={"Theoretical_material_flow [mol/s]":"Theoretical_material_flow [mmol/min]"}).to_string())
# Write into logger
logger.info( self.volumetric_fractions_df.to_string() )
logger.info( (self.material_flow_df*60*1000).rename( columns={"Material_flow [mol/s]":"Material_flow [mmol/min]"}).to_string() )
logger.info( (self.theoretical_material_flow_df*60*1000).rename( columns={"Theoretical_material_flow [mol/s]":"Theoretical_material_flow [mmol/min]"}).to_string() )

return faraday_efficiency_df
103 changes: 11 additions & 92 deletions FAIRFlowChemistry/tools/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import os
import ipywidgets as widgets
from typing import List
from pathlib import Path
from IPython.display import display, clear_output

# Import Dataset
Expand All @@ -28,49 +26,17 @@ def save_dataset(self,_):
# Add project group
self.dataset.general_information.project = self.project.value

# Add authors to the dataset
for aut,aff,ident in zip( self.authors.value.split(","), self.affiliations.value.split(","), self.identifier.value.split(",") ):
self.dataset.general_information.add_to_authors( name = aut.strip(),
affiliation = aff.strip(),
identifier_scheme = self.identifier_scheme.value,
identifier = ident.strip() )

# Add contact (search contact in provided authors)
affili = [ aff for aut,aff in zip(self.authors.value.split(","), self.affiliations.value.split(",")) if aut.strip() == self.contact_text.value.split(",")[0].strip() ]
affili = affili[0] if bool(affili) else None

self.dataset.general_information.contact = dict( name = self.contact_text.value.split(",")[0].strip(),
email = self.contact_text.value.split(",")[1].strip(),
affiliation = affili )

# Add subject
self.dataset.general_information.subject = list( self.subject_selection.value )

# Add related publication
self.dataset.general_information.related_publication = dict( citation = self.related_publication.value.split(",")[0].strip(),
url = self.related_publication.value.split(",")[1].strip() )

# Add topic classifications (if provided)
if self.topic_classification.value:
for i in range(0, len(self.topic_classification.value.split(",")), 2):
self.dataset.general_information.add_to_topic_classification( value = self.topic_classification.value.split(",")[i].strip() ,
vocab_uri = self.topic_classification.value.split(",")[i + 1].strip() )

# Add keywords (if provided)
if self.keywords.value:
for i in range(0, len(self.keywords.value.split(",")), 2):
self.dataset.general_information.add_to_keywords( value = self.keywords.value.split(",")[i].strip() ,
vocabulary_uri = self.keywords.value.split(",")[i + 1].strip() )

# Write dataset #

# Add purpose
self.dataset.general_information.purpose = self.purpose.value

# Write dataset
os.makedirs( f"{os.getcwd()}/{os.path.dirname(self.dataset_text.value)}", exist_ok=True )
with open( "%s.json"%self.dataset_text.value, "w") as f: f.write(self.dataset.json())
with open( f"{os.getcwd()}/{self.dataset_text.value}.json", "w") as f: f.write(self.dataset.json())

def change_dataset(self,_):
self.button_save.description = 'Save dataset as: %s.json'%self.dataset_text.value

def write_dataset(self, subjects: List=[] ) -> None:
def write_dataset(self) -> None:

self.title = widgets.Text(description="Title of the project:",
placeholder="Type the title of the project",
Expand All @@ -87,55 +53,11 @@ def write_dataset(self, subjects: List=[] ) -> None:
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})

self.authors = widgets.Text(description="Author list:",
placeholder="Name the authors of the project (e.g.: author1, author2, ...)",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})

self.affiliations = widgets.Text(description="Affiliations:",
placeholder="Name the affiliation fo each author (e.g.: University of Stuttgart, TUM, ...)",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})


self.identifier_scheme = widgets.Dropdown(options= ["ORCID"],
description="Choose unique identifier scheme:",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})

self.identifier = widgets.Text(description="Unique identifier:",
placeholder="Provide identifier according to choosen identifier scheme (e.g. for ORCID: xxxx-xxxx-xxxx-xxxx) for every author",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})

self.contact_text = widgets.Text(description="Contact:",
placeholder="Name the contact of the project (e.g.: Max Mustermann, [email protected])",
self.purpose = widgets.Text(description="Purpose:",
placeholder="Purpose of this dataset",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})

self.subject_selection = widgets.SelectMultiple( options=subjects,
description="Choose subjects (press and hold 'strg' to select several):",
value=["Chemistry"],
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'} )

self.related_publication = widgets.Text (description="Related publication:",
placeholder="The full bibliographic citation for this related publication and link to the publication web page, separated by a comma (e.g.: M. Mustermann Publication: Test. J. Chem. Phys. xxx, xxx (xxx), https://doi.org/xxx )",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})


self.topic_classification = widgets.Text (description="Topic classification:",
placeholder="[Optional] The classification and the url, seperated by a comma (e.g.: homogeneous catalysis (LCSH), https://xxx, polyethers (LCSH), https://xxx, ... )",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})

self.keywords = widgets.Text (description="Keywords:",
placeholder="[Optional] The keywords and the url, seperated by a comma (e.g.: polymer chemistry (Loterre Chemistry Vocabulary), https://xxx )",
layout=widgets.Layout(width='auto'),
style={'description_width': 'auto'})


self.dataset_text = widgets.Text(description="Dataset destination:",
placeholder="Provide a relative path to save the dataset (e.g. datasets/dummy will be saved as datasets/dummy.json).",
layout=widgets.Layout(width='auto'),
Expand All @@ -160,14 +82,11 @@ def write_dataset(self, subjects: List=[] ) -> None:
# Widgets
v_space = widgets.VBox([widgets.Label(value='')], layout=widgets.Layout(height='30px'))

widgets0 = widgets.VBox([self.title, self.description, self.project,v_space])
widgets1 = widgets.VBox([self.authors, self.affiliations, self.contact_text, v_space, self.identifier_scheme, self.identifier, v_space])
widgets2 = widgets.VBox([self.subject_selection, self.related_publication, self.topic_classification, self.keywords, v_space])
widgets3 = widgets.VBox([self.dataset_text, v_space])
widgets4 = widgets.VBox([self.button_save, self.button_output], layout=widgets.Layout(align_items = 'center') )
widgets0 = widgets.VBox([self.title, self.description, self.project, self.purpose, v_space, self.dataset_text, v_space])
widgets1 = widgets.VBox([self.button_save, self.button_output], layout=widgets.Layout(align_items = 'center') )

# Combine the layout
full_layout = widgets.VBox([widgets0, widgets1, widgets2, widgets3, widgets4])
full_layout = widgets.VBox([widgets0, widgets1])

# Display the layout
display(full_layout)
Expand Down
5 changes: 1 addition & 4 deletions FAIRFlowChemistry/tools/logger_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ def setup_logger( log_file: str="" ):
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

# Create a formatter
formatter = logging.Formatter("%(asctime)s - %(name)s - %(message)s", datefmt="%m-%d-%y %H:%M:%S")

# Create a file handler and set the level to INFO
if log_file:
file_handler = FileHandler( log_file )
file_handler.setLevel(logging.INFO)
file_handler.setFormatter( logging.Formatter( "%(asctime)s - %(name)s - %(message)s", datefmt="%m-%d-%y %H:%M:%S" ) )
logger.addHandler(file_handler)

# Create a console handler and set the level to INFO
# Create a console handler and set the level to WARNING
console_handler = StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter( logging.Formatter( "%(message)s" ) )
Expand Down
Loading

0 comments on commit 085bbc8

Please sign in to comment.