Closed dcslagel closed 4 years ago
@JustinGOSSES,
Commits ccbb41e updates this branch to have 3 examples for reading from Lasio generated LAS/JSON to Wellio.js/Wellioviz.js. I included a markdown version of the ipynb file. It is helpful set 'display the rich diff' setting in-order to read the markdown file easily.
After generating a LAS structure in Lasio, output the structure to a LAS 2.0 file with the following code example, then one of the subsequent 3 methods can be used in Jupyter to successfully read the structure into wellio.js format.
Create LAS structure, and set LAS version to 2.0 by writing out 'scratch_v2.las'
# python
las = lasio.LASFile()
las.well.DATE = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
las.params['ENG'] = lasio.HeaderItem('ENG', value='Kent Inverarity')
las.params['LMF'] = lasio.HeaderItem('LMF', value='GL')
las.other = 'Example of how to create a LAS file from scratch using lasio'
depths = np.arange(10, 50, 0.5)
synth = np.log10(depths)*5+np.random.random(len(depths))
synth[:8] = np.nan
las.add_curve('DEPT', depths, unit='m')
las.add_curve('SYNTH', synth, descr='fake data')
# Write internal structure to a LAS file
las.write('scratch_v2.las', version=2)
# Create an in-memory lasio-json structure
json_images = json.dumps(las, cls=lasio.JSONEncoder)
Lasio LAS access/translation methods
// node
let lasio_obj = '';
let wellio_obj = '';
try {
lasio_obj = JSON.parse(json_images);
wellio_obj = wellio.lasio_obj_2_wellio_obj(lasio_obj);
} catch (e) {
console.log('[');
console.log(e.name + ":: " + e.message);
console.log(']');
}
console.log(wellio_obj);
# python
las_json_dict =json.loads(json_images)
with open('data.json', 'w') as outfile:
json.dump(las_json_dict, outfile)
// node
const path = require('path');
let mydir = process.env.PWD;
let myfile = mydir + path.sep + 'data.json';
let lasio_json_str = '';
let lasio_obj_2 = '';
let wellio_obj_2 = '';
try {
lasio_json_str = wellio.read_lasio_json_file(myfile);
lasio_obj_2 = JSON.parse(lasio_json_str);
wellio_obj_2 = wellio.lasio_obj_2_wellio_obj(lasio_obj_2);
} catch (e) {
console.log('[');
console.log(e.name + ":: " + e.message);
console.log(']');
}
console.log(wellio_obj_2);
// node
const path = require('path');
let mydir_3 = process.env.PWD;
let myfile_3 = mydir + path.sep + 'scratch_v2.las';
let las_str_3 = '';
let wellio_obj_3 = '';
try {
las_str_3 = wellio.loadLAS(myfile_3);
wellio_obj_3 = wellio.las2json(las_str_3);
} catch (e) {
console.log('[');
console.log(e.name + ":: " + e.message);
console.log(']');
}
console.log(wellio_obj_3);
Summary These have been tested on a local jupiter instance. They don't require any changes to Wellio.js to work. So for issue #40, this would resolve the issue just by implementing one of these methods in Jupyter notebooks. Could you check these methods work for you. If they do should we close issue 40 ? (We could merge this branch in-order to have these examples available and documented).
Thank you,
DC
Closing this draft and will post a cleanup review/merge request.
DC
This is a draft discussion branch to clarify how we should handle reading files in the different environments: Node.js command line, Jupyter notebook, Angular bundle. This draft branch is related to issue #40.
This iteration is a rough-draft that enables the demonstration Jupyter notebook to read lasio-json using the current wellio.read_lasio_json_file() implementation.
There are 2 main changes:
This rough-draft identifies the full path to the data.json file to be read. This is needed because the notebook's node.js sees the node.js-install-dir as the current working directory instead of the directory where the Jupyter is started. This draft uses the process.env.PWD to find the directory the the data.json file is actually in. I think this is a sensible solution for the Jupyter notebooks. Search for the line
lasio_json_str = wellio.read_lasio_json_file(myfile);\n",
to get to the significant code changes in the notebook. This solution also needs to be checked to see if it will work on Observable.The other problem is related to the data.json file being illegal JSON because it includes 'NaN' instead of 'null'. The JSON specifications require 'null' and node.js's JSON.parse throws and error on 'NaN'. So I have uploaded a legal version of data.json to enable this demo to work.
The latest on the Lasio master branch translates 'NaN' to 'null' when writing to json files. However, it only does this in the ASCII data section so far.
This draft will probably not work for Angular bundles or other web frontends as node.fs. We will need a test environment to workout that solution.
Thanks, DC