Xu Zhijian commited on
Commit
8d0ef11
·
1 Parent(s): fe063cd

update: new scripts

Browse files
Files changed (2) hide show
  1. scripts/embed.py +0 -55
  2. scripts/embed_static.py +1 -20
scripts/embed.py CHANGED
@@ -141,58 +141,6 @@ def merge_borough_embeddings():
141
  joblib.dump(merged_embeddings, final_output_path)
142
  print(f"Saved final merged embeddings to {final_output_path}")
143
 
144
- def process_static_data(model):
145
- """
146
- Processes the static info JSON file to generate and save embeddings.
147
- """
148
- print("\n--- Starting processing of static info data ---")
149
- static_info_path = os.path.join(DATA_DIR, "expanded_impute_data", "id_info_imputed.json")
150
-
151
- if not os.path.exists(static_info_path):
152
- print(f"Static info source file not found at {static_info_path}. Skipping.")
153
- return
154
-
155
- with open(static_info_path, "r") as f:
156
- id_info = json.load(f)
157
-
158
- # 1. Create a dictionary for the text information
159
- static_info_text = {}
160
- static_info_text['general_info'] = 'This dataset contains Average Speed of a Vehicle Traveled Between End Points data in km/h collected from various locations in New York City by sensors. The sampling rate is every 5 minutes. When no car is detected in the period, the speed is set to 0.'
161
- static_info_text['downtime_prompt'] = "The sensor is down for unknown reasons, readings set to 0. "
162
- static_info_text['channel_info'] = {
163
- ch: f"Sensor {ch} is located at {info['borough']}, with segment of {info['link']}."
164
- for ch, info in id_info.items()
165
- }
166
- # Save the text version
167
- text_output_path = os.path.join(DATA_DIR, 'weather', "static_info.json")
168
- with open(text_output_path, 'w') as f:
169
- json.dump(static_info_text, f, indent=2)
170
- print(f"Saved static info text to {text_output_path}")
171
-
172
- # 2. Collect all texts for embedding
173
- channels = list(static_info_text['channel_info'].keys())
174
- texts_to_embed = (
175
- [static_info_text['general_info'], static_info_text['downtime_prompt']] +
176
- [static_info_text['channel_info'][ch] for ch in channels]
177
- )
178
-
179
- print(f"Embedding {len(texts_to_embed)} static text entries...")
180
- embeddings = model.encode(texts_to_embed, truncate_dim=TRUNCATE_DIM)
181
-
182
- # 3. Create a new dictionary to store the embeddings
183
- static_info_embeddings = {}
184
- static_info_embeddings['general_info'] = embeddings[0:1, :]
185
- static_info_embeddings['downtime_prompt'] = embeddings[1:2, :]
186
- static_info_embeddings['channel_info'] = {
187
- ch: embeddings[i+2:i+3, :]
188
- for i, ch in enumerate(channels)
189
- }
190
-
191
- # 4. Save the dictionary containing the embeddings
192
- output_path = os.path.join(DATA_DIR, 'weather', "static_info_embeddings.pkl")
193
- joblib.dump(static_info_embeddings, output_path)
194
- print(f"Saved static info embeddings to {output_path}")
195
-
196
  def main():
197
  """
198
  Main execution function
@@ -206,9 +154,6 @@ def main():
206
  # 2. Merge the embeddings from all cities
207
  merge_borough_embeddings()
208
 
209
- # 3. Process the static information
210
- process_static_data(model)
211
-
212
  print("\nAll processing complete.")
213
 
214
  if __name__ == "__main__":
 
141
  joblib.dump(merged_embeddings, final_output_path)
142
  print(f"Saved final merged embeddings to {final_output_path}")
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  def main():
145
  """
146
  Main execution function
 
154
  # 2. Merge the embeddings from all cities
155
  merge_borough_embeddings()
156
 
 
 
 
157
  print("\nAll processing complete.")
158
 
159
  if __name__ == "__main__":
scripts/embed_static.py CHANGED
@@ -20,26 +20,7 @@ def create_static_embeddings(
20
  input_path (str): Path to the input static_info.json file.
21
  output_path (str): Path to save the output .pkl file with embeddings.
22
  """
23
- # --- 1. Sanity Checks ---
24
- if not os.path.exists(input_path):
25
- print(f"Error: Input file not found at '{input_path}'")
26
- # Create a dummy file for demonstration if it doesn't exist
27
- print("Creating a dummy 'static_info.json' for demonstration purposes.")
28
- dummy_data = {
29
- "general_info": "This dataset contains the solar power generation data of 16 solar panels in Calgary, Alberta, Canada. The data is collected hourly. ",
30
- "downtime_prompt": "The system is shutdown, thus no power generation.",
31
- "channel_info": {
32
- "CFH_HQ": "The solar panel is located at Calgary Fire Hall Headquarters.",
33
- "WMSC": "The solar panel is located at Whitehorn Multi-Service Centre.",
34
- "SLC": "The solar panel is located at Southland Leisure Centre."
35
- }
36
- }
37
- os.makedirs(os.path.dirname(input_path), exist_ok=True)
38
- with open(input_path, 'w') as f:
39
- json.dump(dummy_data, f, indent=2)
40
- print(f"Dummy file created at '{input_path}'. Please run the script again.")
41
- return
42
-
43
  # --- 2. Initialize Model ---
44
  print("Initializing embedding model...")
45
  # Set up device (use GPU if available)
 
20
  input_path (str): Path to the input static_info.json file.
21
  output_path (str): Path to save the output .pkl file with embeddings.
22
  """
23
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # --- 2. Initialize Model ---
25
  print("Initializing embedding model...")
26
  # Set up device (use GPU if available)