Read and Plot NetCDF Data in Python with xarray and rioxarray

Поділитися
Вставка
  • Опубліковано 19 вер 2024

КОМЕНТАРІ • 12

  • @harleyslade8799
    @harleyslade8799 2 роки тому +3

    Hey, You're my GIS and python hero man!
    These videos have helped so much dealing with geospatial data.
    I've got a problem with xarray to netCDF and I've been pulling my hair out for the better part of a week trying to figure it out.
    I've been playin around with Fatiando's Verde for gridding and interpolating geophysical point data in python. Their programs work nicely and have a built-in xarray gridding and export to NetCDF functionality. Unfortunately the coordinates never seem to export correctly, and instead coordinates are built starting at 0,0 despite being correctly displayed in matplotlib. This is the same when using the function: to_rasterio.
    I decided to try building the NetCDF file from scratch using your tutorial "Create a netCDF dataset with python(NETCDF4)", but I noticed the file that you exported at the end also had one corner at the origin(0, 0) when you loaded it into QGIS.
    No matter what I try when adding the coordinates from the xarray it always ends with the xarray dataArray being the wrong shape to load in as an array.
    I'm just about to resort to georeferencing the output by hand in QGIS by drawing map coordinates. haha.
    Next step I'm going to try is gridding the coordinates separately into an independent numpy array and bypassing the xarray altogether.
    If you have any pointers on getting those coordinates to show up correctly when exporting a netCDF I'd be super grateful.
    Again, great videos, And holy cow I wish these netCDF files were nice like tiffs. Really makes you appreciate GDAL.

    • @harleyslade8799
      @harleyslade8799 2 роки тому +1

      I figured it out!
      I needed to use grid.rio.set_spatial_dims("easting", "northing", inplace=True)
      then grid.rio.write_crs(input_crs=CRS.from_epsg(XXXX), inplace=True)
      then I could finally export to raster with rio.to_raster. to_netCDF probably preserves coordinates too, I'll have to check on that.
      figured I'd post here in case anyone else was having the same issue.

    • @geospatialschool
      @geospatialschool  2 роки тому

      Thanks! Super helpful comment!

  • @CTAC92
    @CTAC92 Рік тому

    17:01 Unable to allocate 2.21 GiB for an array with shape (366, 585, 1386) and data type float64

  • @zulqarnainsatti8007
    @zulqarnainsatti8007 2 роки тому

    Hello... how I can extract a specific year from the (.nc) file?

  • @juliusbamah5338
    @juliusbamah5338 Рік тому +1

    Nice video but i have NetCDF file and am finding it difficult to mask out my AOI. I tried examples from your videos but isnot working for me. Any assistance would be so much appreciated after pulling my hair over two weeks

    • @geospatialschool
      @geospatialschool  Рік тому

      Hard to know how to help without the details, exactly what you've tried, etc

  • @sazzaduleanan4040
    @sazzaduleanan4040 2 роки тому

    Hello there, I have a clipped (of the exact study area that I am interested in) but a pretty big netCDF file (.nc file) of 1.64 gigabytes. Inside that file, there are three dimensions (lat., long., and day) and a data variable of 'monthly_precipitation' from 1901 to 2018. From that file, I need to extract the 'monthly_precipitation' data for only the years of 1980 to 2018 in .csv format. How can I do that ?
    I'm desperately seeking your suggestions as I was madly looking for the hints of the solution of this particular problem for at least last ten days in youtube, github and literally everywhere.
    I appreciate any type of responses from you in advance !

    • @TheAkajan
      @TheAkajan 2 роки тому

      Cheese and butter!
      You could use CDO to clip datasets for your study time period using this command
      cdo seldate,19800101,20181231 inputfile.nc outputfile.nc

  • @danielhamill1602
    @danielhamill1602 2 роки тому

    Nice work dude!

    • @danielhamill1602
      @danielhamill1602 2 роки тому

      I have been confused about how to create cf compliant netcdf files from a time series of GTiff

    • @geospatialschool
      @geospatialschool  2 роки тому

      Welcome to the club. I have a love/hate relationship with NetCDF. They can be really convenient but they never seem to be formatted the same way. Hope you guys are doing well