IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Calcul scientifique Python Discussion :

visualiser fichier grib


Sujet :

Calcul scientifique Python

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 140
    Points
    140
    Par défaut visualiser fichier grib
    Bonjour,

    J'essaie de visualiser un fichier grib avec matplotlib.

    J'ai installé matplotlib, eccodes, cfgrib et ecmwflibs

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    grib = xr.open_dataset(self.file, engine="cfgrib")
     
    ds = grib.isel(step=0, heightAboveGround=0)
    temperature = ds['dpt']
    print(temperature.shape)
    print(type(temperature))
    Résultat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    (601, 801)
    <class 'xarray.core.dataarray.DataArray'>
    Mais quand je veut afficher les données graphiquement avec matplotlib, je fais temperature.plot(), j'ai l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ECCODES ERROR   :  JPEG support not enabled. Please rebuild with -DENABLE_JPG=ON
    Pourquoi il cherche le support jpeg, alors je passe une instruction de matplotlib?
    comment résoudre le problème?

    Merci,
    Nico

  2. #2
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    4 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 4 031
    Points : 9 429
    Points
    9 429
    Par défaut
    hello,


    pour pouvoir t'aider , il va falloir que tu nous donnes plus d'infos :
    1 - Sous quel O.S es tu ?
    2 - Quelle est ta version de python ? les versions des modules utilisés ?
    3 - Quel est ton code complet.


    Moi avec ce code sous windows 11 python 3.10 eccodes 1.7.0 ecmwflibs 0.6.3 cfgrib 0.9.12 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    import xarray as xr
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    import cartopy
    ds = xr.open_dataset("d:/temp/era5-2mt-2019-03-uk.grib", engine="cfgrib")
    ds = ds - 273.15
    fig = plt.figure(figsize=(10, 10))
    ax = plt.axes(projection=ccrs.Robinson())
    ax.coastlines(resolution="10m")
    plot = ds.t2m[0].plot(
        cmap=plt.cm.coolwarm, transform=ccrs.PlateCarree(), cbar_kwargs={"shrink": 0.6}
    )
    plt.title("ERA5 - 2m temperature British Isles March 2019")
    plt.show()
    cela fonctionne et j'obtiens ceci :
    Nom : BritishGrib.png
Affichages : 76
Taille : 84,9 Ko

    Ami calmant, J.P
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 140
    Points
    140
    Par défaut
    Bonjour,

    Je suis sous Windows 10, avec les mêmes versions de eccodes, ecmwflibs et cfgrib, et cartopy version 0.23.0, et Python 3.11.

    Quand je lance le code, j'ai l'erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    mypath\Tests python\format grib2\python\venv\Lib\site-packages\cartopy\io\__init__.py:241: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_physical/ne_10m_coastline.zip
      warnings.warn(f'Downloading: {url}', DownloadWarning)
    Si je supprime l'affichage des coastlines, j'ai bien la carte qui s'affiche.

    Concernant mes données, je teste des jeux de données météo france, téléchargeables ici (modèle Arome)
    Quand je check mon jeu de données, j'ai ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <xarray.Dataset> Size: 2GB
    Dimensions:            (step: 6, heightAboveGround: 24, latitude: 601,
                            longitude: 801)
    Coordinates:
        time               datetime64[ns] 8B ...
      * step               (step) timedelta64[ns] 48B 07:00:00 08:00:00 ... 12:00:00
      * heightAboveGround  (heightAboveGround) float64 192B 20.0 35.0 ... 3e+03
      * latitude           (latitude) float64 5kB 53.0 52.98 52.95 ... 38.03 38.0
      * longitude          (longitude) float64 6kB -8.0 -7.975 -7.95 ... 11.98 12.0
        valid_time         (step) datetime64[ns] 48B ...
    Data variables:
        z                  (step, heightAboveGround, latitude, longitude) float32 277MB ...
        tke                (step, heightAboveGround, latitude, longitude) float32 277MB ...
        clwc               (step, heightAboveGround, latitude, longitude) float32 277MB ...
        crwc               (step, heightAboveGround, latitude, longitude) float32 277MB ...
        cswc               (step, heightAboveGround, latitude, longitude) float32 277MB ...
        ciwc               (step, heightAboveGround, latitude, longitude) float32 277MB ...
        cc                 (step, heightAboveGround, latitude, longitude) float32 277MB ...
        q                  (step, heightAboveGround, latitude, longitude) float32 277MB ...
        dpt                (step, heightAboveGround, latitude, longitude) float32 277MB ...
    Attributes:
        GRIB_edition:            2
        GRIB_centre:             lfpw
        GRIB_centreDescription:  French Weather Service - Toulouse
        GRIB_subCentre:          0
        Conventions:             CF-1.7
        institution:             French Weather Service - Toulouse
        history:                 2024-05-28T07:52 GRIB to CDM+CF via cfgrib-0.9.1...

    J'essaie d'afficher les données de la variable dpt, avec step=0 (07:00:00), et heightAboveGround=0 (20.0)
    mon code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
        ds = xr.open_dataset(myfile, engine="cfgrib")
        fig = plt.figure(figsize=(10, 10))
        ax = plt.axes(projection=ccrs.Robinson())
        plot = ds.dpt[0][0].plot(
           cmap=plt.cm.coolwarm, transform=ccrs.PlateCarree(), cbar_kwargs={"shrink": 0.6}
        )
        plt.show()
    ... et j'ai toujours la même erreur.

    Nico

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 140
    Points
    140
    Par défaut
    Le problème était déjà identifié en 2019. cf. ici et ici

    quid de la solution?

    Nico

  5. #5
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    4 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 4 031
    Points : 9 429
    Points
    9 429
    Par défaut
    moi je n'ai pas d'erreur d'affichage avec ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    import xarray as xr
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    import cartopy
    ds = xr.open_dataset("d:/temp/aromeAntille.grib", engine="cfgrib")
    print(ds)
    fig = plt.figure(figsize=(10, 10))
    ax = plt.axes(projection=ccrs.Robinson())
    ax.coastlines(resolution="10m")
    plot = ds.t[0].plot(
        cmap=plt.cm.coolwarm, transform=ccrs.PlateCarree(), cbar_kwargs={"shrink": 0.6}
    )
    plt.title("ANTIL__0025__HP1__000H__2024-05-27T00_00_00Z ")
    plt.show()
    il utilise le fichier arom-om-ANTIL__0025__HP1__000H__2024-05-27T00_00_00Z.grib2
    <xarray.Dataset> Size: 120MB
    Dimensions: (heightAboveGround: 12, latitude: 529, longitude: 945)
    Coordinates:
    time datetime64[ns] 8B ...
    step timedelta64[ns] 8B ...
    * heightAboveGround (heightAboveGround) float64 96B 20.0 50.0 ... 3e+03
    * latitude (latitude) float64 4kB 22.9 22.88 22.85 ... 9.725 9.7
    * longitude (longitude) float64 8kB 284.7 284.7 284.7 ... 308.3 308.3
    valid_time datetime64[ns] 8B ...
    Data variables:
    wdir (heightAboveGround, latitude, longitude) float32 24MB ...
    z (heightAboveGround, latitude, longitude) float32 24MB ...
    t (heightAboveGround, latitude, longitude) float32 24MB ...
    r (heightAboveGround, latitude, longitude) float32 24MB ...
    pres (heightAboveGround, latitude, longitude) float32 24MB ...
    Attributes:
    GRIB_edition: 2
    GRIB_centre: lfpw
    GRIB_centreDescription: French Weather Service - Toulouse
    GRIB_subCentre: 0
    Conventions: CF-1.7
    institution: French Weather Service - Toulouse

    history: 2024-05-28T11:33 GRIB to CDM+CF via cfgrib-0.9.1...
    Nom : AromeAntille.jpg
Affichages : 63
Taille : 61,3 Ko
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 140
    Points
    140
    Par défaut
    La même chose avec mon fichier sur la France --> ça plante toujours !

    Une piste que j'ai trouvé:
    Le fichier des Antilles (qui fonctionne) a les longitudes au format 0/360°, alors que le fichier sur la France (qui ne fonctionne pas) a les longitudes au format -180/180.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <xarray.Dataset> Size: 17MB
    Dimensions:            (latitude: 601, longitude: 801)
    Coordinates:
        time               datetime64[ns] 8B ...
        step               timedelta64[ns] 8B 07:00:00
        heightAboveGround  float64 8B 20.0
      * latitude           (latitude) float64 5kB 53.0 52.98 52.95 ... 38.03 38.0
      * longitude          (longitude) float64 6kB -8.0 -7.975 -7.95 ... 11.98 12.0
        valid_time         datetime64[ns] 8B ...
    Data variables:
        z                  (latitude, longitude) float32 2MB ...
        tke                (latitude, longitude) float32 2MB ...
        clwc               (latitude, longitude) float32 2MB ...
        crwc               (latitude, longitude) float32 2MB ...
        cswc               (latitude, longitude) float32 2MB ...
        ciwc               (latitude, longitude) float32 2MB ...
        cc                 (latitude, longitude) float32 2MB ...
        q                  (latitude, longitude) float32 2MB ...
        dpt                (latitude, longitude) float32 2MB ...
    Attributes:
        GRIB_edition:            2
        GRIB_centre:             lfpw
        GRIB_centreDescription:  French Weather Service - Toulouse
        GRIB_subCentre:          0
        Conventions:             CF-1.7
        institution:             French Weather Service - Toulouse
        history:                 2024-05-28T15:23 GRIB to CDM+CF via cfgrib-0.9.1...
    Comment modifier le fichier sur la France pour avoir des longitudes au format 0/360 ?

    Je ne sais pas si c'est ça qui fait planter, mais peut-être que Cartopy a des problèmes avec ça ?

    Nico

  7. #7
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    4 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 4 031
    Points : 9 429
    Points
    9 429
    Par défaut
    Quel est le fichier grib que tu utilises car il y a des HP1 SP1 SP2 etc ...
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

  8. #8
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    447
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 447
    Points : 140
    Points
    140
    Par défaut
    HP2 téléchargé ici!
    https://mf-models-on-aws.org/#arome-...-04-27/00/HP2/

    j'ai pris 07H12H.grib2

    Nico

  9. #9
    Expert éminent
    Avatar de jurassic pork
    Homme Profil pro
    Bidouilleur
    Inscrit en
    Décembre 2008
    Messages
    4 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Bidouilleur
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2008
    Messages : 4 031
    Points : 9 429
    Points
    9 429
    Par défaut
    Hello,
    cela ressemble à un problème sous windows car j'ai la même erreur que toi sous windows mais cela fonctionne sous Lubuntu 22.04
    avec ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    import xarray as xr
    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    import cartopy
    ds = xr.open_dataset("/home/user/Documents/arome-france_HP2.grib", engine="cfgrib")
    print(ds)
    fig = plt.figure(figsize=(10, 10))
    ax = plt.axes(projection=ccrs.Robinson())
    ax.coastlines(resolution="10m")
    plot = ds.dpt[0][0].plot(
        cmap=plt.cm.coolwarm, transform=ccrs.PlateCarree(), cbar_kwargs={"shrink": 0.6}
    )
    plt.title("AROME__FRANCE__HP2__ 07H12H ")
    plt.show()


    Nom : aromeLubuntu.jpg
Affichages : 47
Taille : 51,8 Ko

    ami calmant, J.P
    Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Discussions similaires

  1. lire un fichier GRIB
    Par Flaherty Mc Coillean dans le forum Images
    Réponses: 8
    Dernier message: 16/02/2010, 11h45
  2. Visualiser fichiers 3D archicad sur Web ?
    Par rpatruno dans le forum Général Conception Web
    Réponses: 3
    Dernier message: 07/01/2009, 22h39
  3. varbinary et visualisation fichier
    Par icicmoi dans le forum Windows Forms
    Réponses: 8
    Dernier message: 15/03/2008, 19h24
  4. lire des fichiers GRIB avec darwin
    Par kreff dans le forum Applications et environnements graphiques
    Réponses: 1
    Dernier message: 13/09/2007, 01h33
  5. [ASP][MSXML] visualisation fichier XML problème encoding
    Par RobinNono dans le forum XML/XSL et SOAP
    Réponses: 1
    Dernier message: 12/02/2007, 14h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo