Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds orsopy integration for .ort files and ORSO models #131

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

alexhroom
Copy link
Collaborator

@alexhroom alexhroom commented Feb 10, 2025

This PR adds functionality to read .ort data and models. Fixes #104

The interface is through three functions:

  • RATapi.utils.orso.load_ort_data, which loads a list of RAT Data objects from an .ort file
  • RATapi.utils.orso.ort_to_project, which creates a Project with as much of the file data as possible, including both data and contrasts if the model data for a file is defined
  • RATapi.utils.orso.orso_model_to_rat, which turns an ORSO model description (given as either an orsopy SampleModel or a string) into an ORSOSample dataclass, which gives bulk in and bulk out data as well as a list of layers in the model and the parameters required to define them.

@alexhroom alexhroom marked this pull request as draft February 10, 2025 13:06
@alexhroom alexhroom changed the title Adds .ort file reader Adds orsopy integration for .ort files and ORSO models Feb 10, 2025
@alexhroom alexhroom force-pushed the 104-ort branch 3 times, most recently from 5fca75e to b101bb9 Compare February 12, 2025 15:07
@alexhroom alexhroom marked this pull request as ready for review February 13, 2025 13:40
Copy link
Collaborator

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, I've a few questions and things to think about.

In addition to the specific comments, I'm wondering about projects with the "substrate/liquid" geometry, and how they would work with this setup?

[
item
for item in other
if hasattr(item, self.name_field) and getattr(item, self.name_field) not in self.get_names()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there are duplicate names in the second list (which does not have to be a ClassList) - my reading of this is that both would be added.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested that this triggers the errors in extend()?

project.parameters.union(model_info.parameters)
project.layers.extend(model_info.layers)
project.bulk_in.append(model_info.bulk_in)
project.bulk_out.append(model_info.bulk_out)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does parameters require union, but append/extend is ok for the others?

project.resolutions.append(
Resolution(
name=f"{sample.name} Resolution",
type="data",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this is required, given that a data resolution is simply an instruction to the contrast to use the fourth column in the datafile and does not supply any information in and of itself. If you imagine that you have ten datasets, each with four columns, there's no need at all to have ten data resolutions. I'd remove this and let the user decide what they're going to do about resolutions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about if it just adds one data resolution and attaches all contrasts to it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would definitely be better.

Resolution(
name=f"{sample.name} Resolution",
type="constant",
source="Resolution Param 1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, what happens for multiple datasets?

resolution=f"{sample.name} Resolution",
model=model_info.model,
)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I suppose it makes sense to have a fully defined contrast here, and if we have to have these default backgrounds and scalefactors to make use of them, but I'm a bit worried that this only does half of the job for the user, given that after running this routine they will always need to review the background, scalefactor and resolution.

What would you consider to be the guiding principle behind this routine? What do you imagine the user workflow to be? This should help us with how to proceed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I'd like the user workflow to be that it works 'out of the box' - that the project can just be thrown directly into a run. This of course is not amazingly feasible due to backgrounds and scalefactors not being defined, so I wanted to give them 'reasonable' default values. I'm tempted to change it to use some ORSOProject dataclass that users can then plug into a project once they've properly defined their backgrounds and so on.


def orso_model_to_rat(
model: Union[orsopy.fileio.model_language.SampleModel, str], absorption: bool = False
) -> ORSOSample:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The absoprtion parameter is not set in the call from ort_to_project, so how do we set absorption layers if required? Is this available to us in the ort file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jupyter notebook indicates users will use this routine, so that's presumably the plan.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops - i forgot to add it to ort_to_project!

requirements.txt Show resolved Hide resolved
"source": [
"## Reading in data and models from .ort files\n",
"\n",
"It is possible to read data from .ort format files at two different levels of depth."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line could be phrased better, maybe: "It is possible to read both dataset and entire RAT projects from .ort format files"

@alexhroom
Copy link
Collaborator Author

@DrPaulSharp to address your comment about substrate/liquid: the only thing Geometry affects is where the substrate roughness is placed (at the beginning or end). I don't think it's possible to detect which side is the substrate from just the ORSO model

@DrPaulSharp
Copy link
Collaborator

DrPaulSharp commented Feb 18, 2025

Ok, that makes sense. My concern though is that in ort_to_project the project is initialised with "air/substrate" geometry automatically, but if a model is provided that shows the geometry is "substrate/liquid" a user would likely suspect that the reader should recognise this and set the geometry accordingly. Should geometry be added alongside absorption as an input maybe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for ORSO model language via orsopy
2 participants