pvyas96 commited on
Commit
1d3e733
·
verified ·
1 Parent(s): 5358675

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -15,6 +15,7 @@ import lasio
15
  import os
16
  from typing import Optional, Tuple, Dict, Any, List
17
  import datetime
 
18
 
19
  # ------------------------------------
20
  # CONFIGURATION & CONSTANTS
@@ -85,21 +86,31 @@ class DataManager:
85
  Converts DataFrame back to LAS format bytes for download.
86
  If original_las is provided, it preserves headers.
87
  """
 
 
88
  if original_las:
89
- las = original_las
90
- # Update data in LAS object
91
- # Note: setting data in lasio can be tricky if shapes change
92
- # We will construct a new LAS based on the old one's header to be safe
93
- new_las = lasio.LASFile()
94
- new_las.header = las.header
 
 
 
 
 
 
 
 
95
  else:
96
- new_las = lasio.LASFile()
97
  new_las.well.DATE = str(datetime.datetime.now())
98
 
99
- # Add curves
100
  for col in df.columns:
101
- # Check if curve exists to update, or add new
102
  unit = "UNKNOWN"
 
103
  if original_las:
104
  for curve in original_las.curves:
105
  if curve.mnemonic == col:
 
15
  import os
16
  from typing import Optional, Tuple, Dict, Any, List
17
  import datetime
18
+ import copy
19
 
20
  # ------------------------------------
21
  # CONFIGURATION & CONSTANTS
 
86
  Converts DataFrame back to LAS format bytes for download.
87
  If original_las is provided, it preserves headers.
88
  """
89
+ new_las = lasio.LASFile()
90
+
91
  if original_las:
92
+ # FIX: Do not assign .header directly (read-only property).
93
+ # Instead, copy sections item by item.
94
+
95
+ # Copy WELL information (Metadata)
96
+ for item in original_las.well:
97
+ # We use deepcopy to ensure we don't link to the session state object
98
+ new_las.well[item.mnemonic] = copy.deepcopy(item)
99
+
100
+ # Copy PARAMETER information
101
+ for item in original_las.params:
102
+ new_las.params[item.mnemonic] = copy.deepcopy(item)
103
+
104
+ # Copy Other info (often just text)
105
+ new_las.other = original_las.other
106
  else:
107
+ # Set default date if no original file
108
  new_las.well.DATE = str(datetime.datetime.now())
109
 
110
+ # Add curves from the DataFrame
111
  for col in df.columns:
 
112
  unit = "UNKNOWN"
113
+ # Try to preserve units from original LAS if available
114
  if original_las:
115
  for curve in original_las.curves:
116
  if curve.mnemonic == col: