From f7036a29b79296d1b34ee0f1e57644391ccbb762 Mon Sep 17 00:00:00 2001 From: Beforerr <58776897+Beforerr@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:43:26 +0800 Subject: [PATCH] debug: update yearlyname Previous code miss the first file --- pyspedas/utilities/dailynames.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/pyspedas/utilities/dailynames.py b/pyspedas/utilities/dailynames.py index b4d5d69f..03393e51 100644 --- a/pyspedas/utilities/dailynames.py +++ b/pyspedas/utilities/dailynames.py @@ -109,8 +109,6 @@ def yearlynames( directory: str String containing the directory for the generated file names. - - prefix: str file name prefix. @@ -138,23 +136,21 @@ def yearlynames( dates = [] if resolution == "half-year": - # Generate all the January 1st and July 1st dates within the range - potential_dates = [ - datetime(year, month, 1) - for year in range(start_date.year, end_date.year + 1) - for month in [1, 7] - ] + # Adjust the start date to be 6 months prior to the specified start date + if start_date.month <= 6: + adjusted_start_date = datetime(start_date.year - 1, start_date.month + 6, 1) + else: + adjusted_start_date = datetime(start_date.year, start_date.month - 6, 1) + + print(adjusted_start_date) + # Generate all the January 1st and July 1st dates within the range + potential_dates = [datetime(year, month, 1) for year in range(start_date.year, end_date.year + 1) for month in [1, 7]] + # Filter out dates outside the range - dates = [date for date in potential_dates if start_date <= date <= end_date] + dates = [date for date in potential_dates if adjusted_start_date < date <= end_date] elif resolution == "year": - # Generate all the January 1st dates within the range - potential_dates = [ - datetime(year, 1, 1) for year in range(start_date.year, end_date.year + 1) - ] - - # Filter out dates outside the range - dates = [date for date in potential_dates if start_date <= date <= end_date] + dates = [datetime(year, 1, 1) for year in range(start_date.year, end_date.year + 1)] else: raise ValueError("Invalid resolution specified. Choose 'year' or 'half-year'.")