[2]:
from argopy import DataFetcher as ArgoDataFetcher
/home/docs/checkouts/readthedocs.org/user_builds/argopy/checkouts/v0.1.3/argopy/plotters.py:31: 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:
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-01-14T01:05:21
* N_POINTS (N_POINTS) int64 0 1 2 3 4 5 6 ... 518 519 520 521 522 523
LONGITUDE (N_POINTS) float64 -66.77 -66.77 -66.77 ... -64.59 -64.59
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: http://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/05/15
Fetched_constraints: phy_[x=-75.00/-55.00; y=30.00/40.00; z=0.0/100.0; t...
Fetched_url: http://www.ifremer.fr/erddap/tabledap/ArgoFloats.cs...
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:
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-14T01:05:21
* 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
* N_LEVELS (N_LEVELS) int64 0 1 2 3 4 5 6 7 ... 43 44 45 46 47 48 49
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: http://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/05/15
Fetched_constraints: phy_[x=-75.00/-55.00; y=30.00/40.00; z=0.0/100.0; t...
Fetched_url: http://www.ifremer.fr/erddap/tabledap/ArgoFloats.cs...
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-01-14T01:05:21
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: http://www.ifremer.fr/erddap
Fetched_by: docs
Fetched_date: 2020/05/15
Fetched_constraints: phy_[x=-75.00/-55.00; y=30.00/40.00; z=0.0/100.0; t...
Fetched_url: http://www.ifremer.fr/erddap/tabledap/ArgoFloats.cs...
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.
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.
[6]:
df = ArgoDataFetcher().profile(6902746, 34).to_dataframe()
df
[6]:
CYCLE_NUMBER | DATA_MODE | DIRECTION | PLATFORM_NUMBER | POSITION_QC | PRES | PRES_QC | PSAL | PSAL_QC | TEMP | TEMP_QC | TIME_QC | LATITUDE | TIME | LONGITUDE | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
N_POINTS | |||||||||||||||
0 | 34 | D | A | 6902746 | 1 | 3.0 | 1 | 36.262 | 1 | 27.212 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
1 | 34 | D | A | 6902746 | 1 | 4.0 | 1 | 36.262 | 1 | 27.212 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
2 | 34 | D | A | 6902746 | 1 | 5.0 | 1 | 36.263 | 1 | 27.213 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
3 | 34 | D | A | 6902746 | 1 | 6.0 | 1 | 36.262 | 1 | 27.212 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
4 | 34 | D | A | 6902746 | 1 | 7.0 | 1 | 36.262 | 1 | 27.214 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
104 | 34 | D | A | 6902746 | 1 | 1913.0 | 1 | 34.976 | 1 | 3.710 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
105 | 34 | D | A | 6902746 | 1 | 1938.0 | 1 | 34.981 | 1 | 3.718 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
106 | 34 | D | A | 6902746 | 1 | 1964.0 | 1 | 34.984 | 1 | 3.698 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
107 | 34 | D | A | 6902746 | 1 | 1988.0 | 1 | 34.983 | 1 | 3.668 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
108 | 34 | D | A | 6902746 | 1 | 2007.0 | 1 | 34.983 | 1 | 3.644 | 1 | 1 | 18.983 | 2017-12-20 06:58:00 | -58.119 |
109 rows × 15 columns
but keep in mind that this is merely a short cut for the xarray.Dataset.to_dataframe()
method.
Data saving¶
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()
.