1+ import numpy as np
12import pandas as pd
23import os
34import yaml
45from qa4sm_preprocessing .level2 .smos import SMOSL2Reader
56from smos .misc import read_summary_yml , get_first_last_day_images
67from datetime import datetime
78
8-
9- def swath2ts (img_path , ts_path , startdate = None , enddate = None , memory = 4 ):
9+ _default_variables = (
10+ "Soil_Moisture" ,
11+ "Science_Flags" ,
12+ "Confidence_Flags" ,
13+ "Chi_2_P" ,
14+ "RFI_Prob" ,
15+ "N_RFI_X" ,
16+ "N_RFI_Y" ,
17+ "M_AVA0" ,
18+ )
19+
20+ def swath2ts (img_path , ts_path , variables = _default_variables ,
21+ startdate = None , enddate = None , memory = 4 ):
1022 """
1123 Convert SMOS L2 swath data to time series in IndexedRaggedTs format.
1224
@@ -17,6 +29,19 @@ def swath2ts(img_path, ts_path, startdate=None, enddate=None, memory=4):
1729 swath data are found.
1830 ts_path: str
1931 Local directory where the converted time series data will be stored.
32+ variables: tuple or str, optional (default: None)
33+ List of variables to include, None will use the default variables
34+ "Soil_Moisture",
35+ "Soil_Moisture_DQX",
36+ "Science_Flags",
37+ "Confidence_Flags",
38+ "Processing_Flags",
39+ "Chi_2_P",
40+ "RFI_Prob",
41+ "N_RFI_X",
42+ "N_RFI_Y",
43+ "M_AVA0",
44+ "acquisition_time"
2045 startdate: str or datetime, optional (default: None)
2146 First day of the available swath data that should be included in the
2247 time series. If None is passed, then the first available day is used.
@@ -27,7 +52,13 @@ def swath2ts(img_path, ts_path, startdate=None, enddate=None, memory=4):
2752 Size of available memory in GB. More memory will lead to a faster
2853 conversion.
2954 """
30- reader = SMOSL2Reader (img_path )
55+ variables = [v for v in np .atleast_1d (variables )]
56+
57+ if "acquisition_time" not in variables :
58+ variables .append ("acquisition_time" )
59+
60+ reader = SMOSL2Reader (img_path , varnames = variables ,
61+ add_overpass_flag = True )
3162
3263 first_day , last_day = get_first_last_day_images (img_path )
3364
@@ -123,3 +154,9 @@ def extend_ts(img_path, ts_path, memory=4):
123154 else :
124155 print (f"No extension required From: { startdate } To: { last_day } " )
125156
157+ if __name__ == '__main__' :
158+ ts_path = '/tmp/ts'
159+ img_path = "/home/wpreimes/shares/climers/Projects/QA4SM_HR/07_data/SERVICE_DATA/SMOS_L2/SMOSL2_v700-ext/images"
160+ # swath2ts(img_path,
161+ # ts_path=ts_path, startdate='2024-03-01', enddate='2024-03-05')
162+ extend_ts (img_path , ts_path )
0 commit comments