MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Designing a Flexible Mathematica Program for Data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74705] RE: [mg74690] Designing a Flexible Mathematica Program for Data
  • From: "David Annetts" <davidannetts at aapt.net.au>
  • Date: Sun, 1 Apr 2007 04:17:42 -0400 (EDT)
  • References: <200703310637.BAA05737@smc.vnet.net>

Hi,

> I'm using Mathematica to perform data analysis for a project 
> I've been working on for a few years. I have written quite a 
> bit of Mathematica code for automating the task of analyzing the data.
> As time goes by, the type of data I collect changes slightly. 
> I'm looking for a way for the various data set types I have 
> to happily coexist within a single Mathematica session so I 
> can compare and contrast all the data with a minimum of fuss.
> 
> Let's say I want to create a plot of dataset 1 and dataset 2. 
> In both cases, I want the same thing, a plot of parameter a 
> versus parameter b. And let's say I have a bunch of code 
> already written and it works just fine for dataset 1. But, 
> dataset 2 is newer, and the data format is slightly 
> different. The parameters a and b mean the same thing in both 
> cases, it's just that they are represented differently in dataset
> 2 than in dataset 1.
> 
> And let's say I have the following functions:
> readDataset: opens the text file and puts dataset into memory
> generateAandB: based on the data in the dataset, creates a 
> list of parameters a and b for a dataset
> plotAandB: creates a plot of a vs b.
> 
> In this case, I probably need two versions of readDataset and 
> generateAandB, one for each of my dataset types. If I am 
> using a List[], I am probably ok with one plotAandB function.

You might need to write two (or more) functions, but by using options, you
can access them using the same interface.  For example

	ReadMyData[#, DataType->1]& /@ listOfType1Files 
	ReadMyData[#, DataType->2]& /@ listOfType2Files

Instead of

	ReadMyType1Data[#]& /@ listOfType1Files 
	ReadMyType2Data[#]& /@ listOfType2Files 

The key here is not that you don't have to write code to handle the
different formats.  You do.  However, you can separate the individual bits
of code into different routines and as a result, end up with something much
much easier to maintain than some 1000+ line monolithic routine.

> But how can I automate this solution? What if I want to read 
> in 30 datasets with 10 different dataset types?

See above.  Options.
 
> I can't do plotAandB[generateAandB[readDataset[#]]]& /@ 
> listOfDatasets, because I need 10 different generateAandBs 
> and 10 different readDatasets.

Using options as above, you can easily write

	type1s = FileNames[... Type 1];
	type2s = FileNames[... Type 2];
	type3s = FileNames[... Type 3]; etc

	allData = {type1s, type2s, type3s, ...};

	Do[
 		plotAandB[generateAandB[readDataset[#], DataType->jt]]& /@
allData,
		{jt, Max@yourDataTypes}
		];

If you end up plotting the same two parameters from your different data
types, then have the code that reads the data files return numbers in the
same format irrespective of the format would simplify things considerably.
Are you sure this can't be done?  Without any more details, I suspect that
it can be since you want to plot the same two data-derived parameters from
different data sets.

Regards,

Dave.


  • Prev by Date: verification
  • Next by Date: Re: Integrate (a curious result)
  • Previous by thread: Re: verification
  • Next by thread: Re: Integrate (a curious result)