[2]:
from argopy import DataFetcher as ArgoDataFetcher
/home/docs/checkouts/readthedocs.org/user_builds/argopy/checkouts/v0.1.6/argopy/plotters.py:33: UserWarning: argopy requires cartopy installed for full map plotting functionality
warnings.warn("argopy requires cartopy installed for full map plotting functionality")
Manipulating data¶
Once you fetched data, argopy comes with a handy xarray.Dataset
accessor namespace argo
to perform specific manipulation of the data.
Transformation¶
Points vs profiles¶
Fetched data are returned as a 1D array collection of measurements:
[3]:
argo_loader = ArgoDataFetcher().region([-75,-55,30.,40.,0,100., '2011-01-01', '2011-01-15'])
ds_points = argo_loader.to_xarray()
print(ds_points)
<xarray.Dataset>
Dimensions: (N_POINTS: 524)
Coordinates:
LONGITUDE (N_POINTS) float64 -66.77 -66.77 -66.77 ... -64.59 -64.59
* N_POINTS (N_POINTS) int64 0 1 2 3 4 5 6 ... 518 519 520 521 522 523
LATITUDE (N_POINTS) float64 37.28 37.28 37.28 ... 33.07 33.07 33.07
TIME (N_POINTS) datetime64[ns] 2011-01-02T11:14:06 ... 2011-0...
Data variables:
CYCLE_NUMBER (N_POINTS) int64 150 150 150 150 150 150 ... 13 13 13 13 13
DATA_MODE (N_POINTS) <U1 'D' 'D' 'D' 'D' 'D' ... 'D' 'D' 'D' 'D' 'D'
DIRECTION (N_POINTS) <U1 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A' 'A'
PLATFORM_NUMBER (N_POINTS) int64 4900803 4900803 ... 5903377 5903377
POSITION_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
PRES (N_POINTS) float64 5.0 10.0 15.0 20.0 ... 95.97 97.97 99.97
PRES_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
PSAL (N_POINTS) float64 36.67 36.67 36.67 ... 36.67 36.67 36.67
PSAL_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
TEMP (N_POINTS) float64 19.46 19.47 19.47 ... 19.2 19.2 19.2
TEMP_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
TIME_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
Attributes:
DATA_ID: ARGO
DOI: http://doi.org/10.17882/42182
Fetched_from: https://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/08/31
Fetched_constraints: phy_[x=-75.00/-55.00; y=30.00/40.00; z=0.0/100.0; t...
Fetched_uri: https://www.ifremer.fr/erddap/tabledap/ArgoFloats.n...
history: Variables filtered according to DATA_MODE; Variable...
If you prefer to work with a 2D array collection of vertical profiles, simply transform the dataset with argopy.xarray.ArgoAccessor.point2profile()
:
[4]:
ds_profiles = ds_points.argo.point2profile()
print(ds_profiles)
<xarray.Dataset>
Dimensions: (N_LEVELS: 50, N_PROF: 18)
Coordinates:
* N_LEVELS (N_LEVELS) int64 0 1 2 3 4 5 6 7 ... 43 44 45 46 47 48 49
LATITUDE (N_PROF) float64 37.28 33.98 32.88 ... 37.03 34.39 33.07
TIME (N_PROF) datetime64[ns] 2011-01-02T11:14:06 ... 2011-01-...
* N_PROF (N_PROF) int64 7 13 15 0 6 2 9 4 11 5 1 12 10 17 3 8 14 16
LONGITUDE (N_PROF) float64 -66.77 -71.17 -64.93 ... -72.75 -64.59
Data variables:
CYCLE_NUMBER (N_PROF) int64 150 3 11 100 180 280 ... 17 62 148 151 4 13
DATA_MODE (N_PROF) <U1 'D' 'D' 'D' 'D' 'D' ... 'D' 'D' 'D' 'D' 'D'
DIRECTION (N_PROF) <U1 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A' 'A'
PLATFORM_NUMBER (N_PROF) int64 4900803 4901218 5903377 ... 4901218 5903377
POSITION_QC (N_PROF) int64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
PRES (N_PROF, N_LEVELS) float64 5.0 10.0 15.0 ... 99.97 nan
PRES_QC (N_PROF) int64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
PSAL (N_PROF, N_LEVELS) float64 36.67 36.67 36.67 ... 36.67 nan
PSAL_QC (N_PROF) int64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
TEMP (N_PROF, N_LEVELS) float64 19.46 19.47 19.47 ... 19.2 nan
TEMP_QC (N_PROF) int64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
TIME_QC (N_PROF) int64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Attributes:
DATA_ID: ARGO
DOI: http://doi.org/10.17882/42182
Fetched_from: https://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/08/31
Fetched_constraints: phy_[x=-75.00/-55.00; y=30.00/40.00; z=0.0/100.0; t...
Fetched_uri: https://www.ifremer.fr/erddap/tabledap/ArgoFloats.n...
history: Variables filtered according to DATA_MODE; Variable...
You can simply reverse this transformation with the argopy.argo.profile2point()
:
[5]:
ds = ds_profiles.argo.profile2point()
print(ds)
<xarray.Dataset>
Dimensions: (N_POINTS: 524)
Coordinates:
TIME (N_POINTS) datetime64[ns] 2011-01-02T11:14:06 ... 2011-0...
LONGITUDE (N_POINTS) float64 -66.77 -66.77 -66.77 ... -64.59 -64.59
* N_POINTS (N_POINTS) int64 0 1 2 3 4 5 6 ... 518 519 520 521 522 523
LATITUDE (N_POINTS) float64 37.28 37.28 37.28 ... 33.07 33.07 33.07
Data variables:
CYCLE_NUMBER (N_POINTS) int64 150 150 150 150 150 150 ... 13 13 13 13 13
DATA_MODE (N_POINTS) <U1 'D' 'D' 'D' 'D' 'D' ... 'D' 'D' 'D' 'D' 'D'
DIRECTION (N_POINTS) <U1 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A' 'A'
PLATFORM_NUMBER (N_POINTS) int64 4900803 4900803 ... 5903377 5903377
POSITION_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
PRES (N_POINTS) float64 5.0 10.0 15.0 20.0 ... 95.97 97.97 99.97
PRES_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
PSAL (N_POINTS) float64 36.67 36.67 36.67 ... 36.67 36.67 36.67
PSAL_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
TEMP (N_POINTS) float64 19.46 19.47 19.47 ... 19.2 19.2 19.2
TEMP_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
TIME_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
Attributes:
DATA_ID: ARGO
DOI: http://doi.org/10.17882/42182
Fetched_from: https://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/08/31
Fetched_constraints: phy_[x=-75.00/-55.00; y=30.00/40.00; z=0.0/100.0; t...
Fetched_uri: https://www.ifremer.fr/erddap/tabledap/ArgoFloats.n...
history: Variables filtered according to DATA_MODE; Variable...
Interpolation to standard levels¶
Once your dataset is a collection of vertical profiles, you can interpolate variables on standard pressure levels using argopy.xarray.ArgoAccessor.interp_std_levels()
with your levels as input :
[6]:
ds_interp = ds_profiles.argo.interp_std_levels([0,10,20,30,40,50])
print(ds_interp)
<xarray.Dataset>
Dimensions: (N_PROF: 18, PRES_INTERPOLATED: 6)
Coordinates:
LATITUDE (N_PROF) float64 37.28 33.98 32.88 ... 37.03 34.39 33.07
TIME (N_PROF) datetime64[ns] 2011-01-02T11:14:06 ... 2011-0...
* PRES_INTERPOLATED (PRES_INTERPOLATED) int64 0 10 20 30 40 50
* N_PROF (N_PROF) int64 7 13 15 0 6 2 9 4 ... 1 12 10 17 3 8 14 16
LONGITUDE (N_PROF) float64 -66.77 -71.17 -64.93 ... -72.75 -64.59
Data variables:
CYCLE_NUMBER (N_PROF) float64 150.0 3.0 11.0 100.0 ... 151.0 4.0 13.0
DATA_MODE (N_PROF) object 'D' 'D' 'D' 'D' 'D' ... 'D' 'D' 'D' 'D'
DIRECTION (N_PROF) object 'A' 'A' 'A' 'A' 'A' ... 'A' 'A' 'A' 'A'
PLATFORM_NUMBER (N_PROF) float64 4.901e+06 4.901e+06 ... 5.903e+06
PRES (N_PROF, PRES_INTERPOLATED) float64 5.0 10.0 ... 50.0
PSAL (N_PROF, PRES_INTERPOLATED) float64 36.67 36.67 ... 36.68
TEMP (N_PROF, PRES_INTERPOLATED) float64 19.46 19.47 ... 19.24
Attributes:
DATA_ID: ARGO
DOI: http://doi.org/10.17882/42182
Fetched_from: https://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/08/31
Fetched_constraints: phy_[x=-75.00/-55.00; y=30.00/40.00; z=0.0/100.0; t...
Fetched_uri: https://www.ifremer.fr/erddap/tabledap/ArgoFloats.n...
history: Variables filtered according to DATA_MODE; Variable...
Filters¶
If you fetched data with the expert
mode, you may want to use filters to help you curate the data.
[To be added]
Complementary data¶
TEOS-10 variables¶
You can compute additional ocean variables from TEOS-10. The default list (and available right now) of variables is: ‘SA’, ‘CT’, ‘SIG0’, ‘N2’, ‘PV’, ‘PTEMP’. Simply raise an issue to add a new one.
This can be done using the argopy.xarray.ArgoAccessor.teos10()
method and indicating the list of variables you want to compute:
[7]:
ds = ArgoDataFetcher().float(2901623).to_xarray()
ds.argo.teos10(['SA', 'CT', 'PV'])
print(ds)
<xarray.Dataset>
Dimensions: (N_POINTS: 8339)
Coordinates:
LONGITUDE (N_POINTS) float64 92.28 92.28 92.28 ... 94.77 94.77 94.77
* N_POINTS (N_POINTS) int64 0 1 2 3 4 5 ... 8334 8335 8336 8337 8338
LATITUDE (N_POINTS) float64 0.012 0.012 0.012 ... 3.388 3.388 3.388
TIME (N_POINTS) datetime64[ns] 2010-05-14T03:35:00 ... 2013-0...
Data variables:
CYCLE_NUMBER (N_POINTS) int64 0 0 0 0 0 0 0 0 ... 96 96 96 96 96 96 96
DATA_MODE (N_POINTS) <U1 'R' 'R' 'R' 'R' 'R' ... 'R' 'R' 'R' 'R' 'R'
DIRECTION (N_POINTS) <U1 'D' 'D' 'D' 'D' 'D' ... 'A' 'A' 'A' 'A' 'A'
PLATFORM_NUMBER (N_POINTS) int64 2901623 2901623 ... 2901623 2901623
POSITION_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
PRES (N_POINTS) float64 17.0 25.0 35.0 ... 1.112e+03 1.137e+03
PRES_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
PSAL (N_POINTS) float64 34.27 34.28 34.28 ... 34.92 34.92 34.91
PSAL_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
TEMP (N_POINTS) float64 30.16 30.17 30.17 ... 6.176 6.189 6.071
TEMP_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
TIME_QC (N_POINTS) int64 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1
SA (N_POINTS) float64 34.44 34.44 34.44 ... 35.09 35.09 35.08
CT (N_POINTS) float64 30.21 30.21 30.22 ... 6.254 6.269 6.152
PV (N_POINTS) float64 nan -6.868e-15 ... 1.435e-12 nan
Attributes:
DATA_ID: ARGO
DOI: http://doi.org/10.17882/42182
Fetched_from: https://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/08/31
Fetched_constraints: phy_WMO2901623
Fetched_uri: https://www.ifremer.fr/erddap/tabledap/ArgoFloats.n...
history: Variables filtered according to DATA_MODE; Variable...
[8]:
print(ds['SA'])
<xarray.DataArray 'SA' (N_POINTS: 8339)>
array([34.43589931, 34.43691224, 34.43692096, ..., 35.0921157 ,
35.09227648, 35.08238554])
Coordinates:
LONGITUDE (N_POINTS) float64 92.28 92.28 92.28 92.28 ... 94.77 94.77 94.77
* N_POINTS (N_POINTS) int64 0 1 2 3 4 5 6 ... 8333 8334 8335 8336 8337 8338
LATITUDE (N_POINTS) float64 0.012 0.012 0.012 0.012 ... 3.388 3.388 3.388
TIME (N_POINTS) datetime64[ns] 2010-05-14T03:35:00 ... 2013-01-01T0...
Attributes:
standard_name: Absolute Salinity
unit: g/kg
Data models¶
By default argopy works with xarray.DataSet and comes with the xarray.Dataset
accessor namespace argo
.
For your own analysis, you may prefer to work with a Pandas dataframe.
[9]:
df = ArgoDataFetcher().profile(6902746, 34).to_dataframe()
df
[9]:
CYCLE_NUMBER | DATA_MODE | DIRECTION | PLATFORM_NUMBER | POSITION_QC | PRES | PRES_QC | PSAL | PSAL_QC | TEMP | TEMP_QC | TIME_QC | LONGITUDE | LATITUDE | TIME | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
N_POINTS | |||||||||||||||
0 | 34 | D | A | 6902746 | 1 | 3.0 | 1 | 36.262001 | 1 | 27.212000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
1 | 34 | D | A | 6902746 | 1 | 4.0 | 1 | 36.262001 | 1 | 27.212000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
2 | 34 | D | A | 6902746 | 1 | 5.0 | 1 | 36.263000 | 1 | 27.212999 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
3 | 34 | D | A | 6902746 | 1 | 6.0 | 1 | 36.262001 | 1 | 27.212000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
4 | 34 | D | A | 6902746 | 1 | 7.0 | 1 | 36.262001 | 1 | 27.214001 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
104 | 34 | D | A | 6902746 | 1 | 1913.0 | 1 | 34.976002 | 1 | 3.710000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
105 | 34 | D | A | 6902746 | 1 | 1938.0 | 1 | 34.980999 | 1 | 3.718000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
106 | 34 | D | A | 6902746 | 1 | 1964.0 | 1 | 34.984001 | 1 | 3.698000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
107 | 34 | D | A | 6902746 | 1 | 1988.0 | 1 | 34.983002 | 1 | 3.668000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
108 | 34 | D | A | 6902746 | 1 | 2007.0 | 1 | 34.983002 | 1 | 3.644000 | 1 | 1 | -58.119 | 18.983 | 2017-12-20 06:58:00 |
109 rows × 15 columns
but keep in mind that this is merely a short cut for the xarray.Dataset.to_dataframe()
method.
Saving data¶
Once you have your Argo data as xarray.Dataset
, simply use the awesome possibilities of xarray like xarray.Dataset.to_netcdf()
or xarray.Dataset.to_zarr()
.