Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save the T90P as the nc file, the type value is numpy.timedelta64. #1549

Closed
1 task done
CGL5230 opened this issue Dec 6, 2023 · 2 comments
Closed
1 task done

Save the T90P as the nc file, the type value is numpy.timedelta64. #1549

CGL5230 opened this issue Dec 6, 2023 · 2 comments

Comments

@CGL5230
Copy link

CGL5230 commented Dec 6, 2023

Generic Issue

  • xclim version:0.46.0
  • Python version:3.11
  • Operating System:Linux

Description

I save the TG90P index as nc format. But I open the nc file and find the type of TG90P is numpy.timedelta64. The expected type is numpy.

What I Did

I calculated the TG90P by ssp585_tas_p90 = xclim.core.calendar.percentile_doy(tas_AWI_CM_ssp585.tas,per=90) AWI_CM_ssp585_TG90P = xclim.indicators.atmos.tg90p(tas='tas',tas_per=ssp585_tas_p90,freq='YS',ds=tas_AWI_CM_ssp585) and save as the nc format as ssp585_tas_p90.to_netcdf('/home/workdir/WHs_Climate/future/cmip6/indexs/AWI_CM_ssp585_tg90P_p90.nc') AWI_CM_ssp585_TG90P.to_netcdf('/home/workdir/WHs_Climate/future/cmip6/indexs/AWI_CM_ssp585_TG90P.nc')

What I Received

This value is not intuitive, it should be a "number of days" greater than a certain threshold.
image

Code of Conduct

  • I agree to follow this project's Code of Conduct
@CGL5230
Copy link
Author

CGL5230 commented Dec 6, 2023

I read the description of TG90P . I think the type of tg90P should be "number".

.Returns:tg90p (DataArray) – Number of days with mean temperature above the 90th percentile (days_with_air_temperature_above_threshold) [days],

@aulemahal
Copy link
Collaborator

That's a feature of xarray. It reads that the units are "days" and it thinks it will help you by giving you "timedelta" objects.

The workaround is to open the netcdf with decode_timedelta=False. See options on https://docs.xarray.dev/en/stable/generated/xarray.open_dataset.html#xarray.open_dataset.

xr.open_dataset('/home/workdir/WHs_Climate/future/cmip6/indexs/AWI_CM_ssp585_TG90P.nc', decode_timedelta=False)

@CGL5230 CGL5230 closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants