Uploading .stix file into a DstabilityModel (Geolib)

Hi all,

The original problem posted by Jordi (@jdeleau ) is that the parsed_file = DSettlementModel().parse(file_path) is resulting in parsed_file being None. This is actually expected!

What the parse() function is doing is parsing the provided file into the DSettlementModel.
As @yida.tao already discovered in her post.

So the workflow should be as follows:

dsettlement_model= DSettlementModel() # Empty model
dsettlement_model.parse(Input_or_output_file) # parse input or output file into the model

After this, the data is in the model can be used in further calculations.

@bvanderhulst
The snippet in the documentation is kind of misleading:

temp_file = NamedTemporaryFile(suffix='.sld', delete=False, mode='wb')  # create a temporary file with correct suffix; don't delete on close(); remove mode 'b' in case of StringIO/str
temp_file.write(my_bytesio.getvalue())  # write in-memory content (bytes in this case) to file
temp_file.close()  # close (does not delete) the file to ensure the data is actually written to file (instead of kept in buffer)
path = Path(temp_file.name)  # name returns the path in `str`, GEOLIB requires (in most cases) a Path object
parsed_file = DSettlementModel().parse(path)  # obtain the parsed results
os.remove(temp_file.name)  # remove the temporary file to avoid cluttering of files

The second to last line should be replaced by:

dsettlement_model = DSettlementModel() # create empty model
dsettlement_model.parse(path)  # parse file into DSettlementModel() model
1 Like