@@ -124,6 +124,19 @@ def download_instrument(
124124 time_offset = time_offset ,
125125 )
126126
127+ def _get_time_offset (
128+ self , date : datetime .date | None = None
129+ ) -> datetime .timedelta | None :
130+ try :
131+ calibration = self .processor .client .calibration (
132+ self .params .instrument .pid , date or self .params .date
133+ )
134+ if "time_offset" in calibration ["data" ]:
135+ return datetime .timedelta (minutes = calibration ["data" ]["time_offset" ])
136+ except CloudnetAPIError :
137+ pass
138+ return None
139+
127140
128141class ProcessRadar (ProcessInstrument ):
129142 def process_rpg_fmcw_94 (self ) -> None :
@@ -232,18 +245,7 @@ def _add_calibration(
232245
233246class ProcessDopplerLidarWind (ProcessInstrument ):
234247 def process_halo_doppler_lidar (self ) -> None :
235- try :
236- calibration = self .processor .client .calibration (
237- self .params .instrument .pid , self .params .date
238- )
239- time_offset = (
240- datetime .timedelta (minutes = calibration ["data" ]["time_offset" ])
241- if "time_offset" in calibration ["data" ]
242- else None
243- )
244- except CloudnetAPIError :
245- time_offset = None
246-
248+ time_offset = self ._get_time_offset ()
247249 full_paths , self .uuid .raw = self .download_instrument (
248250 include_pattern = r".*\.hpl" ,
249251 exclude_pattern = r"Stare.*" ,
@@ -352,17 +354,7 @@ def _calibration_options(self) -> doppy.product.WindOptions | None:
352354
353355class ProcessDopplerLidar (ProcessInstrument ):
354356 def process_halo_doppler_lidar (self ) -> None :
355- try :
356- calibration = self .processor .client .calibration (
357- self .params .instrument .pid , self .params .date
358- )
359- time_offset = (
360- datetime .timedelta (minutes = calibration ["data" ]["time_offset" ])
361- if calibration is not None and "time_offset" in calibration ["data" ]
362- else None
363- )
364- except CloudnetAPIError :
365- time_offset = None
357+ time_offset = self ._get_time_offset ()
366358 # Co files either have "co" tag or no tags at all.
367359 full_paths_co , raw_uuids_co = self .download_instrument (
368360 filename_prefix = "Stare" ,
@@ -537,17 +529,7 @@ def process_cl31(self) -> None:
537529 self ._call_ceilo2nc ("cl31" )
538530
539531 def process_cl51 (self ) -> None :
540- try :
541- calibration = self .processor .client .calibration (
542- self .params .instrument .pid , self .params .date
543- )
544- time_offset = (
545- datetime .timedelta (minutes = calibration ["data" ]["time_offset" ])
546- if "time_offset" in calibration ["data" ]
547- else None
548- )
549- except CloudnetAPIError :
550- time_offset = None
532+ time_offset = self ._get_time_offset ()
551533 full_paths , self .uuid .raw = self .download_instrument (time_offset = time_offset )
552534 full_paths .sort ()
553535 _concatenate_text_files (full_paths , self .daily_path )
@@ -560,13 +542,13 @@ def process_cl51(self) -> None:
560542 self ._call_ceilo2nc ("cl51" )
561543
562544 def process_cl61d (self ) -> None :
563- current_offset = self ._get_cl61d_time_offset (self .params .date )
545+ current_offset = self ._get_time_offset (self .params .date )
564546 full_paths , raw_uuids = self .download_instrument (
565547 exclude_pattern = "clu-generated"
566548 )
567549 _apply_cl61d_time_offset (full_paths , current_offset )
568550 previous_date = self .params .date - datetime .timedelta (days = 1 )
569- previous_offset = self ._get_cl61d_time_offset (previous_date )
551+ previous_offset = self ._get_time_offset (previous_date )
570552 n_hours_previous = _cl61d_boundary_hours (
571553 current_offset , previous_offset , direction = "previous"
572554 )
@@ -582,7 +564,7 @@ def process_cl61d(self) -> None:
582564 full_paths .extend (paths_previous )
583565 raw_uuids .extend (uuids_previous )
584566 next_date = self .params .date + datetime .timedelta (days = 1 )
585- next_offset = self ._get_cl61d_time_offset (next_date )
567+ next_offset = self ._get_time_offset (next_date )
586568 n_hours_next = _cl61d_boundary_hours (
587569 current_offset , next_offset , direction = "next"
588570 )
@@ -618,17 +600,6 @@ def process_cl61d(self) -> None:
618600 self ._call_ceilo2nc ("cl61d" )
619601 self .uuid .raw = _get_valid_uuids (raw_uuids , full_paths , valid_full_paths )
620602
621- def _get_cl61d_time_offset (self , date : datetime .date ) -> datetime .timedelta | None :
622- try :
623- calibration = self .processor .client .calibration (
624- self .params .instrument .pid , date
625- )
626- if "time_offset" in calibration ["data" ]:
627- return datetime .timedelta (minutes = calibration ["data" ]["time_offset" ])
628- except CloudnetAPIError :
629- pass
630- return None
631-
632603 def process_da10 (self ) -> None :
633604 full_paths , raw_uuids = self .download_instrument ()
634605 valid_full_paths = concat_wrapper .concat_netcdf_files (
@@ -928,14 +899,8 @@ def process_weather_station(self) -> None:
928899 )
929900 if self .params .site .id not in supported_sites :
930901 raise NotImplementedError ("Weather station not implemented for this site" )
931- try :
932- calibration = self .processor .client .calibration (
933- self .params .instrument .pid , self .params .date
934- )
935- except CloudnetAPIError :
936- calibration = None
937- if calibration and calibration .get ("data" , {}).get ("time_offset" ):
938- time_offset = datetime .timedelta (minutes = calibration ["data" ]["time_offset" ])
902+ time_offset = self ._get_time_offset ()
903+ if time_offset is not None :
939904 full_paths , self .uuid .raw = self .download_instrument (
940905 time_offset = time_offset
941906 )
0 commit comments