Missing time variable in netcdf files

Use this Forum to find information on, or ask a question about, NASA Earth Science data.
Post Reply
geopyblacksea
Posts: 1
Joined: Mon Mar 04, 2024 6:37 am America/New_York
Answers: 0

Missing time variable in netcdf files

by geopyblacksea » Mon Mar 04, 2024 6:54 am America/New_York

Hello,

I have many netcdf files without time variable; and because that I can't merge all netcdf files into one, with nco tool.
To understand better how look a netcdf file, I run a simple Python code:
import xarray as xr
dataset = xr.open_dataset('T2000057.L3m_DAY_CHL.x_chlor_a.nc')
print(dataset.attrs) # Print global attributes

for var_name, var in dataset.variables.items():
print(f"\nVariable: {var_name}")
print(var.attrs) # Print variable attributes

The output:
{'product_name': 'T2000057.L3m_DAY_CHL.x_chlor_a.nc', 'instrument': 'MODIS', 'title': 'MODIST Level-3 Equidistant Cylindrical Mapped Image', 'project': 'Ocean Biology Processing Group (NASA/GSFC/OBPG)', 'platform': 'Terra', 'source': 'satellite observations from MODIS-Terra', 'temporal_range': 'day', 'processing_version': 'Unspecified', 'date_created': '2022-10-10T10:33:14.000Z', 'history': 'l3mapgen par=T2000057.L3m_DAY_CHL.x_chlor_a.nc.param ', 'l2_flag_names': 'ATMFAIL,LAND,HILT,HISATZEN,STRAYLIGHT,CLDICE,COCCOLITH,LOWLW,CHLWARN,CHLFAIL,NAVWARN,MAXAERITER,ATMWARN,HISOLZEN,NAVFAIL,FILTER,HIGLINT', 'time_coverage_start': '2000-02-25T21:10:01.000Z', 'time_coverage_end': '2000-02-26T23:49:59.000Z', 'start_orbit_number': 1012, 'end_orbit_number': 1028, 'map_projection': 'PlateCarree', 'latitude_units': 'degrees_north', 'longitude_units': 'degrees_east', 'northernmost_latitude': 47.89, 'southernmost_latitude': 38.84, 'westernmost_longitude': 27.05, 'easternmost_longitude': 42.84, 'geospatial_lat_max': 47.89, 'geospatial_lat_min': 38.84, 'geospatial_lon_max': 42.84, 'geospatial_lon_min': 27.05, 'latitude_step': 0.041705064, 'longitude_step': 0.041662272, 'sw_point_latitude': 38.86085, 'sw_point_longitude': 27.070831, 'spatialResolution': '4.638312 km', 'geospatial_lon_resolution': '4.638312 km', 'geospatial_lat_resolution': '4.638312 km', 'geospatial_lat_units': 'degrees_north', 'geospatial_lon_units': 'degrees_east', 'number_of_lines': 217, 'number_of_columns': 379, 'measure': 'Mean', 'suggested_image_scaling_minimum': 0.01, 'suggested_image_scaling_maximum': 20.0, 'suggested_image_scaling_type': 'LOG', 'suggested_image_scaling_applied': 'No', '_lastModified': '2022-10-10T10:33:14.000Z', 'Conventions': 'CF-1.6 ACDD-1.3', 'institution': 'NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group', 'standard_name_vocabulary': 'CF Standard Name Table v36', 'naming_authority': 'gov.nasa.gsfc.sci.oceandata', 'id': 'L3/T2000057.L3b_DAY_CHL.x.nc', 'license': 'https://science.nasa.gov/earth-science/earth-science-data/data-information-policy/', 'creator_name': 'NASA/GSFC/OBPG', 'publisher_name': 'NASA/GSFC/OBPG', 'creator_email': 'data@oceancolor.gsfc.nasa.gov', 'publisher_email': 'data@oceancolor.gsfc.nasa.gov', 'creator_url': 'https://oceandata.sci.gsfc.nasa.gov', 'publisher_url': 'https://oceandata.sci.gsfc.nasa.gov', 'processing_level': 'L3 Mapped', 'cdm_data_type': 'grid', 'proj4_string': '+proj=eqc +lat_ts=0 +lat_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +lon_0=34.945000', 'data_bins': 3177, 'data_minimum': 0.8330071, 'data_maximum': 21.772257}

Variable: chlor_a
{'long_name': 'Chlorophyll Concentration, OCI Algorithm', 'units': 'mg m^-3', 'standard_name': 'mass_concentration_of_chlorophyll_in_sea_water', 'valid_min': 0.001, 'valid_max': 100.0, 'reference': 'Hu, C., Lee Z., and Franz, B.A. (2012). Chlorophyll-a algorithms for oligotrophic oceans: A novel approach based on three-band reflectance difference, J. Geophys. Res., 117, C01011, doi:10.1029/2011JC007395.', 'display_scale': 'log', 'display_min': 0.01, 'display_max': 20.0}

Variable: lat
{'long_name': 'Latitude', 'units': 'degrees_north', 'standard_name': 'latitude', 'valid_min': -90.0, 'valid_max': 90.0}

Variable: lon
{'long_name': 'Longitude', 'units': 'degrees_east', 'standard_name': 'longitude', 'valid_min': -180.0, 'valid_max': 180.0}

Variable: palette
{}

I try to create new variable, with the following code, but I get many errors:
with nc.Dataset('T2000058.L3m_DAY_CHL.x_chlor_a.nc', 'a') as f:

# new dimension "time"
time_dim = f.createDimension('time', None)

# variable "time"
time_var = f.createVariable('time', 'f8', ('time',))

# attribute for "time"
time_var.units = 'seconds since 2000-01-01 00:00:00'
time_var.calendar = 'standard'

# get the value "time_coverage_start"
time_start = nc.date2num(f.getncattr('time_coverage_start'), time_var.units)

# Add data
time_var[:] = np.arange(0, 1000, dtype='float64') + time_start

# Save
f.sync()

I look forward to advice or ideas.

Tags:

Post Reply