Using python to fill in missing days in a netCDF

61 Views Asked by At

I have a netCDF file that contains daily gridded hurs data. The file currently has 357 time steps (instead of 365) because it is missing specific days (I have listed them below). I want to insert the missing days and assign them Nan values, keeping all other data the same, and the file structure the same. How can I do this?

missing_dates = ['2022-03-01', '2022-04-01', '2022-05-01', '2022-06-01', '2022-07-01',
                '2022-08-01', '2022-09-01', '2022-10-01']

....

print(dsh4)
<xarray.Dataset>
Dimensions:    (time: 357, y: 497, x: 477, bnds: 2)
Coordinates:
    height     float64 ...
    lat        (y, x) float64 ...
    lon        (y, x) float64 ...
  * time       (time) object 2022-01-01 12:00:00 ... 2022-12-31 12:00:00
  * x          (x) float64 -5.95e+06 -5.925e+06 -5.9e+06 ... 5.925e+06 5.95e+06
  * y          (y) float64 -6.2e+06 -6.175e+06 -6.15e+06 ... 6.175e+06 6.2e+06
Dimensions without coordinates: bnds
Data variables:
    crs        |S1 ...
    hurs       (time, y, x) float32 ...
    time_bnds  (time, bnds) object ...
Attributes: (12/153)
    project_id:                                CORDEX
    ipcc_scenario_code:                        RCP85
    institute_id:                              ICTP
    note:                                      The domain is larger than AFR-22
    comment:                                   RegCM CORDEX Africa run
    experiment:                                AFR-22
    ...                                        ...
    driving_experiment:                        NCC-NorESM1-M, rcp85, r1i1p1
    driving_model_id:                          NCC-NorESM1-M
    model_id:                                  ICTP-RegCM4-7
    creation_date:                             2018-12-19-T23:13:30Z
    tracking_id:                               hdl:21.14103/b4b5f875-fdfe-4ef...
    c3s_disclaimer:                            This data has been curated and...
0

There are 0 best solutions below