NOAA-ORR-ERD / PyGnome

The General NOAA Operational Modeling Environment
https://gnome.orr.noaa.gov/doc/pygnome/index.html
Other
55 stars 44 forks source link

object has no attribute 'standard_density' #65

Open egiraldof opened 4 years ago

egiraldof commented 4 years ago

Hello,

I am trying to create a custom substance but I am getting the following error: AttributeError: 'dict' object has no attribute 'standard_density'.


json_data = {'name': u'South_Blend',
                      'api': uc.convert('Density',
                      'gram per cubic centimeter',
                      'API degree', 0.8770),
                    #'api': 29.8,
                      'standart_density': 0.8770,

                      'saturates_fraction': 31.8,
                      'aromatics_fraction': 28.5,
                      'resins_fraction': 7.9,
                      'asphaltenes_fraction': 3.8,

                      'flash_point_min_k': 228.15,
                      'flash_point_max_k': None,
                      'pour_point_min_k': 270.15,
                      'pour_point_max_k': None,
                      'oil_water_interfacial_tension_n_m': None,
                      'oil_water_interfacial_tension_ref_temp_k': None,
                      'oil_seawater_interfacial_tension_n_m': None,
                      'oil_seawater_interfacial_tension_ref_temp_k': None,

                      'bullwinkle_time': None,
                      'bullwinkle_fraction': None,
                      'adhesion_kg_m_2': None,
                      'emulsion_water_fraction_max': None,
                      'solubility': None,

                      'benzene_fraction': None,
                      'naphthenes_fraction': None,
                      'paraffins_fraction': None,
                      'polars_fraction': None,
                      'sulphur_fraction': 0.705,
                      'wax_content_fraction': 6.11,
                      'vanadium_ppm': 78.03,
                      'nickel_ppm': 30.67,
                      'k0y': None,

                      'densities': [{'kg_m_3': 877, 'ref_temp_k': 288.15,
                               'weathering': 0.0}],
                    #'kvis': [{'m_2_s': 3.8335776e-05, 'ref_temp_k': 273.15,
                    #'weathering': 0.0},
                    #{'m_2_s': 1.8262755e-05, 'ref_temp_k': 288.15,
                    #'weathering': 0.0}],
                      'cuts': [{'liquid_temp_k': None, 'vapor_temp_k': 347.85,
                                  'fraction': 0.05},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 376.95,
                                  'fraction': 0.1},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 432.45,
                                  'fraction': 0.2},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 492.15,
                                  'fraction': 0.3},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 547.45,
                                  'fraction': 0.4},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 602.65,
                                  'fraction': 0.5},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 663.75,
                                  'fraction': 0.6},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 726.85,
                                  'fraction': 0.7},
                                 {'liquid_temp_k': None, 'vapor_temp_k': 805.35,
                                  'fraction': 0.8}]}

    print 'adding a spill'
    # for now subsurface spill stays on initial layer
    spill = point_line_release_spill(num_elements=1000,
                                     amount=1000,  # default volume_units=m^3
                                     units='bbl',
                                     start_position=(-78.80375,
                                                     1.85235,
                                                     0.0),
                                     release_time=start_time_release,
                                     end_release_time=end_release,
                                     substance = json_data)

    model.spills += spill`
jay-hennen commented 4 years ago

You need to create and pass in a gnome.spills.substance.GnomeOil or NonWeatheringSubstance in the substance kwarg. You can't just pass in a dict. The following should be enough.

substance = GnomeOil(**json_data)

egiraldof commented 4 years ago

@jay-hennen Thanks for the help!

Now I get this error "sqlalchemy.orm.exc.NoResultFound: Oil with identifier "South_Blend", not found in database. But "South_Blend" is the new substance that I want to customize with the characteristics that are above.

jay-hennen commented 4 years ago

You need to provide a 'component_density' key to your dictionary. May also need other keys; I don't know what they would be.

Initializing a GnomeOil directly from a from-scratch dict is not normal usage (yet), and the necessary parameters aren't published yet. I think you would have better luck loading a generic oil and then overriding the attributes with your values.

@ChrisBarker-NOAA Has the OilLibrary been decoupled from Pygnome yet in this Github version?

@ChrisBarker-NOAA

ChrisBarker-NOAA commented 4 years ago

It should be, yes -- that is you can use a GNOME Oil without any access to the oil_library.

And there should be example GNOME oils in there somewhere, that you can edit. @coconnor8: maybe you could point us to them.

Sorry this isn't properly documented.

coconnor8 commented 4 years ago

Example oils are in gnome.spill.sample_oils