How to get data out of a NetCDF file using Python: depth profile

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

КОМЕНТАРІ • 19

  • @fransiscojefta
    @fransiscojefta 14 днів тому

    Thank you so much Sir your tutorial helps me a lot. it's so insightful!
    but i have a couple of questions sir:
    1. just to make sure, does the prompt from line 1-18 works in jupyter notebook?
    2. If I use a monthly climatology timeframe, does that mean I should average each month first before following the prompt in this video?
    Thank you so much, have a nice day Sir!

    • @LukeDataManager
      @LukeDataManager  13 днів тому

      Pretty much all python code can work in jupyter notebook.
      Regarding your data it really depends what you are trying to achieve.

  • @samuelb1004
    @samuelb1004 Рік тому +2

    Legendary!

  • @MuhammadAsim-mh4xo
    @MuhammadAsim-mh4xo 2 роки тому +1

    Thanks, Luke

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

    very helpful

  • @MatinaNikolopoulou-dp5cz
    @MatinaNikolopoulou-dp5cz Рік тому +1

    Hi Luke, Thank you for this video, it's very helpful. Is it possible to extract only one variable from a netcdf to a new one. I have a netcdf with many variables and I want to extract to a netcdf the one that is called 'temp' , it has dimensions 'time', 'lat', 'lon'.

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

      Hi Matina, you can look at this Jupyter Notebook on accessing data with multiple dimensions: github.com/lhmarsden/NetCDF-CF_workshops/blob/main/Python_workshop_materials/xarray_analyse_ctd_data_whole_cruise.ipynb

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

    Luke, how should the code be changed to access this data:
    [3110400 values with dtype=float32]
    Coordinates:
    * time (time) datetime64[ns] 1901-01-16 1901-02-16 ... 1901-12-16
    * lat (lat) float32 -89.75 -89.25 -88.75 -88.25 ... 88.75 89.25 89.75
    * lon (lon) float32 -179.8 -179.2 -178.8 -178.2 ... 178.8 179.2 179.8
    Attributes:
    time_op_ncl: Climatology: 30 years
    long_name: near-surface temperature
    units: degC
    correlation_decay_distance: 1200.0
    -Thanks!

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

      Hi Shelby, it is difficult for me to know without seeing the variables and what dimensions you have, but you can look at this Jupyter Notebook on accessing data with multiple dimensions: github.com/lhmarsden/NetCDF-CF_workshops/blob/main/Python_workshop_materials/xarray_analyse_ctd_data_whole_cruise.ipynb

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

      So if you have a variable called 'TEMP' with dimensions 'time', 'lat', 'lon' you can dump the variable to a Pandas dataframe
      df = data['TEMP'].to_dataframe()

  • @tilmanmarschallek4602
    @tilmanmarschallek4602 9 місяців тому

    Thanks for the nice Video. Unfortunately I have a problem. I installed xarray with conda. Only problem, when I type in „Import xarray as xr“, the error code: on module named ‘xarray‘ shows up. Any idea how to solve that problem? Chers

    • @LukeDataManager
      @LukeDataManager  9 місяців тому

      Hi, thanks for the comment. It is difficult for me to troubleshoot this without more information. Are you using multiple conda environments? It is difficult to solve this kind of problem without sitting at your computer with you. I advise writing a question clearly explaining your problem on stackoverflow

    • @tilmanmarschallek4602
      @tilmanmarschallek4602 9 місяців тому

      Thanks a lot. Keep up the work👋🏼

  • @alial-wakeel8435
    @alial-wakeel8435 2 роки тому

    Hi Luke,
    Many thanks for sharing this video.
    I'm wondering how is it possible to extract data (of a variable) from a netCDF file by date? Or between two dates.
    To elaborate, I have hourly data of temperature over three years. However, I need to extract those for exactly one year. How is this possible using xarray?
    I really appreciate any possible help with this,

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

      Thanks. If I was doing this, I would first export my variable to a Pandas dataframe
      df = data['TEMPERATURE'].to_dataframe()
      You should now have a dataframe with two columns, time and temperature. You then need to convert your times (probably in hours since time X) to actual datetime values, something like below where 'start_datetime' is a datetime value:
      df['DATETIMES'] = start_datetime + pd.to_timedelta(df['TIME'], unit='h')
      The you need to extract your trim down your dataframe between two desired dates. This is nicely addressed in this answer on stackoverflow:
      stackoverflow.com/a/29370182/14125020

    • @alial-wakeel8435
      @alial-wakeel8435 2 роки тому +1

      @@LukeDataManager
      So many thanks for the help, Luke.
      In fact, I started developing one similar approach taking into consideration the number of hours per (leap) year. It works but quite slow, so I will check your approach and see if I can get quicker results.
      Once again, I really appreciate your help.