|
3 | 3 | import xarray as xr |
4 | 4 |
|
5 | 5 |
|
6 | | -#import pandas as pd # Is this required? |
| 6 | +import pandas as pd |
7 | 7 | from parcels import FieldSet, Field, ParticleSet, JITParticle, Variable, AdvectionRK4, AdvectionRK4_3D |
8 | 8 | from parcels.tools.converters import Geographic, GeographicPolar |
9 | 9 | from datetime import datetime, timedelta |
@@ -298,7 +298,7 @@ def create_particleset(fieldset, particle_settings): |
298 | 298 | windage_coefficients = np.full(lons.shape, particle_settings['windage_coefficient']) |
299 | 299 | else: |
300 | 300 | windage_coefficients = particle_settings['windage_coefficient'] # Assumed to be an array of coefficients |
301 | | - |
| 301 | + |
302 | 302 |
|
303 | 303 | ## Add variables to particle based on fieldset flags |
304 | 304 | to_write_tracer = False |
@@ -366,7 +366,64 @@ def create_particleset(fieldset, particle_settings): |
366 | 366 | windage_coefficient=windage_coefficients |
367 | 367 | ) |
368 | 368 | return pset |
369 | | - |
| 369 | + |
| 370 | + |
| 371 | +def create_particleset_from_file(fieldset, particle_settings): |
| 372 | + """ Helper function to create a Parcels.ParicleSet |
| 373 | +
|
| 374 | + Parameters |
| 375 | + ---------- |
| 376 | + model_settings : |
| 377 | + A dictionary of model settings used to create the fieldset |
| 378 | + particle_settings : |
| 379 | + A dictionary of particle settings used to define some .... |
| 380 | +
|
| 381 | + Returns |
| 382 | + ------- |
| 383 | + fieldset |
| 384 | + A parcels.FieldSet object |
| 385 | + """ |
| 386 | + |
| 387 | + # Load release type information |
| 388 | + release_type = particle_settings['release_type'] |
| 389 | + if release_type == 'coastal': |
| 390 | + release_file = './../../data/release/generated_files/coastal_population_MPW_NEMO0083.csv' |
| 391 | + release_quantity_name = 'MPW_Cell' |
| 392 | + elif release_type == 'rivers': |
| 393 | + release_file = './../../data/release/generated_files/river_emissions_NEMO0083.csv' |
| 394 | + release_quantity_name = 'Emissions' |
| 395 | + elif release_type == 'fisheries': |
| 396 | + release_file = './../../data/release/generated_files/agg_data_fisheries_info.csv' |
| 397 | + release_quantity_name = 'fishing_hours' |
| 398 | + |
| 399 | + particle_locations = pd.read_csv(release_file) |
| 400 | + |
| 401 | + |
| 402 | + # Select specific continent/region/subregion/country/economic status if applicable: |
| 403 | + if 'continent' in particle_settings.keys(): |
| 404 | + particle_locations = particle_locations[particle_locations['Continent'] == particle_settings['continent']] |
| 405 | + if 'region' in particle_settings.keys(): |
| 406 | + particle_locations = particle_locations[particle_locations['Region'] == particle_settings['region']] |
| 407 | + if 'subregion' in particle_settings.keys(): |
| 408 | + particle_locations = particle_locations[particle_locations['Subregion'] == particle_settings['subregion']] |
| 409 | + if 'country' in particle_settings.keys(): |
| 410 | + particle_locations = particle_locations[particle_locations['Country'] == particle_settings['country']] |
| 411 | + if 'economicstatus' in particle_settings.keys(): |
| 412 | + particle_locations = particle_locations[particle_locations['Economic status'] == particle_settings['economicstatus']] |
| 413 | + |
| 414 | + particle_locations = particle_locations.groupby(['Longitude', 'Latitude'])[release_quantity_name].agg('sum').reset_index() |
| 415 | + particle_locations = particle_locations[particle_locations[release_quantity_name]>0] |
| 416 | + |
| 417 | + release_locations = {'lons': particle_locations['Longitude'], |
| 418 | + 'lats': particle_locations['Latitude']} |
| 419 | + |
| 420 | + particle_settings['release_locations'] = release_locations |
| 421 | + |
| 422 | + |
| 423 | + return create_particleset(fieldset, particle_settings) |
| 424 | + |
| 425 | + |
| 426 | + |
370 | 427 | def create_kernel(fieldset, pset): |
371 | 428 | """_summary_ |
372 | 429 |
|
|
0 commit comments