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!
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'.
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
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
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()
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
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
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,
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
@@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.
Legendary!
💪
Thanks, Luke
You're welcome 🙂
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!
Pretty much all python code can work in jupyter notebook.
Regarding your data it really depends what you are trying to achieve.
very helpful
Thanks!
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'.
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
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!
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
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()
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
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
Thanks a lot. Keep up the work👋🏼
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,
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
@@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.