opendrift
opendrift copied to clipboard
Adding new oil type
Hi! What the best way adding new oil? There is no at ADIOS, but I know main parameters. Thanks.
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
Thank you! I have another one question - how to choose number of seeding particles?
This is simply number as input to seed_methods. Please see tutorial and examples.
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
@knutfrode
Hello,
Regarding the subject, I want to add my type of oil slick. I am attaching the .json file that I created. However, I am unable to load the oil type I created. Here are some lines from my script:
import json from opendrift.models.openoil import OpenOil from opendrift.readers import reader_netCDF_CF_generic from importlib.resources import files
o = OpenOil(loglevel=20) oil_json = files('opendrift.models.openoil.adios.extra_oils').joinpath('SANGO_CRUDE_2024.json') o.set_oiltype_from_file(oil_json) print(f" : {o.oiltype.name}")
...
oil_type = o.oiltype.name o.seed_elements(lon=-17.4, lat=14.5, radius=3000, number=1000, time=start_time, z=0, oil_type=oil_type) ...
Hi! Uncommment 42-47 lines here: https://github.com/OpenDrift/opendrift/blob/master/opendrift/models/openoil/adios/dirjs.py
Hi! It works. Thank you!
I made now a code update, so that you may provide the oiltype directly as a json filename or dictionary:
from datetime import datetime, timedelta
from opendrift.models.openoil import OpenOil
o = OpenOil()
o.add_readers_from_list([
'https://tds.hycom.org/thredds/dodsC/FMRC_ESPC-D-V02_uv3z/FMRC_ESPC-D-V02_uv3z_best.ncd',
'https://pae-paha.pacioos.hawaii.edu/thredds/dodsC/ncep_global/NCEP_Global_Atmospheric_Model_best.ncd'])
o.seed_elements(lon=3, lat=60, time=datetime.now(), oil_type='SANGO_CRUDE_2024.json')
o.run(duration=timedelta(hours=12))
o.plot_oil_budget()