I tried to use flopy, so I could try running some optimization procedures with python and modflow. Modflow requires a number of data to work with and we provide that info using different files.
We provide the input and flopy runs modflow
My trouble is that, flopy seems to disregard the input files and gives the same result, no matter what input I give.
Here's the code:
nper = 10
class BASreader:
def __init__(self):
self.ibound = None
self.head = None
with open("inps/bas/ibound", "r") as f:
data = f.read().replace("-", " -").split()
data = [int(x) for x in data]
data = np.array(data).reshape(1, 71, 24)
self.ibound = data
with open("inps/bas/head", "r") as f:
data = f.read().split()
data = [float(x) for x in data]
self.head = np.array(data).reshape(1, 71, 24)
class Modflow:
def __init__(self):
self.modelname = 'outs/gen1'
self.mf = flopy.modflow.Modflow(self.modelname, exe_name=r'G:\Program Files (x86)\Visual MODFLOW\mf2005.exe')
dis = flopy.modflow.ModflowDis.load("inps/yo.dis", self.mf)
basreader = BASreader()
bas = flopy.modflow.ModflowBas(self.mf, ibound=basreader.ibound, strt=basreader.head)
self.prev_headdata = basreader.head
wel = flopy.modflow.ModflowWel(self.mf, stress_period_data=WellProvider(nper).wells)
fname = 'inps/yo.evt'
fhandle = open(fname, 'r')
packages = []
ext_unit_dict = {22: flopy.utils.mfreadnam.NamData('EVT', fname, fhandle, packages)}
evt = flopy.modflow.ModflowEvt.load(fhandle, self.mf, ext_unit_dict=ext_unit_dict)
fhandle.close()
rech = {}
for x in range(nper):
rech[x] = 1.44e-5
rch = flopy.modflow.ModflowRch(self.mf, rech=rech)
stress_period_data = {}
for kper in range(nper):
for kstp in range(int(nper/10)):
stress_period_data[(kper, kstp)] = ['save head',
'save drawdown',
'save budget',
'print head',
'print drawdown',
'print budget']
oc = flopy.modflow.ModflowOc(self.mf, stress_period_data=stress_period_data, compact=True)
chd = flopy.modflow.ModflowChd.load("inps/yo.chd", self.mf)
lpf = flopy.modflow.ModflowLpf(self.mf, hk=14.44, vka=14.44, ipakcb=53, sy=0.22)
self.mf.write_input()
def run(self):
success, buff = self.mf.run_model(silent=True)
headobj = bf.HeadFile(self.modelname + '.hds')
newheaddata = headobj.get_alldata()[-1][0]
return newheaddata
mdflw = Modflow()
mdflw.run()
Now, even if I change the EVT, RCH or WEL info, the results are same.
I even tried to not include the above files, still the results were same.
Any pointers?
This revision of your script results in different head results (since different groundwater recharge values are used). I used the bcf2ss MODFLOW-2005 input files as base files in the revised example.
Not entirely sure why your script wasn't working since your input files weren't available.
import os
import numpy as np
import flopy
class BASreader:
def __init__(self):
self.ibound = None
self.head = None
with open("inps/bas/ibound", "r") as f:
data = f.read().replace("-", " -").split()
data = [int(x) for x in data]
data = np.array(data).reshape(2, 10, 15)
self.ibound = data
with open("inps/bas/head", "r") as f:
data = f.read().split()
data = [float(x) for x in data]
self.head = np.array(data).reshape(2, 10, 15)
class Modflow:
def __init__(self, ws='outs', rech_val=.0040, wel_data=None):
self.model_ws = ws
self.modelname = 'gen1'
self.mf = flopy.modflow.Modflow(self.modelname, exe_name='mf2005',
model_ws=self.model_ws)
dis = flopy.modflow.ModflowDis.load("inps/yo.dis", self.mf, check=False)
nper = dis.nper
nstp = dis.nstp.array
basreader = BASreader()
bas = flopy.modflow.ModflowBas(self.mf, ibound=basreader.ibound,
strt=basreader.head)
self.prev_headdata = basreader.head
bcf = flopy.modflow.ModflowBcf.load("inps/yo.bc6", self.mf)
if wel_data is None:
wel_data = [[1, 2, 3, -35000.],
[1, 7, 3, -35000.]]
wel_spd = {1: wel_data}
wel = flopy.modflow.ModflowWel(self.mf,
stress_period_data=wel_spd)
riv = flopy.modflow.ModflowRiv.load('inps/yo.riv', self.mf, check=False)
rech = {}
for x in range(nper):
rech[x] = rech_val
rch = flopy.modflow.ModflowRch(self.mf, rech=rech)
pcg = flopy.modflow.ModflowPcg.load('inps/yo.pcg', self.mf)
stress_period_data = {}
for kper in range(nper):
for kstp in range(nstp[kper]):
stress_period_data[(kper, kstp)] = ['save head',
'save drawdown',
'save budget',
'print head',
'print drawdown',
'print budget']
oc = flopy.modflow.ModflowOc(self.mf,
stress_period_data=stress_period_data,
compact=True)
self.mf.write_input()
def run(self):
success, buff = self.mf.run_model(silent=True)
fpth = os.path.join(self.model_ws, self.modelname + '.hds')
headobj = flopy.utils.HeadFile(fpth)
newheaddata = headobj.get_data(idx=1)
return newheaddata
if __name__ == "__main__":
m1 = Modflow()
h1 = m1.run()
m2 = Modflow(rech_val=.0041)
h2 = m2.run()
assert np.array_equal(h1, h2), 'h1 does not equal h2'
Related
I couldn't dump the json dict completly
I just could dump the json dict last page. Help me,please.
the coding showed below:
def job_list(url):
htmlFile = requests.get(url)
objSoup = bs4.BeautifulSoup(htmlFile.text,'lxml')
jobs = objSoup.find_all('article',class_='js-job-item')
job_list = []
for job in jobs:
cust_name = job.get('data-cust-name')
print("公司名稱:",cust_name)
job_name = job.get('data-job-name')
print("職稱名稱:",job_name)
d = [('公司名稱',cust_name),('職務名稱', job_name)]
j_dict = dict(d)
job_list.append(j_dict)
url_H = 'https://www.104.com.tw/jobs/search/?ro=0&kwop=7&keyword=藥師&order=1&asc=0&page='
url_T = '&mode=s&jobsource=2021indexpoc'
page_total = 2
for page in range(page_total):
url = url_H+str(page+1)+url_T
job_list(url)
print('-'*70)
time.sleep(random.randint(3,5))
myjob = {'Job':job_list}
fn = '104爬蟲.json'
with open(fn, "w") as fnObj:
json.dump(myjob,fnObj,indent=2,ensure_ascii=False)
Try this code
jobs_to_dump = [] #### added
def job_list(url):
htmlFile = requests.get(url)
objSoup = bs4.BeautifulSoup(htmlFile.text, 'lxml')
jobs = objSoup.find_all('article', class_='js-job-item')
job_list = []
for job in jobs:
cust_name = job.get('data-cust-name')
print("公司名稱:", cust_name)
job_name = job.get('data-job-name')
print("職稱名稱:", job_name)
d = [('公司名稱', cust_name), ('職務名稱', job_name)]
j_dict = dict(d)
jobs_to_dump.append(j_dict) ###modified
url_H = 'https://www.104.com.tw/jobs/search/?ro=0&kwop=7&keyword=藥師&order=1&asc=0&page='
url_T = '&mode=s&jobsource=2021indexpoc'
page_total = 2
for page in range(page_total):
url = url_H + str(page + 1) + url_T
job_list(url)
print('-' * 70)
time.sleep(random.randint(3, 5))
myjob = {'Job': jobs_to_dump} #### modified
fn = '104爬蟲.json'
with open(fn, "w") as fnObj:
json.dump(myjob, fnObj, indent=2, ensure_ascii=False)
I use python to write the program to control the motor, and the error is shown as follows after running:"message": "No value for argument 'speed_a' in function call pylint(no-value-for-parameter)[93,21]' Below is the code I am using:
import serial
import time
#import threading
import struct
from binascii import unhexlify
from crcmod import mkCrcFun
import binascii
import crcmod
def check_code(byte0, byte1, speed_vel, speed_ang):
'计算校验码时需要输入的字节'
read = byte0+byte1+speed_vel+speed_ang #解析校验码要输入的前几位
read=(str(binascii.b2a_hex(read))[2:-1])
print (read)
return (read)
def crc16_modbus(read):
'输出的控制电机指令字节码'
crc16 =crcmod.mkCrcFun(0x18005,rev=True,initCrc=0xFFFF,xorOut=0x0000)
data = read.replace(" ","")
#print (data)
readcrcout=hex(crc16(unhexlify(data))).upper()
str_list = list(readcrcout)
if len(str_list) < 6:
str_list.insert(2, '0'*(6-len(str_list))) # 位数不足补0
crc_data = "".join(str_list)
#print(crc_data)
read = read.strip()+crc_data[4:]+crc_data[2:4]
read = read.encode('UTF-8')
return read
def motor_speed_vel(speed_v,speed_a):
'计算小车线速度speed_v'
DEC1 = speed_v
DEC2 = speed_a
byte2 =(struct.pack("i",DEC1)[-4:-3])#线速度
byte3 =(struct.pack("i",DEC1)[-3:-2])#线速度
speed_vel = byte2 + byte3
byte4 = (struct.pack("i",DEC2)[-4:-3]) #角速度两个字节
byte5 = (struct.pack("i",DEC2)[-3:-2])
speed_ang = byte4+byte5
print (speed_vel,speed_ang)
return (speed_vel,speed_ang)
motor_speed_vel(200,20)
'''
def motor_speed_ang(speed_a):
'角速度的speed_a的byte码'
DEC2 = speed_a
byte4 = (struct.pack("i",DEC2)[-4:-3]) #角速度两个字节
byte5 = (struct.pack("i",DEC2)[-3:-2])
speed_ang = byte4+byte5
print (speed_ang)
return (speed_ang)
motor_speed_ang(20)
#motor_speed_cal(200,20) #设定的 (线速度,角速度)
'''
motor_speed_mode = b'\x01\x2F\x60\x60\x00\x03\x00\x00\x00\x0D'
#motor_status = b'\x43\x50\x00\x51\x00\x68\x95'
motor_start = b'\x01\x44\x21\x00\x31\x00\x00\x01\x00\x01\x75\x34'
motor_stop = b'\x01\x44\x21\x00\x31\x00\x00\x00\x00\x00\xE5\x34' # AB轴失能
class SpeedMotor:
def __init__(self, device,speed_v,speed_a):
# 真实速度
self.rel_speed = 0
# 设置的速度
self.set_speed1 = speed_v
# 设置角速度
self.set_speed2 = speed_a
# 运行状态
self.run = False
# 故障状态
self.fault = None
# 电机电压
self.voltage = 0
# 电机电流
self.current = 0
# 设置串口通讯
self.serial = serial.Serial(device, 115200)
self.serial.timeout = 0
# 设置为速度模式
self.serial.write(motor_speed_mode)
time.sleep(0.1)
# 设置加减速度
# self.serial.write(b'\x0A\x14\x14\x32')
# time.sleep(0.1)
def motor_speed_set(self):
'速度设置'
byte0 = b'\x01'
byte1 = b'\xEA'
speed_vel = motor_speed_vel(self.set_speed1)
speed_ang = motor_speed_vel(self.set_speed2)
read = check_code(byte0, byte1, speed_vel, speed_ang)
speed_code = read
self.serial.write(speed_code)
def motor_start(self):
self.serial.write(motor_start)
self.run = True
def motor_stop(self):
self.run = False
self.serial.write(motor_stop)
m = SpeedMotor('COM5',200,20)
m.motor_start()
#for i in range(100):
# m.set_speed = i
time.sleep(15)
m.motor_stop()`
I don't know if it is because of the problem with my parameter call, or because of the structure of the code, and I am very uncertain about the correctness of the code structure, because I am a beginner.
I'm trying to add a scrollbar to my tkinter window which stays in place and scrolls through a frame. However, whenever I launch the application, the scrollbar is greyed out. Here is the relevant excerpt from my code:
self.bigFrame = ttk.Frame(self,width = 1080,height = 500)
self.hsb = tk.Scrollbar(self.bigFrame,orient = "horizontal")
self.hsb.pack(side = TOP, fill = X)
self.treeCanvas = tk.Canvas(self.bigFrame,width = 1080,height = 500,xscrollcommand = self.hsb.set)
self.treeFrame = tk.Frame(self.treeCanvas,width = 1080,height = 500)
self.treeCanvas.create_window((0,0),window=self.treeFrame,anchor = 'nw')
self.treeCanvas.config(scrollregion = self.treeCanvas.bbox("all"))
self.treeCanvas.pack(side = BOTTOM,fill = X)
self.treeFrame.pack(side = BOTTOM,fill = X)
self.hsb.config(command = self.treeCanvas.xview)
self.tree = ttk.Treeview(self.treeFrame,selectmode='browse',height = 100, columns = ('name','purchaseprice','previousprices','listingprice','buyingformat','postage','fees','potprofit','offers','viewcount','sold','offertaken','username','dispatch','delivered','returned','relist','feedback'))
self.tree.heading('#0',text = 'saleID',anchor = 'w')
self.tree.heading('name',text = "Item Name",anchor = 'w')
self.tree.heading('purchaseprice',text = "Purchase Price",anchor = 'w')
self.tree.heading('previousprices',text = "Previous Prices",anchor = 'w')
self.tree.heading('listingprice',text = "Listing Price", anchor = 'w')
self.tree.heading('buyingformat',text = "Buying Format",anchor = 'w')
self.tree.heading('postage',text = "Postage",anchor = 'w')
self.tree.heading('fees',text = "Fees",anchor = 'w')
self.tree.heading('potprofit',text = "Potential Profit",anchor = 'w')
self.tree.heading('offers',text = "Best Offer",anchor = 'w')
self.tree.heading('viewcount',text = "Viewcount",anchor = 'w')
self.tree.heading('sold',text = "Sold?",anchor = 'w')
self.tree.heading('offertaken',text = "Offer Taken?",anchor = 'w')
self.tree.heading('username',text = "Username",anchor = 'w')
self.tree.heading('dispatch',text = "Dispatched?",anchor = 'w')
self.tree.heading('delivered',text = "Delivered?",anchor = 'w')
self.tree.heading('returned',text = "Returned?",anchor = 'w')
self.tree.heading('relist',text = "Relisted?",anchor = 'w')
self.tree.heading('feedback',text = "Feedback",anchor = 'w')
self.tree.pack(side = BOTTOM, fill = X)
self.bigFrame.grid(row = 11,column = 0,columnspan = 100,pady=(5,0),sticky = 'nw')
self.bigFrame.grid_rowconfigure(0,weight = 1)
self.bigFrame.grid_columnconfigure(0,weight = 1)
self.bigFrame.grid_propagate(False)
I'm sure it's an issue with the ordering of lines, but none of the orders I've tried have worked.
The reason your scrollbar is greyed out is because you are missing this line:
self.treeFrame.update_idletasks()
Below implemented in the rest of your code.
...
self.treeCanvas.create_window((0,0),window=self.treeFrame,anchor = 'nw')
# add this
self.treeFrame.update_idletasks()
bbox = self.treeCanvas.bbox(tk.ALL)
# Update this
self.treeCanvas.config(scrollregion=bbox, width=DISPLAY_WIDTH, height=DISPLAY_HEIGHT)
self.treeCanvas.pack(side = BOTTOM,fill = X)
self.treeFrame.pack(side = BOTTOM,fill = X)
...
Hopefully this answer helps, if not you could try the last answer from this question, which helped me alot.
i first use PyQT4 .
i'm create a QTableWidget to show runing message...
when my program run, it ill crash Within ten minutes.
i try diable my TableUpdate function , and it's don't crash again.
there is my code please help me
class table_work(QThread):
TableDataSignal = pyqtSignal()
def __init__(self,main_self):
# QThread.__init__(self)
super(table_work, self).__init__(main_self)
self.main_self = main_self
self.table_update_list = list()
#pyqtSlot(dict)
def update_table_thread_o(self,work):
try:
row_pos = work['row_position']
data = work['data']
table_key_sort = work['key_sort']
this_table = work['table']
k = 0
for table_key in table_key_sort:
this_table.setItem(row_pos, k, QTableWidgetItem(unicode(data[table_key])))
k += 1
del work
except:
pass
def update_table_thread(self):
main_self = self.main_self
table_work_list = self.table_update_list
while 1:
for work in self.table_update_list:
row_pos = work['row_position']
data = work['data']
table_key_sort = work['key_sort']
this_table = work['table']
k = 0
for table_key in table_key_sort:
this_table.setItem(row_pos, k, QTableWidgetItem(unicode(data[table_key])))
k += 1
time.sleep(0.5)
def run(self):
self.update_table_thread()
this's update table message
def update_table(self,address,change_obj=None,tabe_name='auto_card'):
sample_dict = dict()
table_key_sort = list()
now_table_sort = 0
if tabe_name == "auto_bot":
this_table = self.auto_bot_procc_table
table_data_list = self.auto_bot_procc_table_list
now_table_sort = self.auto_bot_now_table_sort
sample_dict['address'] = address
sample_dict['money'] = 0
sample_dict['run_time'] = 0
sample_dict['item_cd'] = u"60分鐘後"
sample_dict['stat'] = "Ready..."
sample_dict['sort'] = now_table_sort
table_key_sort.append('address')
table_key_sort.append('money')
table_key_sort.append('run_time')
table_key_sort.append('item_cd')
table_key_sort.append('stat')
if tabe_name == "auto_card":
this_table = self.process_table
table_data_list = self.now_procc_table_list
now_table_sort = self.now_table_sort
sample_dict['address'] = address
sample_dict['done_num'] = 0
sample_dict['pre_item'] = ""
sample_dict['procc'] = "Ready"
sample_dict['mission_procc'] = u"待命.."
sample_dict['mission_num'] = 0
sample_dict['mission_line'] = 0
sample_dict['update_time'] = db.get_time()
sample_dict['sort'] = now_table_sort
sample_dict['option'] = ""
table_key_sort.append('address')
table_key_sort.append('done_num')
table_key_sort.append('pre_item')
table_key_sort.append('mission_procc')
table_key_sort.append('procc')
table_key_sort.append('mission_num')
table_key_sort.append('mission_line')
table_key_sort.append('update_time')
if address not in table_data_list:
this_table.insertRow(sample_dict['sort'])
table_data_list[address] = sample_dict
sample_dict['sort'] = self.auto_bot_now_table_sort
self.auto_bot_now_table_sort += 1
acc_data = table_data_list[address]
if change_obj != None:
key = change_obj['key']
val = change_obj['val']
if key in acc_data:
acc_data[key] = val
acc_data['update_time'] = db.get_time()
rowPosition = acc_data['sort']
temp = dict()
temp['row_position'] = rowPosition
temp['data'] = acc_data
temp['key_sort'] = table_key_sort
temp['table'] = this_table
self.TableDataSignal.emit(temp)
del temp
Some time i get a ANS.
i'm a PYQT newbie , After this period of various projects experience.
I understand if you don't use Main Thread to Change UI, Always use sign/emit
even your code is worked,but always use sign/emit, Otherwise there will be a series of disasters.
you just like
class sample(QtCore.QThread):
table_data_change = QtCore.pyqtSignal(dict)
def __init__(self,main_win):
self.main = main_win
self.table_data_change.connect(self.main.change_fn)
def test(self):
data = dict()
data['btn'] = .....
data['val'] = .....
self.table_data_change.emit(data)
Save your time !
For the following program, I am trying to save time copying and pasting tons of code. I would like this program to plot using the data file 19_6.txt and aux.19_6, and then continue by plotting the files with 11,12,20,28,27, and 18 in 19's place with the same code and onto the same plot. Any help would be appreciated. Thanks!
from numpy import *
import matplotlib.pyplot as plt
datasim19 = loadtxt("/home/19_6.txt")
data19 = loadtxt("/home/aux.19_6")
no1=1
no2=2
no3=3
no4=4
no5=5
no7=7
no8=8
no9=9
no10=10
simrecno1inds19 = nonzero(datasim19[:,1]==no1)[0]
simrecno2inds19 = nonzero(datasim19[:,1]==no2)[0]
simrecno3inds19 = nonzero(datasim19[:,1]==no3)[0]
simrecno4inds19 = nonzero(datasim19[:,1]==no4)[0]
simrecno5inds19 = nonzero(datasim19[:,1]==no5)[0]
simrecno7inds19 = nonzero(datasim19[:,1]==no7)[0]
simrecno8inds19 = nonzero(datasim19[:,1]==no8)[0]
simrecno9inds19 = nonzero(datasim19[:,1]==no9)[0]
simrecno10inds19 = nonzero(datasim19[:,1]==no10)[0]
recno1inds19 = nonzero(data19[:,1]==no1)[0]
recno2inds19 = nonzero(data19[:,1]==no2)[0]
recno3inds19 = nonzero(data19[:,1]==no3)[0]
recno4inds19 = nonzero(data19[:,1]==no4)[0]
recno5inds19 = nonzero(data19[:,1]==no5)[0]
recno7inds19 = nonzero(data19[:,1]==no7)[0]
recno8inds19 = nonzero(data19[:,1]==no8)[0]
recno9inds19 = nonzero(data19[:,1]==no9)[0]
recno10inds19 = nonzero(data19[:,1]==no10)[0]
q1sim19 = qsim19[simrecno1inds19]
q2sim19 = qsim19[simrecno2inds19]
q3sim19 = qsim19[simrecno3inds19]
q4sim19 = qsim19[simrecno4inds19]
q5sim19 = qsim19[simrecno5inds19]
q7sim19 = qsim19[simrecno7inds19]
q8sim19 = qsim19[simrecno8inds19]
q9sim19 = qsim19[simrecno9inds19]
q10sim19 = qsim19[simrecno10inds19]
q1_19 = q19[recno1inds19]
q2_19 = q19[recno2inds19]
q3_19 = q19[recno3inds19]
q4_19 = q19[recno4inds19]
q5_19 = q19[recno5inds19]
q7_19 = q19[recno7inds19]
q8_19 = q19[recno8inds19]
q9_19 = q19[recno9inds19]
q10_19 = q19[recno10inds19]
sumq1sim19 = sum(q1sim19)
sumq2sim19 = sum(q2sim19)
sumq3sim19 = sum(q3sim19)
sumq4sim19 = sum(q4sim19)
sumq5sim19 = sum(q5sim19)
sumq7sim19 = sum(q7sim19)
sumq8sim19 = sum(q8sim19)
sumq9sim19 = sum(q9sim19)
sumq10sim19 = sum(q10sim19)
sumq1_19 = sum(q1_19)
sumq2_19 = sum(q2_19)
sumq3_19 = sum(q3_19)
sumq4_19 = sum(q4_19)
sumq5_19 = sum(q5_19)
sumq7_19 = sum(q7_19)
sumq8_19 = sum(q8_19)
sumq9_19 = sum(q9_19)
sumq10_19 = sum(q10_19)
xsim = [no1, no2, no3, no4, no5, no7, no8, no9, no10]
ysim = [sumq1sim_19, sumq2sim_19, sumq3sim_19, sumq4sim_19, sumq5sim_19, sumq7sim_19, sumq8sim_19, sumq9sim_19, sumq10sim_19]
x = [no1, no2, no3, no4, no5,no7, no8, no9, no10]
y = [sumq1_19, sumq2_19, sumq3_19, sumq4_19, sumq5_19, sumq7_19, sumq8_19, sumq9_19, sumq10_19]
plt.plot(x,log(y),'b',label='Data')
plt.plot(xsim,log(ysim),'r',label='Simulation')
plt.legend()
plt.title('Data vs. Simulation')
plt.show()
Tip: when you find yourself using lots of variables called n1, n2, n3 etc. you should probably use lists, dictionaries or other such containers, and loops instead.
For example, try replacing the following code:
simrecno1inds19 = nonzero(datasim19[:,1]==no1)[0]
simrecno2inds19 = nonzero(datasim19[:,1]==no2)[0]
simrecno3inds19 = nonzero(datasim19[:,1]==no3)[0]
simrecno4inds19 = nonzero(datasim19[:,1]==no4)[0]
simrecno5inds19 = nonzero(datasim19[:,1]==no5)[0]
simrecno7inds19 = nonzero(datasim19[:,1]==no7)[0]
simrecno8inds19 = nonzero(datasim19[:,1]==no8)[0]
simrecno9inds19 = nonzero(datasim19[:,1]==no9)[0]
simrecno10inds19 = nonzero(datasim19[:,1]==no10)[0]
With this:
simrecinds19 = [nonzero(datasim19[:,1] == i)[0] for i in range(1, 11)]
Then you can use simrecinds19[0] instead of simrecno1inds19.
You can do something like this:
nList = [19,11,12,20,28,27,18]
for n in nList:
file1 = "/home/" + str(n) + "_6.txt"
file2 = "/home/aux." + str(n) + "_6"
datasim19 = loadtxt(file1)
data19 = loadtxt(file2)
# do the rest of the plotting
You can greatly reduce the size of this script. I'm not quite sure where qsim19 and qsim come from, but take a look:
import numpy as np
import matplotlib.pyplot as plt
for index in [19, 11, 12, 20, 28, 27, 18]:
datasim = loadtxt("/home/%i_6.txt"%index)
data = loadtxt("/home/aux.%i_6"%index)
nos = range(1, 6) + range(7, 11)
simrecno = [np.nonzero(datasim[:,1] == n)[0] for n in nos]
recno = [np.nonzero(data[:,1] == n)[0] for n in nos]
qsim = [qsim[simrecno_i] for simrecno_i in simrecno]
q = [q[recno_i] for recno_i in recno]
sumqsim = [sum(qsim_i) for qsim_i in qsim]
sumq = [sum(q_i) for q_i in q]
xsim = nos
ysim = sumqsim
x = nos
y = sumq
plt.plot(x, log(y), 'b', label='Data')
plt.plot(xsim, log(ysim), 'r', label='Simulation')
plt.legend()
plt.title('Data vs. Simulation')
plt.show()