code: def resam_calendar(
      calendar_raw: np.ndarray,
      freq_raw: Union[str, Freq],
      freq_sam: Union[str, Freq],
      region: str = None,
  ) -> np.ndarray:
      """
      Resample the calendar with frequency freq_raw into the calendar with frequency freq_sam
      Assumption:
          - Fix length (240) of the calendar in each day.
  
      Parameters
      ----------
      calendar_raw : np.ndarray
          The calendar with frequency  freq_raw
      freq_raw : str
          Frequency of the raw calendar
      freq_sam : str
          Sample frequency
      region: str
          Region, for example, "cn", "us"
      Returns
      -------
      np.ndarray
          The calendar with frequency freq_sam
      """
      if region is None:
          region = C["region"]
  
      freq_raw = Freq(freq_raw)
      freq_sam = Freq(freq_sam)
      if not len(calendar_raw):
          return calendar_raw
  
      # if freq_sam is xminute, divide each trading day into several bars evenly
      if freq_sam.base == Freq.NORM_FREQ_MINUTE:
          if freq_raw.base != Freq.NORM_FREQ_MINUTE:
              raise ValueError(
                  "when sampling minute calendar, freq of raw calendar must be minute or min"
              )
          else:
              if freq_raw.count > freq_sam.count:
                  raise ValueError(
                      "raw freq must be higher than sampling freq"
                  )
          _calendar_minute = np.unique(
              list(
                  map(
                      lambda x: cal_sam_minute(
                          x, freq_sam.count, region
                      ),
                      calendar_raw,
                  )
              )
          )
          return _calendar_minute
  
      # else, convert the raw calendar into day calendar, and divide the whole calendar into several bars evenly
      else:
          _calendar_day = np.unique(
              list(
                  map(
                      lambda x: pd.Timestamp(
                          x.year, x.month, x.day, 0, 0, 0
                      ),
                      calendar_raw,
                  )
              )
          )
          if freq_sam.base == Freq.NORM_FREQ_DAY:
              return _calendar_day[:: freq_sam.count]
  
          elif freq_sam.base == Freq.NORM_FREQ_WEEK:
              _day_in_week = np.array(
                  list(map(lambda x: x.dayofweek, _calendar_day))
              )
              _calendar_week = _calendar_day[
                  np.ediff1d(_day_in_week, to_begin=-1) < 0
              ]
              return _calendar_week[:: freq_sam.count]
  
          elif freq_sam.base == Freq.NORM_FREQ_MONTH:
              _day_in_month = np.array(
                  list(map(lambda x: x.day, _calendar_day))
              )
              _calendar_month = _calendar_day[
                  np.ediff1d(_day_in_month, to_begin=-1) < 0
              ]
              return _calendar_month[:: freq_sam.count]
          else:
              raise ValueError("sampling freq must be xmin, xd, xw, xm")
  
file_path: qlib/qlib/utils/resam.py
imports: import numpy
  import pandas
  from functools import partial
  from typing import Union, Callable
  from .None import lazy_sort_index
  from .time import Freq, cal_sam_minute
  from ..config import C
label_desc: Use image node_id 1 for calling a global function with example usage: resam_calendar(calendar_raw, freq_raw, freq_sam, region) and returns: calendar_raw, _calendar_minute, _calendar_day, _calendar_week, _calendar_month