NREL / htem-api-examples

Examples of usage of the HTEM DB API
http://htem.nrel.gov
Other
7 stars 5 forks source link

Rewrite jupyter_parse_api.py to be object oriented #1

Closed somerandomsequence closed 6 years ago

somerandomsequence commented 6 years ago

I think the API helper code will be better organized in an object oriented manner. Let's start with these classes:

And this initial specification:

In addition, let's put these definitions in two files, 'library.py' and 'sample.py' in the 'lib' directory.

meschw04 commented 6 years ago

Made the "lib" directory with files "library.py" and "sample.py". These are coming along pretty well so far, some library.py has a general structure while sample.py is nearly finished. You're right, the class structure is far more convenient. Let me know what you think of the "sample.py" file so I can apply the same concepts to the "library.py" file. Thanks!

somerandomsequence commented 6 years ago

This looks like a great start. I made one issue related to method variable names. In general, let's try to follow the PEP 8 style guidelines:

https://www.python.org/dev/peps/pep-0008/

You may want to try out IntelliJ Idea, an IDE that I've been using. Among other things, with the python module installed, it will highlight areas of code that deviate from PEP8, which is handy.

https://www.jetbrains.com/idea/specials/idea/idea.html

meschw04 commented 6 years ago

Hi Caleb, There are currently functions within "library.py" called "search_by_ids" and "search_by_composition". You state that these are static functions that list "Sample objects". I'm a bit confused. Do you want these functions to look at positions that match certain constraints? Or do you want the functions to look at all samples that match these constraints? What exactly do you want the outputs of these functions to be? Thanks, Marcus

somerandomsequence commented 6 years ago

These functions are static because they don't use the state of the library object. I'm imagining they would return a list of Library objects that match the search criteria. For instance, I could do:

for lib in Library.search_by_composition(["Zn","Ni"]):
  prop = lib.properties()
  print "Library %d" % (lib.id,)
  for t in prop["thickness"]:
    print t

This would find all libraries having Zn or Ni and then print out the unique ID for each library and all the measured thickness values (44 per library).

Does that make sense?

meschw04 commented 6 years ago

Pretty sure I got it right this time. It's being used pretty effectively in the notebooks now, let me know if you think a change is necessary.