gafusion / omas

Ordered Multidimensional Array Structure
http://gafusion.github.io/omas
MIT License
30 stars 14 forks source link

Cannot set time in edge_profiles.profiles_1d[0].time #221

Closed AreWeDreaming closed 1 year ago

AreWeDreaming commented 1 year ago

I found a bug that essentially stops you from writing anything to profiles_1d in the edge_profiles IDS.

This script produces the error:

from omas import ODS

def store_results_in_ods(times):
    """
    Writes results to OMAS core_profiles and edge_profiles.
    Uses the `results` dictionary from `class:ida.core.ida`.
    Assumes IDA uses rho_pol_norm internally
    """
    ods = ODS()
    ods.open("d3d", 170325, 
             options={'EFIT_tree': 'EFIT04'})
    ods["core_profiles"]['code']['name'] = "IDA"
    ods["edge_profiles"]['code']['name'] = "IDA"
    for profile_1d_ods, edge in zip([ods["core_profiles.profiles_1d"],
                                     ods["edge_profiles.profiles_1d"]], 
                                    [False, True]):
        if not edge:
            print("Setting time in core_profiles")
        else:
            print("Setting time in edge_profiles")
        for time_index, time in enumerate(times):
            profile_1d_ods[time_index]["time"] = time

if __name__ == "__main__":
    store_results_in_ods([0.9, 1.0])

Notably, if you do not use ods.open it does work. Also core_profiles.profiles_1d works just fine either way. I will test if load_omas_h5 also produces this issue and update this issue.

AreWeDreaming commented 1 year ago

It works for load_omas_h5. I guess saving edge_profiles for d3d is not implemented and, therefore, it throws an error.

orso82 commented 1 year ago

@AreWeDreaming you may need to add

"edge_profiles.profiles_1d.:": {
  "VALUE": 0
 },

to the https://github.com/gafusion/omas/blob/master/omas/machine_mappings/d3d.json

As a side, if you are using .open() you must also always .close(). The best way to ensure that is by using a with statement.

AreWeDreaming commented 1 year ago

Ok, I'll try that tomorrow. What happens when I don't close?

orso82 commented 1 year ago

You keep many MDS+ connections or file descriptor files open

AreWeDreaming commented 1 year ago

Do those expire eventually? I have been using open without close a lot.

orso82 commented 1 year ago

MDS will only handle 8 connections (i think) and then start closing automatically, which may leave you with ODSs not able to retrieve data. Open files can be a lot depending on configuration of your system, but you cannot write to a file that is open elsewhere for read.

github-actions[bot] commented 1 year ago

Stale issue message