Parsing *.prj with ogstools

Hi,

is it possible to parse the *.prj file using ogs tools?

For example, using the TH2M process, get all parameters (i.e parameter values) for the given phases?

Thanks in advance.

Cheers,

Carlos

Hi, you can read in a prj with ogs6py (from ogstools) to modify an run said prj file, but it doesn’t yet have the functionality to easily read out all the data. But you can do so with lxml (which ogs6py uses too):
to read out all parameters:

from lxml import etree as ET
import pandas as pd

tree = ET.parse('/path/to/you/file.prj')
root = tree.getroot()
params = root.xpath('//parameters/parameter')
parameters = [{child.tag: child.text for child in param} for param in params]
columns = list({key for param in parameters for key in param})
param_df = pd.DataFrame(parameters, columns=columns)
display(param_df)

or to read out all properties of the different phases:

for phase in ["AqueousLiquid", "Solid"]:
    props = root.xpath(f".//phase[type='{phase}']/properties/property")
    properties = [{child.tag: child.text for child in prop} for prop in props]
    columns = list({key for prop in properties for key in prop})
    prop_df = pd.DataFrame(properties, columns=columns)
    print(phase)
    display(prop_df)

The latter won’t collect the information of e.g. Linear properties with independent variables due to the nesting (this code only collect first level children of each property). I hope this helps.
Best, Florian

Hi Carlos,

maybe property_dataframe() already contains most of the information you want.

Best regards,
Christoph

2 Likes

Thanks. It sure helps!

I will try it. Thanks as well.

Hi,

just as a quick observation for the community: this approach will give the medium properties, but in case one needs the properties from the phases (or the components from the phases) one would have to use the approach from @FZill

Cheers,

Carlos