Skip to content

Commit

Permalink
argo OK
Browse files Browse the repository at this point in the history
  • Loading branch information
cfontana00 committed May 16, 2024
1 parent 7c77fc2 commit 59ca53a
Show file tree
Hide file tree
Showing 15 changed files with 758 additions and 61 deletions.
34 changes: 16 additions & 18 deletions config/config_MARIA.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
{
"_____":"GENERAL PARAMETERS",

"date_ini":"2015-03-20",
"date_end":"2015-03-29",
"outdir":"/home/fontana/MODEL/OUTPUTS",
"diagdir":"/home/fontana/MODEL/DIAGS",
"date_ini":"2021-12-11",
"date_end":"2021-12-12",
"outdir":"/path/to/OUTPUT_SMP",
"diagdir":"/path/to/diags/dir",
"river_ini":"2015-01-03",
"river_end":"2015-05-01",


"_____":"RIVER PARAMETERS",

"french_list":["Argens","Var"],
"italian_list":["Magra","Arno","Ombrone","Serchio"],
"river_ini":"2019-05-01",
"river_end":"2019-05-31",
"italian_list":["Arno","Magra","Ombrone","Serchio"],


"_____":"METEO PARAMETERS",

"meteo_ini":"2019-04-01",
"meteo_end":"2019-04-30",
"meteo_ini":"2015-03-10",
"meteo_end":"2015-03-11",
"day_cycle":2,
"n_cycle":30,
"n_cycle":6,
"imin":"500",
"imax":"600",
"jmin":"350",
"jmax":"450",



"_____":"DYFAMED PARAMETERS",

"some_par":"some_par",
Expand All @@ -36,7 +36,7 @@
"some_par":"some_par",


"_____":"PLOT PARAMETERS",
"_____":"2D PLOT PARAMETERS",

"resol":"10m",
"fig_proj":"ccrs.PlateCarree()",
Expand All @@ -53,31 +53,29 @@

"_____":"SECTION PLOT PARAMETERS",


"fig_secx":"8",
"fig_secy":"4",
"sec_lon1":"8.5",
"sec_lat1":"43.",
"sec_lon2":"10.",
"sec_lat2":"43.5",
"sec_dep":"200",
"sec_dep":"600",
"sec_resH":"0.05",
"sec_resV":"1",
"cb_fraction_sec":"0.025",
"cb_pad_sec":"0.06",

"_____":"PROFILE PLOT PARAMETERS",

"fig_prox":"6",
"fig_proy":"8",
"fig_prox":"8",
"fig_proy":"4",
"col1":"r",
"col2":"b",


"_____":"INTERPOLATION PARAMETERS",

"dump":"0.01",
"itp_meth":"linear",
"cmap":"viridis"
"itp_meth":"nearest"

}
4 changes: 4 additions & 0 deletions config/config_TEMPLATE.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"jmin":"350",
"jmax":"450",

"_____":"ARGO",

"argo_ds":"phy",



"_____":"DYFAMED PARAMETERS",
Expand Down
Binary file removed datasets/ARGO/.compare_argo.py.swp
Binary file not shown.
189 changes: 175 additions & 14 deletions datasets/ARGO/compare_argo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@

from fun_gen import *
from fun_io import *
from fun_plot_2D import *
from fun_plot_profile import *
import sys,os
import datetime as dt
import xarray as xr
import datetime as dt
from datetime import datetime

from mpl_toolkits.axes_grid1 import host_subplot
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use("Agg")



# Get args
Expand All @@ -23,6 +31,17 @@
load_config(config)
from fun_gen import *

tag = ''
if argo_ds == 'bgc':
tag = 'bio'

# Create arborescence
# -------------------
os.system('mkdir -p '+diagdir)
os.system('mkdir -p '+diagdir+'/'+config)
savedir = diagdir+'/'+config+'/ARGO'
os.system('mkdir -p '+savedir)

# Load coordinates
# ----------------
lon_mod,lat_mod,lev_mod=load_coords()
Expand All @@ -31,54 +50,196 @@
# Load data
# ---------
savedir = diagdir+'/'+config+'/ARGO'
ds = xr.load_dataset(savedir+'/argo.nc')
ds = xr.open_dataset(savedir+'/'+tag+'argo.nc')

lat = np.array( ds['LATITUDE'])
lon = np.array(ds['LONGITUDE'])
time = np.array(ds['TIME'])
num = np.array(ds['PLATFORM_NUMBER'])
cyc = np.array(ds['CYCLE_NUMBER'])
pres = np.array(ds['PRES_ADJUSTED'])

lat = ds['LATITUDE']
lon = ds['LONGITUDE']
time = ds['TIME']
num = ds['PLATFORM_NUMBER']
cyc = ds['CYCLE_NUMBER']
pres = ds['PRES_ADJUSTED']

time = np.array(time,dtype=str)


# Define profiles position
# ------------------------

lon_uni = np.unique(lon)
print(lon_uni.shape[0],'profiles found\n')


# Loop on profiles
# ----------------
print('Processing\n')
for plon in lon_uni:

# Get all indexes
idx = np.where( lon == plon )

for var in ['CHLA_ADJUSTED','PSAL_ADJUSTED','TEMP_ADJUSTED']:
# Get data lon/lat
data_lon = lon[idx]
data_lat = lat[idx]
data_pres = pres[idx]

pnum = str(num[idx][0])
pcyc = str(cyc[idx][0])
ptime = str(time[idx][0])


print('Float',pnum,'cycle',pcyc)
print('-----')


full_data = []
full_val = []

if var == 'CHLA_ADJUSTED':
varlist = ['PSAL_ADJUSTED','TEMP_ADJUSTED']

if argo_ds == 'bgc':
varlist = np.concatenate((['CHLA'],varlist))

for var in varlist:

if var == 'CHLA':
mod_var = 'chl'
elif var == 'PSAL_ADJUSTED':
mod_var = 'so'
elif var == 'TEMP_ADJUSTED':
mod_var = 'thetao'

# Get data
data = ds[var][idx]

# Get current variable parameters
vname, ftag, cmap, islog, vmod, vmin, vmax, label, units\
= load_variable(config,mod_var)

# Convert date
dstr = str(time[idx][0]).split('T')[0]
jd = dt.datetime.strptime(dstr,'%Y-%m-%d').toordinal()
dstr = str(time[idx][0]).replace('.000000000','')
date = dt.datetime.strptime(dstr,'%Y-%m-%dT%H:%M:%S')
jd = date.toordinal()

hours,mnt = date.strftime('%H'),date.strftime('%M')
hours = int(np.round(float(hours)+float(mnt)/60.))
if hours == 24:
hours = 0


# Get filename
fname,dtag = get_filename(int(np.floor(jd)),ftag)

print(fname,dtag)

# Interpolate model on data
try:
val = get_model_val_3d(fname,hours,vname,\
lon_mod,lat_mod,lev_mod,\
data_lon,data_lat,data_pres)
except Exception as e:
print('Interpolation failed')
val = data_pres
val[:] = np.nan

full_val.append(val)
full_data.append(data)


full_val = np.array(full_val)
full_data = np.array(full_data)

# Plot profile
# ------------

os.system('mkdir -p '+savedir+'/'+tag+str(pnum))

fout = savedir+'/'+tag+str(pnum)+'/profile_'+pcyc+'.'+fig_fmt
ptime = ptime.replace('.000000000','')

if argo_ds == 'bgc':
mchl,mpsal,mtemp = full_val[0],full_val[1],full_val[2]
dchl,dpsal,dtemp = full_data[0],full_data[1],full_data[2]

plot_profiles(fout,ptime,-data_pres,\
mchl,dchl,'Chlorophyll (mg.m$^{-3}$)',\
mpsal,dpsal,'Salinity',\
mtemp,dtemp,'Temperature (°C)')
else:
mpsal,mtemp = full_val[0],full_val[1]
dpsal,dtemp = full_data[0],full_data[1]

plot_profiles(fout,ptime,-data_pres,\
mpsal,dpsal,'Salinity',\
mtemp,dtemp,'Temperature (°C)')




# Plot trajectories
# -----------------

print('Plot trajectories ...')

# Load proj
exec('proj = ' + fig_proj)

pos = []
prof = []

# Loop on Argo float
for n in np.unique(num):

print(n)


# Initialize map
extent = [lon_mod.min(),lon_mod.max(),lat_mod.min(),lat_mod.max()]
fig, ax = plt.subplots(1,1,figsize=(float(fig_sx), float(fig_sy)), subplot_kw={'projection': proj})
init_fig(ax,extent,proj)

# Get all indexes
idx = np.where( num == n )

plon = np.unique( lon[idx])
plat = np.unique( lat[idx])
txt = np.unique(cyc[idx])

pos.append([plon,plat,n])


plt.plot(plon,plat,marker='+',linestyle='-')

for i in [0,plon.shape[0]-1]:
plt.text(plon[i],plat[i],str(txt[i]),fontsize=8)

# Save figure
fout = savedir+'/'+tag+str(n)+'/map'+'.'+fig_fmt
savefig(fout)

plt.close()


# Figure for all trajectories
fig, ax = plt.subplots(1,1,figsize=(float(fig_sx), float(fig_sy)), subplot_kw={'projection': proj})
init_fig(ax,extent,proj)


for p in pos:

lon = np.array(p[0])
lat = np.array(p[1])

plt.plot(lon,lat,marker='+',linestyle='none')
plt.text(lon[0],lat[0],str(p[2]))

# Save figure
fout = savedir+'/map'+tag+'.'+fig_fmt
savefig(fout)

plt.close()



exit()



Expand Down
16 changes: 14 additions & 2 deletions datasets/ARGO/get_argo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ------------------------- #
# Routine to get Argo data #
# ------------------------- #
import warnings
warnings.simplefilter("ignore")

import numpy as np

Expand Down Expand Up @@ -52,11 +54,14 @@
# -------------
box = [lon_min, lon_max, lat_min, lat_max, 0, 300, date_ini, date_end]

f = DataFetcher(ds='bgc', mode='expert', params='all',
f = DataFetcher(ds=argo_ds, mode='expert', params='all',
parallel=True, progress=True, cache=False,
chunks_maxsize={'time': 30},
)




f = f.region(box).load()

ds = f.data
Expand All @@ -67,6 +72,13 @@

# Save data
# ---------
ds.to_netcdf(path=savedir+'/argo.nc', mode='w', format=None, group=None, engine=None, encoding=None, unlimited_dims=None, compute=True, invalid_netcdf=False)
tag=''
if argo_ds == 'bgc':
tag = 'bio'

fname = savedir+'/'+tag+'argo.nc'
ds.to_netcdf(path=fname, mode='w', format=None, group=None, engine=None, encoding=None, unlimited_dims=None, compute=True, invalid_netcdf=False)

print('[SAVED]',fname)


Loading

0 comments on commit 59ca53a

Please sign in to comment.