Skip to content

Commit

Permalink
Refactor catalytic_measurement.py fix sample references
Browse files Browse the repository at this point in the history
  • Loading branch information
schumannj committed Jan 26, 2024
1 parent fc8a942 commit 2a6ed39
Showing 1 changed file with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from nomad.datamodel.metainfo.basesections import (
PubChemPureSubstanceSection,
CompositeSystem
CompositeSystem, CompositeSystemReference
)

from nomad.metainfo import (
Expand Down Expand Up @@ -64,11 +64,11 @@ def add_activity(archive):
if not archive.results.properties.catalytic.reactivity:
archive.results.properties.catalytic.reactivity = Reactivity()

class CatalystSample(CompositeSystem, EntryData):
'''Example section for a catalyst sample.'''
m_def = Section(
categories=[NOMADMeasurementsCategory],
label='Catalyst Sample')
# class CatalystSample(CompositeSystem, EntryData):
# '''Example section for a catalyst sample.'''
# m_def = Section(
# categories=[NOMADMeasurementsCategory],
# label='Catalyst Sample')


class Reagent(ArchiveSection):
Expand Down Expand Up @@ -183,6 +183,13 @@ def normalize(self, archive, logger):
if reagent.flow_rate is None and reagent.gas_concentration_in is not None:
reagent.flow_rate = self.set_total_flow_rate * reagent.gas_concentration_in

if self.m_parent.catalyst is not None:
if self.m_parent.catalyst.catalyst_mass is not None:
if self.weight_hourly_space_velocity is None and self.set_total_flow_rate is not None:
self.weight_hourly_space_velocity = self.set_total_flow_rate / self.m_parent.catalyst.catalyst_mass
if self.contact_time is None and self.set_total_flow_rate is not None:
self.contact_time = self.m_parent.catalyst.catalyst_mass / self.set_total_flow_rate

add_activity(archive)
if self.set_temperature is not None:
archive.results.properties.catalytic.reactivity.test_temperatures = self.set_temperature
Expand Down Expand Up @@ -220,9 +227,9 @@ class ReactorFilling(ArchiveSection):
catalyst_name = Quantity(
type=str, shape=[], a_eln=ELNAnnotation(component='StringEditQuantity'))

# sample_reference = Quantity(
# type=CatalystSample, description='A reference to the sample used for the measurement.',
# a_eln=ELNAnnotation(component='ReferenceEditQuantity', label='Entity Reference'))
sample_reference = Quantity(
type=CompositeSystem, description='A reference to the sample used for the measurement.',
a_eln=ELNAnnotation(component='ReferenceEditQuantity', label='Entity Reference'))

catalyst_mass = Quantity(
type=np.float64, shape=[], unit='mg', a_eln=ELNAnnotation(component='NumberEditQuantity'))
Expand Down Expand Up @@ -262,7 +269,16 @@ class ReactorFilling(ArchiveSection):
def normalize(self, archive, logger):
super(ReactorFilling, self).normalize(archive, logger)

if self.sample_reference is None:
if self.m_root().data.samples is not None:
self.sample_reference = self.m_root().data.samples[0].reference
if self.sample_reference is not None:
print(self.m_root().data.samples)
if self.m_root().data.samples == []:
sample1_reference = CompositeSystemReference(reference=self.sample_reference)
self.m_root().data.samples.append(sample1_reference)
elif self.m_root().data.samples.reference is None:
self.m_root().data.samples.reference = self.sample_reference
self.sample_reference.normalize(archive, logger)

if self.catalyst_name is None and self.sample_reference is not None:
Expand Down Expand Up @@ -337,59 +353,72 @@ def normalize(self, archive, logger):

#Figures definitions:
self.figures = []

if self.section_runs is not None:
figT=go.Figure()
x=[0,]
y=[]
for i,run in enumerate(self.section_runs):
if run.set_temperature is not None:
y.append(run.set_temperature.to('kelvin'))
if i == len(self.section_runs)-1:
try:
if run.set_temperature_section_stop is not None:
y.append(run.set_temperature_section_stop.to('kelvin'))
except:
y.append(run.set_temperature.to('kelvin'))
try:
if run.set_temperature_section_stop is not None:
y.append(run.set_temperature_section_stop.to('kelvin'))
except:
y.append(run.set_temperature.to('kelvin'))
if run.set_pressure is not None:
if i == 0:
figP=go.Figure()
y_p=[]
y_p.append(run.set_pressure.to('bar'))
try:
if run.set_pressure_section_stop is not None:
y_p.append(run.set_pressure_section_stop.to('bar'))
except:
y_p.append(run.set_pressure.to('bar'))
if run.time_on_stream is not None:
x.append(run.time_on_stream.to('hour'))
if i != len(self.section_runs)-1:
x.append(run.time_on_stream.to('hour'))
x_text="time (h)"
else:
x=range(len(y))
elif i == len(self.section_runs)-1:
for j in range(1, len(self.section_runs)):
x.append(j)
if j != len(self.section_runs)-1:
x.append(j)
x_text='step'
if run.reagents != []:
for n,reagent in enumerate(run.reagents):
if n == 0 and i == 0:
figR=go.Figure()
reagent_n, runs_n = (len(run.reagents), len(self.section_runs))
y_r=[[0 for k in range(runs_n)] for l in range(reagent_n) ]
reagent_name=[0 for k in range(reagent_n)]
y_r=[[0 for k in range(2*runs_n)] for l in range(reagent_n+1) ]
reagent_name=[0 for k in range(reagent_n+1)]
if i==0:
reagent_name[n]=reagent.name
if n == len(run.reagents)-1:
reagent_name[n+1]=['total flow rate']
if reagent.flow_rate is not None:
if reagent.name == reagent_name[n]:
y_r[n][i]=(reagent.flow_rate.to('mL/minute'))
y_r[n][2*i]=(reagent.flow_rate.to('mL/minute'))
y_r[n][2*i+1]=(reagent.flow_rate.to('mL/minute'))
y_r_text="Flow rates (mL/min)"
else:
logger.warning('Reagent name has changed in run'+str(i+1)+'.')
return
if n == len(run.reagents)-1:
y_r[n+1][2*i]=(run.set_total_flow_rate.to('mL/minute'))
y_r[n+1][2*i+1]=(run.set_total_flow_rate.to('mL/minute'))
elif reagent.gas_concentration_in is not None:
y_r[n][i]=(reagent.gas_concentration_in)
y_r_text="gas concentrations"
if i == len(self.section_runs)-1:
y_r[n].append(y_r[n][i])
# y_r[n].append(y_r[n][i])
figR.add_trace(go.Scatter(x=x, y=y_r[n], name=reagent.name))
# if run.set_total_flow_rate is not None:
# figR.add_trace(go.Scatter(x=x,y=run.set_total_flow_rate, name='Total Flow Rates'))

if n == len(run.reagents)-1:
figR.add_trace(go.Scatter(x=x, y=y_r[n+1], name='Total Flow Rates'))
figT.add_trace(go.Scatter(x=x, y=y, name='Temperature'))
figT.update_layout(title_text="Temperature")
figT.update_xaxes(title_text=x_text,)
figT.update_xaxes(title_text=x_text)
figT.update_yaxes(title_text="Temperature (K)")
self.figures.append(PlotlyFigure(label='Temperature', figure=figT.to_plotly_json()))

Expand Down

0 comments on commit 2a6ed39

Please sign in to comment.