|
3 | 3 | import xarray as xr |
4 | 4 |
|
5 | 5 |
|
| 6 | +import pandas as pd |
6 | 7 | from parcels import FieldSet, Field, ParticleSet, JITParticle, Variable, AdvectionRK4, AdvectionRK4_3D |
7 | 8 | from parcels.tools.converters import Geographic, GeographicPolar |
8 | 9 | from datetime import datetime, timedelta |
@@ -354,7 +355,63 @@ def create_particleset(fieldset, particle_settings): |
354 | 355 | windage_coefficient=windage_coefficients |
355 | 356 | ) |
356 | 357 | return pset |
357 | | - |
| 358 | + |
| 359 | +def create_particleset_from_file(fieldset, particle_settings): |
| 360 | + """ Helper function to create a Parcels.ParicleSet |
| 361 | +
|
| 362 | + Parameters |
| 363 | + ---------- |
| 364 | + model_settings : |
| 365 | + A dictionary of model settings used to create the fieldset |
| 366 | + particle_settings : |
| 367 | + A dictionary of particle settings used to define some .... |
| 368 | +
|
| 369 | + Returns |
| 370 | + ------- |
| 371 | + fieldset |
| 372 | + A parcels.FieldSet object |
| 373 | + """ |
| 374 | + |
| 375 | + # Load release type information |
| 376 | + release_type = particle_settings['release_type'] |
| 377 | + if release_type == 'coastal': |
| 378 | + release_file = './data/coastal_population_MPW_NEMO0083.csv' |
| 379 | + release_quantity_name = 'MPW_Cell' |
| 380 | + elif release_type == 'rivers': |
| 381 | + release_file = './data/river_emissions_NEMO0083.csv' |
| 382 | + release_quantity_name = 'Emissions' |
| 383 | + elif release_type == 'fisheries': |
| 384 | + release_file = './data/agg_data_fisheries_info.csv' |
| 385 | + release_quantity_name = 'fishing_hours' |
| 386 | + |
| 387 | + particle_locations = pd.read_csv(release_file) |
| 388 | + |
| 389 | + |
| 390 | + # Select specific continent/region/subregion/country/economic status if applicable: |
| 391 | + if 'continent' in particle_settings.keys(): |
| 392 | + particle_locations = particle_locations[particle_locations['Continent'] == particle_settings['continent']] |
| 393 | + if 'region' in particle_settings.keys(): |
| 394 | + particle_locations = particle_locations[particle_locations['Region'] == particle_settings['region']] |
| 395 | + if 'subregion' in particle_settings.keys(): |
| 396 | + particle_locations = particle_locations[particle_locations['Subregion'] == particle_settings['subregion']] |
| 397 | + if 'country' in particle_settings.keys(): |
| 398 | + particle_locations = particle_locations[particle_locations['Country'] == particle_settings['country']] |
| 399 | + if 'economicstatus' in particle_settings.keys(): |
| 400 | + particle_locations = particle_locations[particle_locations['Economic status'] == particle_settings['economicstatus']] |
| 401 | + |
| 402 | + particle_locations = particle_locations.groupby(['Longitude', 'Latitude'])[release_quantity_name].agg('sum').reset_index() |
| 403 | + particle_locations = particle_locations[particle_locations[release_quantity_name]>0] |
| 404 | + |
| 405 | + release_locations = {'lons': particle_locations['Longitude'], |
| 406 | + 'lats': particle_locations['Latitude']} |
| 407 | + |
| 408 | + particle_settings['release_locations'] = release_locations |
| 409 | + |
| 410 | + |
| 411 | + return create_particleset(fieldset, particle_settings) |
| 412 | + |
| 413 | + |
| 414 | + |
358 | 415 | def create_kernel(fieldset, pset): |
359 | 416 | """_summary_ |
360 | 417 |
|
|
0 commit comments