-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_Coq_macha_shape.py
85 lines (74 loc) · 2.91 KB
/
run_Coq_macha_shape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys
from datetime import datetime, timedelta
import numpy as np
import math
#import pandas as pd
#from opendrift.readers import reader_global_landmask
#from opendrift.readers import reader_netCDF_CF_generic
from opendrift.readers import reader_ROMS_native
#from opendrift.models.larvaloco import SeaLice
#from opendrift.models.oceandrift import OceanDrift
#from opendrift.models.virtual_conDVM import LarvaVirtual
from opendrift.models.virtual_sinDVM import LarvaVirtual
o = LarvaVirtual(loglevel=0)
filename = 'croco_his_Y2000_15M.nc';
#filecoord = 'PuntosCosta.txt';
fileshape = 'AMmachaCoqbo.shp'
mosa_native = reader_ROMS_native.Reader(filename)
mosa_native.interpolation='linearND'
o.add_reader(mosa_native)
print(mosa_native)
start_date = mosa_native.start_time + timedelta(days=278) # 5 octubre 2000
#end_date = mosa_native.end_time
outname='Part_Coq_macha'
#particulas_total=10000
dias_deriva = 25 # PLD macha
num_part = 40 # 7200 =1 per hour for 1 month
#mindep = -20
#maxdep = -40
#zd = np.random.rand(num_part)
#zd = zd*(maxdep - mindep) + mindep
all = np.empty([0,7])
o.set_config('general:coastline_action', 'previous')
o.set_config('IBM:complete_pld',dias_deriva)
#paso = 1;
for j in range(0,18):
frec_seed = timedelta(days=j*5) # frecuencia : cada 5 dias por 3 meses
for i in range(0,24):
ini_date = start_date + frec_seed + timedelta(hours=i)
print(ini_date)
o.seed_from_shapefile(fileshape,
number = num_part,
layername = None,
featurenum = None,
time = ini_date)
lons_start = o.elements_scheduled.lon
lats_start = o.elements_scheduled.lat
time_start = o.elements_scheduled_time
o.run(end_time = ini_date + timedelta(days=dias_deriva),
time_step=timedelta(minutes=60),
outfile = outname + '.nc',
export_variables=['status','time'])
#o.plot(linecolor='z', 'trayect_dia'+str(i)++'.png')
index_of_first, index_of_last = o.index_of_activation_and_deactivation()
lons = o.get_property('lon')[0]
lats = o.get_property('lat')[0]
status = o.get_property('status')[0]
tiempo = o.get_time_array()[0]
lons_end = lons[index_of_last, range(lons.shape[1])]
lats_end = lats[index_of_last, range(lons.shape[1])]
status_end = status[index_of_last, range(lons.shape[1])]
time_end = [tiempo[i] for i in index_of_last]
uno = np.column_stack([time_start, lons_start, lats_start, time_end, lons_end, lats_end, status_end])
all = np.append(all, uno, axis=0)
#paso = paso + 1
# outname='trayect_ene_hr_'+ str(i) +'.png';
# o.plot(linecolor='z', filename = outname)
np.savetxt('Part_Coq_macha.txt', all, fmt='%s %.4f %.4f %s %.4f %.4f %i')
print(o)
#print("Guardando Figura")
#elements=np.arange(0,17280,4)
#o.plot(linecolor='z', filename = outname + '.png')
#o.set_config('environment:fallback:y_sea_water_velocity', 0)
#o.animation(filename = outname + '.mp4')
print("Fin simulacion")