1919
2020
2121def time_intpl (file_path , prefix ):
22- """ Interpolation of chemistry fields with respect to time variable.
22+
2323 """
24+ Interpolate chemistry fields with respect to time between consecutive NetCDF files.
25+
26+ This function generates new NetCDF files at intermediate times between existing
27+ CAM-Chem output files. Takes the arithmetic mean of chemical and surface pressure
28+ fields and creates interpolated 'time' and 'datesec' variables.
29+
30+ Parameters
31+ ----------
32+ file_path : str
33+ Path to the directory containing the input NetCDF files.
34+ prefix : str
35+ Filename prefix for identifying the input NetCDF files to interpolate.
36+
37+ Returns
38+ -------
39+ None
40+
41+ """
42+
2443 files = sorted ([f for f in os .listdir (file_path ) if f .startswith (prefix )])
2544
2645 for i in range (len (files ) - 1 ):
@@ -160,15 +179,25 @@ def date_from_days_since_ref(days_since_ref, ref_date):
160179
161180def extract_timeslice (in_file , out_file_template , spec_intpl , ref_date ):
162181 """
163- - Extract a time slice from the input NetCDF file.
164- - Adjust longitude from [0, 360) to (-180, 180].
165-
166- Parameters:
167- - in_file (str): Path to the input NetCDF file containing data for each time step.
168- - out_file_template (str): Template for the output NetCDF file name with strftime placeholder.
169- - spec_intpl (list): List with species to be copied from in_file.
170-
171- Returns:
182+ Extract a single time slice from a NetCDF file and adjust longitudes.
183+
184+ Copies selected species and metadata from an input NetCDF file into a new
185+ NetCDF file for each time step.
186+ Longitudes are adjusted from [0, 360) to [-180, 180).
187+
188+ Parameters
189+ ----------
190+ in_file : str
191+ Path to the input NetCDF file.
192+ out_file_template : str
193+ Template string for the output filename.
194+ spec_intpl : list of str
195+ List of chemical species to extract from the input file.
196+ ref_date : str
197+ Reference date (YYYY-MM-DD HH:MM:SS) used to convert time variables.
198+
199+ Returns
200+ -------
172201 None
173202 """
174203
@@ -325,6 +354,26 @@ def extract_timeslice(in_file, out_file_template, spec_intpl, ref_date):
325354
326355
327356def log_intpl_timeslice (pres_m , pres , var_data ):
357+ """
358+ Perform vertical interpolation of chemical data using log-pressure weighting.
359+
360+ For each chemistry level, the two nearest meteorological levels are identified
361+ and a logarithmic interpolation is applied.
362+
363+ Parameters
364+ ----------
365+ pres_m : ndarray
366+ Pressure on meteorological levels (Pa).
367+ pres : ndarray
368+ Pressure on chemical levels (Pa).
369+ var_data : ndarray
370+ Chemical field data to interpolate.
371+
372+ Returns
373+ -------
374+ ndarray
375+ Interpolated chemical field on meteorological levels.
376+ """
328377 pres_m_flipped = np .flip (pres_m , axis = 0 )
329378 pres_flipped = np .flip (pres , axis = 0 )
330379 var_data_flipped = np .flip (var_data , axis = 0 )
@@ -375,8 +424,24 @@ def log_intpl_timeslice(pres_m, pres, var_data):
375424
376425
377426def hybrid_pressure_interpolation (in_ds , out_ds , var_name , time_indices ):
378- """Perform vertical interpolation of 'var_name'.
379- The interpolation is linear with the log pressure.
427+ """
428+ Interpolate chemical variable vertically using log-pressure interpolation.
429+
430+ Parameters
431+ ----------
432+ in_ds : netCDF4.Dataset
433+ Input dataset containing the chemical variable.
434+ out_ds : netCDF4.Dataset
435+ Output dataset with meteorological levels.
436+ var_name : str
437+ Name of the chemical variable to interpolate.
438+ time_indices : list of int
439+ Time indices to process in the datasets.
440+
441+ Returns
442+ -------
443+ ndarray
444+ Array of vertically interpolated variable on meteorological levels.
380445 """
381446 # Pressure on vertical levels of meteo data
382447 pres_m = out_ds ['pres_m' ][:]
@@ -398,19 +463,33 @@ def hybrid_pressure_interpolation(in_ds, out_ds, var_name, time_indices):
398463
399464def vert_intpl (chem_filename , meteo_filename , out_filename , spec , start_chunk ,
400465 end_chunk , ref_date ):
401- """Perform vertical interpolation of atmospheric chemical fields using meteorological data.
402-
403- Parameters:
404- - chem_filename (str): Path to the netCDF file containing atmospheric chemical data.
405- - meteo_filename (str): Path to the netCDF file containing meteorological data.
406- - out_filename (str): Path to the output netCDF file for interpolated data.
407- - species (list): List of chemical species names to be interpolated.
408- - start_chunk (datetime object): Start of simulation time.
409- - end_chunk (datetime object): End of simulation time.
410-
411- Returns:
466+ """
467+ Perform vertical interpolation of chemical fields using meteorological data.
468+
469+ This function interpolates chemical species from their CAM-Chem vertical levels
470+ onto the hybrid sigma-pressure levels of the meteorological dataset.
471+
472+ Parameters
473+ ----------
474+ chem_filename : str
475+ Path to the NetCDF file containing chemical data.
476+ meteo_filename : str
477+ Path to the NetCDF file containing meteorological data.
478+ out_filename : str
479+ Path for the output NetCDF file with interpolated results.
480+ spec : list of str
481+ List of chemical species to interpolate.
482+ start_chunk : datetime.datetime
483+ Start of the simulation time window to process.
484+ end_chunk : datetime.datetime
485+ End of the simulation time window to process.
486+ ref_date : str
487+ Reference date (YYYY-MM-DD HH:MM:SS) used to convert time variables.
488+
489+ Returns
490+ -------
412491 None
413-
492+
414493 """
415494
416495 with Dataset (chem_filename , 'r' ) as c_ds , Dataset (meteo_filename ,
0 commit comments