harbor run -t openthoughts/tasktrove-exp-rpt-issue-issue-4402harbor download openthoughts/tasktrove-exp-rpt-issue-issue-4402SELF-CONTAINED TASK INSTRUCTION: NcML-like processor for variable rename and attribute injection (no patch revealed)
Overview You will implement a tiny NcML-like processor in a self-contained fixture. The goal is to transform a local NetCDF file by renaming a variable (from orgName to name) and injecting or updating a simple attribute on the renamed variable, driven by a small NcML-like file. The workflow should feel like a minimal Terminal-Bench style fixture and remain self-contained (no remote dependencies beyond standard Python and netCDF4 tooling).
What you need to implement
Files to create/modify in /app/
Before state (provided as code blocks) Note: The following code blocks represent the initial, baseline, or “before” state you will replace/extend. Do not copy these as final behavior; they illustrate the current starting point for the task.
# app/ncml_apply.py - before
#!/usr/bin/env python3
import sys
from netCDF4 import Dataset
def main(input_nc, mod_ncml, output_nc):
# Very naive: just copy input to output, ignore mod_ncml
src = Dataset(input_nc, 'r')
dst = Dataset(output_nc, 'w', format=src.file_format)
# Copy dimensions
for name, dim in src.dimensions.items():
try:
dst_dim_len = len(dim)
except TypeError:
dst_dim_len = None
if dst_dim_len is None:
dst.createDimension(name, None)
else:
dst.createDimension(name, dst_dim_len)
# Copy variables and data
for name, var in src.variables.items():
v = dst.createVariable(name, var.dtype, var.dimensions)
v[:] = var[:]
for attr_key, attr_val in var.attrs.items():
v.setncattr(attr_key, attr_val)
# Copy global attributes
for attr in src.ncattrs():
setattr(dst, attr, getattr(src, attr))
src.close()
dst.close()
if __name__ == '__main__':
if len(sys.argv) != 4:
print("Usage: ncml_apply.py input.nc mod.ncml output.nc")
sys.exit(1)
main(sys.argv[1], sys.argv[2], sys.argv[3])
<!-- app/mod.ncml - before -->
<ncml>
<!-- Placeholder: future processor will rename variables and set attributes -->
</ncml>
# app/input_generator.py - helper to create input.nc
#!/usr/bin/env python3
import numpy as np
from netCDF4 import Dataset
def main(out_nc='input.nc'):
ds = Dataset(out_nc, 'w', format='NETCDF4')
ds.title = 'Benchmark input NetCDF'
ds.createDimension('time', 3)
temper = ds.createVariable('temperature', 'f4', ('time',))
temper[:] = np.array([280, 281, 279], dtype='float32')
ds.close()
if __name__ == '__main__':
import sys
out = sys.argv[1] if len(sys.argv) > 1 else 'input.nc'
main(out)
What to implement (described behavior, not the patch)
Implement ncml_apply.py so that it:
The workflow should behave as follows:
Provide a minimal, robust approach that does not require non-standard libraries beyond Python 3 and netCDF4.
Produce a log file benchmark.log capturing timings and any warnings.
Provide a one-line verification command using ncdump that demonstrates the expected result, for example:
ncdump -h output.nc | grep -A1 "temp" | grep -q "units = 'K'" && echo OK
Notes for implementation
How to run (instructions you can include in your patch/text file)
What to deliver
Important constraints
One-line verification (example) ncdump -h output.nc | grep -A1 "temp" | grep -q "units = 'K'" && echo OK
You may include any small, minimal helper code you need as part of the /app/ workspace to complete the task. The key deliverable is a working ncml_apply.py that performs the described transformation driven by mod.ncml.