Read Breizhcrops EOPatch files#

[1]:
import os
import numpy as np
from marshmallow import fields, Schema
from marshmallow.validate import OneOf
from eolearn.core import EOPatch, FeatureType
[2]:
eop = EOPatch.load("../../eopatches/eopatch_5453")
/home/elena/anaconda3/envs/aitlas-py37/lib/python3.7/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)
[3]:
eop
[3]:
EOPatch(
  data: {
    FEATURES_S2: numpy.ndarray(shape=(28, 100, 100, 11), dtype=float32)
    S1_COH_ASC_VH_VV_DES_VH_VV_mean_1month: numpy.ndarray(shape=(12, 100, 100, 4), dtype=float32)
    S1_COH_ASC_VH_VV_DES_VH_VV_p10_1month: numpy.ndarray(shape=(12, 100, 100, 4), dtype=float32)
    S1_COH_weekly_interp: numpy.ndarray(shape=(61, 100, 100, 4), dtype=float32)
    S1_SIG_ASC_VH_VV_DES_VH_VV_cov_2months: numpy.ndarray(shape=(6, 100, 100, 4), dtype=float32)
    S1_SIG_ASC_VH_VV_DES_VH_VV_mean_2months: numpy.ndarray(shape=(6, 100, 100, 4), dtype=float32)
    S1_SIG_ASC_VVVH_DES_VVVH_ratio_weekly: numpy.ndarray(shape=(61, 100, 100, 2), dtype=float32)
    S1_SIG_weekly_interp: numpy.ndarray(shape=(61, 100, 100, 4), dtype=float32)
  }
  mask: {}
  scalar: {}
  label: {}
  vector: {}
  data_timeless: {
    S1_COH_ASC_VH_VV_DES_VH_VV_std_yearly: numpy.ndarray(shape=(100, 100, 4), dtype=float32)
  }
  mask_timeless: {
    CROP_TYPE: numpy.ndarray(shape=(100, 100, 1), dtype=uint16)
    CROP_TYPE_ERODED: numpy.ndarray(shape=(100, 100, 1), dtype=uint16)
    CROP_TYPE_EU: numpy.ndarray(shape=(100, 100, 1), dtype=uint16)
    CROP_TYPE_EU_ERODED: numpy.ndarray(shape=(100, 100, 1), dtype=uint16)
  }
  scalar_timeless: {}
  label_timeless: {}
  vector_timeless: {
    CROP_TYPE_GDF: geopandas.GeoDataFrame(columns=['polygon_id', 'ct_code', 'ct_eu_code', 'geometry', 'ct_id', 'ct_eu_id'], length=95, crs=EPSG:32633)
  }
  meta_info: {
    country: 'Slovenia'
    ct_code_list:      ct_code                   ct_name  ct_id   ct_eu_code  \
0          0              ni v uporabi      1  NUAA+WA+FA9
1          1            pšenica (jara)      2        C1100
2          2                 rž (jara)      3        C1200
3          3               pira (jara)      4        C1100
4          4                      ajda      5        C1900
..       ...                       ...    ...          ...
184      825     trda pšenica (ozimna)    185        C1100
185      831        vrtni mak (ozimni)    186        I1190
186      833       krmni grah (ozimni)    187        P1100
187      835  pšenica horasan (ozimna)    188        C1900
188      900                     hmelj    189        I4000

                                            ct_eu_name ct_eu_id
0                                       Other farmland      105
1                                      Wheat and spelt        5
2              Rye and winter cereal mixtures (maslin)       10
3                                      Wheat and spelt        5
4    Other cereals n.e.c. (buckwheat, millet, canar...       22
..                                                 ...      ...
184                                    Wheat and spelt        5
185                         Other oilseed crops n.e.c.       90
186                                         Field peas      110
187  Other cereals n.e.c. (buckwheat, millet, canar...       22
188                                               Hops       97

[189 rows x 6 columns]
    ct_eu_hierarchy:     ct_eu_code                                         ct_eu_name    level  \
0          ARA                                        Arable land  level_2
1        ARA99                     Other arable land crops n.e.c.  level_3
2        C0000  Cereals for the production of grain (including...  level_3
3        C1000  Cereals (excluding rice) for the production of...  level_4
4        C1100                                    Wheat and spelt  level_5
..         ...                                                ...      ...
194      W1120  Grapes for wines with protected geographical i...  level_6
195      W1190    Grapes for other wines n.e.c. (without PDO/PGI)  level_6
196      W1200                               Grapes for table use  level_5
197      W1300                                 Grapes for raisins  level_5
198      W1900                   Grapes for other purposes n.e.c.  level_5

    level_8 level_7 level_6 level_5 level_4 level_3 level_2 level_1
0       NaN     NaN     NaN     NaN     NaN     NaN     ARA     UAA
1       NaN     NaN     NaN     NaN     NaN   ARA99     ARA     UAA
2       NaN     NaN     NaN     NaN     NaN   C0000     ARA     UAA
3       NaN     NaN     NaN     NaN   C1000   C0000     ARA     UAA
4       NaN     NaN     NaN   C1100   C1000   C0000     ARA     UAA
..      ...     ...     ...     ...     ...     ...     ...     ...
194     NaN     NaN   W1120   W1100   W1000   H0000    PECR     UAA
195     NaN     NaN   W1190   W1100   W1000   H0000    PECR     UAA
196     NaN     NaN     NaN   W1200   W1000   H0000    PECR     UAA
197     NaN     NaN     NaN   W1300   W1000   H0000    PECR     UAA
198     NaN     NaN     NaN   W1900   W1000   H0000    PECR     UAA

[199 rows x 11 columns]
    maxcc: 0.8
    service_type: 'processing'
    size_x: 100
    size_y: 100
    time_difference: datetime.timedelta(seconds=7200)
    time_interval: (datetime.datetime(2017, 1, 1, 0, 0), datetime.datetime(2017, 12, 31, 23, 59, 59))
    year: 2017
  }
  bbox: BBox(((554000.0, 5091000.0), (555000.0, 5092000.0)), crs=CRS('32633'))
  timestamp: [datetime.datetime(2017, 3, 1, 0, 0), ..., datetime.datetime(2017, 11, 26, 0, 0)], length=28
)
[4]:
eop.meta_info["ct_code_list"]
/home/elena/anaconda3/envs/aitlas-py37/lib/python3.7/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)
[4]:
ct_code ct_name ct_id ct_eu_code ct_eu_name ct_eu_id
0 0 ni v uporabi 1 NUAA+WA+FA9 Other farmland 105
1 1 pšenica (jara) 2 C1100 Wheat and spelt 5
2 2 rž (jara) 3 C1200 Rye and winter cereal mixtures (maslin) 10
3 3 pira (jara) 4 C1100 Wheat and spelt 5
4 4 ajda 5 C1900 Other cereals n.e.c. (buckwheat, millet, canar... 22
... ... ... ... ... ... ...
184 825 trda pšenica (ozimna) 185 C1100 Wheat and spelt 5
185 831 vrtni mak (ozimni) 186 I1190 Other oilseed crops n.e.c. 90
186 833 krmni grah (ozimni) 187 P1100 Field peas 110
187 835 pšenica horasan (ozimna) 188 C1900 Other cereals n.e.c. (buckwheat, millet, canar... 22
188 900 hmelj 189 I4000 Hops 97

189 rows × 6 columns

[5]:
eop.meta_info["ct_eu_hierarchy"]
/home/elena/anaconda3/envs/aitlas-py37/lib/python3.7/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)
[5]:
ct_eu_code ct_eu_name level level_8 level_7 level_6 level_5 level_4 level_3 level_2 level_1
0 ARA Arable land level_2 NaN NaN NaN NaN NaN NaN ARA UAA
1 ARA99 Other arable land crops n.e.c. level_3 NaN NaN NaN NaN NaN ARA99 ARA UAA
2 C0000 Cereals for the production of grain (including... level_3 NaN NaN NaN NaN NaN C0000 ARA UAA
3 C1000 Cereals (excluding rice) for the production of... level_4 NaN NaN NaN NaN C1000 C0000 ARA UAA
4 C1100 Wheat and spelt level_5 NaN NaN NaN C1100 C1000 C0000 ARA UAA
... ... ... ... ... ... ... ... ... ... ... ...
194 W1120 Grapes for wines with protected geographical i... level_6 NaN NaN W1120 W1100 W1000 H0000 PECR UAA
195 W1190 Grapes for other wines n.e.c. (without PDO/PGI) level_6 NaN NaN W1190 W1100 W1000 H0000 PECR UAA
196 W1200 Grapes for table use level_5 NaN NaN NaN W1200 W1000 H0000 PECR UAA
197 W1300 Grapes for raisins level_5 NaN NaN NaN W1300 W1000 H0000 PECR UAA
198 W1900 Grapes for other purposes n.e.c. level_5 NaN NaN NaN W1900 W1000 H0000 PECR UAA

199 rows × 11 columns

Each EOPatch is 100x100 pixels, containing timeseries for each pixel for multiple features

[6]:
import matplotlib.pyplot as plt
plt.figure(figsize=(10,10))
plt.imshow(eop.data['FEATURES_S2'][12][...,[0,1,2]] * 2.5)
/home/elena/anaconda3/envs/aitlas-py37/lib/python3.7/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)
[6]:
<matplotlib.image.AxesImage at 0x7f0304317b00>
../_images/examples_breizhcrops_eopatch_data_analysis_8_2.png

Each EOPatch contains information about the “crop fields” it contains?

[7]:
eop.vector_timeless["CROP_TYPE_GDF"]
/home/elena/anaconda3/envs/aitlas-py37/lib/python3.7/site-packages/ipykernel/ipkernel.py:283: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.
  and should_run_async(code)
[7]:
polygon_id ct_code ct_eu_code geometry ct_id ct_eu_id
0 2207423.00000000000 204 J0000 MULTIPOLYGON (((554154.665 5091148.769, 554288... 75 101
1 2964049.00000000000 801 C1100 MULTIPOLYGON (((554436.408 5091544.271, 554545... 173 5
2 3077572.00000000000 801 C1100 MULTIPOLYGON (((554634.457 5091016.958, 554769... 173 5
3 2964043.00000000000 801 C1100 MULTIPOLYGON (((554472.410 5091686.704, 554581... 173 5
4 3051327.00000000000 5 C1500 MULTIPOLYGON (((554027.728 5091339.028, 554030... 6 19
... ... ... ... ... ... ...
90 2114371.00000000000 204 J0000 MULTIPOLYGON (((554156.819 5091203.299, 554155... 75 101
91 2964307.00000000000 809 C1300 MULTIPOLYGON (((554376.712 5091902.957, 554379... 179 13
92 2207417.00000000000 204 J0000 MULTIPOLYGON (((554335.377 5091010.159, 554491... 75 101
93 2588116.00000000000 204 J0000 MULTIPOLYGON (((554233.185 5090966.385, 554125... 75 101
94 3051299.00000000000 30 I1130 MULTIPOLYGON (((554619.762 5091061.089, 554624... 27 87

95 rows × 6 columns

[ ]:
eop.vector_timeless["CROP_TYPE_GDF"].iloc[0].geometry

Crop types mask

[9]:
import matplotlib.pyplot as plt
plt.figure(figsize=(10,10))
plt.imshow(eop.mask_timeless['CROP_TYPE'])
[9]:
<matplotlib.image.AxesImage at 0x7f0304214d30>
../_images/examples_breizhcrops_eopatch_data_analysis_13_1.png