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

Adding new oil type #1492

Open
soltkreig opened this issue Feb 4, 2025 · 4 comments
Open

Adding new oil type #1492

soltkreig opened this issue Feb 4, 2025 · 4 comments

Comments

@soltkreig
Copy link

Hi! What the best way adding new oil? There is no at ADIOS, but I know main parameters. Thanks.

@knutfrode
Copy link
Collaborator

Hi,
You would have to create an ADIOS oil using e.g. the ADIOS library, or manually edit a json file like this one:
https://github.com/OpenDrift/opendrift/blob/master/opendrift/models/openoil/adios/extra_oils/AD04011.json

Then you could add the custom oil as in this test/example:
https://github.com/OpenDrift/opendrift/blob/master/tests/models/openoil/test_openoil_custom_type.py

@soltkreig
Copy link
Author

Thank you! I have another one question - how to choose number of seeding particles?

@knutfrode
Copy link
Collaborator

This is simply number as input to seed_methods. Please see tutorial and examples.

@soltkreig
Copy link
Author

soltkreig commented Feb 4, 2025

I always get:

10:28:57 INFO    opendrift.models.openoil.openoil:1706: Oil type not specified, using default: GENERIC BUNKER C
10:28:57 INFO    opendrift.models.openoil.adios.dirjs:86: Querying ADIOS database for oil: GENERIC BUNKER C
10:28:57 INFO    opendrift.models.openoil.openoil:1715: Using density 988.1 and viscosity 0.021692333877975645 of oiltype GENERIC BUNKER C

My code:

import json
from importlib_resources import files
from datetime import datetime
from opendrift.models.openoil import OpenOil
from opendrift.readers import reader_netCDF_CF_generic

# Path to your custom oil JSON (adjust the package path and filename as needed)
oiljson = files('opendrift.models.openoil.adios.extra_oils').joinpath('AD04011.json')

# Create the OpenOil model instance
o = OpenOil(loglevel=20)

# Option 1: Load custom oil from JSON using set_oiltype_by_json
with open(oiljson) as f:
    oil_data = json.load(f)
o.set_oiltype_by_json(oil_data)
print("Custom oil loaded:", o.oiltype.name)
#readers were here
o.add_reader([reader_wave, reader_wind, reader_sal, reader_temp, reader_vel])

# Set additional configurations
o.set_config('processes:biodegradation', True)
o.set_config('processes:evaporation', True)
o.set_config('processes:emulsification', True)
o.set_config('drift:vertical_mixing', True)
o.set_config('general:seafloor_action', 'deactivate')
o.set_config('general:coastline_action', 'stranding')
o.set_config('vertical_mixing:timestep', 5)
o.set_config('environment:fallback:x_wind', 0)
o.set_config('environment:fallback:y_wind', 0)

# Define simulation start and end times
time0 = datetime(2024, 12, 17, 0, 0)
time1 = datetime(2025, 2, 7, 0, 0)

# Seed the simulation with oil elements
o.seed_elements(lon=36.551702, lat=45.109599, radius=2000, number=50000,
                time=time0, z=0)

# Run the simulation
o.run(time_step=900, time_step_output=3600, end_time=time1, outfile='result_2k_50k.nc')
print(o)
# Option 2 (alternative): Load custom oil directly from file
# o.set_oiltype_from_file(oiljson)
# print("Using custom oil:", o.oiltype.name)

# Set up readers for environmental data
reader_wave = reader_netCDF_CF_generic.Reader(
    '/home/jovyan/people/murtazin/opendrift/datasets/cmems_mod_blk_wav_anfc_2.5km_PT1H-i_multi-vars_27.25E-42.00E_40.50N-47.33N_2024-12-16-2025-02-12.nc'
)
reader_wind = reader_netCDF_CF_generic.Reader(
    'https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'
)
reader_sal = reader_netCDF_CF_generic.Reader(
    '/home/jovyan/people/murtazin/opendrift/datasets/cmems_mod_blk_phy-sal_anfc_2.5km_P1D-m_so_27.25E-42.00E_40.50N-47.33N_0.50-2258.95m_2024-12-16-2025-02-11.nc'
)
reader_temp = reader_netCDF_CF_generic.Reader(
    '/home/jovyan/people/murtazin/opendrift/datasets/cmems_mod_blk_phy-temp_anfc_2.5km_P1D-m_bottomT-thetao_27.25E-42.00E_40.50N-47.33N_0.50-2142.12m_2024-12-16-2025-02-11.nc'
)
reader_vel = reader_netCDF_CF_generic.Reader(
    '/home/jovyan/people/murtazin/opendrift/datasets/cmems_mod_blk_phy-cur_anfc_2.5km_P1D-m_uo-vo-wo_27.33E-42.00E_40.55N-47.33N_0.50-2258.95m_2022-11-05-2025-02-08.nc'
)
o.add_reader([reader_wave, reader_wind, reader_sal, reader_temp, reader_vel])

# Set additional configurations
o.set_config('processes:biodegradation', True)
o.set_config('processes:evaporation', True)
o.set_config('processes:emulsification', True)
o.set_config('drift:vertical_mixing', True)
o.set_config('general:seafloor_action', 'deactivate')
o.set_config('general:coastline_action', 'stranding')
o.set_config('vertical_mixing:timestep', 5)
o.set_config('environment:fallback:x_wind', 0)
o.set_config('environment:fallback:y_wind', 0)

# Define simulation start and end times
time0 = datetime(2024, 12, 17, 0, 0)
time1 = datetime(2025, 2, 7, 0, 0)

# Seed the simulation with oil elements
o.seed_elements(lon=36.551702, lat=45.109599, radius=2000, number=50000,
                time=time0, z=-5)
11:39:07 DEBUG   opendrift.models.oceandrift:115: No machine learning correction available.
11:39:07 DEBUG   opendrift.config:168: Adding 40 config items from environment
11:39:07 DEBUG   opendrift.config:168: Adding 5 config items from environment
11:39:07 DEBUG   opendrift.config:168: Adding 18 config items from __init__
11:39:07 DEBUG   opendrift.config:178:   Overwriting config item readers:max_number_of_fails
11:39:07 DEBUG   opendrift.config:168: Adding 6 config items from __init__
11:39:07 INFO    opendrift.models.basemodel:511: OpenDriftSimulation initialised (version 1.12.0 / v1.12.0-68-g89582bb-dirty)
11:39:07 DEBUG   opendrift.config:168: Adding 15 config items from oceandrift
11:39:07 DEBUG   opendrift.config:178:   Overwriting config item seed:z
11:39:07 DEBUG   opendrift.config:168: Adding 15 config items from openoil
11:39:07 DEBUG   opendrift.models.openoil.adios.oil:76: Parsing Oil: AD04011 / Mazut M100

Image

@knutfrode

@soltkreig soltkreig reopened this Feb 4, 2025
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

No branches or pull requests

2 participants